2 ## This file is part of the coreboot project.
4 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
5 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
6 ## Copyright (C) 2009-2010 coresystems GmbH
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; version 2 of the License.
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program; if not, write to the Free Software
19 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
25 export top := $(shell pwd)
26 export src := $(top)/src
27 export srck := $(top)/util/kconfig
28 export obj ?= $(top)/build
29 export objk := $(obj)/util/kconfig
30 export sconfig := $(top)/util/sconfig
31 export yapps2_py := $(sconfig)/yapps2.py
32 export config_g := $(sconfig)/config.g
35 export KERNELVERSION := 2.3
36 export KCONFIG_AUTOHEADER := $(obj)/config.h
37 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
40 KBUILD_DEFCONFIG := configs/defconfig
41 UNAME_RELEASE := $(shell uname -r)
42 HAVE_DOTCONFIG := $(wildcard .config)
43 MAKEFLAGS += -rR --no-print-directory
45 # Make is silent per default, but 'make V=1' will show all compiler calls.
53 CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
56 HOSTCFLAGS := -I$(srck) -I$(objk) -g
57 HOSTCXXFLAGS := -I$(srck) -I$(objk)
58 LIBGCC_FILE_NAME := $(shell $(CC) -print-libgcc-file-name)
63 DOXYGEN_OUTPUT_DIR := doxygen
65 ifeq ($(strip $(HAVE_DOTCONFIG)),)
71 include $(top)/.config
73 ARCHDIR-$(CONFIG_ARCH_X86) := i386
74 ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
76 MAINBOARDDIR=$(shell echo $(CONFIG_MAINBOARD_DIR))
79 PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
82 BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers util/x86emu
83 BUILD-y += util/cbfstool
84 BUILD-$(CONFIG_ARCH_X86) += src/pc80
86 ifneq ($(CONFIG_LOCALVERSION),"")
87 COREBOOT_EXTRA_VERSION := -$(shell echo $(CONFIG_LOCALVERSION))
90 # The primary target needs to be here before we include the
96 #######################################################################
99 CBFSTOOL:=$(obj)/util/cbfstool/cbfstool
101 $(obj)/mainboard/$(MAINBOARDDIR)/config.py: $(yapps2_py) $(config_g)
102 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
103 python $(yapps2_py) $(config_g) $(obj)/mainboard/$(MAINBOARDDIR)/config.py
106 # needed objects that every mainboard uses
107 # Creation of these is architecture and mainboard independent
108 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(obj)/mainboard/$(MAINBOARDDIR)/config.py
109 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
110 (cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig export PYTHONPATH; python config.py $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR))
112 $(obj)/mainboard/$(MAINBOARDDIR)/static.o: $(obj)/mainboard/$(MAINBOARDDIR)/static.c
115 objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
121 types:=obj initobj driver smmobj
122 includemakefiles=$(foreach type,$(2), $(eval $(type)-y:=)) $(eval subdirs-y:=) $(eval include $(1)) $(if $(strip $(3)),$(foreach type,$(2),$(eval $(type)s+=$$(patsubst src/%,$(obj)/%,$$(addprefix $(dir $(1)),$$($(type)-y)))))) $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
123 evaluate_subdirs=$(eval cursubdirs:=$(subdirs)) $(eval subdirs:=) $(foreach dir,$(cursubdirs),$(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types),$(1)))) $(if $(subdirs),$(eval $(call evaluate_subdirs, $(1))))
125 # collect all object files eligible for building
126 subdirs:=$(PLATFORM-y) $(BUILD-y)
127 $(eval $(call evaluate_subdirs, modify))
129 allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
130 alldirs:=$(sort $(abspath $(dir $(allobjs))))
131 source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
132 allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
136 # fetch rules (protected in POST_EVALUATION) that rely on the variables filled above
137 subdirs:=$(PLATFORM-y) $(BUILD-y)
138 $(eval $(call evaluate_subdirs))
141 define c_dsl_template
142 $(obj)/$(1)%.c: src/$(1)%.dsl $(obj)/build.h
143 @printf " IASL $$(subst $$(shell pwd)/,,$$(@))\n"
144 iasl -p $$(basename $$@) -tc $$<
145 perl -pi -e 's/AmlCode/AmlCode_$$(notdir $$(basename $$@))/g' $$(basename $$@).hex
146 mv $$(basename $$@).hex $$@
149 define objs_c_template
150 $(obj)/$(1)%.o: src/$(1)%.c $(obj)/build.h
151 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
152 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
155 define objs_S_template
156 $(obj)/$(1)%.o: src/$(1)%.S $(obj)/build.h
157 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
158 $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
161 define initobjs_c_template
162 $(obj)/$(1)%.o: src/$(1)%.c $(obj)/build.h
163 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
164 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
167 define initobjs_S_template
168 $(obj)/$(1)%.o: src/$(1)%.S $(obj)/build.h
169 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
170 $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
173 define drivers_c_template
174 $(obj)/$(1)%.o: src/$(1)%.c $(obj)/build.h
175 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
176 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
179 define drivers_S_template
180 $(obj)/$(1)%.o: src/$(1)%.S
181 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
182 $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
185 define smmobjs_c_template
186 $(obj)/$(1)%.o: src/$(1)%.c
187 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
188 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
191 define smmobjs_S_template
192 $(obj)/$(1)%.o: src/$(1)%.S
193 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
194 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
197 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
198 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
199 $(eval $(call usetemplate,c,dsl))
200 $(eval $(call usetemplate,objs,c))
201 $(eval $(call usetemplate,objs,S))
202 $(eval $(call usetemplate,initobjs,c))
203 $(eval $(call usetemplate,initobjs,S))
204 $(eval $(call usetemplate,drivers,c))
205 $(eval $(call usetemplate,drivers,S))
206 $(eval $(call usetemplate,smmobjs,c))
207 $(eval $(call usetemplate,smmobjs,S))
211 @echo initobjs:=$(initobjs)
212 @echo drivers:=$(drivers)
213 @echo smmobjs:=$(smmobjs)
214 @echo alldirs:=$(alldirs)
215 @echo allsrc=$(allsrc)
217 OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
218 INCLUDES := -I$(top)/src -I$(top)/src/include -I$(obj) -I$(top)/src/arch/$(ARCHDIR-y)/include
219 INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
220 INCLUDES += -I$(top)/util/x86emu/include
221 INCLUDES += -include $(obj)/build.h
223 try-run= $(shell set -e; \
225 if ($(1)) > /dev/null 2>&1; \
230 cc-option= $(call try-run,\
231 $(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
233 STACKPROTECT += $(call cc-option, -fno-stack-protector,)
235 CFLAGS = $(STACKPROTECT) $(INCLUDES) -Os -nostdinc
236 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
237 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
238 CFLAGS += -Wstrict-aliasing -Wshadow
239 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
242 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
244 CBFS_COMPRESS_FLAG:=l
245 CBFS_PAYLOAD_COMPRESS_FLAG:=
246 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
247 CBFS_PAYLOAD_COMPRESS_FLAG:=l
250 coreboot: prepare prepare2 $(obj)/coreboot.rom
256 mkdir -p $(obj)/util/kconfig/lxdialog
257 test -n "$(alldirs)" && mkdir -p $(alldirs) || true
259 prepare2: $(obj)/build.h
262 @printf " GEN build.h\n"
264 printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" > $(obj)/build.ht
265 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
266 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
267 printf "\n" >> $(obj)/build.ht
268 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
269 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
270 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
271 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
272 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
273 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s)\"\n" >> $(obj)/build.ht
274 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname)\"\n" >> $(obj)/build.ht
275 printf "#include \"config.h\"\n" >> $(obj)/build.ht
276 mv $(obj)/build.ht $(obj)/build.h
282 doxyclean: doxygen-clean
284 rm -rf $(DOXYGEN_OUTPUT_DIR)
287 rm -f $(allobjs) $(obj)/coreboot* .xcompile
288 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
289 rm -f $(obj)/option_table.* $(obj)/crt0_includes.h $(obj)/ldscript
290 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
291 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/auto.inc $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
292 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
293 $(MAKE) -C util/sconfig clean
297 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
300 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
302 # This include must come _before_ the pattern rules below!
303 # Order _does_ matter for pattern rules.
304 include util/kconfig/Makefile
306 $(obj)/ldoptions: $(obj)/config.h
307 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
309 _OS=$(shell uname -s |cut -c-7)
311 ifeq ($(_OS),MINGW32)
312 STACK=-Wl,--stack,16384000
314 ifeq ($(_OS),CYGWIN_)
315 STACK=-Wl,--stack,16384000
317 $(obj)/romcc: $(top)/util/romcc/romcc.c
318 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
319 $(HOSTCC) -g -O2 $(STACK) -Wall -o $@ $<
321 .PHONY: $(PHONY) prepare prepare2 clean distclean doxygen doxy coreboot