Include stdint.h in libpayload's rdtsc.h.
[coreboot.git] / Makefile.inc
blobe499bacc4e0052f2398df588406e3ec101a0db37
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.
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 2>/dev/null || git describe; else echo unknown; fi)
24 #######################################################################
25 # Basic component discovery
26 ARCHDIR-$(CONFIG_ARCH_X86) := x86
27 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
28 export MAINBOARDDIR
30 ## Final build results, which CBFSTOOL uses to create the final
31 ## rom image file, are placed under $(objcbfs).
32 ## These typically have suffixes .debug .elf .bin and .map
33 export objcbfs := $(obj)/cbfs/$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
35 ## Based on the active configuration, Makefile conditionally collects
36 ## the required assembly includes and saves them in a file.
37 ## Such files that do not have a clear one-to-one relation to a source
38 ## file under src/ are placed and built under $(objgenerated)
39 export objgenerated := $(obj)/generated
41 #######################################################################
42 # root rule to resolve if in build mode (ie. configuration exists)
43 real-target: $(obj)/config.h coreboot
44 coreboot: build-dirs $(obj)/coreboot.rom
46 #######################################################################
47 # our phony targets
48 PHONY+= clean-abuild coreboot lint lint-stable build-dirs
50 #######################################################################
51 # root source directories of coreboot
52 subdirs-y := src/lib src/boot src/console src/devices src/ec src/southbridge
53 subdirs-y += src/northbridge src/superio src/drivers src/cpu src/vendorcode
54 subdirs-y += util/cbfstool util/sconfig util/nvramtool
55 subdirs-y += src/arch/$(ARCHDIR-y)
56 subdirs-y += src/mainboard/$(MAINBOARDDIR)
58 subdirs-y += site-local
60 #######################################################################
61 # Add source classes and their build options
62 classes-y := ramstage romstage driver smm cpu_microcode
64 romstage-c-ccopts:=-D__PRE_RAM__
65 romstage-S-ccopts:=-D__PRE_RAM__
66 ifeq ($(CONFIG_TRACE),y)
67 ramstage-c-ccopts:= -finstrument-functions
68 endif
70 ifeq ($(CONFIG_USE_BLOBS),y)
71 forgetthis:=$(shell git submodule update --init --checkout 3rdparty)
72 else
73 ifeq ($(CONFIG_REQUIRES_BLOB),y)
74 $(error Your current configuration requires binary-only components, but you did not choose to use them)
75 endif
76 endif
78 smm-c-ccopts:=-D__SMM__
79 smm-S-ccopts:=-D__SMM__
81 # SMM TSEG base is dynamic
82 ifeq ($(CONFIG_SMM_TSEG),y)
83 smm-c-ccopts += -fpic
84 endif
86 ramstage-c-deps:=$$(OPTION_TABLE_H)
87 romstage-c-deps:=$$(OPTION_TABLE_H)
89 #######################################################################
90 # Add handler to compile ACPI's ASL
91 define ramstage-objs_asl_template
92 $(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h
93         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
94         $(CC) -x assembler-with-cpp -E -MMD -MT $$(@) -D__ACPI__ -P -include $(src)/include/kconfig.h -I$(obj) -I$(src) -I$(src)/include -I$(src)/arch/$(ARCHDIR-y)/include -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
95         cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$(basename $$@)).asl
96         mv $$(basename $$@).hex $$(basename $$@).c
97         $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
98         # keep %.o: %.c rule from catching the temporary .c file after a make clean
99         mv $$(basename $$@).c $$(basename $$@).hex
100 endef
102 #######################################################################
103 # Parse plaintext cmos defaults into binary format
104 # arg1: source file
105 # arg2: binary file name
106 cbfs-files-processor-nvramtool= \
107         $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
108                 printf "    CREATE     $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
110 #######################################################################
111 # Link VSA binary to ELF-ish stage
112 # arg1: source file
113 # arg2: binary file name
114 cbfs-files-processor-vsa= \
115         $(eval $(2): $(1) ; \
116                 printf "    CREATE     $(2) (from $(1))\n";  $(OBJCOPY) --set-start 0x20 --adjust-vma 0x60000 -I binary -O elf32-i386 -B i386 $(1) $(2).tmp && $(LD) -m elf_i386 -e 0x60020 --section-start .data=0x60000 $(2).tmp -o $(2))
118 #######################################################################
119 # Add handler for arbitrary files in CBFS
120 $(call add-special-class,cbfs-files)
121 cbfs-files-handler= \
122                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
123                 $(eval $(2)-file:=$(word 1, $(subst :, ,$($(2)-file)))) \
124                 $(if $(wildcard $(1)$($(2)-file)), \
125                         $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
126                         $(eval tmp-cbfs-file:= $($(2)-file))) \
127                 $(if $(tmp-cbfs-method), \
128                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
129                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
130                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
131                 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$($(2)-position)) \
132                 $(eval $(2)-name:=) \
133                 $(eval $(2)-type:=) \
134                 $(eval $(2)-compression:=) \
135                 $(eval $(2)-position:=)
137 #######################################################################
138 # a variety of flags for our build
139 CBFS_COMPRESS_FLAG:=
140 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
141 CBFS_COMPRESS_FLAG:=l
142 endif
144 CBFS_PAYLOAD_COMPRESS_FLAG:=
145 CBFS_PAYLOAD_COMPRESS_NAME:=none
146 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
147 CBFS_PAYLOAD_COMPRESS_FLAG:=l
148 CBFS_PAYLOAD_COMPRESS_NAME:=LZMA
149 endif
151 ifneq ($(CONFIG_LOCALVERSION),"")
152 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
153 endif
155 INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
156 INCLUDES += -Isrc/devices/oprom/include
157 # abspath is a workaround for romcc
158 INCLUDES += -include $(src)/include/kconfig.h
160 CFLAGS = $(INCLUDES) -Os -pipe -g -nostdinc
161 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
162 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
163 CFLAGS += -Wstrict-aliasing -Wshadow
164 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
165 CFLAGS += -Werror
166 endif
167 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
169 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options
171 #######################################################################
172 # generate build support files
173 $(obj)/build.h: .xcompile
174         @printf "    GEN        build.h\n"
175         rm -f $(obj)/build.h
176         printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
177         printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
178         printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
179         printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht
180         printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
181         printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
182         printf "#define COREBOOT_BUILD_YEAR `LANG= date +"%-y"`\n" >> $(obj)/build.ht
183         printf "#define COREBOOT_BUILD_MONTH `LANG= date +"%-m"` \n" >> $(obj)/build.ht
184         printf "#define COREBOOT_BUILD_DAY `LANG= date +"%-d"`\n" >> $(obj)/build.ht
185         printf "#define COREBOOT_BUILD_WEEKDAY `LANG= date +"%-u"`\n" >> $(obj)/build.ht
186         printf "#define COREBOOT_DMI_DATE \"`LANG= date +"%m/%d/%Y"`\"\n" >> $(obj)/build.ht
187         printf "\n" >> $(obj)/build.ht
188         printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
189         printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
190         printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
191         printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
192         printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
193         printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null || hostname 2>/dev/null)\"\n" >> $(obj)/build.ht
194         printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
195         printf "#endif\n" >> $(obj)/build.ht
196         mv $(obj)/build.ht $(obj)/build.h
198 $(obj)/ldoptions: $(obj)/config.h
199         awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
201 build-dirs:
202         mkdir -p $(objcbfs) $(objgenerated)
204 #######################################################################
205 # Build the tools
206 CBFSTOOL:=$(obj)/cbfstool
208 $(CBFSTOOL): $(objutil)/cbfstool/cbfstool
209         cp $< $@
211 _WINCHECK=$(shell uname -o 2> /dev/null)
212 STACK=
213 ifeq ($(_WINCHECK),Msys)
214         STACK=-Wl,--stack,16384000
215 endif
216 ifeq ($(_WINCHECK),Cygwin)
217         STACK=-Wl,--stack,16384000
218 endif
220 ROMCC:= $(objutil)/romcc/romcc
221 $(ROMCC): $(top)/util/romcc/romcc.c
222         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
223         @# Note: Adding -O2 here might cause problems. For details see:
224         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
225         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
227 #######################################################################
228 # needed objects that every mainboard uses
229 # Creation of these is architecture and mainboard independent
230 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(objutil)/sconfig/sconfig
231         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
232         mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
233         $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
235 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
236 romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
238 $(objutil)/%.o: $(objutil)/%.c
239         @printf "    HOSTCC     $(subst $(objutil)/,,$(@))\n"
240         $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
242 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
243         @printf "    CC         $(subst $(obj)/,,$(@))\n"
244         $(CC) -MMD $(CFLAGS) -c -o $@ $<
246 $(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
247         @printf "    CC         $(subst $(obj)/,,$(@))\n"
248         $(CC) -MMD -D__PRE_RAM__ $(CFLAGS) -c -o $@ $<
250 #######################################################################
251 # Clean up rules
252 clean-abuild:
253         rm -rf coreboot-builds
255 clean-for-update-target:
256         rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
257         rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
258         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
259         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
260         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
261         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
262         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
263         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
264         $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean OUT=$(abspath $(obj)) HOSTCC="$(HOSTCC)" CC="$(CC)" LD="$(LD)"
266 clean-target:
267         rm -f $(obj)/coreboot*
269 #######################################################################
270 # Development utilities
271 printcrt0s:
272         @echo crt0s=$(crt0s)
273         @echo ldscripts=$(ldscripts)
275 update:
276         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
278 lint lint-stable:
279         FAILED=0; LINTLOG=`mktemp .tmpconfig.lintXXXXX`; \
280         for script in util/lint/$@-*; do \
281                 echo; echo `basename $$script`; \
282                 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
283                 echo ========; \
284                 $$script > $$LINTLOG; \
285                 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
286                         printf "success\n\n"; \
287                 else \
288                         echo test failed: ; \
289                         cat $$LINTLOG; \
290                         rm -f $$LINTLOG; \
291                         FAILED=$$(( $$FAILED + 1 )); \
292                 fi; \
293                 echo ========; \
294         done; \
295         test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." &&  exit 1; }; \
296         rm -f $$LINTLOG
298 gitconfig:
299         mkdir -p .git/hooks
300         for hook in commit-msg pre-commit ; do                       \
301                 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o  \
302                 ! -x .git/hooks/$$hook ]; then                       \
303                         cp util/gitconfig/$$hook .git/hooks/$$hook;  \
304                         chmod +x .git/hooks/$$hook;                  \
305                 fi;                                                  \
306         done
307         (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)
309 crossgcc: clean-for-update
310         $(MAKE) -C util/crossgcc build-without-gdb
312 crosstools: clean-for-update
313         $(MAKE) -C util/crossgcc build
315 crossgcc-clean: clean-for-update
316         $(MAKE) -C util/crossgcc clean
318 tools: $(objutil)/kconfig/conf $(objutil)/cbfstool/cbfstool $(objutil)/nvramtool/nvramtool $(objutil)/romcc/romcc $(objutil)/sconfig/sconfig