Provide mechanism to local additions to the build
[coreboot.git] / Makefile.inc
1 ##
2 ## This file is part of the coreboot project.
3 ##
4 ## Copyright (C) 2011 secunet Security Networks AG
5 ##
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.
9 ##
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.
14 ##
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
18 ##
19
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)
23
24 #######################################################################
25 # Basic component discovery
26 ARCHDIR-$(CONFIG_ARCH_X86) := x86
27 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
28 export MAINBOARDDIR
29
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
34
35 #######################################################################
36 # our phony targets
37 PHONY+= clean-abuild coreboot
38
39 #######################################################################
40 # root source directories of coreboot
41 subdirs-y := src/lib src/boot src/console src/devices src/ec src/southbridge src/northbridge src/superio src/drivers src/cpu
42 subdirs-y += util/cbfstool util/sconfig
43 subdirs-y += src/arch/$(ARCHDIR-y)
44 subdirs-y += src/mainboard/$(MAINBOARDDIR)
45
46 subdirs-$(CONFIG_ARCH_X86) += src/pc80
47
48 subdirs-y += site-local
49
50 #######################################################################
51 # Add source classes and their build options
52 classes-y := ramstage romstage driver smm
53
54 romstage-c-ccopts:=-D__PRE_RAM__
55 romstage-S-ccopts:=-D__PRE_RAM__
56 ifeq ($(CONFIG_TRACE),y)
57 ramstage-c-ccopts:= -finstrument-functions
58 endif
59
60 smm-c-ccopts:=-D__SMM__
61 smm-S-ccopts:=-D__SMM__
62
63 ramstage-c-deps:=$$(OPTION_TABLE_H)
64 romstage-c-deps:=$$(OPTION_TABLE_H)
65
66 #######################################################################
67 # Add handler to compile ACPI's ASL
68 define ramstage-objs_asl_template
69 $(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h
70         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
71         $(CC) -x assembler-with-cpp -E -MMD -MT $$(@) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
72         cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$(basename $$@)).asl
73         mv $$(basename $$@).hex $$(basename $$@).c
74         $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
75         # keep %.o: %.c rule from catching the temporary .c file after a make clean
76         mv $$(basename $$@).c $$(basename $$@).hex
77 endef
78
79 #######################################################################
80 # Add handler for arbitrary files in CBFS
81 $(call add-special-class,cbfs-files)
82 cbfs-files-handler= \
83                 $(if $(wildcard $(1)$($(2)-file)), \
84                         $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
85                         $(eval tmp-cbfs-file:= $($(2)-file))) \
86                 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-position)) \
87                 $(eval $(2)-name:=) \
88                 $(eval $(2)-type:=) \
89                 $(eval $(2)-position:=)
90
91 #######################################################################
92 # a variety of flags for our build
93 CBFS_COMPRESS_FLAG:=
94 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
95 CBFS_COMPRESS_FLAG:=l
96 endif
97
98 CBFS_PAYLOAD_COMPRESS_FLAG:=
99 CBFS_PAYLOAD_COMPRESS_NAME:=none
100 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
101 CBFS_PAYLOAD_COMPRESS_FLAG:=l
102 CBFS_PAYLOAD_COMPRESS_NAME:=LZMA
103 endif
104
105 ifneq ($(CONFIG_LOCALVERSION),"")
106 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
107 endif
108
109 INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
110 INCLUDES += -Isrc/devices/oprom/include
111 # abspath is a workaround for romcc
112 INCLUDES += -include $(abspath $(obj)/config.h)
113
114 CFLAGS = $(INCLUDES) -Os -pipe -g -nostdinc
115 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
116 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
117 CFLAGS += -Wstrict-aliasing -Wshadow
118 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
119 CFLAGS += -Werror
120 endif
121 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
122
123 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options
124
125 #######################################################################
126 # generate build support files
127 $(obj)/build.h: .xcompile
128         @printf "    GEN        build.h\n"
129         rm -f $(obj)/build.h
130         printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
131         printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
132         printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
133         printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht
134         printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
135         printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
136         printf "#define COREBOOT_DMI_DATE \"`LANG= date +"%m/%d/%Y"`\"\n" >> $(obj)/build.ht
137         printf "\n" >> $(obj)/build.ht
138         printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
139         printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
140         printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
141         printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
142         printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
143         printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht
144         printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
145         printf "#endif\n" >> $(obj)/build.ht
146         mv $(obj)/build.ht $(obj)/build.h
147
148 $(obj)/ldoptions: $(obj)/config.h
149         awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
150
151 #######################################################################
152 # Build the tools
153 CBFSTOOL:=$(obj)/cbfstool
154
155 $(CBFSTOOL): $(objutil)/cbfstool/cbfstool
156         cp $< $@
157
158 _WINCHECK=$(shell uname -o 2> /dev/null)
159 STACK=
160 ifeq ($(_WINCHECK),Msys)
161         STACK=-Wl,--stack,16384000
162 endif
163 ifeq ($(_WINCHECK),Cygwin)
164         STACK=-Wl,--stack,16384000
165 endif
166
167 ROMCC:= $(objutil)/romcc/romcc
168 $(ROMCC): $(top)/util/romcc/romcc.c
169         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
170         @# Note: Adding -O2 here might cause problems. For details see:
171         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
172         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
173
174 #######################################################################
175 # needed objects that every mainboard uses
176 # Creation of these is architecture and mainboard independent
177 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(objutil)/sconfig/sconfig
178         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
179         mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
180         $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
181
182 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
183
184 $(objutil)/%.o: $(objutil)/%.c
185         @printf "    HOSTCC     $(subst $(objutil)/,,$(@))\n"
186         $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
187
188 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
189         @printf "    CC         $(subst $(obj)/,,$(@))\n"
190         $(CC) -MMD $(CFLAGS) -c -o $@ $<
191
192 #######################################################################
193 # Clean up rules
194 clean-abuild:
195         rm -rf coreboot-builds
196
197 clean-for-update-target:
198         rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
199         rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
200         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
201         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
202         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
203         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
204         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
205         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
206         $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean
207
208 clean-target:
209         rm -f $(obj)/coreboot*
210
211 #######################################################################
212 # Development utilities
213 printcrt0s:
214         @echo crt0s=$(crt0s)
215         @echo ldscripts=$(ldscripts)
216
217 update:
218         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
219
220 lint:
221         FAILED=0; LINTLOG=`mktemp`; \
222         for script in util/lint/lint-*; do \
223                 echo; echo `basename $$script`; \
224                 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
225                 echo ========; \
226                 $$script > $$LINTLOG; \
227                 if [ `wc -l $$LINTLOG | cut -d' ' -f1` -eq 0 ]; then \
228                         printf "success\n\n"; \
229                 else \
230                         echo test failed: ; \
231                         cat $$LINTLOG; \
232                         rm -f $$LINTLOG; \
233                         FAILED=$$(( $$FAILED + 1 )); \
234                 fi; \
235                 echo ========; \
236         done; \
237         test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." &&  exit 1; }; \
238         rm -f $$LINTLOG
239
240 gitconfig:
241         if ! [ -x .git/hooks/commit-msg ]; then cp util/gitconfig/commit-msg .git/hooks/commit-msg; chmod +x .git/hooks/commit-msg; fi
242         (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)
243
244 crossgcc: clean-for-update
245         $(MAKE) -C util/crossgcc build-without-gdb
246
247 crosstools: clean-for-update
248         $(MAKE) -C util/crossgcc build
249
250 crossgcc-clean: clean-for-update
251         $(MAKE) -C util/crossgcc clean
252