summaryrefslogtreecommitdiffstats
path: root/scripts/Makefile.build
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Makefile.build')
-rw-r--r--scripts/Makefile.build172
1 files changed, 45 insertions, 127 deletions
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index db687d5f9e..25347eee01 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -16,6 +16,8 @@ lib-y :=
lib-m :=
pbl-y :=
always :=
+always-y :=
+always-m :=
targets :=
subdir-y :=
subdir-m :=
@@ -43,17 +45,14 @@ include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-di
include scripts/Makefile.lib
# Do not include host rules unless needed
-ifneq ($(hostprogs-y)$(hostprogs-m),)
+ifneq ($(hostprogs),)
include scripts/Makefile.host
endif
-ifneq ($(KBUILD_SRC),)
-# Create output directory if not already present
-_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
-
-# Create directories for object files if directory does not exist
-# Needed when obj-y := dir/file.o syntax is used
-_dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
+# Do not include userprogs rules unless needed.
+userprogs := $(sort $(userprogs))
+ifneq ($(userprogs),)
+include scripts/Makefile.userprogs
endif
ifndef obj
@@ -67,12 +66,12 @@ lib-target := $(obj)/lib.a
endif
ifneq ($(strip $(obj-y) $(obj-m) $(obj-) $(lib-target) $(pbl-y)),)
-builtin-target := $(obj)/built-in.o
+builtin-target := $(obj)/built-in.a
endif
ifeq ($(CONFIG_PBL_IMAGE), y)
ifneq ($(strip $(pbl-y) $(builtin-target)),)
-pbl-target := $(obj)/built-in-pbl.o
+pbl-target := $(obj)/built-in.pbl.a
endif
endif
@@ -80,37 +79,21 @@ endif
__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(pbl-target) $(extra-y)) \
$(if $(KBUILD_MODULES),$(obj-m)) \
- $(subdir-ym) $(always)
+ $(subdir-ym) $(always-y)
@:
# Linus' kernel sanity checking tool
ifeq ($(KBUILD_CHECKSRC),1)
quiet_cmd_checksrc = CHECK $<
- cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
+ cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
else ifeq ($(KBUILD_CHECKSRC),2)
quiet_cmd_force_checksrc = CHECK $<
- cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
+ cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
endif
# Compile C sources (.c)
# ---------------------------------------------------------------------------
-# Default is built-in, unless we know otherwise
-modkern_cflags := $(CFLAGS_KERNEL)
-quiet_modtag := $(empty) $(empty)
-
-$(real-objs-m) : modkern_cflags := $(CFLAGS_MODULE)
-$(real-objs-m:.o=.i) : modkern_cflags := $(CFLAGS_MODULE)
-$(real-objs-m:.o=.s) : modkern_cflags := $(CFLAGS_MODULE)
-$(real-objs-m:.o=.lst): modkern_cflags := $(CFLAGS_MODULE)
-
-$(real-objs-m) : quiet_modtag := [M]
-$(real-objs-m:.o=.i) : quiet_modtag := [M]
-$(real-objs-m:.o=.s) : quiet_modtag := [M]
-$(real-objs-m:.o=.lst): quiet_modtag := [M]
-
-$(obj-m) : quiet_modtag := [M]
-
# Default for not multi-part modules
modname = $(basetarget)
@@ -135,80 +118,23 @@ cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
%.i: %.c FORCE
$(call if_changed_dep,cc_i_c)
-quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
-cmd_cc_symtypes_c = \
- $(CPP) -D__GENKSYMS__ $(c_flags) $< \
- | $(GENKSYMS) -T $@ >/dev/null; \
- test -s $@ || rm -f $@
-
-%.symtypes : %.c FORCE
- $(call if_changed_dep,cc_symtypes_c)
-
# C (.c) files
# The C file is compiled and updated dependency information is generated.
# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
-quiet_cmd_pbl_cc_o_c = PBLCC $@
-
-ifndef CONFIG_MODVERSIONS
-cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
-cmd_pbl_cc_o_c = $(CC) -D__PBL__ $(c_flags) $(PBL_CPPFLAGS) -c -o $@ $<
-
-else
-# When module versioning is enabled the following steps are executed:
-# o compile a .tmp_<file>.o from <file>.c
-# o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does
-# not export symbols, we just rename .tmp_<file>.o to <file>.o and
-# are done.
-# o otherwise, we calculate symbol versions using the good old
-# genksyms on the preprocessed source and postprocess them in a way
-# that they are usable as a linker script
-# o generate <file>.o from .tmp_<file>.o using the linker to
-# replace the unresolved symbols __crc_exported_symbol with
-# the actual value of the checksum generated by genksyms
-
-cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
-cmd_modversions = \
- if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
- $(CPP) -D__GENKSYMS__ $(c_flags) $< \
- | $(GENKSYMS) $(if $(KBUILD_SYMTYPES), \
- -T $(@D)/$(@F:.o=.symtypes)) -a $(ARCH) \
- > $(@D)/.tmp_$(@F:.o=.ver); \
- \
- $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
- -T $(@D)/.tmp_$(@F:.o=.ver); \
- rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
- else \
- mv -f $(@D)/.tmp_$(@F) $@; \
- fi;
-endif
+ cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
define rule_cc_o_c
- $(call echo-cmd,checksrc) $(cmd_checksrc) \
- $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \
- $(cmd_modversions) \
- scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \
- $(dot-target).tmp; \
- rm -f $(depfile); \
- mv -f $(dot-target).tmp $(dot-target).cmd
-endef
-
-define rule_pbl_cc_o_c
- $(call echo-cmd,checksrc) $(cmd_checksrc) \
- $(call echo-cmd,pbl_cc_o_c) $(cmd_pbl_cc_o_c); \
- $(cmd_modversions) \
- scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,pbl_cc_o_c)' > \
- $(dot-target).tmp; \
- rm -f $(depfile); \
- mv -f $(dot-target).tmp $(dot-target).cmd
+ $(call cmd,checksrc)
+ $(call cmd_and_fixdep,cc_o_c)
endef
# Built-in and composite module parts
-pbl-%.o: %.c FORCE
+%.pbl.o: %.c FORCE
$(call cmd,force_checksrc)
- $(call if_changed_rule,pbl_cc_o_c)
+ $(call if_changed_rule,cc_o_c)
%.o: %.c FORCE
$(call cmd,force_checksrc)
@@ -232,11 +158,6 @@ quiet_cmd_cc_lst_c = MKLST $@
# Compile assembler sources (.S)
# ---------------------------------------------------------------------------
-modkern_aflags := $(AFLAGS_KERNEL)
-
-$(real-objs-m) : modkern_aflags := $(AFLAGS_MODULE)
-$(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE)
-
quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
@@ -246,17 +167,15 @@ cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
quiet_cmd_as_o_S = AS $(quiet_modtag) $@
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
-quiet_cmd_pbl_as_o_S = PBLAS $@
-cmd_pbl_as_o_S = $(CC) -D__PBL__ $(a_flags) $(PBL_CPPFLAGS) -c -o $@ $<
-
-pbl-%.o: %.S FORCE
- $(call if_changed_dep,pbl_as_o_S)
+%.pbl.o: %.S FORCE
+ $(call if_changed_dep,as_o_S)
%.o: %.S FORCE
$(call if_changed_dep,as_o_S)
-targets += $(real-objs-y) $(real-objs-m) $(lib-y) $(pbl-y)
-targets += $(extra-y) $(MAKECMDGOALS) $(always)
+targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y)
+targets += $(pbl-y)
+targets += $(extra-y) $(always-y) $(MAKECMDGOALS)
# Linker scripts preprocessor (.lds.S -> .lds)
# ---------------------------------------------------------------------------
@@ -273,33 +192,20 @@ quiet_cmd_cpp_lds_S = LDS $@
$(sort $(subdir-obj-y)): $(subdir-ym) ;
#
-# Rule to compile a set of .o files into one .o file
+# Rule to compile a set of .o files into one .a file (without symbol table)
#
-ifdef builtin-target
-quiet_cmd_link_o_target = LD $@
-# If the list of objects to link is empty, just create an empty built-in.o
-cmd_link_o_target = $(if $(strip $(obj-y)),\
- $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\
- rm -f $@; $(AR) rcs $@)
+quiet_cmd_ar_builtin = AR $(quiet_modtag) $@
+ cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs)
-$(builtin-target): $(obj-y) FORCE
- $(call if_changed,link_o_target)
+$(builtin-target): $(real-obj-y) FORCE
+ $(call if_changed,ar_builtin)
targets += $(builtin-target)
-endif # builtin-target
-
-ifdef pbl-target
-quiet_cmd_pbl_link_o_target = PBLLD $@
-# If the list of objects to link is empty, just create an empty built-in-pbl.o
-cmd_pbl_link_o_target = $(if $(strip $(pbl-y)),\
- $(LD) $(ld_flags) -r -o $@ $(filter $(pbl-y), $^),\
- rm -f $@; $(AR) rcs $@)
$(pbl-target): $(pbl-y) FORCE
- $(call if_changed,pbl_link_o_target)
+ $(call if_changed,ar_builtin)
targets += $(pbl-target)
-endif # pbl-target
#
# Rule to compile a set of .o files into one .a file
@@ -352,10 +258,14 @@ intermediate_targets = $(foreach sfx, $(2), \
$(filter %$(strip $(1)), $(targets))))
# %.asn1.o <- %.asn1.[ch] <- %.asn1
# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
+# %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso
+# %.dtb.pbl.o <- %.dtb.S <- %.dtb <- %.dts (Barebox only)
# %.lex.o <- %.lex.c <- %.l
# %.tab.o <- %.tab.[ch] <- %.y
targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
- $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
+ $(call intermediate_targets, .dtb.o, .dtb.S .dtb.z .dtb) \
+ $(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo.z .dtbo) \
+ $(call intermediate_targets, .dtb.pbl.o, .dtb.S .dtb.z .dtb) \
$(call intermediate_targets, .lex.o, .lex.c) \
$(call intermediate_targets, .tab.o, .tab.c .tab.h)
@@ -378,11 +288,19 @@ FORCE:
# optimization, we don't need to read them if the target does not
# exist, we will rebuild anyway in that case.
-targets := $(wildcard $(sort $(targets)))
-cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
+existing-targets := $(wildcard $(sort $(targets)))
-ifneq ($(cmd_files),)
- include $(cmd_files)
+-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
+
+ifdef building_out_of_srctree
+# Create directories for object files if they do not exist
+obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
+# If targets exist, their directories apparently exist. Skip mkdir.
+existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
+obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
+ifneq ($(obj-dirs),)
+$(shell mkdir -p $(obj-dirs))
+endif
endif
.PHONY: $(PHONY)