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 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
26 export src := $(top)/src
27 export srck := $(top)/util/kconfig
28 export obj ?= $(top)/build
29 export objk := $(obj)/util/kconfig
30 export sconfig := $(top)/util/sconfig
31 export yapps2_py := $(sconfig)/yapps2.py
32 export config_g := $(sconfig)/config.g
35 export KERNELVERSION := 4.0
36 export KCONFIG_AUTOHEADER := $(obj)/config.h
37 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
40 KBUILD_DEFCONFIG := configs/defconfig
41 UNAME_RELEASE := $(shell uname -r)
42 HAVE_DOTCONFIG := $(wildcard .config)
43 MAKEFLAGS += -rR --no-print-directory
45 # Make is silent per default, but 'make V=1' will show all compiler calls.
53 CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
56 HOSTCFLAGS := -I$(srck) -I$(objk) -g
57 HOSTCXXFLAGS := -I$(srck) -I$(objk)
58 LIBGCC_FILE_NAME := $(shell $(CC) -print-libgcc-file-name)
63 DOXYGEN_OUTPUT_DIR := doxygen
65 ifeq ($(strip $(HAVE_DOTCONFIG)),)
71 include $(top)/.config
73 ARCHDIR-$(CONFIG_ARCH_X86) := i386
74 ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
76 MAINBOARDDIR=$(subst ",,$(CONFIG_MAINBOARD_DIR))
79 PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
82 BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers util/x86emu
83 BUILD-y += util/cbfstool
84 BUILD-$(CONFIG_ARCH_X86) += src/pc80
86 ifneq ($(CONFIG_LOCALVERSION),"")
87 COREBOOT_EXTRA_VERSION := -$(subst ",,$(CONFIG_LOCALVERSION))
90 # The primary target needs to be here before we include the
96 #######################################################################
99 CBFSTOOL:=$(obj)/util/cbfstool/cbfstool
101 $(obj)/mainboard/$(MAINBOARDDIR)/config.py: $(yapps2_py) $(config_g)
102 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
103 python $(yapps2_py) $(config_g) $(obj)/mainboard/$(MAINBOARDDIR)/config.py
106 # needed objects that every mainboard uses
107 # Creation of these is architecture and mainboard independent
108 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(obj)/mainboard/$(MAINBOARDDIR)/config.py
109 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
110 (cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig export PYTHONPATH; python config.py $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR))
112 $(obj)/mainboard/$(MAINBOARDDIR)/static.o: $(obj)/mainboard/$(MAINBOARDDIR)/static.c
115 objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
121 types:=obj initobj driver smmobj
123 # Clean -y variables, include Makefile.inc
124 # If $(3) is non-empty, add paths to files in X-y, and add them to Xs
125 # Add subdirs-y to subdirs
127 $(foreach type,$(2), $(eval $(type)-y:=)) \
128 $(eval subdirs-y:=) \
129 $(eval -include $(1)) \
130 $(if $(strip $(3)), \
131 $(foreach type,$(2), \
133 $$(patsubst util/%, \
137 $$(addprefix $(dir $(1)),$$($(type)-y))))))) \
138 $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
140 # For each path in $(subdirs) call includemakefiles, passing $(1) as $(3)
141 # Repeat until subdirs is empty
143 $(eval cursubdirs:=$(subdirs)) \
145 $(foreach dir,$(cursubdirs), \
146 $(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types),$(1)))) \
147 $(if $(subdirs),$(eval $(call evaluate_subdirs, $(1))))
149 # collect all object files eligible for building
150 subdirs:=$(PLATFORM-y) $(BUILD-y)
151 $(eval $(call evaluate_subdirs, modify))
153 initobjs:=$(addsuffix .initobj.o, $(basename $(initobjs)))
154 drivers:=$(addsuffix .driver.o, $(basename $(drivers)))
155 smmobjs:=$(addsuffix .smmobj.o, $(basename $(smmobjs)))
157 allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
158 alldirs:=$(sort $(abspath $(dir $(allobjs))))
159 source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
160 allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
164 # fetch rules (protected in POST_EVALUATION) that rely on the variables filled above
165 subdirs:=$(PLATFORM-y) $(BUILD-y)
166 $(eval $(call evaluate_subdirs))
169 define objs_asl_template
170 $(obj)/$(1)%.o: src/$(1)%.asl
171 @printf " IASL $$(subst $(top)/,,$$(@))\n"
172 $(CPP) -D__ACPI__ -P $(CPPFLAGS) -include $(obj)/config.h -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
173 iasl -p $$(basename $$@) -tc $$(basename $$@).asl
174 mv $$(basename $$@).hex $$(basename $$@).c
175 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $$@))), -DAmlCode=AmlCode_$$(basename $$(notdir $$@))) -c -o $$@ $$(basename $$@).c
178 define objs_c_template
179 $(obj)/$(1)%.o: $(1)%.c $(obj)/config.h
180 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
181 $(CC) $$(CFLAGS) -c -o $$@ $$<
183 $(obj)/$(1)%.o: src/$(1)%.c $(obj)/config.h
184 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
185 $(CC) $$(CFLAGS) -c -o $$@ $$<
188 define objs_S_template
189 $(obj)/$(1)%.o: $(1)%.S $(obj)/config.h
190 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
191 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
193 $(obj)/$(1)%.o: src/$(1)%.S $(obj)/config.h
194 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
195 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
198 define initobjs_c_template
199 $(obj)/$(1)%.initobj.o: src/$(1)%.c $(obj)/config.h
200 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
201 $(CC) $$(CFLAGS) -c -o $$@ $$<
204 define initobjs_S_template
205 $(obj)/$(1)%.initobj.o: src/$(1)%.S $(obj)/config.h
206 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
207 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
210 define drivers_c_template
211 $(obj)/$(1)%.driver.o: src/$(1)%.c $(obj)/config.h
212 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
213 $(CC) $$(CFLAGS) -c -o $$@ $$<
216 define drivers_S_template
217 $(obj)/$(1)%.driver.o: src/$(1)%.S
218 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
219 $(CC) -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
222 define smmobjs_c_template
223 $(obj)/$(1)%.smmobj.o: src/$(1)%.c
224 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
225 $(CC) $$(CFLAGS) -c -o $$@ $$<
228 define smmobjs_S_template
229 $(obj)/$(1)%.smmobj.o: src/$(1)%.S
230 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
231 $(CC) $$(CFLAGS) -c -o $$@ $$<
234 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
235 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
236 $(eval $(call usetemplate,objs,asl))
237 $(eval $(call usetemplate,objs,c))
238 $(eval $(call usetemplate,objs,S))
239 $(eval $(call usetemplate,initobjs,c))
240 $(eval $(call usetemplate,initobjs,S))
241 $(eval $(call usetemplate,drivers,c))
242 $(eval $(call usetemplate,drivers,S))
243 $(eval $(call usetemplate,smmobjs,c))
244 $(eval $(call usetemplate,smmobjs,S))
248 @echo initobjs:=$(initobjs)
249 @echo drivers:=$(drivers)
250 @echo smmobjs:=$(smmobjs)
251 @echo alldirs:=$(alldirs)
252 @echo allsrc=$(allsrc)
255 @echo $(patsubst $(top)/%,%,$(crt0s))
257 OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
258 INCLUDES := -I$(top)/src -I$(top)/src/include -I$(obj) -I$(top)/src/arch/$(ARCHDIR-y)/include
259 INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
260 INCLUDES += -I$(top)/util/x86emu/include
261 INCLUDES += -include $(obj)/config.h
263 CFLAGS = $(INCLUDES) -Os -nostdinc
264 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
265 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
266 CFLAGS += -Wstrict-aliasing -Wshadow
267 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
270 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
272 CBFS_COMPRESS_FLAG:=l
273 CBFS_PAYLOAD_COMPRESS_FLAG:=
274 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
275 CBFS_PAYLOAD_COMPRESS_FLAG:=l
278 coreboot: prepare prepare2 $(obj)/coreboot.rom
284 mkdir -p $(obj)/util/kconfig/lxdialog $(obj)/util/cbfstool
285 test -n "$(alldirs)" && mkdir -p $(alldirs) || true
287 prepare2: $(obj)/build.h
290 @printf " GEN build.h\n"
292 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
293 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
294 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
295 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
296 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
297 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
298 printf "\n" >> $(obj)/build.ht
299 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
300 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
301 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
302 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
303 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
304 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s)\"\n" >> $(obj)/build.ht
305 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname)\"\n" >> $(obj)/build.ht
306 printf "#endif\n" >> $(obj)/build.ht
307 mv $(obj)/build.ht $(obj)/build.h
311 $(DOXYGEN) documentation/Doxyfile.coreboot
313 doxyclean: doxygen-clean
315 rm -rf $(DOXYGEN_OUTPUT_DIR)
317 clean-for-update: doxygen-clean
318 rm -f $(objs) $(initobjs) $(drivers) $(smmobjs) .xcompile
319 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
320 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
321 rm -f $(obj)/option_table.* $(obj)/crt0_includes.h $(obj)/ldscript
322 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
323 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/auto.inc $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
324 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
325 $(MAKE) -C util/sconfig clean
327 clean: clean-for-update
328 rm -f $(obj)/coreboot*
332 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
335 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
337 # This include must come _before_ the pattern rules below!
338 # Order _does_ matter for pattern rules.
339 include util/kconfig/Makefile
341 $(obj)/ldoptions: $(obj)/config.h
342 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
344 _OS=$(shell uname -s |cut -c-7)
346 ifeq ($(_OS),MINGW32)
347 STACK=-Wl,--stack,16384000
349 ifeq ($(_OS),CYGWIN_)
350 STACK=-Wl,--stack,16384000
352 $(obj)/romcc: $(top)/util/romcc/romcc.c
353 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
354 @# Note: Adding -O2 here might cause problems. For details see:
355 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
356 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
358 .PHONY: $(PHONY) prepare prepare2 clean distclean doxygen doxy coreboot