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