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 ifeq ($(INNER_SCANBUILD),y)
26 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
29 ifeq ($(INNER_SCANBUILD),y)
31 HOSTCC:=$(CC_real) --hostcc
32 HOSTCXX:=$(CC_real) --hostcxx
36 export src := $(top)/src
37 export srck := $(top)/util/kconfig
38 export obj ?= $(top)/build
39 export objk := $(obj)/util/kconfig
40 export sconfig := $(top)/util/sconfig
41 export yapps2_py := $(sconfig)/yapps2.py
42 export config_g := $(sconfig)/config.g
45 export KERNELVERSION := 4.0
46 export KCONFIG_AUTOHEADER := $(obj)/config.h
47 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
50 KBUILD_DEFCONFIG := configs/defconfig
51 UNAME_RELEASE := $(shell uname -r)
52 HAVE_DOTCONFIG := $(wildcard .config)
53 MAKEFLAGS += -rR --no-print-directory
55 # Make is silent per default, but 'make V=1' will show all compiler calls.
63 CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
67 HOSTCFLAGS := -I$(srck) -I$(objk) -g
68 HOSTCXXFLAGS := -I$(srck) -I$(objk)
69 LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && $(CC) -print-libgcc-file-name)
72 DOXYGEN_OUTPUT_DIR := doxygen
74 ifeq ($(strip $(HAVE_DOTCONFIG)),)
80 include $(top)/.config
82 ifneq ($(INNER_SCANBUILD),y)
83 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
89 ifeq ($(CONFIG_CCACHE),y)
90 CCACHE:=CCACHE_COMPILERCHECK=content $(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH))))
92 $(error ccache selected, but not found in PATH)
95 HOSTCC := $(CCACHE) $(HOSTCC)
96 HOSTCXX := $(CCACHE) $(HOSTCXX)
97 ROMCC := $(CCACHE) $(ROMCC)
100 strip_quotes = $(subst ",,$(subst \",,$(1)))
102 ARCHDIR-$(CONFIG_ARCH_X86) := i386
103 ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
105 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
108 PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
111 BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers
112 BUILD-y += util/cbfstool
113 BUILD-$(CONFIG_ARCH_X86) += src/pc80
115 ifneq ($(CONFIG_LOCALVERSION),"")
116 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
119 # The primary target needs to be here before we include the
122 ifeq ($(INNER_SCANBUILD),y)
123 CONFIG_SCANBUILD_ENABLE:=
126 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
127 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
128 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
131 echo '#!/bin/sh' > .ccwrap
132 echo 'CC="$(CC)"' >> .ccwrap
133 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
134 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
135 echo 'eval $$CC $$*' >> .ccwrap
137 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
139 all: $(obj)/config.h coreboot
145 #######################################################################
148 CBFSTOOL:=$(obj)/util/cbfstool/cbfstool
150 $(obj)/mainboard/$(MAINBOARDDIR)/config.py: $(yapps2_py) $(config_g)
151 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
152 python $(yapps2_py) $(config_g) $(obj)/mainboard/$(MAINBOARDDIR)/config.py
155 # needed objects that every mainboard uses
156 # Creation of these is architecture and mainboard independent
157 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(obj)/mainboard/$(MAINBOARDDIR)/config.py
158 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
159 (cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig export PYTHONPATH; python config.py $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR))
161 objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
167 types:=obj initobj driver smmobj
169 # Clean -y variables, include Makefile.inc
170 # If $(3) is non-empty, add paths to files in X-y, and add them to Xs
171 # Add subdirs-y to subdirs
173 $(foreach type,$(2), $(eval $(type)-y:=)) \
174 $(eval subdirs-y:=) \
175 $(eval -include $(1)) \
176 $(if $(strip $(3)), \
177 $(foreach type,$(2), \
179 $$(abspath $$(patsubst src/%, \
181 $$(addprefix $(dir $(1)),$$($(type)-y))))))) \
182 $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
184 # For each path in $(subdirs) call includemakefiles, passing $(1) as $(3)
185 # Repeat until subdirs is empty
187 $(eval cursubdirs:=$(subdirs)) \
189 $(foreach dir,$(cursubdirs), \
190 $(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types),$(1)))) \
191 $(if $(subdirs),$(eval $(call evaluate_subdirs, $(1))))
193 # collect all object files eligible for building
194 subdirs:=$(PLATFORM-y) $(BUILD-y)
195 $(eval $(call evaluate_subdirs, modify))
197 initobjs:=$(addsuffix .initobj.o, $(basename $(initobjs)))
198 drivers:=$(addsuffix .driver.o, $(basename $(drivers)))
199 smmobjs:=$(addsuffix .smmobj.o, $(basename $(smmobjs)))
201 allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
202 alldirs:=$(sort $(abspath $(dir $(allobjs))))
203 source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
204 allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
208 # fetch rules (protected in POST_EVALUATION) that rely on the variables filled above
209 subdirs:=$(PLATFORM-y) $(BUILD-y)
210 $(eval $(call evaluate_subdirs))
213 define objs_asl_template
214 $(obj)/$(1)%.o: src/$(1)%.asl
215 @printf " IASL $$(subst $(top)/,,$$(@))\n"
216 $(CPP) -D__ACPI__ -P -include $(obj)/config.h -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
217 iasl -p $$(basename $$@) -tc $$(basename $$@).asl
218 mv $$(basename $$@).hex $$(basename $$@).c
219 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $$@))), -DAmlCode=AmlCode_$$(basename $$(notdir $$@))) -c -o $$@ $$(basename $$@).c
222 # macro to define template macros that are used by use_template macro
223 define create_cc_template
224 # $1 obj class (objs, initobjs, ...)
225 # $2 source suffix (c, S)
226 # $3 .o infix ("" ".initobj", ...)
227 # $4 additional compiler flags
228 de$(EMPTY)fine $(1)_$(2)_template
229 $(obj)/$$(1)%$(3).o: src/$$(1)%.$(2) $(obj)/config.h
230 printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
231 $(CC) $(4) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
235 $(eval $(call create_cc_template,objs,c))
236 $(eval $(call create_cc_template,objs,S,,-DASSEMBLY))
237 $(eval $(call create_cc_template,initobjs,c,.initobj))
238 $(eval $(call create_cc_template,initobjs,S,.initobj,-DASSEMBLY))
239 $(eval $(call create_cc_template,drivers,c,.driver))
240 $(eval $(call create_cc_template,drivers,S,.driver,-DASSEMBLY))
241 $(eval $(call create_cc_template,smmobjs,c,.smmobj))
242 $(eval $(call create_cc_template,smmobjs,S,.smmobj))
244 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
245 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
246 $(eval $(call usetemplate,objs,asl))
247 $(eval $(call usetemplate,objs,c))
248 $(eval $(call usetemplate,objs,S))
249 $(eval $(call usetemplate,initobjs,c))
250 $(eval $(call usetemplate,initobjs,S))
251 $(eval $(call usetemplate,drivers,c))
252 $(eval $(call usetemplate,drivers,S))
253 $(eval $(call usetemplate,smmobjs,c))
254 $(eval $(call usetemplate,smmobjs,S))
256 DEPENDENCIES = $(objs:.o=.d) $(initobjs:.o=.d) $(drivers:.o=.d) $(smmobjs:.o=.d)
257 -include $(DEPENDENCIES)
261 @echo initobjs:=$(initobjs)
262 @echo drivers:=$(drivers)
263 @echo smmobjs:=$(smmobjs)
264 @echo alldirs:=$(alldirs)
265 @echo allsrc=$(allsrc)
266 @echo DEPENDENCIES=$(DEPENDENCIES)
267 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
270 @echo $(patsubst $(top)/%,%,$(crt0s))
272 OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
273 INCLUDES := -I$(top)/src -I$(top)/src/include -I$(obj) -I$(top)/src/arch/$(ARCHDIR-y)/include
274 INCLUDES += -I$(top)/src/devices/oprom/include
275 INCLUDES += -include $(obj)/config.h
277 CFLAGS = $(INCLUDES) -Os -nostdinc -pipe
278 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
279 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
280 CFLAGS += -Wstrict-aliasing -Wshadow
281 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
284 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
286 CBFS_COMPRESS_FLAG:=l
287 CBFS_PAYLOAD_COMPRESS_FLAG:=
288 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
289 CBFS_PAYLOAD_COMPRESS_FLAG:=l
292 coreboot: prepare $(obj)/coreboot.rom
298 mkdir -p $(obj)/util/kconfig/lxdialog $(obj)/util/cbfstool
299 test -n "$(alldirs)" && mkdir -p $(alldirs) || true
301 $(obj)/build.h: .xcompile
302 @printf " GEN build.h\n"
304 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
305 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
306 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
307 printf "#define COREBOOT_VERSION \"$(KERNELVERSION)-r$(shell if [ -d $(top)/.svn -a -f `which svnversion` ]; then svnversion $(top); else if [ -d $(top)/.git -a -f `which git` ]; then git --git-dir=/$(top)/.git log|grep git-svn-id|cut -f 2 -d@|cut -f 1 -d' '|sort -g|tail -1; fi; fi)\"\n" >> $(obj)/build.ht
308 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
309 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
310 printf "\n" >> $(obj)/build.ht
311 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
312 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
313 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
314 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
315 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
316 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht
317 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
318 printf "#endif\n" >> $(obj)/build.ht
319 mv $(obj)/build.ht $(obj)/build.h
323 $(DOXYGEN) documentation/Doxyfile.coreboot
325 doxyclean: doxygen-clean
327 rm -rf $(DOXYGEN_OUTPUT_DIR)
329 clean-for-update: doxygen-clean
330 rm -f $(objs) $(initobjs) $(drivers) $(smmobjs) .xcompile
331 rm -f $(DEPENDENCIES)
332 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
333 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
334 rm -f $(obj)/option_table.* $(obj)/crt0_includes.h $(obj)/ldscript
335 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
336 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
337 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
338 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
339 rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
340 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
341 $(MAKE) -C util/sconfig clean
343 clean: clean-for-update
344 rm -f $(obj)/coreboot* .ccwrap
348 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
351 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
353 # This include must come _before_ the pattern rules below!
354 # Order _does_ matter for pattern rules.
355 include util/kconfig/Makefile
357 $(obj)/ldoptions: $(obj)/config.h
358 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
360 _OS=$(shell uname -s |cut -c-7)
362 ifeq ($(_OS),MINGW32)
363 STACK=-Wl,--stack,16384000
365 ifeq ($(_OS),CYGWIN_)
366 STACK=-Wl,--stack,16384000
368 $(obj)/romcc: $(top)/util/romcc/romcc.c
369 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
370 @# Note: Adding -O2 here might cause problems. For details see:
371 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
372 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
374 .PHONY: $(PHONY) prepare clean distclean doxygen doxy coreboot .xcompile