mb/google/rex: Enable ACPI and add ACPI table
[coreboot.git] / Makefile
blobf9bb258de9f2202a427a2fc86d2b859258030d33
1 ## SPDX-License-Identifier: BSD-3-Clause
3 ifneq ($(words $(CURDIR)),1)
4 $(error Error: Path to the main directory cannot contain spaces)
5 endif
6 top := $(CURDIR)
7 src := src
8 srck := $(top)/util/kconfig
9 obj ?= build
10 override obj := $(subst $(top)/,,$(abspath $(obj)))
11 xcompile ?= $(obj)/xcompile
12 objutil ?= $(obj)/util
13 objk := $(objutil)/kconfig
14 absobj := $(abspath $(obj))
16 additional-dirs :=
18 VBOOT_HOST_BUILD ?= $(abspath $(objutil)/vboot_lib)
20 COREBOOT_EXPORTS := COREBOOT_EXPORTS
21 COREBOOT_EXPORTS += top src srck obj objutil objk
23 DOTCONFIG ?= $(top)/.config
24 KCONFIG_CONFIG = $(DOTCONFIG)
25 KCONFIG_AUTOADS := $(obj)/cb-config.ads
26 KCONFIG_AUTOHEADER := $(obj)/config.h
27 KCONFIG_AUTOCONFIG := $(obj)/auto.conf
28 KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
29 KCONFIG_SPLITCONFIG := $(obj)/config/
30 KCONFIG_TRISTATE := $(obj)/tristate.conf
31 KCONFIG_NEGATIVES := 1
32 KCONFIG_STRICT := 1
33 KCONFIG_PACKAGE := CB.Config
35 COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
36 COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
37 COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
38 COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
40 # directory containing the toplevel Makefile.inc
41 TOPLEVEL := .
43 CONFIG_SHELL := sh
44 KBUILD_DEFCONFIG := configs/defconfig
45 UNAME_RELEASE := $(shell uname -r)
46 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
47 MAKEFLAGS += -rR --no-print-directory
49 # Make is silent per default, but 'make V=1' will show all compiler calls.
50 Q:=@
51 ifneq ($(V),1)
52 ifneq ($(Q),)
53 .SILENT:
54 MAKEFLAGS += -s
55 quiet_errors := 2>/dev/null
56 endif
57 endif
59 # Disable implicit/built-in rules to make Makefile errors fail fast.
60 .SUFFIXES:
62 HOSTCFLAGS := -g
63 HOSTCXXFLAGS := -g
65 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
67 export $(COREBOOT_EXPORTS)
69 all: real-all
71 help_coreboot help::
72 @echo '*** coreboot platform targets ***'
73 @echo ' Use "make [target] V=1" for extra build debug information'
74 @echo ' all - Build coreboot'
75 @echo ' clean - Remove coreboot build artifacts'
76 @echo ' distclean - Remove build artifacts and config files'
77 @echo ' sphinx - Build sphinx documentation for coreboot'
78 @echo ' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
79 @echo ' filelist - Show files used in current build'
80 @echo ' printall - print makefile info for debugging'
81 @echo ' gitconfig - set up git to submit patches to coreboot'
82 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
83 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
84 @echo
86 # This include must come _before_ the pattern rules below!
87 # Order _does_ matter for pattern rules.
88 include $(srck)/Makefile.inc
90 # Three cases where we don't need fully populated $(obj) lists:
91 # 1. when no .config exists
92 # 2. when make config (in any flavour) is run
93 # 3. when make distclean is run
94 # Don't waste time on reading all Makefile.incs in these cases
95 ifeq ($(strip $(HAVE_DOTCONFIG)),)
96 NOCOMPILE:=1
97 endif
98 ifneq ($(MAKECMDGOALS),)
99 ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
100 NOCOMPILE:=1
101 endif
102 ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
103 NOMKDIR:=1
104 UNIT_TEST:=1
105 endif
106 endif
108 ifneq ($(filter help%, $(MAKECMDGOALS)), )
109 NOCOMPILE:=1
110 UNIT_TEST:=1
111 else
112 ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
113 ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
114 $(error Cannot mix unit-tests targets with other targets)
115 endif
116 UNIT_TEST:=1
117 NOCOMPILE:=
118 endif
119 endif
121 $(xcompile): util/xcompile/xcompile
122 rm -f $@
123 $< $(XGCCPATH) > $@.tmp
124 \mv -f $@.tmp $@ 2> /dev/null
125 rm -f $@.tmp
127 ifeq ($(NOCOMPILE),1)
128 # We also don't use .xcompile in the no-compile situations, so
129 # provide some reasonable defaults.
130 HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
131 HOSTCXX ?= g++
133 include $(TOPLEVEL)/Makefile.inc
134 include $(TOPLEVEL)/payloads/Makefile.inc
135 include $(TOPLEVEL)/util/testing/Makefile.inc
136 -include $(TOPLEVEL)/site-local/Makefile.inc
137 include $(TOPLEVEL)/tests/Makefile.inc
138 real-all:
139 @echo "Error: Trying to build, but NOCOMPILE is set." >&2
140 @echo " Please file a bug with the following information:"
141 @echo "- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
142 @echo "- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
143 @echo "- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
144 @exit 1
145 else
147 ifneq ($(UNIT_TEST),1)
148 include $(DOTCONFIG)
149 endif
151 # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
152 # wait for make to generate the file.
153 $(if $(wildcard $(xcompile)),, $(shell \
154 mkdir -p $(dir $(xcompile)) && \
155 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
157 include $(xcompile)
159 ifneq ($(XCOMPILE_COMPLETE),1)
160 $(shell rm -f $(xcompile))
161 $(error $(xcompile) deleted because it's invalid. \
162 Restarting the build should fix that, or explain the problem)
163 endif
165 # reproducible builds
166 LANG:=C
167 LC_ALL:=C
168 TZ:=UTC0
169 ifneq ($(NOCOMPILE),1)
170 SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
171 endif
172 # don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
173 # are reproducible
174 export LANG LC_ALL TZ SOURCE_DATE_EPOCH
176 ifneq ($(CONFIG_MMX),y)
177 CFLAGS_x86_32 += -mno-mmx
178 endif
180 ifneq ($(UNIT_TEST),1)
181 include toolchain.inc
182 endif
184 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
185 # fix makefile syntax highlighting after strip macro \" "))
187 # The primary target needs to be here before we include the
188 # other files
190 real-all: real-target
192 # must come rather early
193 .SECONDARY:
194 .SECONDEXPANSION:
195 .DELETE_ON_ERROR:
197 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
198 $(MAKE) olddefconfig
199 $(MAKE) syncconfig
201 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
202 true
204 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
205 $(objutil)/kconfig/toada CB.Config <$< >$@
207 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
208 cp $< $@
210 # Add a new class of source/object files to the build system
211 add-class= \
212 $(eval $(1)-srcs:=) \
213 $(eval $(1)-objs:=) \
214 $(eval classes+=$(1))
216 # Special classes are managed types with special behaviour
217 # On parse time, for each entry in variable $(1)-y
218 # a handler $(1)-handler is executed with the arguments:
219 # * $(1): directory the parser is in
220 # * $(2): current entry
221 add-special-class= \
222 $(eval $(1):=) \
223 $(eval special-classes+=$(1))
225 # Converts one or more source file paths to their corresponding build/ paths.
226 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
227 # their name.
228 # $1 stage name
229 # $2 file path (list)
230 src-to-obj=\
231 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
232 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
233 $(patsubst 3rdparty/%,$(obj)/%,\
234 $(patsubst src/%,$(obj)/%,\
235 $(patsubst %.ads,%.o,\
236 $(patsubst %.adb,%.o,\
237 $(patsubst %.c,%.o,\
238 $(patsubst %.S,%.o,\
239 $(subst .$(1),,$(2))))))))))
241 # Converts one or more source file paths to the corresponding build/ paths
242 # of their Ada library information (.ali) files.
243 # $1 stage name
244 # $2 file path (list)
245 src-to-ali=\
246 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
247 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
248 $(patsubst 3rdparty/%,$(obj)/%,\
249 $(patsubst src/%,$(obj)/%,\
250 $(patsubst %.ads,%.ali,\
251 $(patsubst %.adb,%.ali,\
252 $(subst .$(1),,\
253 $(filter %.ads %.adb,$(2)))))))))
255 # Clean -y variables, include Makefile.inc
256 # Add paths to files in X-y to X-srcs
257 # Add subdirs-y to subdirs
258 includemakefiles= \
259 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
260 $(eval -include $(1)) \
261 $(foreach class,$(classes-y), $(call add-class,$(class))) \
262 $(foreach special,$(special-classes), \
263 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
264 $(foreach class,$(classes), \
265 $(eval $(class)-srcs+= \
266 $$(subst $(absobj)/,$(obj)/, \
267 $$(subst $(top)/,, \
268 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
269 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
271 # For each path in $(subdirs) call includemakefiles
272 # Repeat until subdirs is empty
273 evaluate_subdirs= \
274 $(eval cursubdirs:=$(subdirs)) \
275 $(eval subdirs:=) \
276 $(foreach dir,$(cursubdirs), \
277 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
278 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
280 # collect all object files eligible for building
281 subdirs:=$(TOPLEVEL)
282 postinclude-hooks :=
284 # Don't iterate through Makefile.incs under src/ when building tests
285 ifneq ($(UNIT_TEST),1)
286 $(eval $(call evaluate_subdirs))
287 else
288 include $(TOPLEVEL)/tests/Makefile.inc
289 endif
291 ifeq ($(FAILBUILD),1)
292 $(error cannot continue build)
293 endif
295 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
296 $(eval $(postinclude-hooks))
298 # Eliminate duplicate mentions of source files in a class
299 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
301 # Build Kconfig .ads if necessary
302 ifeq ($(CONFIG_RAMSTAGE_ADA),y)
303 ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
304 endif
306 # To track dependencies, we need all Ada specification (.ads) files in
307 # *-srcs. Extract / filter all specification files that have a matching
308 # body (.adb) file here (specifications without a body are valid sources
309 # in Ada).
310 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
311 $(filter \
312 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
313 $(filter %.ads,$($(class)-srcs)))))
314 $(foreach class,$(classes),$(eval $(class)-srcs := \
315 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
317 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
318 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
320 # For Ada includes
321 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
323 # Save all objs before processing them (for dependency inclusion)
324 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
326 # Call post-processors if they're defined
327 $(foreach class,$(classes),\
328 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
330 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
331 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
332 alldirs:=$(sort $(abspath $(dir $(allobjs))))
334 # Reads dependencies from an Ada library information (.ali) file
335 # Only basenames (with suffix) are preserved so we have to look the
336 # paths up in $($(stage)-srcs).
337 # $1 stage name
338 # $2 ali file
339 create_ada_deps=$$(if $(2),\
340 gnat.adc \
341 $$(filter \
342 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
343 $$($(1)-srcs) $$($(1)-extra-specs)))
345 # macro to define template macros that are used by use_template macro
346 define create_cc_template
347 # $1 obj class
348 # $2 source suffix (c, S, ld, ...)
349 # $3 additional compiler flags
350 # $4 additional dependencies
351 ifn$(EMPTY)def $(1)-objs_$(2)_template
352 de$(EMPTY)fine $(1)-objs_$(2)_template
353 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
354 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
355 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
356 $(GCC_$(1)) \
357 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
358 $(3) -c -o $$$$@ $$$$<
359 el$(EMPTY)se
360 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
361 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
362 $(CC_$(1)) \
363 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
364 $(3) -c -o $$$$@ $$$$<
365 end$(EMPTY)if
366 en$(EMPTY)def
367 end$(EMPTY)if
368 endef
370 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
371 $(foreach class,$(classes), \
372 $(foreach type,$(call filetypes-of-class,$(class)), \
373 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
374 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
375 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
377 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
378 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
380 # To supported complex package initializations, we need to call the
381 # emitted code explicitly. gnatbind gathers all the calls for us
382 # and exports them as a procedure $(stage)_adainit(). Every stage that
383 # uses Ada code has to call it!
384 define gnatbind_template
385 # $1 class
386 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
387 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
388 # We have to give gnatbind a simple filename (without leading
389 # path components) so just cd there.
390 cd $$(dir $$@) && \
391 $$(GNATBIND_$(1)) -a -n \
392 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
393 -L$(1)_ada -o $$(notdir $$@) \
394 $$(subst $$(dir $$@),,$$^)
395 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
396 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
397 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
398 $(1)-objs += $$(obj)/$(1)/b__$(1).o
399 $($(1)-alis): %.ali: %.o ;
400 endef
402 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
403 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
405 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
406 -include $(DEPENDENCIES)
408 printall:
409 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
410 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
411 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
412 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
413 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
414 endif
416 ifndef NOMKDIR
417 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
418 endif
420 $(obj)/project_filelist.txt:
421 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
422 echo "*** Error: Project must be built before generating file list ***"; \
423 exit 1; \
425 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
426 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
427 grep -v '\.o$$' > $(obj)/project_filelist.txt
429 filelist: $(obj)/project_filelist.txt
430 printf "\nFiles used in build:\n"
431 cat $(obj)/project_filelist.txt
433 #works with either exuberant ctags or ctags.emacs
434 ctags-project: clean-ctags $(obj)/project_filelist.txt
435 cat $(obj)/project_filelist.txt | \
436 xargs ctags -o tags
438 cscope-project: clean-cscope $(obj)/project_filelist.txt
439 cat $(obj)/project_filelist.txt | xargs cscope -b
441 cscope:
442 cscope -bR
444 sphinx:
445 $(MAKE) -C Documentation -f Makefile.sphinx html
447 sphinx-lint:
448 $(MAKE) SPHINXOPTS=-W -C Documentation -f Makefile.sphinx html
450 clean-for-update:
451 rm -rf $(obj) .xcompile
453 clean: clean-for-update clean-utils clean-payloads
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 sphinx sphinx-lint
477 .PHONY: ctags-project cscope-project clean-ctags