From patchwork Sat Mar 27 10:09:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: various build system improvements Date: Sat, 27 Mar 2010 10:09:40 -0000 From: Patrick Georgi X-Patchwork-Id: 1165 Message-Id: <4BADD964.8060305@georgi-clan.de> To: coreboot@coreboot.org Hi, attached patch improves various aspects in the build system: make only needs to read Makefile.incs once, thanks to the SECONDEXPANSION feature of GNU make (and we rely on GNU make for lots of things already) File paths are relative to the root directory, which simplifies debugging (make V=1 gives shorter command lines) and helps ccache finding matches for checkouts in different directories (even though it should normalize paths itself) It's abuild tested. Signed-off-by: Patrick Georgi Acked-by: Ronald G. Minnich Index: src/cpu/x86/smm/Makefile.inc =================================================================== --- src/cpu/x86/smm/Makefile.inc (Revision 5303) +++ src/cpu/x86/smm/Makefile.inc (Arbeitskopie) @@ -25,9 +25,7 @@ smmobj-y += smihandler.o smmobj-y += smiutil.o -ifdef POST_EVALUATION - -$(obj)/cpu/x86/smm/smm.o: $(smmobjs) +$(obj)/cpu/x86/smm/smm.o: $$(smmobjs) $(CC) $(LDFLAGS) -nostdlib -r -o $@ $^ $(obj)/cpu/x86/smm/smm: $(obj)/cpu/x86/smm/smm.o $(src)/cpu/x86/smm/smm.ld $(obj)/ldoptions @@ -42,5 +40,3 @@ @printf " CC $(subst $(obj)/,,$(@))\n" $(CC) $(CFLAGS) -c -o $@ $< -endif - Index: src/arch/i386/Makefile.bootblock.inc =================================================================== --- src/arch/i386/Makefile.bootblock.inc (Revision 5303) +++ src/arch/i386/Makefile.bootblock.inc (Arbeitskopie) @@ -1,5 +1,3 @@ -ifdef POST_EVALUATION - ####################################################################### # Build the final rom image @@ -49,12 +47,12 @@ bootblock_romccflags := -mcpu=k7 -msse -O2 endif -$(obj)/bootblock/ldscript.ld: $(bootblock_ldscripts) $(obj)/ldoptions +$(obj)/bootblock/ldscript.ld: $$(bootblock_lds) $(obj)/ldoptions @printf " GEN $(subst $(obj)/,,$(@))\n" mkdir -p $(obj)/bootblock printf '$(foreach ldscript,ldoptions $(bootblock_lds),INCLUDE "$(ldscript)"\n)' > $@ -$(obj)/bootblock/bootblock.c: $(bootblock_inc) +$(obj)/bootblock/bootblock.c: $$(bootblock_inc) @printf " GEN $(subst $(obj)/,,$(@))\n" mkdir -p $(obj)/bootblock printf '$(foreach crt0,config.h $(bootblock_inc),#include "$(crt0)"\n)' > $@ @@ -80,7 +78,7 @@ ####################################################################### # Build the romstage -$(obj)/coreboot.romstage: $(obj)/coreboot.pre1 $(initobjs) $(obj)/romstage/ldscript.ld +$(obj)/coreboot.romstage: $(obj)/coreboot.pre1 $$(initobjs) $(obj)/romstage/ldscript.ld @printf " LINK $(subst $(obj)/,,$(@))\n" printf "CONFIG_ROMBASE = 0x0;\nAUTO_XIP_ROM_BASE = 0x0;\n" > $(obj)/location.ld $(CC) -nostdlib -nostartfiles -static -o $(obj)/romstage.elf -L$(obj) -T $(obj)/romstage/ldscript.ld $(initobjs) @@ -93,12 +91,12 @@ $(NM) -n $(obj)/romstage.elf | sort > $(obj)/romstage.map $(OBJCOPY) -O binary $(obj)/romstage.elf $@ -$(obj)/romstage/ldscript.ld: $(ldscripts) $(obj)/ldoptions +$(obj)/romstage/ldscript.ld: $$(ldscripts) $(obj)/ldoptions @printf " GEN $(subst $(obj)/,,$(@))\n" mkdir -p $(obj)/romstage printf '$(foreach ldscript,ldoptions location.ld $(ldscripts),INCLUDE "$(ldscript:$(obj)/%=%)"\n)' > $@ -$(obj)/romstage/crt0_includes.h: $(crt0s) +$(obj)/romstage/crt0_includes.h: $$(crt0s) @printf " GEN $(subst $(obj)/,,$(@))\n" mkdir -p $(obj)/romstage printf '$(foreach crt0,config.h $(crt0s),#include "$(crt0:$(obj)/%=%)"\n)' > $@ @@ -111,4 +109,3 @@ @printf " CC $(subst $(obj)/,,$(@))\n" $(CC) -x assembler-with-cpp -DASSEMBLY -E -I$(src)/include -I$(src)/arch/i386/include -I$(obj) -I$(obj)/romstage -include $(obj)/config.h -I. -I$(src) $< > $@.new && mv $@.new $@ -endif Index: src/arch/i386/Makefile.bigbootblock.inc =================================================================== --- src/arch/i386/Makefile.bigbootblock.inc (Revision 5303) +++ src/arch/i386/Makefile.bigbootblock.inc (Arbeitskopie) @@ -1,5 +1,3 @@ -ifdef POST_EVALUATION - ####################################################################### # Build the final rom image @@ -14,11 +12,11 @@ @printf " OBJCOPY $(subst $(obj)/,,$(@))\n" $(OBJCOPY) -O binary $< $@ -$(obj)/ldscript.ld: $(ldscripts) $(obj)/ldoptions +$(obj)/ldscript.ld: $$(ldscripts) $(obj)/ldoptions printf 'INCLUDE "ldoptions"\n' > $@ printf '$(foreach ldscript,$(ldscripts),INCLUDE "$(ldscript:$(obj)/%=%)"\n)' >> $@ -$(obj)/crt0_includes.h: $(crt0s) +$(obj)/crt0_includes.h: $$(crt0s) @printf " GEN $(subst $(obj)/,,$(@))\n" printf '$(foreach crt0,config.h $(crt0s),#include "$(crt0:$(obj)/%=%)"\n)' > $@ @@ -30,9 +28,8 @@ @printf " CC $(subst $(obj)/,,$(@))\n" $(CC) -MMD -x assembler-with-cpp -DASSEMBLY -E -I$(src)/include -I$(src)/arch/i386/include -I$(obj) -include $(obj)/config.h -I. -I$(src) $< > $@.new && mv $@.new $@ -$(obj)/coreboot: $(initobjs) $(obj)/ldscript.ld +$(obj)/coreboot: $$(initobjs) $(obj)/ldscript.ld @printf " LINK $(subst $(obj)/,,$(@))\n" $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(obj)/ldscript.ld $(initobjs) $(NM) -n $(obj)/coreboot | sort > $(obj)/coreboot.map -endif Index: src/arch/i386/Makefile.inc =================================================================== --- src/arch/i386/Makefile.inc (Revision 5303) +++ src/arch/i386/Makefile.inc (Arbeitskopie) @@ -7,8 +7,6 @@ obj-$(CONFIG_HAVE_OPTION_TABLE) += ../../option_table.o -ifdef POST_EVALUATION - ####################################################################### # Build the final rom image COREBOOT_ROM_DEPENDENCIES:= @@ -73,14 +71,14 @@ $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(src)/arch/i386/coreboot_ram.ld $(obj)/coreboot_ram.o $(NM) -n $(obj)/coreboot_ram | sort > $(obj)/coreboot_ram.map -$(obj)/coreboot_ram.o: $(obj)/arch/i386/lib/c_start.o $(drivers) $(obj)/coreboot.a $(LIBGCC_FILE_NAME) +$(obj)/coreboot_ram.o: $(obj)/arch/i386/lib/c_start.o $$(drivers) $(obj)/coreboot.a $(LIBGCC_FILE_NAME) @printf " CC $(subst $(obj)/,,$(@))\n" $(CC) -nostdlib -r -o $@ $(obj)/arch/i386/lib/c_start.o $(drivers) -Wl,--start-group $(obj)/coreboot.a $(LIBGCC_FILE_NAME) -Wl,--end-group -$(obj)/coreboot.a: $(objs) +$(obj)/coreboot.a: $$(objs) @printf " AR $(subst $(obj)/,,$(@))\n" rm -f $(obj)/coreboot.a - $(AR) cr $(obj)/coreboot.a $(objs) + $(AR) cr $(obj)/coreboot.a $^ ####################################################################### # done @@ -195,7 +193,7 @@ $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc: $(src)/mainboard/$(MAINBOARDDIR)/romstage.c $(obj)/romcc $(OPTION_TABLE_H) $(obj)/build.h printf " ROMCC romstage.inc\n" - $(ROMCC) -c -S $(ROMCCFLAGS) -include $(obj)/build.h -I. $(INCLUDES) $< -o $@ + $(ROMCC) -c -S $(ROMCCFLAGS) -I. $(INCLUDES) $< -o $@ else @@ -205,7 +203,7 @@ $(obj)/mainboard/$(MAINBOARDDIR)/romstage.pre.inc: $(src)/mainboard/$(MAINBOARDDIR)/romstage.c $(OPTION_TABLE_H) $(obj)/build.h printf " CC romstage.inc\n" - $(CC) -MMD $(CFLAGS) -include $(obj)/build.h -I$(src) -I. -c -S $< -o $@ + $(CC) -MMD $(CFLAGS) -I$(src) -I. -c -S $< -o $@ $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc: $(obj)/mainboard/$(MAINBOARDDIR)/romstage.pre.inc printf " POST romstage.inc\n" @@ -213,9 +211,6 @@ mv $@.tmp $@ endif -else -# Only in first pass - # Things that appear in every board initobjs += $(obj)/mainboard/$(MAINBOARDDIR)/crt0.o objs += $(obj)/mainboard/$(MAINBOARDDIR)/mainboard.o @@ -249,8 +244,6 @@ objs += $(obj)/mainboard/$(MAINBOARDDIR)/get_bus_conf.o endif -endif - ifeq ($(CONFIG_TINY_BOOTBLOCK),y) include $(src)/arch/i386/Makefile.bootblock.inc else Index: src/arch/i386/lib/Makefile.inc =================================================================== --- src/arch/i386/lib/Makefile.inc (Revision 5303) +++ src/arch/i386/lib/Makefile.inc (Arbeitskopie) @@ -8,8 +8,3 @@ initobj-y += printk_init.o initobj-y += cbfs_and_run.o - -ifdef POST_EVALUATION -$(obj)/arch/i386/lib/console.o :: $(obj)/build.h -endif - Index: util/abuild/abuild =================================================================== --- util/abuild/abuild (Revision 5303) +++ util/abuild/abuild (Arbeitskopie) @@ -18,7 +18,7 @@ ABUILD_VERSION="0.9" # Where shall we place all the build trees? -TARGET=$( pwd )/coreboot-builds +TARGET=coreboot-builds XMLFILE=$( pwd )/abuild.xml # path to payload. Should be more generic Index: util/cbfstool/Makefile.inc =================================================================== --- util/cbfstool/Makefile.inc (Revision 5303) +++ util/cbfstool/Makefile.inc (Arbeitskopie) @@ -1,6 +1,3 @@ - -ifdef POST_EVALUATION - cbfsobj := cbfsobj += common.o cbfsobj += compress.o @@ -53,5 +50,3 @@ printf " HOSTCXX $(subst $(obj)/,,$(@)) (link)\n" $(HOSTCXX) $(CBFSTOOLFLAGS) -o $@ $(addprefix $(obj)/util/cbfstool/,$(cbfsobj)) -endif - Index: Makefile =================================================================== --- Makefile (Revision 5303) +++ Makefile (Arbeitskopie) @@ -33,9 +33,9 @@ endif export top := $(PWD) -export src := $(top)/src +export src := src export srck := $(top)/util/kconfig -export obj ?= $(top)/build +export obj ?= build export objk := $(obj)/util/kconfig export sconfig := $(top)/util/sconfig export yapps2_py := $(sconfig)/yapps2.py @@ -136,9 +136,12 @@ chmod +x .ccwrap scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y else -all: $(obj)/config.h coreboot +all: $(obj)/config.h $(obj)/build.h coreboot endif +# must come rather early +.SECONDEXPANSION: + $(obj)/config.h: $(MAKE) oldconfig @@ -156,7 +159,7 @@ # Creation of these is architecture and mainboard independent $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(obj)/mainboard/$(MAINBOARDDIR)/config.py mkdir -p $(obj)/mainboard/$(MAINBOARDDIR) - (cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig export PYTHONPATH; python config.py $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR)) + (PYTHONPATH=$(top)/util/sconfig python $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR)) objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o initobjs:= @@ -173,12 +176,12 @@ $(foreach type,$(2), $(eval $(type)-y:=)) \ $(eval subdirs-y:=) \ $(eval -include $(1)) \ - $(if $(strip $(3)), \ - $(foreach type,$(2), \ - $(eval $(type)s+= \ - $$(abspath $$(patsubst src/%, \ - $(obj)/%, \ - $$(addprefix $(dir $(1)),$$($(type)-y))))))) \ + $(foreach type,$(2), \ + $(eval $(type)s+= \ + $$(subst $(top)/,, \ + $$(abspath $$(patsubst src/%, \ + $(obj)/%, \ + $$(addprefix $(dir $(1)),$$($(type)-y))))))) \ $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))) # For each path in $(subdirs) call includemakefiles, passing $(1) as $(3) @@ -187,12 +190,12 @@ $(eval cursubdirs:=$(subdirs)) \ $(eval subdirs:=) \ $(foreach dir,$(cursubdirs), \ - $(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types),$(1)))) \ - $(if $(subdirs),$(eval $(call evaluate_subdirs, $(1)))) + $(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types)))) \ + $(if $(subdirs),$(eval $(call evaluate_subdirs))) # collect all object files eligible for building subdirs:=$(PLATFORM-y) $(BUILD-y) -$(eval $(call evaluate_subdirs, modify)) +$(eval $(call evaluate_subdirs)) initobjs:=$(addsuffix .initobj.o, $(basename $(initobjs))) drivers:=$(addsuffix .driver.o, $(basename $(drivers))) @@ -203,17 +206,10 @@ source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs)) allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S)) -POST_EVALUATION:=y - -# fetch rules (protected in POST_EVALUATION) that rely on the variables filled above -subdirs:=$(PLATFORM-y) $(BUILD-y) -$(eval $(call evaluate_subdirs)) - - define objs_asl_template $(obj)/$(1)%.o: src/$(1)%.asl @printf " IASL $$(subst $(top)/,,$$(@))\n" - $(CPP) -D__ACPI__ -P -include $(obj)/config.h -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl + $(CPP) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl iasl -p $$(basename $$@) -tc $$(basename $$@).asl mv $$(basename $$@).hex $$(basename $$@).c $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $$@))), -DAmlCode=AmlCode_$$(basename $$(notdir $$@))) -c -o $$@ $$(basename $$@).c @@ -226,7 +222,7 @@ # $3 .o infix ("" ".initobj", ...) # $4 additional compiler flags de$(EMPTY)fine $(1)_$(2)_template -$(obj)/$$(1)%$(3).o: src/$$(1)%.$(2) $(obj)/config.h +$(obj)/$$(1)%$(3).o: src/$$(1)%.$(2) | $(obj)/build.h $(obj)/config.h printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n" $(CC) $(4) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$< en$(EMPTY)def @@ -270,9 +266,10 @@ @echo $(patsubst $(top)/%,%,$(crt0s)) OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y)) -INCLUDES := -I$(top)/src -I$(top)/src/include -I$(obj) -I$(top)/src/arch/$(ARCHDIR-y)/include -INCLUDES += -I$(top)/src/devices/oprom/include -INCLUDES += -include $(obj)/config.h +INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include +INCLUDES += -Isrc/devices/oprom/include +# abspath is a workaround for romcc +INCLUDES += -include $(abspath $(obj)/config.h) -include $(abspath $(obj)/build.h) CFLAGS = $(INCLUDES) -Os -nostdinc -pipe CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes @@ -298,7 +295,7 @@ mkdir -p $(obj)/util/kconfig/lxdialog $(obj)/util/cbfstool test -n "$(alldirs)" && mkdir -p $(alldirs) || true -$(obj)/build.h: .xcompile +$(obj)/build.h $(abspath $(obj)/build.h): .xcompile @printf " GEN build.h\n" rm -f $(obj)/build.h printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht