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>
7 ## Redistribution and use in source and binary forms, with or without
8 ## modification, are permitted provided that the following conditions
10 ## 1. Redistributions of source code must retain the above copyright
11 ## notice, this list of conditions and the following disclaimer.
12 ## 2. Redistributions in binary form must reproduce the above copyright
13 ## notice, this list of conditions and the following disclaimer in the
14 ## documentation and/or other materials provided with the distribution.
15 ## 3. The name of the author may not be used to endorse or promote products
16 ## derived from this software without specific prior written permission.
18 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
34 export top := $(shell pwd)
35 export src := $(top)/src
36 export srck := $(top)/util/kconfig
37 export obj := $(top)/build
38 export objk := $(top)/build/util/kconfig
39 export sconfig := $(top)/util/sconfig
40 export yapps2_py := $(sconfig)/yapps2.py
41 export config_g := $(sconfig)/config.g
44 export KERNELVERSION := 2.3
45 export KCONFIG_AUTOHEADER := $(obj)/config.h
46 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
47 export COREBOOT_V2 := 1
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 $(CC) -print-libgcc-file-name)
73 DOXYGEN_OUTPUT_DIR := doxygen
75 ifeq ($(strip $(HAVE_DOTCONFIG)),)
81 include $(top)/.config
83 ARCHDIR-$(CONFIG_ARCH_X86) := i386
84 ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
86 MAINBOARDDIR=$(shell echo $(CONFIG_MAINBOARD_DIR))
89 PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
92 BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers util/x86emu
93 BUILD-y += util/cbfstool
94 BUILD-$(CONFIG_ARCH_X86) += src/pc80
96 # The primary target needs to be here before we include the
102 #######################################################################
105 CBFSTOOL:=$(obj)/util/cbfstool/cbfstool
107 $(obj)/mainboard/$(MAINBOARDDIR)/config.py: $(yapps2_py) $(config_g)
108 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
109 python $(yapps2_py) $(config_g) $(obj)/mainboard/$(MAINBOARDDIR)/config.py
112 # needed objects that every mainboard uses
113 # Creation of these is architecture and mainboard independent
114 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(obj)/mainboard/$(MAINBOARDDIR)/config.py
115 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
116 (cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig export PYTHONPATH; python config.py $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR))
118 $(obj)/mainboard/$(MAINBOARDDIR)/static.o: $(obj)/mainboard/$(MAINBOARDDIR)/static.c
121 objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
127 types:=obj initobj driver smmobj
128 src_types:=crt0 ldscript
129 includemakefiles=$(foreach type,$(2), $(eval $(type)-y:=)) $(eval subdirs-y:=) $(eval include $(1)) $(if $(strip $(3)),$(foreach type,$(2),$(eval $(type)s+=$$(patsubst src/%,$(obj)/%,$$(addprefix $(dir $(1)),$$($(type)-y)))))) $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
130 evaluate_subdirs=$(eval cursubdirs:=$(subdirs)) $(eval subdirs:=) $(foreach dir,$(cursubdirs),$(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types) $(src_types),$(1)))) $(if $(subdirs),$(eval $(call evaluate_subdirs, $(1))))
132 # collect all object files eligible for building
133 subdirs:=$(PLATFORM-y) $(BUILD-y)
134 $(eval $(call evaluate_subdirs, modify))
136 allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
137 alldirs:=$(sort $(abspath $(dir $(allobjs))))
138 source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
139 allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
143 # fetch rules (protected in POST_EVALUATION) that rely on the variables filled above
144 subdirs:=$(PLATFORM-y) $(BUILD-y)
145 $(eval $(call evaluate_subdirs))
148 define c_dsl_template
149 $(obj)/$(1)%.c: src/$(1)%.dsl
150 @printf " IASL $$(subst $$(shell pwd)/,,$$(@))\n"
151 iasl -p $$(basename $$@) -tc $$<
152 perl -pi -e 's/AmlCode/AmlCode_$$(notdir $$(basename $$@))/g' $$(basename $$@).hex
153 mv $$(basename $$@).hex $$@
156 define objs_c_template
157 $(obj)/$(1)%.o: src/$(1)%.c
158 @printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
159 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
162 define objs_S_template
163 $(obj)/$(1)%.o: src/$(1)%.S
164 @printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
165 $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
168 define initobjs_c_template
169 $(obj)/$(1)%.o: src/$(1)%.c
170 @printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
171 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
174 define initobjs_S_template
175 $(obj)/$(1)%.o: src/$(1)%.S
176 @printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
177 $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
180 define drivers_c_template
181 $(obj)/$(1)%.o: src/$(1)%.c
182 @printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
183 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
186 define drivers_S_template
187 $(obj)/$(1)%.o: src/$(1)%.S
188 @printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
189 $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
192 define smmobjs_c_template
193 $(obj)/$(1)%.o: src/$(1)%.c
194 @printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
195 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
198 define smmobjs_S_template
199 $(obj)/$(1)%.o: src/$(1)%.S
200 @printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
201 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
204 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
205 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
206 $(eval $(call usetemplate,c,dsl))
207 $(eval $(call usetemplate,objs,c))
208 $(eval $(call usetemplate,objs,S))
209 $(eval $(call usetemplate,initobjs,c))
210 $(eval $(call usetemplate,initobjs,S))
211 $(eval $(call usetemplate,drivers,c))
212 $(eval $(call usetemplate,drivers,S))
213 $(eval $(call usetemplate,smmobjs,c))
214 $(eval $(call usetemplate,smmobjs,S))
218 @echo initobjs:=$(initobjs)
219 @echo drivers:=$(drivers)
220 @echo smmobjs:=$(smmobjs)
221 @echo alldirs:=$(alldirs)
222 @echo allsrc=$(allsrc)
224 OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
225 INCLUDES := -I$(top)/src -I$(top)/src/include -I$(obj) -I$(top)/src/arch/$(ARCHDIR-y)/include
226 INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
227 INCLUDES += -I$(top)/util/x86emu/include
228 INCLUDES += -include $(obj)/build.h
230 try-run= $(shell set -e; \
232 if ($(1)) > /dev/null 2>&1; \
237 cc-option= $(call try-run,\
238 $(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
240 STACKPROTECT += $(call cc-option, -fno-stack-protector,)
242 CFLAGS = $(STACKPROTECT) $(INCLUDES) $(MAINBOARD_OPTIONS) -Os -nostdinc
243 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
244 CFLAGS +=-Wwrite-strings -Wredundant-decls -Wno-trigraphs
245 CFLAGS += -Wstrict-aliasing -Wshadow
246 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
248 CBFS_COMPRESS_FLAG:=l
249 CBFS_PAYLOAD_COMPRESS_FLAG:=
250 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
251 CBFS_PAYLOAD_COMPRESS_FLAG:=l
254 coreboot: prepare prepare2 $(obj)/coreboot.rom
260 mkdir -p $(obj)/util/kconfig/lxdialog
261 test -n "$(alldirs)" && mkdir -p $(alldirs) || true
264 @printf " GEN $(subst $(shell pwd)/,,$(obj)/build.h)\n"
265 printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" > $(obj)/build.h
266 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.h
267 printf "#define COREBOOT_V2 \"$(COREBOOT_V2)\"\n" >> $(obj)/build.h
268 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.h
269 printf "\n" >> $(obj)/build.h
270 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.h
271 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.h
272 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.h
273 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.h
274 printf "#define COREBOOT_COMPILE_BY \"$(shell PATH=$$PATH:/usr/ucb whoami)\"\n" >> $(obj)/build.h
275 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname)\"\n" >> $(obj)/build.h
276 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname)\"\n" >> $(obj)/build.h
277 printf "#include \"config.h\"\n" >> $(obj)/build.h
283 doxyclean: doxygen-clean
285 rm -rf $(DOXYGEN_OUTPUT_DIR)
288 rm -f $(allobjs) build/coreboot* .xcompile
289 rm -f build/option_table.* build/crt0_includes.h build/ldscript
290 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
291 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/auto.inc $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
292 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
296 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
299 dongle.py -c /dev/term/1 build/coreboot.rom EOF
301 # This include must come _before_ the pattern rules below!
302 # Order _does_ matter for pattern rules.
303 include util/kconfig/Makefile
305 $(obj)/ldoptions: $(obj)/config.h
306 # cat $(obj)/config.h | grep -v \" |grep -v AUTOCONF_INCLUDED | grep \#define | sed s/\#define\ // | sed s/\ /\ =\ / | sed 's/$$/;/' > $(obj)/ldoptions
307 awk '/^#define ([^"])* ([^"])*$$/ {print $$2 " = " $$3 ";";}' $< > $@
309 $(obj)/romcc: $(top)/util/romcc/romcc.c
310 @printf " HOSTCC romcc"
311 $(HOSTCC) -g -O2 -Wall -o $@ $<
313 .PHONY: $(PHONY) prepare prepare2 clean distclean doxygen doxy coreboot