2 ## This file is part of the coreboot project.
4 ## Copyright (C) 2011 secunet Security Networks AG
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; version 2 of the License.
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, write to the Free Software
17 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #######################################################################
21 # misleadingly named, this is the coreboot version
22 export KERNELVERSION := $(shell if [ -d "$(top)/.git" -a -f "`which git`" ]; then git describe --dirty; else echo unknown; fi)
24 #######################################################################
25 # Basic component discovery
26 ARCHDIR-$(CONFIG_ARCH_X86) := x86
27 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
30 #######################################################################
31 # root rule to resolve if in build mode (ie. configuration exists)
32 real-target: $(obj)/config.h coreboot
33 coreboot: $(obj)/coreboot.rom
35 #######################################################################
37 PHONY+= clean-abuild coreboot lint lint-stable
39 #######################################################################
40 # root source directories of coreboot
41 subdirs-y := src/lib src/boot src/console src/devices src/ec src/southbridge
42 subdirs-y += src/northbridge src/superio src/drivers src/cpu src/vendorcode
43 subdirs-y += util/cbfstool util/sconfig util/nvramtool
44 subdirs-y += src/arch/$(ARCHDIR-y)
45 subdirs-y += src/mainboard/$(MAINBOARDDIR)
47 subdirs-$(CONFIG_ARCH_X86) += src/pc80
49 subdirs-y += site-local
51 #######################################################################
52 # Add source classes and their build options
53 classes-y := ramstage romstage driver smm
55 romstage-c-ccopts:=-D__PRE_RAM__
56 romstage-S-ccopts:=-D__PRE_RAM__
57 ifeq ($(CONFIG_TRACE),y)
58 ramstage-c-ccopts:= -finstrument-functions
61 smm-c-ccopts:=-D__SMM__
62 smm-S-ccopts:=-D__SMM__
64 # SMM TSEG base is dynamic
65 ifeq ($(CONFIG_SMM_TSEG),y)
69 ramstage-c-deps:=$$(OPTION_TABLE_H)
70 romstage-c-deps:=$$(OPTION_TABLE_H)
72 #######################################################################
73 # Add handler to compile ACPI's ASL
74 define ramstage-objs_asl_template
75 $(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h
76 @printf " IASL $$(subst $(top)/,,$$(@))\n"
77 $(CC) -x assembler-with-cpp -E -MMD -MT $$(@) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/include -I$(src)/arch/$(ARCHDIR-y)/include -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
78 cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$(basename $$@)).asl
79 mv $$(basename $$@).hex $$(basename $$@).c
80 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
81 # keep %.o: %.c rule from catching the temporary .c file after a make clean
82 mv $$(basename $$@).c $$(basename $$@).hex
85 #######################################################################
86 # Parse plaintext cmos defaults into binary format
88 # arg2: binary file name
89 cbfs-files-processor-nvramtool= \
90 $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
91 printf " CREATE $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
93 #######################################################################
94 # Add handler for arbitrary files in CBFS
95 $(call add-special-class,cbfs-files)
97 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
98 $(eval $(2)-file:=$(word 1, $(subst :, ,$($(2)-file)))) \
99 $(if $(wildcard $(1)$($(2)-file)), \
100 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
101 $(eval tmp-cbfs-file:= $($(2)-file))) \
102 $(if $(tmp-cbfs-method), \
103 $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
104 $(eval tmp-cbfs-file:=$(shell mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
105 $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
106 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-position)) \
107 $(eval $(2)-name:=) \
108 $(eval $(2)-type:=) \
109 $(eval $(2)-position:=)
111 #######################################################################
112 # a variety of flags for our build
114 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
115 CBFS_COMPRESS_FLAG:=l
118 CBFS_PAYLOAD_COMPRESS_FLAG:=
119 CBFS_PAYLOAD_COMPRESS_NAME:=none
120 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
121 CBFS_PAYLOAD_COMPRESS_FLAG:=l
122 CBFS_PAYLOAD_COMPRESS_NAME:=LZMA
125 ifneq ($(CONFIG_LOCALVERSION),"")
126 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
129 INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
130 INCLUDES += -Isrc/devices/oprom/include
131 # abspath is a workaround for romcc
132 INCLUDES += -include $(abspath $(obj)/config.h)
134 CFLAGS = $(INCLUDES) -Os -pipe -g -nostdinc
135 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
136 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
137 CFLAGS += -Wstrict-aliasing -Wshadow
138 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
141 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
143 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options
145 #######################################################################
146 # generate build support files
147 $(obj)/build.h: .xcompile
148 @printf " GEN build.h\n"
150 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
151 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
152 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
153 printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht
154 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
155 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
156 printf "#define COREBOOT_DMI_DATE \"`LANG= date +"%m/%d/%Y"`\"\n" >> $(obj)/build.ht
157 printf "\n" >> $(obj)/build.ht
158 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
159 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
160 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
161 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
162 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
163 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht
164 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
165 printf "#endif\n" >> $(obj)/build.ht
166 mv $(obj)/build.ht $(obj)/build.h
168 $(obj)/ldoptions: $(obj)/config.h
169 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
171 #######################################################################
173 CBFSTOOL:=$(obj)/cbfstool
175 $(CBFSTOOL): $(objutil)/cbfstool/cbfstool
178 _WINCHECK=$(shell uname -o 2> /dev/null)
180 ifeq ($(_WINCHECK),Msys)
181 STACK=-Wl,--stack,16384000
183 ifeq ($(_WINCHECK),Cygwin)
184 STACK=-Wl,--stack,16384000
187 ROMCC:= $(objutil)/romcc/romcc
188 $(ROMCC): $(top)/util/romcc/romcc.c
189 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
190 @# Note: Adding -O2 here might cause problems. For details see:
191 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
192 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
194 #######################################################################
195 # needed objects that every mainboard uses
196 # Creation of these is architecture and mainboard independent
197 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig
198 @printf " SCONFIG $(subst $(src)/,,$(<))\n"
199 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
200 $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
202 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
204 $(objutil)/%.o: $(objutil)/%.c
205 @printf " HOSTCC $(subst $(objutil)/,,$(@))\n"
206 $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
208 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
209 @printf " CC $(subst $(obj)/,,$(@))\n"
210 $(CC) -MMD $(CFLAGS) -c -o $@ $<
212 #######################################################################
215 rm -rf coreboot-builds
217 clean-for-update-target:
218 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
219 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
220 rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
221 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
222 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
223 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
224 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
225 rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
226 $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean OUT=$(abspath $(obj)) HOSTCC="$(HOSTCC)" CC="$(CC)" LD="$(LD)"
229 rm -f $(obj)/coreboot*
231 #######################################################################
232 # Development utilities
235 @echo ldscripts=$(ldscripts)
238 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
241 FAILED=0; LINTLOG=`mktemp`; \
242 for script in util/lint/$@-*; do \
243 echo; echo `basename $$script`; \
244 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
246 $$script > $$LINTLOG; \
247 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
248 printf "success\n\n"; \
250 echo test failed: ; \
253 FAILED=$$(( $$FAILED + 1 )); \
257 test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." && exit 1; }; \
261 for hook in commit-msg pre-commit; do if ! [ -x .git/hooks/$$hook ]; then cp util/gitconfig/$$hook .git/hooks/$$hook; chmod +x .git/hooks/$$hook; fi; done
262 (git config --global user.name >/dev/null && git config --global user.email >/dev/null) || (printf 'Please configure your name and email in git:\n\n git config --global user.name "Your Name Comes Here"\n git config --global user.email your.email@example.com\n'; exit 1)
264 crossgcc: clean-for-update
265 $(MAKE) -C util/crossgcc build-without-gdb
267 crosstools: clean-for-update
268 $(MAKE) -C util/crossgcc build
270 crossgcc-clean: clean-for-update
271 $(MAKE) -C util/crossgcc clean