tegra210_lp0: make sure to build with compiler.h included
[coreboot.git] / Makefile
blob1d4a4889aff1f0245a09783b5a7e21aba6c8a00d
1 ##
2 ## This file is part of the coreboot project.
3 ##
4 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
5 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
6 ## Copyright (C) 2009-2010 coresystems GmbH
7 ## Copyright (C) 2011 secunet Security Networks AG
8 ##
9 ## Redistribution and use in source and binary forms, with or without
10 ## modification, are permitted provided that the following conditions
11 ## are met:
12 ## 1. Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## 2. Redistributions in binary form must reproduce the above copyright
15 ## notice, this list of conditions and the following disclaimer in the
16 ## documentation and/or other materials provided with the distribution.
17 ## 3. The name of the author may not be used to endorse or promote products
18 ## derived from this software without specific prior written permission.
20 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 ## SUCH DAMAGE.
33 top := $(CURDIR)
34 src := src
35 srck := $(top)/util/kconfig
36 obj ?= build
37 override obj := $(subst $(top)/,,$(abspath $(obj)))
38 objutil ?= $(obj)/util
39 objk := $(objutil)/kconfig
40 absobj := $(abspath $(obj))
42 COREBOOT_EXPORTS := COREBOOT_EXPORTS
43 COREBOOT_EXPORTS += top src srck obj objutil objk
45 DOTCONFIG ?= $(top)/.config
46 KCONFIG_CONFIG = $(DOTCONFIG)
47 KCONFIG_AUTOHEADER := $(obj)/config.h
48 KCONFIG_AUTOCONFIG := $(obj)/auto.conf
49 KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
50 KCONFIG_SPLITCONFIG := $(obj)/config
51 KCONFIG_TRISTATE := $(obj)/tristate.conf
52 KCONFIG_NEGATIVES := 1
53 KCONFIG_STRICT := 1
55 COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
56 COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
57 COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
59 # directory containing the toplevel Makefile.inc
60 TOPLEVEL := .
62 CONFIG_SHELL := sh
63 KBUILD_DEFCONFIG := configs/defconfig
64 UNAME_RELEASE := $(shell uname -r)
65 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
66 MAKEFLAGS += -rR --no-print-directory
68 # Make is silent per default, but 'make V=1' will show all compiler calls.
69 Q:=@
70 ifneq ($(V),1)
71 ifneq ($(Q),)
72 .SILENT:
73 endif
74 endif
76 # Disable implicit/built-in rules to make Makefile errors fail fast.
77 .SUFFIXES:
79 HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
80 HOSTCXX = g++
81 HOSTCFLAGS := -g
82 HOSTCXXFLAGS := -g
84 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
86 DOXYGEN := doxygen
87 DOXYGEN_OUTPUT_DIR := doxygen
89 export $(COREBOOT_EXPORTS)
91 all: real-all
93 help_coreboot help::
94 @echo '*** coreboot platform targets ***'
95 @echo ' Use "make [target] V=1" for extra build debug information'
96 @echo ' all - Build coreboot'
97 @echo ' clean - Remove coreboot build artifacts'
98 @echo ' distclean - Remove build artifacts and config files'
99 @echo ' doxygen - Build doxygen documentation for coreboot'
100 @echo ' doxyplatform - Build doxygen documentation for the current platform'
101 @echo ' filelist - Show files used in current build'
102 @echo ' printall - print makefile info for debugging'
103 @echo ' gitconfig - set up git to submit patches to coreboot'
104 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
105 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
106 @echo
108 # This include must come _before_ the pattern rules below!
109 # Order _does_ matter for pattern rules.
110 include $(srck)/Makefile
112 # Three cases where we don't need fully populated $(obj) lists:
113 # 1. when no .config exists
114 # 2. when make config (in any flavour) is run
115 # 3. when make distclean is run
116 # Don't waste time on reading all Makefile.incs in these cases
117 ifeq ($(strip $(HAVE_DOTCONFIG)),)
118 NOCOMPILE:=1
119 endif
120 ifneq ($(MAKECMDGOALS),)
121 ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
122 NOCOMPILE:=1
123 endif
124 ifeq ($(MAKECMDGOALS), %clean)
125 NOMKDIR:=1
126 endif
127 endif
129 ifeq ($(NOCOMPILE),1)
130 include $(TOPLEVEL)/Makefile.inc
131 include $(TOPLEVEL)/payloads/Makefile.inc
132 include $(TOPLEVEL)/util/testing/Makefile.inc
133 -include $(TOPLEVEL)/site-local/Makefile.inc
134 real-all:
135 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
136 @echo "Please specify a config file or run 'make menuconfig' to" >&2
137 @echo "generate a new config file." >&2
138 @exit 1
139 else
141 include $(DOTCONFIG)
143 # in addition to the dependency below, create the file if it doesn't exist
144 # to silence stupid warnings about a file that would be generated anyway.
145 $(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
147 .xcompile: util/xcompile/xcompile
148 rm -f $@
149 $< $(XGCCPATH) > $@.tmp
150 \mv -f $@.tmp $@ 2> /dev/null
151 rm -f $@.tmp
153 -include .xcompile
155 ifneq ($(XCOMPILE_COMPLETE),1)
156 $(shell rm -f .xcompile)
157 $(error .xcompile deleted because it's invalid. \
158 Restarting the build should fix that, or explain the problem)
159 endif
161 ifneq ($(CONFIG_MMX),y)
162 CFLAGS_x86_32 += -mno-mmx
163 endif
165 include toolchain.inc
167 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
168 # fix makefile syntax highlighting after strip macro \" "))
170 # The primary target needs to be here before we include the
171 # other files
173 real-all: real-target
175 # must come rather early
176 .SECONDEXPANSION:
177 .DELETE_ON_ERROR:
179 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
180 +$(MAKE) oldconfig
182 # Add a new class of source/object files to the build system
183 add-class= \
184 $(eval $(1)-srcs:=) \
185 $(eval $(1)-objs:=) \
186 $(eval classes+=$(1))
188 # Special classes are managed types with special behaviour
189 # On parse time, for each entry in variable $(1)-y
190 # a handler $(1)-handler is executed with the arguments:
191 # * $(1): directory the parser is in
192 # * $(2): current entry
193 add-special-class= \
194 $(eval $(1):=) \
195 $(eval special-classes+=$(1))
197 # Converts one or more source file paths to their corresponding build/ paths.
198 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
199 # their name.
200 # $1 stage name
201 # $2 file path (list)
202 src-to-obj=\
203 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
204 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
205 $(patsubst 3rdparty/%,$(obj)/%,\
206 $(patsubst src/%,$(obj)/%,\
207 $(patsubst %.ads,%.o,\
208 $(patsubst %.adb,%.o,\
209 $(patsubst %.c,%.o,\
210 $(patsubst %.S,%.o,\
211 $(subst .$(1),,$(2))))))))))
213 # Converts one or more source file paths to the corresponding build/ paths
214 # of their Ada library information (.ali) files.
215 # $1 stage name
216 # $2 file path (list)
217 src-to-ali=\
218 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
219 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
220 $(patsubst 3rdparty/%,$(obj)/%,\
221 $(patsubst src/%,$(obj)/%,\
222 $(patsubst %.ads,%.ali,\
223 $(patsubst %.adb,%.ali,\
224 $(subst .$(1),,\
225 $(filter %.ads %.adb,$(2)))))))))
227 # Clean -y variables, include Makefile.inc
228 # Add paths to files in X-y to X-srcs
229 # Add subdirs-y to subdirs
230 includemakefiles= \
231 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
232 $(eval -include $(1)) \
233 $(foreach class,$(classes-y), $(call add-class,$(class))) \
234 $(foreach class,$(classes), \
235 $(eval $(class)-srcs+= \
236 $$(subst $(absobj)/,$(obj)/, \
237 $$(subst $(top)/,, \
238 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
239 $(foreach special,$(special-classes), \
240 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
241 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
243 # For each path in $(subdirs) call includemakefiles
244 # Repeat until subdirs is empty
245 evaluate_subdirs= \
246 $(eval cursubdirs:=$(subdirs)) \
247 $(eval subdirs:=) \
248 $(foreach dir,$(cursubdirs), \
249 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
250 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
252 # collect all object files eligible for building
253 subdirs:=$(TOPLEVEL)
254 postinclude-hooks :=
255 $(eval $(call evaluate_subdirs))
256 ifeq ($(FAILBUILD),1)
257 $(error cannot continue build)
258 endif
260 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
261 $(eval $(postinclude-hooks))
263 # Eliminate duplicate mentions of source files in a class
264 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
266 # To track dependencies, we need all Ada specification (.ads) files in
267 # *-srcs. Extract / filter all specification files that have a matching
268 # body (.adb) file here (specifications without a body are valid sources
269 # in Ada).
270 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
271 $(filter \
272 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
273 $(filter %.ads,$($(class)-srcs)))))
274 $(foreach class,$(classes),$(eval $(class)-srcs := \
275 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
277 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
278 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
280 # For Ada includes
281 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
283 # Save all objs before processing them (for dependency inclusion)
284 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
286 # Call post-processors if they're defined
287 $(foreach class,$(classes),\
288 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
290 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
291 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
292 alldirs:=$(sort $(abspath $(dir $(allobjs))))
294 # Reads dependencies from an Ada library information (.ali) file
295 # Only basenames (with suffix) are preserved so we have to look the
296 # paths up in $($(stage)-srcs).
297 # $1 stage name
298 # $2 ali file
299 create_ada_deps=$$(if $(2),\
300 gnat.adc \
301 $$(filter \
302 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
303 $$($(1)-srcs) $$($(1)-extra-specs)))
305 # macro to define template macros that are used by use_template macro
306 define create_cc_template
307 # $1 obj class
308 # $2 source suffix (c, S, ld, ...)
309 # $3 additional compiler flags
310 # $4 additional dependencies
311 ifn$(EMPTY)def $(1)-objs_$(2)_template
312 de$(EMPTY)fine $(1)-objs_$(2)_template
313 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
314 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(KCONFIG_AUTOHEADER) $(4)
315 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
316 $(GCC_$(1)) \
317 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
318 $(3) -c -o $$$$@ $$$$<
319 el$(EMPTY)se
320 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
321 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
322 $(CC_$(1)) \
323 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
324 $(3) -c -o $$$$@ $$$$<
325 end$(EMPTY)if
326 en$(EMPTY)def
327 end$(EMPTY)if
328 endef
330 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
331 $(foreach class,$(classes), \
332 $(foreach type,$(call filetypes-of-class,$(class)), \
333 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
334 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
335 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
337 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
338 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
340 # To supported complex package initializations, we need to call the
341 # emitted code explicitly. gnatbind gathers all the calls for us
342 # and exports them as a procedure $(stage)_adainit(). Every stage that
343 # uses Ada code has to call it!
344 define gnatbind_template
345 # $1 class
346 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
347 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
348 # We have to give gnatbind a simple filename (without leading
349 # path components) so just cd there.
350 cd $$(dir $$@) && \
351 $$(GNATBIND_$(1)) -a -n \
352 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
353 -L$(1)_ada -o $$(notdir $$@) \
354 $$(subst $$(dir $$@),,$$^)
355 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
356 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
357 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
358 $(1)-objs += $$(obj)/$(1)/b__$(1).o
359 $($(1)-alis): %.ali: %.o ;
360 endef
362 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
363 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
365 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
366 -include $(DEPENDENCIES)
368 printall:
369 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
370 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
371 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
372 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
373 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
374 endif
376 ifndef NOMKDIR
377 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
378 endif
380 $(obj)/project_filelist.txt:
381 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
382 echo "*** Error: Project must be built before generating file list ***"; \
383 exit 1; \
385 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
386 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
387 grep -v '\.o$$' > $(obj)/project_filelist.txt
389 filelist: $(obj)/project_filelist.txt
390 printf "\nFiles used in build:\n"
391 cat $(obj)/project_filelist.txt
393 #works with either exuberant ctags or ctags.emacs
394 ctags-project: clean-ctags $(obj)/project_filelist.txt
395 cat $(obj)/project_filelist.txt | \
396 xargs ctags -o tags
398 cscope-project: clean-cscope $(obj)/project_filelist.txt
399 cat $(obj)/project_filelist.txt | xargs cscope -b
401 cscope:
402 cscope -bR
404 doxy: doxygen
405 doxygen:
406 $(DOXYGEN) Documentation/Doxyfile.coreboot
408 doxygen_simple:
409 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
411 doxyplatform doxygen_platform: $(obj)/project_filelist.txt
412 echo
413 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
414 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
415 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
416 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
417 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
418 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
420 doxyclean: doxygen-clean
421 doxygen-clean:
422 rm -rf $(DOXYGEN_OUTPUT_DIR)
424 clean-for-update: doxygen-clean clean-for-update-target
425 rm -rf $(obj) .xcompile
427 clean: clean-for-update clean-target clean-utils
428 rm -f .ccwrap
430 clean-cscope:
431 rm -f cscope.out
433 clean-ctags:
434 rm -f tags
436 clean-utils:
437 $(foreach tool, $(TOOLLIST), \
438 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
440 distclean-utils:
441 $(foreach tool, $(TOOLLIST), \
442 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
443 rm -f /util/$(tool)/junit.xml;)
445 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
446 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
447 rm -rf coreboot-builds coreboot-builds-chromeos
448 rm -f abuild*.xml junit.xml* util/lint/junit.xml
450 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
451 .PHONY: ctags-project cscope-project clean-ctags