Documentation/releases: Finalize 4.11, start 4.12
[coreboot.git] / Makefile
blobf3f9592649433e5434e80d69d7670179366fcabc
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 ifneq ($(words $(CURDIR)),1)
34 $(error Error: Path to the main directory cannot contain spaces)
35 endif
36 top := $(CURDIR)
37 src := src
38 srck := $(top)/util/kconfig
39 obj ?= build
40 override obj := $(subst $(top)/,,$(abspath $(obj)))
41 objutil ?= $(obj)/util
42 objk := $(objutil)/kconfig
43 absobj := $(abspath $(obj))
45 COREBOOT_EXPORTS := COREBOOT_EXPORTS
46 COREBOOT_EXPORTS += top src srck obj objutil objk
48 # reproducible builds
49 LANG:=C
50 LC_ALL:=C
51 TZ:=UTC0
52 COREBOOT_EXPORTS += LANG LC_ALL TZ
54 DOTCONFIG ?= $(top)/.config
55 KCONFIG_CONFIG = $(DOTCONFIG)
56 KCONFIG_AUTOADS := $(obj)/cb-config.ads
57 KCONFIG_AUTOHEADER := $(obj)/config.h
58 KCONFIG_AUTOCONFIG := $(obj)/auto.conf
59 KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
60 KCONFIG_SPLITCONFIG := $(obj)/config
61 KCONFIG_TRISTATE := $(obj)/tristate.conf
62 KCONFIG_NEGATIVES := 1
63 KCONFIG_STRICT := 1
64 KCONFIG_PACKAGE := CB.Config
66 COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
67 COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
68 COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
69 COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
71 # directory containing the toplevel Makefile.inc
72 TOPLEVEL := .
74 CONFIG_SHELL := sh
75 KBUILD_DEFCONFIG := configs/defconfig
76 UNAME_RELEASE := $(shell uname -r)
77 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
78 MAKEFLAGS += -rR --no-print-directory
80 # Make is silent per default, but 'make V=1' will show all compiler calls.
81 Q:=@
82 ifneq ($(V),1)
83 ifneq ($(Q),)
84 .SILENT:
85 endif
86 endif
88 # Disable implicit/built-in rules to make Makefile errors fail fast.
89 .SUFFIXES:
91 HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
92 HOSTCXX = g++
93 HOSTCFLAGS := -g
94 HOSTCXXFLAGS := -g
96 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
98 DOXYGEN := doxygen
99 DOXYGEN_OUTPUT_DIR := doxygen
101 export $(COREBOOT_EXPORTS)
103 all: real-all
105 help_coreboot help::
106 @echo '*** coreboot platform targets ***'
107 @echo ' Use "make [target] V=1" for extra build debug information'
108 @echo ' all - Build coreboot'
109 @echo ' clean - Remove coreboot build artifacts'
110 @echo ' distclean - Remove build artifacts and config files'
111 @echo ' doxygen - Build doxygen documentation for coreboot'
112 @echo ' doxyplatform - Build doxygen documentation for the current platform'
113 @echo ' filelist - Show files used in current build'
114 @echo ' printall - print makefile info for debugging'
115 @echo ' gitconfig - set up git to submit patches to coreboot'
116 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
117 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
118 @echo
120 # This include must come _before_ the pattern rules below!
121 # Order _does_ matter for pattern rules.
122 include $(srck)/Makefile
124 # Three cases where we don't need fully populated $(obj) lists:
125 # 1. when no .config exists
126 # 2. when make config (in any flavour) is run
127 # 3. when make distclean is run
128 # Don't waste time on reading all Makefile.incs in these cases
129 ifeq ($(strip $(HAVE_DOTCONFIG)),)
130 NOCOMPILE:=1
131 endif
132 ifneq ($(MAKECMDGOALS),)
133 ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
134 NOCOMPILE:=1
135 endif
136 ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
137 NOMKDIR:=1
138 endif
139 endif
141 .xcompile: util/xcompile/xcompile
142 rm -f $@
143 $< $(XGCCPATH) > $@.tmp
144 \mv -f $@.tmp $@ 2> /dev/null
145 rm -f $@.tmp
147 ifeq ($(NOCOMPILE),1)
148 include $(TOPLEVEL)/Makefile.inc
149 include $(TOPLEVEL)/payloads/Makefile.inc
150 include $(TOPLEVEL)/util/testing/Makefile.inc
151 -include $(TOPLEVEL)/site-local/Makefile.inc
152 real-all:
153 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
154 @echo "Please specify a config file or run 'make menuconfig' to" >&2
155 @echo "generate a new config file." >&2
156 @exit 1
157 else
159 include $(DOTCONFIG)
161 # in addition to the dependency below, create the file if it doesn't exist
162 # to silence stupid warnings about a file that would be generated anyway.
163 $(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
165 -include .xcompile
167 ifneq ($(XCOMPILE_COMPLETE),1)
168 $(shell rm -f .xcompile)
169 $(error .xcompile deleted because it's invalid. \
170 Restarting the build should fix that, or explain the problem)
171 endif
173 ifneq ($(CONFIG_MMX),y)
174 CFLAGS_x86_32 += -mno-mmx
175 endif
177 include toolchain.inc
179 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
180 # fix makefile syntax highlighting after strip macro \" "))
182 # The primary target needs to be here before we include the
183 # other files
185 real-all: real-target
187 # must come rather early
188 .SECONDEXPANSION:
189 .DELETE_ON_ERROR:
191 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
192 +$(MAKE) oldconfig
194 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
195 true
197 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
198 $(objutil)/kconfig/toada CB.Config <$< >$@
200 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
201 cp $< $@
203 # Add a new class of source/object files to the build system
204 add-class= \
205 $(eval $(1)-srcs:=) \
206 $(eval $(1)-objs:=) \
207 $(eval classes+=$(1))
209 # Special classes are managed types with special behaviour
210 # On parse time, for each entry in variable $(1)-y
211 # a handler $(1)-handler is executed with the arguments:
212 # * $(1): directory the parser is in
213 # * $(2): current entry
214 add-special-class= \
215 $(eval $(1):=) \
216 $(eval special-classes+=$(1))
218 # Converts one or more source file paths to their corresponding build/ paths.
219 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
220 # their name.
221 # $1 stage name
222 # $2 file path (list)
223 src-to-obj=\
224 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
225 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
226 $(patsubst 3rdparty/%,$(obj)/%,\
227 $(patsubst src/%,$(obj)/%,\
228 $(patsubst %.ads,%.o,\
229 $(patsubst %.adb,%.o,\
230 $(patsubst %.c,%.o,\
231 $(patsubst %.S,%.o,\
232 $(subst .$(1),,$(2))))))))))
234 # Converts one or more source file paths to the corresponding build/ paths
235 # of their Ada library information (.ali) files.
236 # $1 stage name
237 # $2 file path (list)
238 src-to-ali=\
239 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
240 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
241 $(patsubst 3rdparty/%,$(obj)/%,\
242 $(patsubst src/%,$(obj)/%,\
243 $(patsubst %.ads,%.ali,\
244 $(patsubst %.adb,%.ali,\
245 $(subst .$(1),,\
246 $(filter %.ads %.adb,$(2)))))))))
248 # Clean -y variables, include Makefile.inc
249 # Add paths to files in X-y to X-srcs
250 # Add subdirs-y to subdirs
251 includemakefiles= \
252 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
253 $(eval -include $(1)) \
254 $(foreach class,$(classes-y), $(call add-class,$(class))) \
255 $(foreach special,$(special-classes), \
256 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
257 $(foreach class,$(classes), \
258 $(eval $(class)-srcs+= \
259 $$(subst $(absobj)/,$(obj)/, \
260 $$(subst $(top)/,, \
261 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
262 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
264 # For each path in $(subdirs) call includemakefiles
265 # Repeat until subdirs is empty
266 evaluate_subdirs= \
267 $(eval cursubdirs:=$(subdirs)) \
268 $(eval subdirs:=) \
269 $(foreach dir,$(cursubdirs), \
270 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
271 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
273 # collect all object files eligible for building
274 subdirs:=$(TOPLEVEL)
275 postinclude-hooks :=
276 $(eval $(call evaluate_subdirs))
277 ifeq ($(FAILBUILD),1)
278 $(error cannot continue build)
279 endif
281 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
282 $(eval $(postinclude-hooks))
284 # Eliminate duplicate mentions of source files in a class
285 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
287 # Build Kconfig .ads if necessary
288 ifeq ($(CONFIG_RAMSTAGE_ADA),y)
289 ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
290 endif
292 # To track dependencies, we need all Ada specification (.ads) files in
293 # *-srcs. Extract / filter all specification files that have a matching
294 # body (.adb) file here (specifications without a body are valid sources
295 # in Ada).
296 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
297 $(filter \
298 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
299 $(filter %.ads,$($(class)-srcs)))))
300 $(foreach class,$(classes),$(eval $(class)-srcs := \
301 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
303 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
304 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
306 # For Ada includes
307 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
309 # Save all objs before processing them (for dependency inclusion)
310 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
312 # Call post-processors if they're defined
313 $(foreach class,$(classes),\
314 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
316 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
317 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
318 alldirs:=$(sort $(abspath $(dir $(allobjs))))
320 # Reads dependencies from an Ada library information (.ali) file
321 # Only basenames (with suffix) are preserved so we have to look the
322 # paths up in $($(stage)-srcs).
323 # $1 stage name
324 # $2 ali file
325 create_ada_deps=$$(if $(2),\
326 gnat.adc \
327 $$(filter \
328 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
329 $$($(1)-srcs) $$($(1)-extra-specs)))
331 # macro to define template macros that are used by use_template macro
332 define create_cc_template
333 # $1 obj class
334 # $2 source suffix (c, S, ld, ...)
335 # $3 additional compiler flags
336 # $4 additional dependencies
337 ifn$(EMPTY)def $(1)-objs_$(2)_template
338 de$(EMPTY)fine $(1)-objs_$(2)_template
339 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
340 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
341 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
342 $(GCC_$(1)) \
343 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
344 $(3) -c -o $$$$@ $$$$<
345 el$(EMPTY)se
346 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
347 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
348 $(CC_$(1)) \
349 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
350 $(3) -c -o $$$$@ $$$$<
351 end$(EMPTY)if
352 en$(EMPTY)def
353 end$(EMPTY)if
354 endef
356 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
357 $(foreach class,$(classes), \
358 $(foreach type,$(call filetypes-of-class,$(class)), \
359 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
360 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
361 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
363 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
364 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
366 # To supported complex package initializations, we need to call the
367 # emitted code explicitly. gnatbind gathers all the calls for us
368 # and exports them as a procedure $(stage)_adainit(). Every stage that
369 # uses Ada code has to call it!
370 define gnatbind_template
371 # $1 class
372 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
373 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
374 # We have to give gnatbind a simple filename (without leading
375 # path components) so just cd there.
376 cd $$(dir $$@) && \
377 $$(GNATBIND_$(1)) -a -n \
378 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
379 -L$(1)_ada -o $$(notdir $$@) \
380 $$(subst $$(dir $$@),,$$^)
381 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
382 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
383 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
384 $(1)-objs += $$(obj)/$(1)/b__$(1).o
385 $($(1)-alis): %.ali: %.o ;
386 endef
388 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
389 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
391 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
392 -include $(DEPENDENCIES)
394 printall:
395 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
396 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
397 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
398 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
399 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
400 endif
402 ifndef NOMKDIR
403 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
404 endif
406 $(obj)/project_filelist.txt:
407 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
408 echo "*** Error: Project must be built before generating file list ***"; \
409 exit 1; \
411 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
412 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
413 grep -v '\.o$$' > $(obj)/project_filelist.txt
415 filelist: $(obj)/project_filelist.txt
416 printf "\nFiles used in build:\n"
417 cat $(obj)/project_filelist.txt
419 #works with either exuberant ctags or ctags.emacs
420 ctags-project: clean-ctags $(obj)/project_filelist.txt
421 cat $(obj)/project_filelist.txt | \
422 xargs ctags -o tags
424 cscope-project: clean-cscope $(obj)/project_filelist.txt
425 cat $(obj)/project_filelist.txt | xargs cscope -b
427 cscope:
428 cscope -bR
430 doxy: doxygen
431 doxygen:
432 $(DOXYGEN) Documentation/Doxyfile.coreboot
434 doxygen_simple:
435 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
437 doxyplatform doxygen_platform: $(obj)/project_filelist.txt
438 echo
439 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
440 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
441 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
442 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
443 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
444 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
446 doxyclean: doxygen-clean
447 doxygen-clean:
448 rm -rf $(DOXYGEN_OUTPUT_DIR)
450 clean-for-update: doxygen-clean clean-for-update-target
451 rm -rf $(obj) .xcompile
453 clean: clean-for-update clean-target clean-utils
454 rm -f .ccwrap
456 clean-cscope:
457 rm -f cscope.out
459 clean-ctags:
460 rm -f tags
462 clean-utils:
463 $(foreach tool, $(TOOLLIST), \
464 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
466 distclean-utils:
467 $(foreach tool, $(TOOLLIST), \
468 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
469 rm -f /util/$(tool)/junit.xml;)
471 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
472 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
473 rm -rf coreboot-builds coreboot-builds-chromeos
474 rm -f abuild*.xml junit.xml* util/lint/junit.xml
476 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
477 .PHONY: ctags-project cscope-project clean-ctags