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
66 HOSTCFLAGS := -I$(srck) -I$(objk) -g
67 HOSTCXXFLAGS := -I$(srck) -I$(objk)
68 LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && $(CC) -print-libgcc-file-name)
71 DOXYGEN_OUTPUT_DIR := doxygen
73 ifeq ($(strip $(HAVE_DOTCONFIG)),)
79 include $(top)/.config
81 ifneq ($(INNER_SCANBUILD),y)
82 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
88 ARCHDIR-$(CONFIG_ARCH_X86) := i386
89 ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
91 MAINBOARDDIR=$(subst ",,$(CONFIG_MAINBOARD_DIR))
94 PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
97 BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers util/x86emu
98 BUILD-y += util/cbfstool
99 BUILD-$(CONFIG_ARCH_X86) += src/pc80
101 ifneq ($(CONFIG_LOCALVERSION),"")
102 COREBOOT_EXTRA_VERSION := -$(subst ",,$(CONFIG_LOCALVERSION))
105 # The primary target needs to be here before we include the
108 ifeq ($(INNER_SCANBUILD),y)
109 CONFIG_SCANBUILD_ENABLE:=
112 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
113 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
114 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
117 echo '#!/bin/sh' > .ccwrap
118 echo 'CC="$(CC)"' >> .ccwrap
119 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
120 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
121 echo 'eval $$CC $$*' >> .ccwrap
123 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
129 #######################################################################
132 CBFSTOOL:=$(obj)/util/cbfstool/cbfstool
134 $(obj)/mainboard/$(MAINBOARDDIR)/config.py: $(yapps2_py) $(config_g)
135 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
136 python $(yapps2_py) $(config_g) $(obj)/mainboard/$(MAINBOARDDIR)/config.py
139 # needed objects that every mainboard uses
140 # Creation of these is architecture and mainboard independent
141 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(obj)/mainboard/$(MAINBOARDDIR)/config.py
142 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
143 (cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig export PYTHONPATH; python config.py $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR))
145 $(obj)/mainboard/$(MAINBOARDDIR)/static.o: $(obj)/mainboard/$(MAINBOARDDIR)/static.c
146 @printf " CC $(subst $(obj)/,,$(@))\n"
147 $(CC) $(CFLAGS) -c -o $@ $<
149 $(obj)/arch/i386/../../option_table.o: $(obj)/arch/i386/../../option_table.c
150 @printf " CC $(subst $(obj)/,,$(@))\n"
151 $(CC) $(CFLAGS) -c -o $@ $<
153 objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
159 types:=obj initobj driver smmobj
161 # Clean -y variables, include Makefile.inc
162 # If $(3) is non-empty, add paths to files in X-y, and add them to Xs
163 # Add subdirs-y to subdirs
165 $(foreach type,$(2), $(eval $(type)-y:=)) \
166 $(eval subdirs-y:=) \
167 $(eval -include $(1)) \
168 $(if $(strip $(3)), \
169 $(foreach type,$(2), \
171 $$(patsubst util/%, \
175 $$(addprefix $(dir $(1)),$$($(type)-y))))))) \
176 $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
178 # For each path in $(subdirs) call includemakefiles, passing $(1) as $(3)
179 # Repeat until subdirs is empty
181 $(eval cursubdirs:=$(subdirs)) \
183 $(foreach dir,$(cursubdirs), \
184 $(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types),$(1)))) \
185 $(if $(subdirs),$(eval $(call evaluate_subdirs, $(1))))
187 # collect all object files eligible for building
188 subdirs:=$(PLATFORM-y) $(BUILD-y)
189 $(eval $(call evaluate_subdirs, modify))
191 initobjs:=$(addsuffix .initobj.o, $(basename $(initobjs)))
192 drivers:=$(addsuffix .driver.o, $(basename $(drivers)))
193 smmobjs:=$(addsuffix .smmobj.o, $(basename $(smmobjs)))
195 allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
196 alldirs:=$(sort $(abspath $(dir $(allobjs))))
197 source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
198 allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
202 # fetch rules (protected in POST_EVALUATION) that rely on the variables filled above
203 subdirs:=$(PLATFORM-y) $(BUILD-y)
204 $(eval $(call evaluate_subdirs))
207 define objs_asl_template
208 $(obj)/$(1)%.o: src/$(1)%.asl
209 @printf " IASL $$(subst $(top)/,,$$(@))\n"
210 $(CPP) -D__ACPI__ -P $(CPPFLAGS) -include $(obj)/config.h -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
211 iasl -p $$(basename $$@) -tc $$(basename $$@).asl
212 mv $$(basename $$@).hex $$(basename $$@).c
213 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $$@))), -DAmlCode=AmlCode_$$(basename $$(notdir $$@))) -c -o $$@ $$(basename $$@).c
216 define objs_c_template
217 $(obj)/$(1)%.o: $(1)%.c $(obj)/config.h
218 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
219 $(CC) $$(CFLAGS) -c -o $$@ $$<
221 $(obj)/$(1)%.o: src/$(1)%.c $(obj)/config.h
222 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
223 $(CC) $$(CFLAGS) -c -o $$@ $$<
226 define objs_S_template
227 $(obj)/$(1)%.o: $(1)%.S $(obj)/config.h
228 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
229 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
231 $(obj)/$(1)%.o: src/$(1)%.S $(obj)/config.h
232 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
233 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
236 define initobjs_c_template
237 $(obj)/$(1)%.initobj.o: src/$(1)%.c $(obj)/config.h
238 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
239 $(CC) $$(CFLAGS) -c -o $$@ $$<
242 define initobjs_S_template
243 $(obj)/$(1)%.initobj.o: src/$(1)%.S $(obj)/config.h
244 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
245 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
248 define drivers_c_template
249 $(obj)/$(1)%.driver.o: src/$(1)%.c $(obj)/config.h
250 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
251 $(CC) $$(CFLAGS) -c -o $$@ $$<
254 define drivers_S_template
255 $(obj)/$(1)%.driver.o: src/$(1)%.S
256 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
257 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
260 define smmobjs_c_template
261 $(obj)/$(1)%.smmobj.o: src/$(1)%.c
262 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
263 $(CC) $$(CFLAGS) -c -o $$@ $$<
266 define smmobjs_S_template
267 $(obj)/$(1)%.smmobj.o: src/$(1)%.S
268 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
269 $(CC) $$(CFLAGS) -c -o $$@ $$<
272 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
273 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
274 $(eval $(call usetemplate,objs,asl))
275 $(eval $(call usetemplate,objs,c))
276 $(eval $(call usetemplate,objs,S))
277 $(eval $(call usetemplate,initobjs,c))
278 $(eval $(call usetemplate,initobjs,S))
279 $(eval $(call usetemplate,drivers,c))
280 $(eval $(call usetemplate,drivers,S))
281 $(eval $(call usetemplate,smmobjs,c))
282 $(eval $(call usetemplate,smmobjs,S))
286 @echo initobjs:=$(initobjs)
287 @echo drivers:=$(drivers)
288 @echo smmobjs:=$(smmobjs)
289 @echo alldirs:=$(alldirs)
290 @echo allsrc=$(allsrc)
291 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
294 @echo $(patsubst $(top)/%,%,$(crt0s))
296 OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
297 INCLUDES := -I$(top)/src -I$(top)/src/include -I$(obj) -I$(top)/src/arch/$(ARCHDIR-y)/include
298 INCLUDES += -I$(top)/util/x86emu/include
299 INCLUDES += -include $(obj)/config.h
301 CFLAGS = $(INCLUDES) -Os -nostdinc
302 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
303 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
304 CFLAGS += -Wstrict-aliasing -Wshadow
305 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
308 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
310 CBFS_COMPRESS_FLAG:=l
311 CBFS_PAYLOAD_COMPRESS_FLAG:=
312 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
313 CBFS_PAYLOAD_COMPRESS_FLAG:=l
316 coreboot: prepare $(obj)/coreboot.rom
322 mkdir -p $(obj)/util/kconfig/lxdialog $(obj)/util/cbfstool
323 test -n "$(alldirs)" && mkdir -p $(alldirs) || true
325 $(obj)/build.h: .xcompile
326 @printf " GEN build.h\n"
328 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
329 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
330 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
331 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
332 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
333 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
334 printf "\n" >> $(obj)/build.ht
335 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
336 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
337 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
338 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
339 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
340 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s)\"\n" >> $(obj)/build.ht
341 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname)\"\n" >> $(obj)/build.ht
342 printf "#endif\n" >> $(obj)/build.ht
343 mv $(obj)/build.ht $(obj)/build.h
347 $(DOXYGEN) documentation/Doxyfile.coreboot
349 doxyclean: doxygen-clean
351 rm -rf $(DOXYGEN_OUTPUT_DIR)
353 clean-for-update: doxygen-clean
354 rm -f $(objs) $(initobjs) $(drivers) $(smmobjs) .xcompile
355 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
356 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
357 rm -f $(obj)/option_table.* $(obj)/crt0_includes.h $(obj)/ldscript
358 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
359 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/auto.inc $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
360 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
361 $(MAKE) -C util/sconfig clean
363 clean: clean-for-update
364 rm -f $(obj)/coreboot* .ccwrap
368 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
371 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
373 # This include must come _before_ the pattern rules below!
374 # Order _does_ matter for pattern rules.
375 include util/kconfig/Makefile
377 $(obj)/ldoptions: $(obj)/config.h
378 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
380 _OS=$(shell uname -s |cut -c-7)
382 ifeq ($(_OS),MINGW32)
383 STACK=-Wl,--stack,16384000
385 ifeq ($(_OS),CYGWIN_)
386 STACK=-Wl,--stack,16384000
388 $(obj)/romcc: $(top)/util/romcc/romcc.c
389 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
390 @# Note: Adding -O2 here might cause problems. For details see:
391 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
392 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
394 .PHONY: $(PHONY) prepare clean distclean doxygen doxy coreboot .xcompile