-$(obj)$(BOARD)-spl.bin: $(obj)u-boot-spl.bin
- $(OBJTREE)/tools/mk$(BOARD)spl \
- $(obj)u-boot-spl.bin $(obj)$(BOARD)-spl.bin
-endif
-
-$(obj)$(SPL_BIN).bin: $(obj)$(SPL_BIN)
- $(OBJCOPY) $(OBJCFLAGS) -O binary $< $@
-
-GEN_UBOOT = \
- cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) $(__START) \
- --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
- -Map $(SPL_BIN).map -o $(SPL_BIN)
-
-$(obj)$(SPL_BIN): depend $(START) $(LIBS) $(obj)u-boot-spl.lds
- $(GEN_UBOOT)
-
-# Tentative step for Kbuild-style makefiles coexist with conventional U-Boot style makefiles
-# U-Boot conventional sub makefiles always include some other makefiles.
-# So, the build system searches a line beginning with "include" before entering into the sub makefile
-# in order to distinguish which style it is.
-# If the Makefile include a "include" line, we assume it is an U-Boot style makefile.
-# Otherwise, it is treated as a Kbuild-style makefile.
-select_makefile = \
- if grep -q "^include" $1/Makefile; then \
- $(MAKE) -C $1; \
- else \
- $(MAKE) -C $1 -f $(TOPDIR)/scripts/Makefile.build; \
- mv $(dir $@)built-in.o $@; \
- fi
-
-# We do not need to build $(START) explicitly.
-# It is built while we are at $(CPUDIR)/lib$(CPU).o build.
-$(START): depend
- if grep -q "^include" $(SRCTREE)$(dir $(subst $(SPLTREE),,$@))Makefile; then \
- $(MAKE) -C $(SRCTREE)/$(START_PATH) $@; \
- fi
-
-$(LIBS): depend
- +$(call select_makefile, $(SRCTREE)$(dir $(subst $(SPLTREE),,$@)))
-
-$(obj)u-boot-spl.lds: $(LDSCRIPT) depend
- $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -I$(obj). -ansi -D__ASSEMBLY__ -P - < $< > $@
-
-depend: $(obj).depend
-.PHONY: depend
-
-# defines $(obj).depend target
-include $(SRCTREE)/rules.mk
+ifdef CONFIG_VAR_SIZE_SPL
+VAR_SIZE_PARAM = --vs
+else
+VAR_SIZE_PARAM =
+endif
+$(obj)/$(BOARD)-spl.bin: $(obj)/u-boot-spl.bin
+ $(if $(wildcard $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl),\
+ $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl,\
+ $(objtree)/tools/mkexynosspl) $(VAR_SIZE_PARAM) $< $@
+endif
+
+quiet_cmd_objcopy = OBJCOPY $@
+cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
+
+OBJCOPYFLAGS_$(SPL_BIN).bin = $(SPL_OBJCFLAGS) -O binary
+
+$(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN) FORCE
+ $(call if_changed,objcopy)
+
+LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL)
+ifneq ($(CONFIG_SPL_TEXT_BASE),)
+LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
+endif
+
+ifdef CONFIG_SUNXI
+quiet_cmd_mksunxiboot = MKSUNXI $@
+cmd_mksunxiboot = $(objtree)/tools/mksunxiboot $< $@
+$(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin
+ $(call if_changed,mksunxiboot)
+endif
+
+quiet_cmd_u-boot-spl = LD $@
+ cmd_u-boot-spl = cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \
+ $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \
+ $(patsubst $(obj)/%,%,$(u-boot-spl-main)) --end-group \
+ $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN)
+
+$(obj)/$(SPL_BIN): $(u-boot-spl-init) $(u-boot-spl-main) $(obj)/u-boot-spl.lds
+ $(call cmd,u-boot-spl)
+
+$(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ;
+
+PHONY += $(u-boot-spl-dirs)
+$(u-boot-spl-dirs):
+ $(Q)$(MAKE) $(build)=$@
+
+quiet_cmd_cpp_lds = LDS $@
+cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \
+ -D__ASSEMBLY__ -x assembler-with-cpp -P -o $@ $<
+
+$(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE
+ $(call if_changed_dep,cpp_lds)
+
+# read all saved command lines
+
+targets := $(wildcard $(sort $(targets)))
+cmd_files := $(wildcard $(obj)/.*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
+
+ifneq ($(cmd_files),)
+ $(cmd_files): ; # Do not try to update included dependency files
+ include $(cmd_files)
+endif
+
+PHONY += FORCE
+FORCE:
+
+# Declare the contents of the .PHONY variable as phony. We keep that
+# information in a variable so we can use it in if_changed and friends.
+.PHONY: $(PHONY)