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)
25 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
27 ifeq ($(INNER_SCANBUILD),y)
29 HOSTCC:=$(CC_real) --hostcc
30 HOSTCXX:=$(CC_real) --hostcxx
34 export src := $(top)/src
35 export srck := $(top)/util/kconfig
36 export obj ?= $(top)/build
37 export objk := $(obj)/util/kconfig
38 export sconfig := $(top)/util/sconfig
39 export yapps2_py := $(sconfig)/yapps2.py
40 export config_g := $(sconfig)/config.g
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
64 HOSTCFLAGS := -I$(srck) -I$(objk) -g
65 HOSTCXXFLAGS := -I$(srck) -I$(objk)
66 LIBGCC_FILE_NAME := $(shell $(CC) -print-libgcc-file-name)
71 DOXYGEN_OUTPUT_DIR := doxygen
73 ifeq ($(strip $(HAVE_DOTCONFIG)),)
79 include $(top)/.config
81 ARCHDIR-$(CONFIG_ARCH_X86) := i386
82 ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
84 MAINBOARDDIR=$(subst ",,$(CONFIG_MAINBOARD_DIR))
87 PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
90 BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers util/x86emu
91 BUILD-y += util/cbfstool
92 BUILD-$(CONFIG_ARCH_X86) += src/pc80
94 ifneq ($(CONFIG_LOCALVERSION),"")
95 COREBOOT_EXTRA_VERSION := -$(subst ",,$(CONFIG_LOCALVERSION))
98 # The primary target needs to be here before we include the
101 ifeq ($(INNER_SCANBUILD),y)
102 CONFIG_SCANBUILD_ENABLE:=
105 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
106 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
107 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
110 echo '#!/bin/sh' > .ccwrap
111 echo 'CC="$(CC)"' >> .ccwrap
112 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
113 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
114 echo 'eval $$CC $$*' >> .ccwrap
116 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
122 #######################################################################
125 CBFSTOOL:=$(obj)/util/cbfstool/cbfstool
127 $(obj)/mainboard/$(MAINBOARDDIR)/config.py: $(yapps2_py) $(config_g)
128 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
129 python $(yapps2_py) $(config_g) $(obj)/mainboard/$(MAINBOARDDIR)/config.py
132 # needed objects that every mainboard uses
133 # Creation of these is architecture and mainboard independent
134 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(obj)/mainboard/$(MAINBOARDDIR)/config.py
135 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
136 (cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig export PYTHONPATH; python config.py $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR))
138 $(obj)/mainboard/$(MAINBOARDDIR)/static.o: $(obj)/mainboard/$(MAINBOARDDIR)/static.c
139 @printf " CC $(subst $(obj)/,,$(@))\n"
140 $(CC) $(CFLAGS) -c -o $@ $<
142 $(obj)/arch/i386/../../option_table.o: $(obj)/arch/i386/../../option_table.c
143 @printf " CC $(subst $(obj)/,,$(@))\n"
144 $(CC) $(CFLAGS) -c -o $@ $<
146 objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
152 types:=obj initobj driver smmobj
154 # Clean -y variables, include Makefile.inc
155 # If $(3) is non-empty, add paths to files in X-y, and add them to Xs
156 # Add subdirs-y to subdirs
158 $(foreach type,$(2), $(eval $(type)-y:=)) \
159 $(eval subdirs-y:=) \
160 $(eval -include $(1)) \
161 $(if $(strip $(3)), \
162 $(foreach type,$(2), \
164 $$(patsubst util/%, \
168 $$(addprefix $(dir $(1)),$$($(type)-y))))))) \
169 $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
171 # For each path in $(subdirs) call includemakefiles, passing $(1) as $(3)
172 # Repeat until subdirs is empty
174 $(eval cursubdirs:=$(subdirs)) \
176 $(foreach dir,$(cursubdirs), \
177 $(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types),$(1)))) \
178 $(if $(subdirs),$(eval $(call evaluate_subdirs, $(1))))
180 # collect all object files eligible for building
181 subdirs:=$(PLATFORM-y) $(BUILD-y)
182 $(eval $(call evaluate_subdirs, modify))
184 initobjs:=$(addsuffix .initobj.o, $(basename $(initobjs)))
185 drivers:=$(addsuffix .driver.o, $(basename $(drivers)))
186 smmobjs:=$(addsuffix .smmobj.o, $(basename $(smmobjs)))
188 allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
189 alldirs:=$(sort $(abspath $(dir $(allobjs))))
190 source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
191 allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
195 # fetch rules (protected in POST_EVALUATION) that rely on the variables filled above
196 subdirs:=$(PLATFORM-y) $(BUILD-y)
197 $(eval $(call evaluate_subdirs))
200 define objs_asl_template
201 $(obj)/$(1)%.o: src/$(1)%.asl
202 @printf " IASL $$(subst $(top)/,,$$(@))\n"
203 $(CPP) -D__ACPI__ -P $(CPPFLAGS) -include $(obj)/config.h -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
204 iasl -p $$(basename $$@) -tc $$(basename $$@).asl
205 mv $$(basename $$@).hex $$(basename $$@).c
206 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $$@))), -DAmlCode=AmlCode_$$(basename $$(notdir $$@))) -c -o $$@ $$(basename $$@).c
209 define objs_c_template
210 $(obj)/$(1)%.o: $(1)%.c $(obj)/config.h
211 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
212 $(CC) $$(CFLAGS) -c -o $$@ $$<
214 $(obj)/$(1)%.o: src/$(1)%.c $(obj)/config.h
215 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
216 $(CC) $$(CFLAGS) -c -o $$@ $$<
219 define objs_S_template
220 $(obj)/$(1)%.o: $(1)%.S $(obj)/config.h
221 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
222 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
224 $(obj)/$(1)%.o: src/$(1)%.S $(obj)/config.h
225 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
226 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
229 define initobjs_c_template
230 $(obj)/$(1)%.initobj.o: src/$(1)%.c $(obj)/config.h
231 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
232 $(CC) $$(CFLAGS) -c -o $$@ $$<
235 define initobjs_S_template
236 $(obj)/$(1)%.initobj.o: src/$(1)%.S $(obj)/config.h
237 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
238 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
241 define drivers_c_template
242 $(obj)/$(1)%.driver.o: src/$(1)%.c $(obj)/config.h
243 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
244 $(CC) $$(CFLAGS) -c -o $$@ $$<
247 define drivers_S_template
248 $(obj)/$(1)%.driver.o: src/$(1)%.S
249 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
250 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
253 define smmobjs_c_template
254 $(obj)/$(1)%.smmobj.o: src/$(1)%.c
255 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
256 $(CC) $$(CFLAGS) -c -o $$@ $$<
259 define smmobjs_S_template
260 $(obj)/$(1)%.smmobj.o: src/$(1)%.S
261 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
262 $(CC) $$(CFLAGS) -c -o $$@ $$<
265 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
266 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
267 $(eval $(call usetemplate,objs,asl))
268 $(eval $(call usetemplate,objs,c))
269 $(eval $(call usetemplate,objs,S))
270 $(eval $(call usetemplate,initobjs,c))
271 $(eval $(call usetemplate,initobjs,S))
272 $(eval $(call usetemplate,drivers,c))
273 $(eval $(call usetemplate,drivers,S))
274 $(eval $(call usetemplate,smmobjs,c))
275 $(eval $(call usetemplate,smmobjs,S))
279 @echo initobjs:=$(initobjs)
280 @echo drivers:=$(drivers)
281 @echo smmobjs:=$(smmobjs)
282 @echo alldirs:=$(alldirs)
283 @echo allsrc=$(allsrc)
286 @echo $(patsubst $(top)/%,%,$(crt0s))
288 OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
289 INCLUDES := -I$(top)/src -I$(top)/src/include -I$(obj) -I$(top)/src/arch/$(ARCHDIR-y)/include
290 INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
291 INCLUDES += -I$(top)/util/x86emu/include
292 INCLUDES += -include $(obj)/config.h
294 CFLAGS = $(INCLUDES) -Os -nostdinc
295 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
296 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
297 CFLAGS += -Wstrict-aliasing -Wshadow
298 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
301 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
303 CBFS_COMPRESS_FLAG:=l
304 CBFS_PAYLOAD_COMPRESS_FLAG:=
305 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
306 CBFS_PAYLOAD_COMPRESS_FLAG:=l
309 coreboot: prepare prepare2 $(obj)/coreboot.rom
315 mkdir -p $(obj)/util/kconfig/lxdialog $(obj)/util/cbfstool
316 test -n "$(alldirs)" && mkdir -p $(alldirs) || true
318 prepare2: $(obj)/build.h
321 @printf " GEN build.h\n"
323 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
324 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
325 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
326 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
327 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
328 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
329 printf "\n" >> $(obj)/build.ht
330 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
331 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
332 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
333 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
334 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
335 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s)\"\n" >> $(obj)/build.ht
336 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname)\"\n" >> $(obj)/build.ht
337 printf "#endif\n" >> $(obj)/build.ht
338 mv $(obj)/build.ht $(obj)/build.h
342 $(DOXYGEN) documentation/Doxyfile.coreboot
344 doxyclean: doxygen-clean
346 rm -rf $(DOXYGEN_OUTPUT_DIR)
348 clean-for-update: doxygen-clean
349 rm -f $(objs) $(initobjs) $(drivers) $(smmobjs) .xcompile
350 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
351 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
352 rm -f $(obj)/option_table.* $(obj)/crt0_includes.h $(obj)/ldscript
353 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
354 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/auto.inc $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
355 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
356 $(MAKE) -C util/sconfig clean
358 clean: clean-for-update
359 rm -f $(obj)/coreboot* .ccwrap
363 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
366 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
368 # This include must come _before_ the pattern rules below!
369 # Order _does_ matter for pattern rules.
370 include util/kconfig/Makefile
372 $(obj)/ldoptions: $(obj)/config.h
373 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
375 _OS=$(shell uname -s |cut -c-7)
377 ifeq ($(_OS),MINGW32)
378 STACK=-Wl,--stack,16384000
380 ifeq ($(_OS),CYGWIN_)
381 STACK=-Wl,--stack,16384000
383 $(obj)/romcc: $(top)/util/romcc/romcc.c
384 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
385 @# Note: Adding -O2 here might cause problems. For details see:
386 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
387 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
389 .PHONY: $(PHONY) prepare prepare2 clean distclean doxygen doxy coreboot