diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Makefile.build | 98 | ||||
-rw-r--r-- | scripts/Makefile.host | 2 | ||||
-rw-r--r-- | scripts/Makefile.lib | 71 |
3 files changed, 64 insertions, 107 deletions
diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 0232158570..00f627791a 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -49,15 +49,6 @@ ifneq ($(hostprogs)$(hostprogs-y)$(hostprogs-m),) include scripts/Makefile.host endif -ifdef building_out_of_srctree -# 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))) -endif - ifndef obj $(warning kbuild: Makefile.build is included improperly) endif @@ -69,12 +60,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 @@ -97,22 +88,6 @@ 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) @@ -143,24 +118,17 @@ cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $< quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< -quiet_cmd_pbl_cc_o_c = PBLCC $@ - cmd_pbl_cc_o_c = $(CC) -D__PBL__ $(c_flags) $(PBL_CPPFLAGS) -c -o $@ $< define rule_cc_o_c $(call cmd,checksrc) $(call cmd_and_fixdep,cc_o_c) endef -define rule_pbl_cc_o_c - $(call cmd,checksrc) - $(call cmd_and_fixdep,pbl_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) @@ -184,11 +152,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 $@ $< @@ -198,16 +161,14 @@ 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 += $(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) @@ -225,33 +186,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 @@ -304,10 +252,12 @@ intermediate_targets = $(foreach sfx, $(2), \ $(filter %$(strip $(1)), $(targets)))) # %.asn1.o <- %.asn1.[ch] <- %.asn1 # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts +# %.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.pbl.o, .dtb.S .dtb) \ $(call intermediate_targets, .lex.o, .lex.c) \ $(call intermediate_targets, .tab.o, .tab.c .tab.h) @@ -330,11 +280,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))) + +-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) -ifneq ($(cmd_files),) - include $(cmd_files) +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) diff --git a/scripts/Makefile.host b/scripts/Makefile.host index 55b565ce3f..038b3054ab 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -76,8 +76,6 @@ host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti)) host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs)) host-objdirs := $(addprefix $(obj)/,$(host-objdirs)) -obj-dirs += $(host-objdirs) - ##### # Handle options to gcc. Support building with separate output directory diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 39cc24b196..3799e777cd 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -20,19 +20,9 @@ obj-m := $(filter-out $(obj-y),$(obj-m)) lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) - -pbl-y += $(pbl-dtb-y) -obj-y += $(obj-dtb-y) -extra-y += $(patsubst %.dtb.o,%.dtb.S,$(obj-dtb-y)) -extra-y += $(patsubst %.dtb.o,%.dtb,$(obj-dtb-y)) -extra-y += $(patsubst %.dtb.o,%.dtb.S,$(pbl-dtb-y)) -extra-y += $(patsubst %.dtb.o,%.dtb,$(pbl-dtb-y)) -extra-y += $(patsubst %.dtb.o,%.dtb.S,$(lwl-dtb-y)) -extra-y += $(patsubst %.dtb.o,%.dtb,$(lwl-dtb-y)) - # Handle objects in subdirs # --------------------------------------------------------------------------- -# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o +# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a # and add the directory to the list of dirs to descend into: $(subdir-y) # o if we encounter foo/ in $(obj-m), remove it from $(obj-m) # and add the directory to the list of dirs to descend into: $(subdir-m) @@ -40,29 +30,29 @@ extra-y += $(patsubst %.dtb.o,%.dtb,$(lwl-dtb-y)) # lowlevel is present in the PBL if enabled # otherwise in barebox ifeq ($(CONFIG_PBL_IMAGE), y) -pbl-y += $(lwl-y) $(lwl-dtb-y) +pbl-y += $(lwl-y) else -obj-y += $(lwl-y) $(lwl-dtb-y) +obj-y += $(lwl-y) endif obj-y += $(obj-pbl-y) pbl-y += $(obj-pbl-y) -# add pbl- prefix to the target -pbl-y := $(shell echo $(pbl-y) | sed -e 's%\(\([^ \t]\+/\)*\)\([^ \t]*\.o\)%\2pbl-\3%g') +# pbl objects are suffixed with .pbl.o +pbl-y := $(patsubst %.o,%.pbl.o,$(pbl-y)) # add subdir from $(obj-y) too so we do not need to have the dir define in # both $(obj-y) and $(pbl-y) __pbl-y := $(filter-out $(pbl-y), $(filter %/, $(obj-y))) pbl-y += $(__pbl-y) -pbl-y := $(sort $(patsubst %/, %/built-in-pbl.o, $(pbl-y))) +pbl-y := $(sort $(patsubst %/, %/built-in.pbl.a, $(pbl-y))) __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) subdir-y += $(__subdir-y) __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) subdir-m += $(__subdir-m) -obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) +obj-y := $(patsubst %/, %/built-in.a, $(obj-y)) obj-m := $(filter-out %/, $(obj-m)) # Subdirectories we need to descend into @@ -83,16 +73,19 @@ multi-objs := $(multi-objs-y) $(multi-objs-m) # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to # tell kbuild to descend -__subdir-obj-y := $(filter %/built-in-pbl.o, $(pbl-y)) -subdir-obj-y := $(filter %/built-in.o, $(obj-y)) +__subdir-obj-y := $(filter %/built-in.pbl.a, $(pbl-y)) +subdir-obj-y := $(filter %/built-in.a, $(obj-y)) subdir-obj-y += $(__subdir-obj-y) -# $(obj-dirs) is a list of directories that contain object files -obj-dirs := $(dir $(multi-objs) $(obj-y) $(pbl-y)) +obj-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX).o,$(bbenv-y)) +extra-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX),$(bbenv-y)) +extra-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX).S,$(bbenv-y)) +extra-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX).o,$(bbenv-y)) -# Replace multi-part objects by their individual parts, look at local dir only -real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) -real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) +# Replace multi-part objects by their individual parts, +# including built-in.a from subdirectories +real-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) +real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)) $($(m:.o=-))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m))) always-y += $(always-m) @@ -106,16 +99,14 @@ obj-m := $(addprefix $(obj)/,$(obj-m)) lib-y := $(addprefix $(obj)/,$(lib-y)) pbl-y := $(addprefix $(obj)/,$(pbl-y)) subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y)) -real-objs-y := $(addprefix $(obj)/,$(real-objs-y)) -real-objs-m := $(addprefix $(obj)/,$(real-objs-m)) +real-obj-y := $(addprefix $(obj)/,$(real-obj-y)) +real-obj-m := $(addprefix $(obj)/,$(real-obj-m)) single-used-m := $(addprefix $(obj)/,$(single-used-m)) multi-used-y := $(addprefix $(obj)/,$(multi-used-y)) multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) -obj-dirs := $(addprefix $(obj)/,$(obj-dirs)) -bbenv-y := $(addprefix $(obj)/,$(bbenv-y)) # target with $(obj)/ and its suffix stripped target-stem = $(basename $(patsubst $(obj)/%,%,$@)) @@ -162,12 +153,27 @@ __a_flags = $(call flags,_a_flags) __cpp_flags = $(call flags,_cpp_flags) endif +part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y) +part-of-pbl = $(if $(filter $(basename $@).o, $(pbl-y))$(filter $@, $(pbl-target)),y) +quiet_modtag = $(if $(part-of-pbl),[P],$(if $(part-of-module),[M], )) + +pbl_cppflags = $(if $(part-of-pbl), -D__PBL__ $(PBL_CPPFLAGS)) + +modkern_cflags = \ + $(if $(part-of-module), \ + $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ + $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags)) + +modkern_aflags = $(if $(part-of-module), \ + $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \ + $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)) + c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \ - $(__c_flags) $(modkern_cflags) \ + $(__c_flags) $(modkern_cflags) $(pbl_cppflags) \ -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \ - $(__a_flags) $(modkern_aflags) + $(__a_flags) $(modkern_aflags) $(pbl_cppflags) cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags) @@ -309,11 +315,6 @@ $(obj)/%.dtb: $(src)/%.dts FORCE dtc-tmp = $(subst $(comma),_,$(dot-target).dts) -obj-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX).o,$(bbenv-y)) -extra-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX),$(bbenv-y)) -extra-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX).S,$(bbenv-y)) -extra-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX).o,$(bbenv-y)) - quiet_cmd_env_S = ENV.S $@ cmd_env_S = \ ( \ |