mainboard: Drop invalid `VGA_BIOS_FILE` defaults
[coreboot.git] / Makefile
blob97ed805a6718c40831fe57f676d42d7c9057de80
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 # reproducible builds
24 LANG:=C
25 LC_ALL:=C
26 TZ:=UTC0
27 ifneq ($(NOCOMPILE),1)
28 SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
29 endif
30 # don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
31 # are reproducible
32 export LANG LC_ALL TZ SOURCE_DATE_EPOCH
34 DOTCONFIG ?= $(top)/.config
35 KCONFIG_CONFIG = $(DOTCONFIG)
36 KCONFIG_AUTOADS := $(obj)/cb-config.ads
37 KCONFIG_AUTOHEADER := $(obj)/config.h
38 KCONFIG_AUTOCONFIG := $(obj)/auto.conf
39 KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
40 KCONFIG_SPLITCONFIG := $(obj)/config/
41 KCONFIG_TRISTATE := $(obj)/tristate.conf
42 KCONFIG_NEGATIVES := 1
43 KCONFIG_STRICT := 1
44 KCONFIG_PACKAGE := CB.Config
46 COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
47 COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
48 COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
49 COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
51 # directory containing the toplevel Makefile.inc
52 TOPLEVEL := .
54 CONFIG_SHELL := sh
55 KBUILD_DEFCONFIG := configs/defconfig
56 UNAME_RELEASE := $(shell uname -r)
57 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
58 MAKEFLAGS += -rR --no-print-directory
60 # Make is silent per default, but 'make V=1' will show all compiler calls.
61 Q:=@
62 ifneq ($(V),1)
63 ifneq ($(Q),)
64 .SILENT:
65 MAKEFLAGS += -s
66 endif
67 endif
69 # Disable implicit/built-in rules to make Makefile errors fail fast.
70 .SUFFIXES:
72 HOSTCFLAGS := -g
73 HOSTCXXFLAGS := -g
75 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
77 DOXYGEN := doxygen
78 DOXYGEN_OUTPUT_DIR := doxygen
80 export $(COREBOOT_EXPORTS)
82 all: real-all
84 help_coreboot help::
85 @echo '*** coreboot platform targets ***'
86 @echo ' Use "make [target] V=1" for extra build debug information'
87 @echo ' all - Build coreboot'
88 @echo ' clean - Remove coreboot build artifacts'
89 @echo ' distclean - Remove build artifacts and config files'
90 @echo ' doxygen - Build doxygen documentation for coreboot'
91 @echo ' doxyplatform - Build doxygen documentation for the current platform'
92 @echo ' sphinx - Build sphinx documentation for coreboot'
93 @echo ' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
94 @echo ' filelist - Show files used in current build'
95 @echo ' printall - print makefile info for debugging'
96 @echo ' gitconfig - set up git to submit patches to coreboot'
97 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
98 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
99 @echo
101 # This include must come _before_ the pattern rules below!
102 # Order _does_ matter for pattern rules.
103 include $(srck)/Makefile.inc
105 # Three cases where we don't need fully populated $(obj) lists:
106 # 1. when no .config exists
107 # 2. when make config (in any flavour) is run
108 # 3. when make distclean is run
109 # Don't waste time on reading all Makefile.incs in these cases
110 ifeq ($(strip $(HAVE_DOTCONFIG)),)
111 NOCOMPILE:=1
112 endif
113 ifneq ($(MAKECMDGOALS),)
114 ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
115 NOCOMPILE:=1
116 endif
117 ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
118 NOMKDIR:=1
119 UNIT_TEST:=1
120 endif
121 endif
123 ifneq ($(filter help%, $(MAKECMDGOALS)), )
124 NOCOMPILE:=1
125 UNIT_TEST:=1
126 else
127 ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
128 ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
129 $(error Cannot mix unit-tests targets with other targets)
130 endif
131 UNIT_TEST:=1
132 NOCOMPILE:=
133 endif
134 endif
136 $(xcompile): util/xcompile/xcompile
137 rm -f $@
138 $< $(XGCCPATH) > $@.tmp
139 \mv -f $@.tmp $@ 2> /dev/null
140 rm -f $@.tmp
142 ifeq ($(NOCOMPILE),1)
143 # We also don't use .xcompile in the no-compile situations, so
144 # provide some reasonable defaults.
145 HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
146 HOSTCXX ?= g++
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 include $(TOPLEVEL)/tests/Makefile.inc
153 real-all:
154 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
155 @echo "Please specify a config file or run 'make menuconfig' to" >&2
156 @echo "generate a new config file." >&2
157 @exit 1
158 else
160 ifneq ($(UNIT_TEST),1)
161 include $(DOTCONFIG)
162 endif
164 # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
165 # wait for make to generate the file.
166 $(if $(wildcard $(xcompile)),, $(shell \
167 mkdir -p $(dir $(xcompile)) && \
168 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
170 include $(xcompile)
172 ifneq ($(XCOMPILE_COMPLETE),1)
173 $(shell rm -f $(xcompile))
174 $(error $(xcompile) deleted because it's invalid. \
175 Restarting the build should fix that, or explain the problem)
176 endif
178 ifneq ($(CONFIG_MMX),y)
179 CFLAGS_x86_32 += -mno-mmx
180 endif
182 ifneq ($(UNIT_TEST),1)
183 include toolchain.inc
184 endif
186 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
187 # fix makefile syntax highlighting after strip macro \" "))
189 # The primary target needs to be here before we include the
190 # other files
192 real-all: real-target
194 # must come rather early
195 .SECONDEXPANSION:
196 .DELETE_ON_ERROR:
198 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
199 $(MAKE) olddefconfig
200 $(MAKE) syncconfig
202 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
203 true
205 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
206 $(objutil)/kconfig/toada CB.Config <$< >$@
208 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
209 cp $< $@
211 # Add a new class of source/object files to the build system
212 add-class= \
213 $(eval $(1)-srcs:=) \
214 $(eval $(1)-objs:=) \
215 $(eval classes+=$(1))
217 # Special classes are managed types with special behaviour
218 # On parse time, for each entry in variable $(1)-y
219 # a handler $(1)-handler is executed with the arguments:
220 # * $(1): directory the parser is in
221 # * $(2): current entry
222 add-special-class= \
223 $(eval $(1):=) \
224 $(eval special-classes+=$(1))
226 # Converts one or more source file paths to their corresponding build/ paths.
227 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
228 # their name.
229 # $1 stage name
230 # $2 file path (list)
231 src-to-obj=\
232 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
233 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
234 $(patsubst 3rdparty/%,$(obj)/%,\
235 $(patsubst src/%,$(obj)/%,\
236 $(patsubst %.ads,%.o,\
237 $(patsubst %.adb,%.o,\
238 $(patsubst %.c,%.o,\
239 $(patsubst %.S,%.o,\
240 $(subst .$(1),,$(2))))))))))
242 # Converts one or more source file paths to the corresponding build/ paths
243 # of their Ada library information (.ali) files.
244 # $1 stage name
245 # $2 file path (list)
246 src-to-ali=\
247 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
248 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
249 $(patsubst 3rdparty/%,$(obj)/%,\
250 $(patsubst src/%,$(obj)/%,\
251 $(patsubst %.ads,%.ali,\
252 $(patsubst %.adb,%.ali,\
253 $(subst .$(1),,\
254 $(filter %.ads %.adb,$(2)))))))))
256 # Clean -y variables, include Makefile.inc
257 # Add paths to files in X-y to X-srcs
258 # Add subdirs-y to subdirs
259 includemakefiles= \
260 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
261 $(eval -include $(1)) \
262 $(foreach class,$(classes-y), $(call add-class,$(class))) \
263 $(foreach special,$(special-classes), \
264 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
265 $(foreach class,$(classes), \
266 $(eval $(class)-srcs+= \
267 $$(subst $(absobj)/,$(obj)/, \
268 $$(subst $(top)/,, \
269 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
270 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
272 # For each path in $(subdirs) call includemakefiles
273 # Repeat until subdirs is empty
274 evaluate_subdirs= \
275 $(eval cursubdirs:=$(subdirs)) \
276 $(eval subdirs:=) \
277 $(foreach dir,$(cursubdirs), \
278 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
279 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
281 # collect all object files eligible for building
282 subdirs:=$(TOPLEVEL)
283 postinclude-hooks :=
285 # Don't iterate through Makefile.incs under src/ when building tests
286 ifneq ($(UNIT_TEST),1)
287 $(eval $(call evaluate_subdirs))
288 else
289 include $(TOPLEVEL)/tests/Makefile.inc
290 endif
292 ifeq ($(FAILBUILD),1)
293 $(error cannot continue build)
294 endif
296 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
297 $(eval $(postinclude-hooks))
299 # Eliminate duplicate mentions of source files in a class
300 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
302 # Build Kconfig .ads if necessary
303 ifeq ($(CONFIG_RAMSTAGE_ADA),y)
304 ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
305 endif
307 # To track dependencies, we need all Ada specification (.ads) files in
308 # *-srcs. Extract / filter all specification files that have a matching
309 # body (.adb) file here (specifications without a body are valid sources
310 # in Ada).
311 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
312 $(filter \
313 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
314 $(filter %.ads,$($(class)-srcs)))))
315 $(foreach class,$(classes),$(eval $(class)-srcs := \
316 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
318 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
319 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
321 # For Ada includes
322 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
324 # Save all objs before processing them (for dependency inclusion)
325 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
327 # Call post-processors if they're defined
328 $(foreach class,$(classes),\
329 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
331 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
332 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
333 alldirs:=$(sort $(abspath $(dir $(allobjs))))
335 # Reads dependencies from an Ada library information (.ali) file
336 # Only basenames (with suffix) are preserved so we have to look the
337 # paths up in $($(stage)-srcs).
338 # $1 stage name
339 # $2 ali file
340 create_ada_deps=$$(if $(2),\
341 gnat.adc \
342 $$(filter \
343 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
344 $$($(1)-srcs) $$($(1)-extra-specs)))
346 # macro to define template macros that are used by use_template macro
347 define create_cc_template
348 # $1 obj class
349 # $2 source suffix (c, S, ld, ...)
350 # $3 additional compiler flags
351 # $4 additional dependencies
352 ifn$(EMPTY)def $(1)-objs_$(2)_template
353 de$(EMPTY)fine $(1)-objs_$(2)_template
354 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
355 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
356 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
357 $(GCC_$(1)) \
358 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
359 $(3) -c -o $$$$@ $$$$<
360 el$(EMPTY)se
361 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
362 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
363 $(CC_$(1)) \
364 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
365 $(3) -c -o $$$$@ $$$$<
366 end$(EMPTY)if
367 en$(EMPTY)def
368 end$(EMPTY)if
369 endef
371 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
372 $(foreach class,$(classes), \
373 $(foreach type,$(call filetypes-of-class,$(class)), \
374 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
375 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
376 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
378 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
379 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
381 # To supported complex package initializations, we need to call the
382 # emitted code explicitly. gnatbind gathers all the calls for us
383 # and exports them as a procedure $(stage)_adainit(). Every stage that
384 # uses Ada code has to call it!
385 define gnatbind_template
386 # $1 class
387 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
388 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
389 # We have to give gnatbind a simple filename (without leading
390 # path components) so just cd there.
391 cd $$(dir $$@) && \
392 $$(GNATBIND_$(1)) -a -n \
393 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
394 -L$(1)_ada -o $$(notdir $$@) \
395 $$(subst $$(dir $$@),,$$^)
396 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
397 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
398 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
399 $(1)-objs += $$(obj)/$(1)/b__$(1).o
400 $($(1)-alis): %.ali: %.o ;
401 endef
403 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
404 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
406 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
407 -include $(DEPENDENCIES)
409 printall:
410 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
411 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
412 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
413 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
414 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
415 endif
417 ifndef NOMKDIR
418 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
419 endif
421 $(obj)/project_filelist.txt:
422 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
423 echo "*** Error: Project must be built before generating file list ***"; \
424 exit 1; \
426 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
427 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
428 grep -v '\.o$$' > $(obj)/project_filelist.txt
430 filelist: $(obj)/project_filelist.txt
431 printf "\nFiles used in build:\n"
432 cat $(obj)/project_filelist.txt
434 #works with either exuberant ctags or ctags.emacs
435 ctags-project: clean-ctags $(obj)/project_filelist.txt
436 cat $(obj)/project_filelist.txt | \
437 xargs ctags -o tags
439 cscope-project: clean-cscope $(obj)/project_filelist.txt
440 cat $(obj)/project_filelist.txt | xargs cscope -b
442 cscope:
443 cscope -bR
445 sphinx:
446 $(MAKE) -C Documentation -f Makefile.sphinx html
448 sphinx-lint:
449 $(MAKE) SPHINXOPTS=-W -C Documentation -f Makefile.sphinx html
451 doxy: doxygen
452 doxygen:
453 $(DOXYGEN) Documentation/Doxyfile.coreboot
455 doxygen_simple:
456 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
458 doxyplatform doxygen_platform: $(obj)/project_filelist.txt
459 echo
460 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
461 export DOXYGEN_OUTPUT_DIR="$$( echo $(DOXYGEN_OUTPUT_DIR)/$(call strip_quotes, $(CONFIG_MAINBOARD_VENDOR))_$(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER)) | sed 's|[^A-Za-z0-9/]|_|g' )"; \
462 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
463 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
464 export DOXYGEN_PLATFORM="$(call strip_quotes, $(CONFIG_MAINBOARD_DIR)) \($(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER))\) version $(KERNELVERSION)"; \
465 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
467 doxyclean: doxygen-clean
468 doxygen-clean:
469 rm -rf $(DOXYGEN_OUTPUT_DIR)
471 clean-for-update: doxygen-clean clean-for-update-target
472 rm -rf $(obj) .xcompile
474 clean: clean-for-update clean-target clean-utils
475 rm -f .ccwrap
477 clean-cscope:
478 rm -f cscope.out
480 clean-ctags:
481 rm -f tags
483 clean-utils:
484 $(foreach tool, $(TOOLLIST), \
485 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
487 distclean-utils:
488 $(foreach tool, $(TOOLLIST), \
489 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
490 rm -f /util/$(tool)/junit.xml;)
492 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
493 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
494 rm -rf coreboot-builds coreboot-builds-chromeos
495 rm -f abuild*.xml junit.xml* util/lint/junit.xml
497 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple sphinx sphinx-lint
498 .PHONY: ctags-project cscope-project clean-ctags