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
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
)
50 HAVE_DOTCONFIG
:= $(wildcard .config
)
51 MAKEFLAGS
+= -rR
--no-print-directory
53 # Make is silent per default, but 'make V=1' will show all compiler calls.
61 CPP
:= $(CC
) -x assembler-with-cpp
-DASSEMBLY
-E
62 ROMCC
:= $(objutil
)/romcc
/romcc
65 HOSTCFLAGS
:= -I
$(srck
) -I
$(objk
) -g
66 HOSTCXXFLAGS
:= -I
$(srck
) -I
$(objk
)
67 LIBGCC_FILE_NAME
:= $(shell test -r
`$(CC) -print-libgcc-file-name` && $(CC
) -print-libgcc-file-name
)
70 DOXYGEN_OUTPUT_DIR
:= doxygen
72 # Three cases where we don't need fully populated $(obj) lists:
73 # 1. when no .config exists
74 # 2. when make config (in any flavour) is run
75 # 3. when make distclean is run
76 # Don't waste time on reading all Makefile.incs in these cases
77 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
80 ifneq ($(MAKECMDGOALS
),)
81 ifneq ($(filter %config
distclean,$(MAKECMDGOALS
)),)
91 include $(top
)/.config
93 ifneq ($(INNER_SCANBUILD
),y
)
94 ifeq ($(CONFIG_COMPILER_LLVM_CLANG
),y
)
100 ifeq ($(CONFIG_CCACHE
),y
)
101 CCACHE
:=CCACHE_COMPILERCHECK
=content
$(wildcard $(addsuffix /ccache
,$(subst :, ,$(PATH
))))
103 $(error ccache selected
, but not found in PATH
)
105 CC
:= $(CCACHE
) $(CC
)
106 HOSTCC
:= $(CCACHE
) $(HOSTCC
)
107 HOSTCXX
:= $(CCACHE
) $(HOSTCXX
)
108 ROMCC
:= $(CCACHE
) $(ROMCC
)
111 strip_quotes
= $(subst ",,$(subst \",,$(1)))
113 ARCHDIR-$(CONFIG_ARCH_X86) := i386
114 ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
116 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
119 PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
122 BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers
123 BUILD-y += util/cbfstool util/sconfig
124 BUILD-$(CONFIG_ARCH_X86) += src/pc80
126 ifneq ($(CONFIG_LOCALVERSION),"")
127 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
130 # The primary target needs to be here before we include the
133 ifeq ($(INNER_SCANBUILD),y)
134 CONFIG_SCANBUILD_ENABLE:=
137 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
138 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
139 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
142 echo '#!/bin/sh' > .ccwrap
143 echo 'CC="$(CC
)"' >> .ccwrap
144 echo 'if [ "$$1" = "--hostcc
" ]; then shift; CC="$(HOSTCC
)"; fi' >> .ccwrap
145 echo 'if [ "$$1" = "--hostcxx
" ]; then shift; CC="$(HOSTCXX
)"; fi' >> .ccwrap
146 echo 'eval $$CC $$*' >> .ccwrap
148 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
150 all: $(obj)/config.h coreboot
153 # must come rather early
159 #######################################################################
162 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
164 # needed objects that every mainboard uses
165 # Creation of these is architecture and mainboard independent
166 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig
167 @printf " SCONFIG
$(subst $(src
)/,,$(<))\n"
168 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
169 $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
171 $(objutil)/%.o: $(objutil)/%.c
172 @printf " HOSTCC
$(subst $(objutil
)/,,$(@
))\n"
173 $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
175 $(obj)/%.o: $(obj)/%.c $(obj)/config.h
176 @printf " CC
$(subst $(obj
)/,,$(@
))\n"
177 $(CC) -MMD $(CFLAGS) -c -o $@ $<
179 objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
183 types:=obj initobj driver smmobj
185 # Clean -y variables, include Makefile.inc
186 # If $(3) is non-empty, add paths to files in X-y, and add them to Xs
187 # Add subdirs-y to subdirs
189 $(foreach type,$(2), $(eval $(type)-y:=)) \
190 $(eval subdirs-y:=) \
191 $(eval -include $(1)) \
192 $(foreach type,$(2), \
195 $$(abspath $$(patsubst src/%, \
197 $$(addprefix $(dir $(1)),$$($(type)-y))))))) \
198 $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
200 # For each path in $(subdirs) call includemakefiles, passing $(1) as $(3)
201 # Repeat until subdirs is empty
203 $(eval cursubdirs:=$(subdirs)) \
205 $(foreach dir,$(cursubdirs), \
206 $(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types)))) \
207 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
209 # collect all object files eligible for building
210 subdirs:=$(PLATFORM-y) $(BUILD-y)
211 $(eval $(call evaluate_subdirs))
213 initobjs:=$(addsuffix .initobj.o, $(basename $(initobjs)))
214 drivers:=$(addsuffix .driver.o, $(basename $(drivers)))
215 smmobjs:=$(addsuffix .smmobj.o, $(basename $(smmobjs)))
217 allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
218 alldirs:=$(sort $(abspath $(dir $(allobjs))))
219 source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
220 allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
222 define objs_asl_template
223 $(obj)/$(1)%.o: src/$(1)%.asl
224 @printf " IASL
$$(subst $(top
)/,,$$(@
))\n"
225 $(CPP) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
226 iasl -p $$(basename $$@) -tc $$(basename $$@).asl
227 mv $$(basename $$@).hex $$(basename $$@).c
228 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $$@))), -DAmlCode=AmlCode_$$(basename $$(notdir $$@))) -c -o $$@ $$(basename $$@).c
229 # keep %.o: %.c rule from catching the temporary .c file after a make clean
230 mv $$(basename $$@).c $$(basename $$@).hex
233 # macro to define template macros that are used by use_template macro
234 define create_cc_template
235 # $1 obj class (objs, initobjs, ...)
236 # $2 source suffix (c, S)
237 # $3 .o infix ("" ".initobj
", ...)
238 # $4 additional compiler flags
239 de$(EMPTY)fine $(1)_$(2)_template
240 $(obj)/$$(1)%$(3).o: src/$$(1)%.$(2) $(obj)/config.h
241 @printf " CC
$$$$(subst $$$$(obj
)/,,$$$$(@
))\n"
242 $(CC) $(4) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
246 $(eval $(call create_cc_template,objs,c))
247 $(eval $(call create_cc_template,objs,S,,-DASSEMBLY))
248 $(eval $(call create_cc_template,initobjs,c,.initobj,-D__PRE_RAM__))
249 $(eval $(call create_cc_template,initobjs,S,.initobj,-DASSEMBLY -D__PRE_RAM__))
250 $(eval $(call create_cc_template,drivers,c,.driver))
251 $(eval $(call create_cc_template,drivers,S,.driver,-DASSEMBLY))
252 $(eval $(call create_cc_template,smmobjs,c,.smmobj))
253 $(eval $(call create_cc_template,smmobjs,S,.smmobj))
255 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
256 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
257 $(eval $(call usetemplate,objs,asl))
258 $(eval $(call usetemplate,objs,c))
259 $(eval $(call usetemplate,objs,S))
260 $(eval $(call usetemplate,initobjs,c))
261 $(eval $(call usetemplate,initobjs,S))
262 $(eval $(call usetemplate,drivers,c))
263 $(eval $(call usetemplate,drivers,S))
264 $(eval $(call usetemplate,smmobjs,c))
265 $(eval $(call usetemplate,smmobjs,S))
267 DEPENDENCIES = $(objs:.o=.d) $(initobjs:.o=.d) $(drivers:.o=.d) $(smmobjs:.o=.d)
268 -include $(DEPENDENCIES)
272 @echo initobjs:=$(initobjs)
273 @echo drivers:=$(drivers)
274 @echo smmobjs:=$(smmobjs)
275 @echo alldirs:=$(alldirs)
276 @echo allsrc=$(allsrc)
277 @echo DEPENDENCIES=$(DEPENDENCIES)
278 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
282 @echo ldscripts=$(ldscripts)
284 OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
285 INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
286 INCLUDES += -Isrc/devices/oprom/include
287 # abspath is a workaround for romcc
288 INCLUDES += -include $(abspath $(obj)/config.h)
290 CFLAGS = $(INCLUDES) -Os -nostdinc -pipe
291 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
292 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
293 CFLAGS += -Wstrict-aliasing -Wshadow
294 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
297 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
299 CBFS_COMPRESS_FLAG:=l
300 CBFS_PAYLOAD_COMPRESS_FLAG:=
301 CBFS_PAYLOAD_COMPRESS_NAME:=none
302 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
303 CBFS_PAYLOAD_COMPRESS_FLAG:=l
304 CBFS_PAYLOAD_COMPRESS_NAME:=LZMA
307 coreboot: $(obj)/coreboot.rom
311 $(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options $(alldirs))
313 $(obj)/build.h: .xcompile
314 @printf " GEN build.h
\n"
316 printf "/* build system definitions
(autogenerated
) */\n" > $(obj)/build.ht
317 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
318 printf
"#define __BUILD_H\n\n" >> $(obj
)/build.ht
319 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
320 printf
"#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj
)/build.ht
321 printf
"#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj
)/build.ht
322 printf
"\n" >> $(obj
)/build.ht
323 printf
"#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj
)/build.ht
324 printf
"#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj
)/build.ht
325 printf
"#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj
)/build.ht
326 printf
"#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj
)/build.ht
327 printf
"#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj
)/build.ht
328 printf
"#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj
)/build.ht
329 printf
"#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux
" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj
)/build.ht
330 printf
"#endif\n" >> $(obj
)/build.ht
331 mv
$(obj
)/build.ht
$(obj
)/build.h
335 $(DOXYGEN
) documentation
/Doxyfile.coreboot
337 doxyclean
: doxygen-clean
339 rm -rf
$(DOXYGEN_OUTPUT_DIR
)
341 clean-for-update
: doxygen-clean
342 rm -f
$(objs
) $(initobjs
) $(drivers
) $(smmobjs
) .xcompile
343 rm -f
$(DEPENDENCIES
)
344 rm -f
$(obj
)/coreboot_ram
* $(obj
)/coreboot.romstage
$(obj
)/coreboot.pre
* $(obj
)/coreboot.bootblock
$(obj
)/coreboot.a
345 rm -rf
$(obj
)/bootblock
* $(obj
)/romstage
* $(obj
)/location.
*
346 rm -f
$(obj
)/option_table.
* $(obj
)/crt0.S
$(obj
)/ldscript
347 rm -f
$(obj
)/mainboard
/$(MAINBOARDDIR
)/static.c
$(obj
)/mainboard
/$(MAINBOARDDIR
)/config.py
$(obj
)/mainboard
/$(MAINBOARDDIR
)/static.dot
348 rm -f
$(obj
)/mainboard
/$(MAINBOARDDIR
)/crt0.s
$(obj
)/mainboard
/$(MAINBOARDDIR
)/crt0.disasm
349 rm -f
$(obj
)/mainboard
/$(MAINBOARDDIR
)/romstage.inc
350 rm -f
$(obj
)/mainboard
/$(MAINBOARDDIR
)/bootblock.
* $(obj
)/mainboard
/$(MAINBOARDDIR
)/dsdt.
*
351 rm -f
$(obj
)/cpu
/x86
/smm
/smm_bin.c
$(obj
)/cpu
/x86
/smm
/smm.
* $(obj
)/cpu
/x86
/smm
/smm
352 rmdir
-p
$(alldirs
) 2>/dev
/null
>/dev
/null || true
354 clean: clean-for-update
355 rm -f
$(obj
)/coreboot
* .ccwrap
359 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig
* .ccwrap .xcompile
362 dongle.py
-c
/dev
/term
/1 $(obj
)/coreboot.rom EOF
364 # This include must come _before_ the pattern rules below!
365 # Order _does_ matter for pattern rules.
366 include util
/kconfig
/Makefile
368 $(obj
)/ldoptions
: $(obj
)/config.h
369 awk
'/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
371 _WINCHECK
=$(shell uname
-o
2> /dev
/null
)
373 ifeq ($(_WINCHECK
),Msys
)
374 STACK
=-Wl
,--stack
,16384000
376 ifeq ($(_WINCHECK
),Cygwin
)
377 STACK
=-Wl
,--stack
,16384000
380 $(objutil
)/romcc
/romcc
: $(top
)/util
/romcc
/romcc.c
381 @printf
" HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
382 @
# Note: Adding -O2 here might cause problems. For details see:
383 @
# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
384 $(HOSTCC
) -g
$(STACK
) -Wall
-o
$@
$<
386 .PHONY
: $(PHONY
) clean distclean doxygen doxy coreboot .xcompile