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
35 export top := $(CURDIR)
37 export srck := $(top)/util/kconfig
39 export objutil ?= $(obj)/util
40 export objk := $(objutil)/kconfig
43 export KERNELVERSION := 4.0
44 export KCONFIG_AUTOHEADER := $(obj)/config.h
45 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
48 KBUILD_DEFCONFIG := configs/defconfig
49 UNAME_RELEASE := $(shell uname -r)
51 KCONFIG_CONFIG = $(DOTCONFIG)
53 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
54 MAKEFLAGS += -rR --no-print-directory
56 # Make is silent per default, but 'make V=1' will show all compiler calls.
64 CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
65 ROMCC:= $(objutil)/romcc/romcc
68 HOSTCFLAGS := -I$(srck) -I$(objk) -g
69 HOSTCXXFLAGS := -I$(srck) -I$(objk)
70 LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && $(CC) -print-libgcc-file-name)
73 DOXYGEN_OUTPUT_DIR := doxygen
75 # Three cases where we don't need fully populated $(obj) lists:
76 # 1. when no .config exists
77 # 2. when make config (in any flavour) is run
78 # 3. when make distclean is run
79 # Don't waste time on reading all Makefile.incs in these cases
80 ifeq ($(strip $(HAVE_DOTCONFIG)),)
83 ifneq ($(MAKECMDGOALS),)
84 ifneq ($(filter %config distclean,$(MAKECMDGOALS)),)
94 include $(HAVE_DOTCONFIG)
96 ifneq ($(INNER_SCANBUILD),y)
97 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
103 ifeq ($(CONFIG_CCACHE),y)
104 CCACHE:=$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH))))
106 $(error ccache selected, but not found in PATH)
108 CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
109 CC := $(CCACHE) $(CC)
110 HOSTCC := $(CCACHE) $(HOSTCC)
111 HOSTCXX := $(CCACHE) $(HOSTCXX)
112 ROMCC := $(CCACHE) $(ROMCC)
115 strip_quotes = $(subst ",,$(subst \",,$(1)))
117 ARCHDIR-$(CONFIG_ARCH_X86) := i386
118 ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
120 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
123 PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
126 BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers
127 BUILD-y += util/cbfstool util/sconfig
128 BUILD-$(CONFIG_ARCH_X86) += src/pc80
130 ifneq ($(CONFIG_LOCALVERSION),"")
131 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
134 # The primary target needs to be here before we include the
137 ifeq ($(INNER_SCANBUILD),y)
138 CONFIG_SCANBUILD_ENABLE:=
141 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
142 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
143 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
146 echo '#!/bin/sh' > .ccwrap
147 echo 'CC="$(CC)"' >> .ccwrap
148 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
149 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
150 echo 'eval $$CC $$*' >> .ccwrap
152 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
154 all: $(obj)/config.h coreboot
157 # must come rather early
163 #######################################################################
166 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
168 # needed objects that every mainboard uses
169 # Creation of these is architecture and mainboard independent
170 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig
171 @printf " SCONFIG $(subst $(src)/,,$(<))\n"
172 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
173 $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
175 $(objutil)/%.o: $(objutil)/%.c
176 @printf " HOSTCC $(subst $(objutil)/,,$(@))\n"
177 $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
179 $(obj)/%.ramstage.o: $(obj)/%.c $(obj)/config.h
180 @printf " CC $(subst $(obj)/,,$(@))\n"
181 $(CC) -MMD $(CFLAGS) -c -o $@ $<
183 ramstage-srcs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
192 types:=ramstage romstage driver smm
194 # Clean -y variables, include Makefile.inc
195 # Add paths to files in X-y to X-srcs
196 # Add subdirs-y to subdirs
198 $(foreach type,$(2), $(eval $(type)-y:=)) \
199 $(eval subdirs-y:=) \
200 $(eval -include $(1)) \
201 $(foreach type,$(2), \
202 $(eval $(type)-srcs+= \
204 $$(abspath $$(addprefix $(dir $(1)),$$($(type)-y)))))) \
205 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
207 # For each path in $(subdirs) call includemakefiles
208 # Repeat until subdirs is empty
210 $(eval cursubdirs:=$(subdirs)) \
212 $(foreach dir,$(cursubdirs), \
213 $(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types)))) \
214 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
216 # collect all object files eligible for building
217 subdirs:=$(PLATFORM-y) $(BUILD-y)
218 $(eval $(call evaluate_subdirs))
220 src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
222 ramstage-objs:=$(call src-to-obj,ramstage)
223 romstage-objs:=$(call src-to-obj,romstage)
224 driver-objs:=$(call src-to-obj,driver)
225 smm-objs:=$(call src-to-obj,smm)
227 allsrcs:=$(foreach var, $(addsuffix -srcs,$(types)), $($(var)))
228 allobjs:=$(foreach var, $(addsuffix -objs,$(types)), $($(var)))
229 alldirs:=$(sort $(abspath $(dir $(allobjs))))
231 define ramstage-objs_asl_template
232 $(obj)/$(1).ramstage.o: src/$(1).asl
233 @printf " IASL $$(subst $(top)/,,$$(@))\n"
234 $(CPP) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
235 iasl -p $$(obj)/$(1) -tc $$(basename $$@).asl
236 mv $$(obj)/$(1).hex $$(basename $$@).c
237 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
238 # keep %.o: %.c rule from catching the temporary .c file after a make clean
239 mv $$(basename $$@).c $$(basename $$@).hex
242 # macro to define template macros that are used by use_template macro
243 define create_cc_template
244 # $1 obj class (ramstage, romstage, driver, smm)
245 # $2 source suffix (c, S)
246 # $3 additional compiler flags
247 de$(EMPTY)fine $(1)-objs_$(2)_template
248 $(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h
249 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
250 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
254 $(eval $(call create_cc_template,ramstage,c))
255 $(eval $(call create_cc_template,ramstage,S,-DASSEMBLY))
256 $(eval $(call create_cc_template,romstage,c,-D__PRE_RAM__))
257 $(eval $(call create_cc_template,romstage,S,-DASSEMBLY -D__PRE_RAM__))
258 $(eval $(call create_cc_template,driver,c))
259 $(eval $(call create_cc_template,driver,S,-DASSEMBLY))
260 $(eval $(call create_cc_template,smm,c))
261 $(eval $(call create_cc_template,smm,S))
263 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
264 $(eval $(foreach type,$(types),$(call foreach-src,$(type))))
266 DEPENDENCIES = $(ramstage-objs:.o=.d) $(romstage-objs:.o=.d) $(driver-objs:.o=.d) $(smm-objs:.o=.d)
267 -include $(DEPENDENCIES)
270 @echo ramstage-objs:=$(ramstage-objs)
271 @echo romstage-objs:=$(romstage-objs)
272 @echo driver-objs:=$(driver-objs)
273 @echo smm-objs:=$(smm-objs)
274 @echo alldirs:=$(alldirs)
275 @echo allsrcs=$(allsrcs)
276 @echo DEPENDENCIES=$(DEPENDENCIES)
277 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
281 @echo ldscripts=$(ldscripts)
283 OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
284 INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
285 INCLUDES += -Isrc/devices/oprom/include
286 # abspath is a workaround for romcc
287 INCLUDES += -include $(abspath $(obj)/config.h)
289 CFLAGS = $(INCLUDES) -Os -nostdinc -pipe -g
290 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
291 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
292 CFLAGS += -Wstrict-aliasing -Wshadow
293 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
296 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
298 CBFS_COMPRESS_FLAG:=l
299 CBFS_PAYLOAD_COMPRESS_FLAG:=
300 CBFS_PAYLOAD_COMPRESS_NAME:=none
301 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
302 CBFS_PAYLOAD_COMPRESS_FLAG:=l
303 CBFS_PAYLOAD_COMPRESS_NAME:=LZMA
306 coreboot: $(obj)/coreboot.rom
310 $(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options $(alldirs))
312 $(obj)/build.h: .xcompile
313 @printf " GEN build.h\n"
315 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
316 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
317 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
318 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
319 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
320 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
321 printf "\n" >> $(obj)/build.ht
322 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
323 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
324 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
325 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
326 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
327 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht
328 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
329 printf "#endif\n" >> $(obj)/build.ht
330 mv $(obj)/build.ht $(obj)/build.h
337 $(DOXYGEN) documentation/Doxyfile.coreboot
339 doxyclean: doxygen-clean
341 rm -rf $(DOXYGEN_OUTPUT_DIR)
343 clean-for-update: doxygen-clean
344 rm -f $(ramstage-objs) $(romstage-objs) $(driver-objs) $(smm-objs) .xcompile
345 rm -f $(DEPENDENCIES)
346 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
347 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
348 rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
349 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
350 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
351 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
352 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
353 rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
354 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
356 clean: clean-for-update
357 rm -f $(obj)/coreboot* .ccwrap
360 rm -rf coreboot-builds
365 distclean: clean-cscope
367 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
370 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
373 FAILED=0; LINTLOG=`mktemp`; \
374 for script in util/lint/lint-*; do \
375 echo; echo `basename $$script`; \
376 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
378 $$script > $$LINTLOG; \
379 if [ `wc -l $$LINTLOG | cut -d' ' -f1` -eq 0 ]; then \
380 printf "success\n\n"; \
382 echo test failed: ; \
385 FAILED=$$(( $$FAILED + 1 )); \
389 test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." && exit 1; }; \
392 # This include must come _before_ the pattern rules below!
393 # Order _does_ matter for pattern rules.
394 include util/kconfig/Makefile
396 $(obj)/ldoptions: $(obj)/config.h
397 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
399 _WINCHECK=$(shell uname -o 2> /dev/null)
401 ifeq ($(_WINCHECK),Msys)
402 STACK=-Wl,--stack,16384000
404 ifeq ($(_WINCHECK),Cygwin)
405 STACK=-Wl,--stack,16384000
408 $(objutil)/romcc/romcc: $(top)/util/romcc/romcc.c
409 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
410 @# Note: Adding -O2 here might cause problems. For details see:
411 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
412 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
414 .PHONY: $(PHONY) clean clean-abuild clean-cscope cscope distclean doxygen doxy coreboot .xcompile