Calculate transcoder flags based on pipe config
[coreboot.git] / Makefile.inc
blob0fb86ce643b98629b73218db6ef30ffc8d9f8118
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`" ]; \
23        then git describe --dirty --always || git describe; \
24        else echo 4.0$(KERNELREVISION); fi)
26 #######################################################################
27 # Basic component discovery
28 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
29 export MAINBOARDDIR
31 ## Final build results, which CBFSTOOL uses to create the final
32 ## rom image file, are placed under $(objcbfs).
33 ## These typically have suffixes .debug .elf .bin and .map
34 export objcbfs := $(obj)/cbfs/$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
36 ## Based on the active configuration, Makefile conditionally collects
37 ## the required assembly includes and saves them in a file.
38 ## Such files that do not have a clear one-to-one relation to a source
39 ## file under src/ are placed and built under $(objgenerated)
40 export objgenerated := $(obj)/generated
42 #######################################################################
43 # root rule to resolve if in build mode (ie. configuration exists)
44 real-target: $(obj)/config.h coreboot
45 coreboot: build-dirs $(obj)/coreboot.rom
47 #######################################################################
48 # our phony targets
49 PHONY+= clean-abuild coreboot lint lint-stable build-dirs
51 #######################################################################
52 # root source directories of coreboot
53 subdirs-y := src/lib src/console src/device src/ec src/southbridge
54 subdirs-y += src/northbridge src/superio src/drivers src/cpu src/vendorcode
55 subdirs-y += util/cbfstool util/sconfig util/nvramtool
56 subdirs-y += src/arch/$(ARCHDIR-y)
57 subdirs-y += src/mainboard/$(MAINBOARDDIR)
59 subdirs-y += site-local
61 #######################################################################
62 # Add source classes and their build options
63 classes-y := ramstage romstage bootblock smm smmstub cpu_microcode rmodules
65 #######################################################################
66 # Helper functions for ramstage postprocess
67 spc :=
68 spc +=
69 $(spc) :=
70 $(spc) +=
72 # files-in-dir-recursive,dir,files
73 files-in-dir-recursive=$(filter $(1)%,$(2))
75 # parent-dir,dir/
76 parent-dir=$(dir $(subst $( ),/,$(strip $(subst /, ,$(1)))))
78 # filters out exactly the directory specified
79 # filter-out-dir,dir_to_keep,dirs
80 filter-out-dir=$(filter-out $(1),$(2))
82 # filters out dir_to_keep and all its parents
83 # filter-out-dirs,dir_to_keep,dirs
84 filter-out-dirs=$(if $(filter-out ./,$(1)),$(call filter-out-dirs,$(call parent-dir,$(1)),$(call filter-out-dir,$(1),$(2))),$(call filter-out-dir,$(1),$(2)))
86 # dir-wildcards,dirs
87 dir-wildcards=$(addsuffix %,$(1))
89 # files-in-dir,dir,files
90 files-in-dir=$(filter-out $(call dir-wildcards,$(call filter-out-dirs,$(1),$(dir $(2)))),$(call files-in-dir-recursive,$(1),$(2)))
92 #######################################################################
93 # reduce command line length by linking the objects of each
94 # directory into an intermediate file
95 ramstage-postprocess=$(foreach d,$(sort $(dir $(1))), \
96         $(eval $(d)ramstage.o: $(call files-in-dir,$(d),$(1)); $$(LD) -o $$@ -r $$^ ) \
97         $(eval ramstage-objs:=$(d)ramstage.o $(filter-out $(call files-in-dir,$(d),$(1)),$(ramstage-objs))))
99 romstage-c-ccopts:=-D__PRE_RAM__
100 romstage-S-ccopts:=-D__PRE_RAM__
101 ifeq ($(CONFIG_TRACE),y)
102 ramstage-c-ccopts:= -finstrument-functions
103 endif
104 ifeq ($(CONFIG_COVERAGE),y)
105 ramstage-c-ccopts+=-fprofile-arcs -ftest-coverage
106 endif
108 ifeq ($(CONFIG_USE_BLOBS),y)
109 forgetthis:=$(shell git submodule update --init --checkout 3rdparty)
110 endif
112 bootblock-c-ccopts:=-D__BOOT_BLOCK__ -D__PRE_RAM__
113 bootblock-S-ccopts:=-D__BOOT_BLOCK__ -D__PRE_RAM__
115 smmstub-c-ccopts:=-D__SMM__
116 smmstub-S-ccopts:=-D__SMM__
117 smm-c-ccopts:=-D__SMM__
118 smm-S-ccopts:=-D__SMM__
120 # SMM TSEG base is dynamic
121 ifneq ($(CONFIG_SMM_MODULES),y)
122 ifeq ($(CONFIG_SMM_TSEG),y)
123 smm-c-ccopts += -fpic
124 endif
125 endif
127 ramstage-c-deps:=$$(OPTION_TABLE_H)
128 romstage-c-deps:=$$(OPTION_TABLE_H)
129 bootblock-c-deps:=$$(OPTION_TABLE_H)
130 smm-c-deps:=$$(OPTION_TABLE_H)
132 #######################################################################
133 # Add handler to compile ACPI's ASL
134 define ramstage-objs_asl_template
135 $(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h
136         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
137         $(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
138         cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$(basename $$@)).asl
139         mv $$(basename $$@).hex $$(basename $$@).c
140         $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
141         # keep %.o: %.c rule from catching the temporary .c file after a make clean
142         mv $$(basename $$@).c $$(basename $$@).hex
143 endef
145 #######################################################################
146 # Parse plaintext cmos defaults into binary format
147 # arg1: source file
148 # arg2: binary file name
149 cbfs-files-processor-nvramtool= \
150         $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
151                 printf "    CREATE     $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
153 #######################################################################
154 # Link VSA binary to ELF-ish stage
155 # arg1: source file
156 # arg2: binary file name
157 cbfs-files-processor-vsa= \
158         $(eval $(2): $(1) ; \
159                 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))
161 #######################################################################
162 # Add handler for arbitrary files in CBFS
163 $(call add-special-class,cbfs-files)
164 cbfs-files-handler= \
165                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
166                 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
167                 $(if $(wildcard $(1)$($(2)-file)), \
168                         $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
169                         $(eval tmp-cbfs-file:= $($(2)-file))) \
170                 $(if $(strip $($(2)-required)), \
171                         $(if $(wildcard $(tmp-cbfs-file)),, \
172                                 $(info This build configuration requires $($(2)-required)) \
173                                 $(eval FAILBUILD:=1) \
174                         )) \
175                 $(if $(tmp-cbfs-method), \
176                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
177                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
178                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
179                 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$($(2)-position)) \
180                 $(eval $(2)-name:=) \
181                 $(eval $(2)-type:=) \
182                 $(eval $(2)-compression:=) \
183                 $(eval $(2)-position:=) \
184                 $(eval $(2)-required:=)
186 #######################################################################
187 # a variety of flags for our build
188 CBFS_COMPRESS_FLAG:=none
189 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
190 CBFS_COMPRESS_FLAG:=LZMA
191 endif
193 CBFS_PAYLOAD_COMPRESS_FLAG:=none
194 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
195 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
196 endif
198 ifneq ($(CONFIG_LOCALVERSION),"")
199 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
200 endif
202 INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
203 INCLUDES += -Isrc/device/oprom/include
204 # abspath is a workaround for romcc
205 INCLUDES += -include $(src)/include/kconfig.h
207 CFLAGS = $(INCLUDES) -Os -pipe -g -nostdinc
208 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
209 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
210 CFLAGS += -Wstrict-aliasing -Wshadow
211 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
212 CFLAGS += -Werror
213 endif
214 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
216 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
217                    $(objutil)/ifdfake $(objutil)/options
219 #######################################################################
220 # generate build support files
221 $(obj)/build.h: .xcompile
222         @printf "    GEN        build.h\n"
223         rm -f $(obj)/build.h
224         printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
225         printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
226         printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
227         printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht
228         printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
229         printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
230         printf "#define COREBOOT_BUILD_YEAR_BCD 0x`LANG= date +"%y"`\n" >> $(obj)/build.ht
231         printf "#define COREBOOT_BUILD_MONTH_BCD 0x`LANG= date +"%m"`\n" >> $(obj)/build.ht
232         printf "#define COREBOOT_BUILD_DAY_BCD 0x`LANG= date +"%d"`\n" >> $(obj)/build.ht
233         printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x`LANG= date +"%w"`\n" >> $(obj)/build.ht
234         printf "#define COREBOOT_DMI_DATE \"`LANG= date +"%m/%d/%Y"`\"\n" >> $(obj)/build.ht
235         printf "\n" >> $(obj)/build.ht
236         printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
237         printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
238         printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
239         printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
240         printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
241         printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null || hostname 2>/dev/null)\"\n" >> $(obj)/build.ht
242         printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
243         printf "#endif\n" >> $(obj)/build.ht
244         mv $(obj)/build.ht $(obj)/build.h
246 $(obj)/ldoptions: $(obj)/config.h
247         awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
249 build-dirs:
250         mkdir -p $(objcbfs) $(objgenerated)
252 #######################################################################
253 # Build the tools
254 CBFSTOOL:=$(obj)/cbfstool
256 $(CBFSTOOL): $(objutil)/cbfstool/cbfstool
257         cp $< $@
259 _WINCHECK=$(shell uname -o 2> /dev/null)
260 STACK=
261 ifeq ($(_WINCHECK),Msys)
262         STACK=-Wl,--stack,16384000
263 endif
264 ifeq ($(_WINCHECK),Cygwin)
265         STACK=-Wl,--stack,16384000
266 endif
268 ROMCC:= $(objutil)/romcc/romcc
269 $(ROMCC): $(top)/util/romcc/romcc.c
270         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
271         @# Note: Adding -O2 here might cause problems. For details see:
272         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
273         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
275 IFDTOOL:=$(objutil)/ifdtool/ifdtool
276 $(IFDTOOL): $(top)/util/ifdtool/ifdtool.c
277         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
278         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
280 IFDFAKE:=$(objutil)/ifdfake/ifdfake
281 $(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
282         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
283         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
285 #######################################################################
286 # needed objects that every mainboard uses
287 # Creation of these is architecture and mainboard independent
288 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(objutil)/sconfig/sconfig
289         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
290         mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
291         $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
293 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
294 romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
296 $(objutil)/%.o: $(objutil)/%.c
297         @printf "    HOSTCC     $(subst $(objutil)/,,$(@))\n"
298         $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
300 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
301         @printf "    CC         $(subst $(obj)/,,$(@))\n"
302         $(CC) -MMD $(CFLAGS) -c -o $@ $<
304 $(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
305         @printf "    CC         $(subst $(obj)/,,$(@))\n"
306         $(CC) -MMD -D__PRE_RAM__ $(CFLAGS) -c -o $@ $<
308 $(obj)/%.bootblock.o $(abspath $(obj))/%.bootblock.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
309         @printf "    CC         $(subst $(obj)/,,$(@))\n"
310         $(CC) -MMD $(bootblock-c-ccopts) $(CFLAGS) -c -o $@ $<
312 #######################################################################
313 # Clean up rules
314 clean-abuild:
315         rm -rf coreboot-builds
317 clean-for-update-target:
318         rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
319         rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
320         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
321         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
322         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
323         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
324         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
325         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
326         $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean OUT=$(abspath $(obj)) HOSTCC="$(HOSTCC)" CC="$(CC)" LD="$(LD)"
328 clean-target:
329         rm -f $(obj)/coreboot*
331 #######################################################################
332 # Development utilities
333 printcrt0s:
334         @echo crt0s=$(crt0s)
335         @echo ldscripts=$(ldscripts)
337 update:
338         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
340 lint lint-stable:
341         FAILED=0; LINTLOG=`mktemp .tmpconfig.lintXXXXX`; \
342         for script in util/lint/$@-*; do \
343                 echo; echo `basename $$script`; \
344                 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
345                 echo ========; \
346                 $$script > $$LINTLOG; \
347                 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
348                         printf "success\n\n"; \
349                 else \
350                         echo test failed: ; \
351                         cat $$LINTLOG; \
352                         rm -f $$LINTLOG; \
353                         FAILED=$$(( $$FAILED + 1 )); \
354                 fi; \
355                 echo ========; \
356         done; \
357         test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." &&  exit 1; }; \
358         rm -f $$LINTLOG
360 gitconfig:
361         mkdir -p .git/hooks
362         for hook in commit-msg pre-commit ; do                       \
363                 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o  \
364                 ! -x .git/hooks/$$hook ]; then                       \
365                         cp util/gitconfig/$$hook .git/hooks/$$hook;  \
366                         chmod +x .git/hooks/$$hook;                  \
367                 fi;                                                  \
368         done
369         git config remote.origin.push HEAD:refs/for/master
370         (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)
372 crossgcc: clean-for-update
373         $(MAKE) -C util/crossgcc build-without-gdb
375 crosstools: clean-for-update
376         $(MAKE) -C util/crossgcc build
378 crossgcc-clean: clean-for-update
379         $(MAKE) -C util/crossgcc clean
381 tools: $(objutil)/kconfig/conf $(objutil)/cbfstool/cbfstool $(objutil)/nvramtool/nvramtool $(objutil)/romcc/romcc $(objutil)/sconfig/sconfig