Mathias Krause (mathias.krause@secunet.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/746
-gerrit
commit baf1339a1334616c73cbbf9cd7743d54b4a86ff3 Author: Mathias Krause mathias.krause@secunet.com Date: Tue Mar 6 13:37:05 2012 +0100
makefile: build system cleanup
This patch cleans up the include hierarchies for the Makefile system to decrease the knowledge of the main Makefile about every subdirectory. This allows us to add new drivers without the need to patch the main Makefile but, instead, just add a line to the appropriate Makefile.inc.
Also all standard make variables are cleaned up (e.g. CFLAGS, CPPFLAGS,..). This, in turn, allows modifying them as needed in the included Makefile.inc to add flags or even library dependencies.
It's no Linux Kbuild yet, but we're close ;)
Change-Id: I67be4fcdd07d6960a7e46bfb6a3c0ea41f280e2b Signed-off-by: Mathias Krause mathias.krause@secunet.com --- Makefile | 63 +++++++++++++++++++++----------------------- drivers/Makefile.inc | 5 ++- drivers/flash/Makefile.inc | 1 - i386/Makefile.inc | 3 +- main/Makefile.inc | 5 ++- main/grub/Makefile.inc | 2 - 6 files changed, 38 insertions(+), 41 deletions(-)
diff --git a/Makefile b/Makefile index 46a265f..20b21bf 100644 --- a/Makefile +++ b/Makefile @@ -49,17 +49,27 @@ ifneq ($(Q),) endif endif
+try-run = $(shell set -e; \ + TMP=".$$$$.tmp"; \ + if ($(1)) > /dev/null 2>&1; \ + then echo "$(2)"; \ + else echo "$(3)"; \ + fi; \ + rm -rf "$$TMP") + +cc-option = $(call try-run,$(CC) $(1) -S -xc /dev/null -o "$$TMP",$(1),$(2)) + $(if $(wildcard .xcompile),,$(shell bash util/xcompile/xcompile > .xcompile)) include .xcompile
-CROSS_PREFIX = +CROSS_PREFIX ?= CC ?= $(CROSS_PREFIX)gcc -m32 AS ?= $(CROSS_PREFIX)as --32 LD ?= $(CROSS_PREFIX)ld -belf32-i386 -STRIP ?= $(CROSS_PREFIX)strip NM ?= $(CROSS_PREFIX)nm -HOSTCC = gcc -HOSTCXX = g++ +STRIP ?= $(CROSS_PREFIX)strip +HOSTCC ?= gcc +HOSTCXX ?= g++ HOSTCFLAGS := -I$(srck) -I$(objk) -pipe HOSTCXXFLAGS := -I$(srck) -I$(objk) -pipe
@@ -72,45 +82,32 @@ else
include $(src)/.config
-ARCHDIR-$(CONFIG_TARGET_I386) := i386 - -PLATFORM-y += $(ARCHDIR-y)/Makefile.inc -TARGETS-y := - -BUILD-y := main/Makefile.inc main/grub/Makefile.inc fs/Makefile.inc -BUILD-y += drivers/Makefile.inc -BUILD-y += drivers/flash/Makefile.inc - -include $(PLATFORM-y) $(BUILD-y) - LIBPAYLOAD_PREFIX ?= $(obj)/libpayload LIBPAYLOAD = $(LIBPAYLOAD_PREFIX)/lib/libpayload.a INCPAYLOAD = $(LIBPAYLOAD_PREFIX)/include LIBGCC = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) +GCCINCDIR = $(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
-OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y)) -INCLUDES := -I$(INCPAYLOAD) -I$(INCPAYLOAD)/$(ARCHDIR-y) -Iinclude -I$(ARCHDIR-y)/include -Ibuild -INCLUDES += -I$(GCCINCDIR) +ARCHDIR-$(CONFIG_TARGET_I386) := i386
-try-run= $(shell set -e; \ -TMP=".$$$$.tmp"; \ -if ($(1)) > /dev/null 2>&1; \ -then echo "$(2)"; \ -else echo "$(3)"; \ -fi; rm -rf "$$TMP") +CPPFLAGS := -nostdinc -imacros $(obj)/config.h +CPPFLAGS += -I$(INCPAYLOAD) -I$(INCPAYLOAD)/$(ARCHDIR-y) +CPPFLAGS += -I$(ARCHDIR-y)/include -Iinclude -I$(obj) +CPPFLAGS += -I$(GCCINCDIR)
-cc-option= $(call try-run,\ -$(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2)) +CFLAGS := -Wall -Wshadow -Os -pipe +CFLAGS += -fomit-frame-pointer -fno-common -ffreestanding -fno-strict-aliasing +CFLAGS += $(call cc-option, -fno-stack-protector,)
-STACKPROTECT += $(call cc-option, -fno-stack-protector,) +LIBS := $(LIBPAYLOAD) $(LIBGCC)
-GCCINCDIR = $(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include -CPPFLAGS = -nostdinc -imacros $(obj)/config.h -Iinclude -I$(GCCINCDIR) -MD -CFLAGS += $(STACKPROTECT) $(INCLUDES) -Wall -Os -fomit-frame-pointer -fno-common -ffreestanding -fno-strict-aliasing -Wshadow -pipe +SUBDIRS-y += main/ fs/ drivers/ +SUBDIRS-y += $(ARCHDIR-y)/
-TARGET = $(obj)/filo.elf +$(foreach subdir,$(SUBDIRS-y),$(eval include $(subdir)/Makefile.inc))
-HAVE_LIBCONFIG := $(wildcard $(LIBCONFIG_PATH)) +TARGET := $(obj)/filo.elf +OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
all: prepare $(TARGET) @@ -132,7 +129,7 @@ endif
$(obj)/filo: $(OBJS) $(LIBPAYLOAD) printf " LD $(subst $(shell pwd)/,,$(@))\n" - $(LD) -N -T $(ARCHDIR-y)/ldscript -o $@ $(OBJS) $(LIBPAYLOAD) $(LIBGCC) + $(LD) -N -T $(ARCHDIR-y)/ldscript $(OBJS) --start-group $(LIBS) --end-group -o $@
$(TARGET): $(obj)/filo $(obj)/filo.map printf " STRIP $(subst $(shell pwd)/,,$(@))\n" diff --git a/drivers/Makefile.inc b/drivers/Makefile.inc index 8f814e0..f93c287 100644 --- a/drivers/Makefile.inc +++ b/drivers/Makefile.inc @@ -16,9 +16,10 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
+include drivers/flash/Makefile.inc + TARGETS-$(CONFIG_IDE_DISK) += drivers/ide.o TARGETS-$(CONFIG_IDE_NEW_DISK) += drivers/ide_new.o TARGETS-$(CONFIG_VIA_SOUND) += drivers/via-sound.o TARGETS-$(CONFIG_USB_DISK) += drivers/usb.o -TARGETS-y += drivers/intel.o - +TARGETS-$(CONFIG_TARGET_I386) += drivers/intel.o diff --git a/drivers/flash/Makefile.inc b/drivers/flash/Makefile.inc index a862773..48bf1a1 100644 --- a/drivers/flash/Makefile.inc +++ b/drivers/flash/Makefile.inc @@ -17,4 +17,3 @@ #
TARGETS-$(CONFIG_FLASH_DISK) += drivers/flash/lxflash.o - diff --git a/i386/Makefile.inc b/i386/Makefile.inc index 8f1a305..ce3e5c8 100644 --- a/i386/Makefile.inc +++ b/i386/Makefile.inc @@ -16,7 +16,8 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
-TARGETS-y += i386/context.o i386/switch.S.o i386/segment.o i386/timer.o i386/sys_info.o +TARGETS-$(CONFIG_TARGET_I386) += i386/context.o i386/switch.S.o i386/segment.o +TARGETS-$(CONFIG_TARGET_I386) += i386/timer.o i386/sys_info.o TARGETS-$(CONFIG_LINUX_LOADER) += i386/linux_load.o TARGETS-$(CONFIG_WINCE_LOADER) += i386/wince_load.o TARGETS-$(CONFIG_ARTEC_BOOT) += i386/artecboot.o diff --git a/main/Makefile.inc b/main/Makefile.inc index e2fab04..fc7c851 100644 --- a/main/Makefile.inc +++ b/main/Makefile.inc @@ -16,8 +16,9 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
-TARGETS-$(CONFIG_MULTIBOOT_IMAGE) += main/mb_hdr.o +include main/grub/Makefile.inc + TARGETS-y += main/filo.o main/strtox.o TARGETS-y += main/elfload.o main/ipchecksum.o TARGETS-$(CONFIG_SUPPORT_SOUND) += main/sound.o - +TARGETS-$(CONFIG_MULTIBOOT_IMAGE) += main/mb_hdr.o diff --git a/main/grub/Makefile.inc b/main/grub/Makefile.inc index b79f08f..00273f3 100644 --- a/main/grub/Makefile.inc +++ b/main/grub/Makefile.inc @@ -16,9 +16,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
- TARGETS-$(CONFIG_USE_GRUB) += main/grub/grub.o main/grub/builtins.o TARGETS-$(CONFIG_USE_GRUB) += main/grub/cmdline.o main/grub/char_io.o TARGETS-$(CONFIG_USE_GRUB) += main/grub/completions.o TARGETS-$(CONFIG_USE_MD5_PASSWORDS) += main/grub/md5.o -