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