util/abuild: Ensure that non-Chrome OS builds are non-Chrome OS
[coreboot.git] / Makefile
blobec0f95b59556d5dcbfd95bd02a7fa2642d068d9c
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 VBOOT_HOST_BUILD ?= $(abspath $(objutil)/vboot_lib)
18 COREBOOT_EXPORTS := COREBOOT_EXPORTS
19 COREBOOT_EXPORTS += top src srck obj objutil objk
21 # reproducible builds
22 LANG:=C
23 LC_ALL:=C
24 TZ:=UTC0
25 COREBOOT_EXPORTS += LANG LC_ALL TZ
27 DOTCONFIG ?= $(top)/.config
28 KCONFIG_CONFIG = $(DOTCONFIG)
29 KCONFIG_AUTOADS := $(obj)/cb-config.ads
30 KCONFIG_AUTOHEADER := $(obj)/config.h
31 KCONFIG_AUTOCONFIG := $(obj)/auto.conf
32 KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
33 KCONFIG_SPLITCONFIG := $(obj)/config
34 KCONFIG_TRISTATE := $(obj)/tristate.conf
35 KCONFIG_NEGATIVES := 1
36 KCONFIG_STRICT := 1
37 KCONFIG_PACKAGE := CB.Config
39 COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
40 COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
41 COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
42 COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
44 # directory containing the toplevel Makefile.inc
45 TOPLEVEL := .
47 CONFIG_SHELL := sh
48 KBUILD_DEFCONFIG := configs/defconfig
49 UNAME_RELEASE := $(shell uname -r)
50 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
51 MAKEFLAGS += -rR --no-print-directory
53 # Make is silent per default, but 'make V=1' will show all compiler calls.
54 Q:=@
55 ifneq ($(V),1)
56 ifneq ($(Q),)
57 .SILENT:
58 MAKEFLAGS += -s
59 endif
60 endif
62 # Disable implicit/built-in rules to make Makefile errors fail fast.
63 .SUFFIXES:
65 HOSTCFLAGS := -g
66 HOSTCXXFLAGS := -g
68 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
70 DOXYGEN := doxygen
71 DOXYGEN_OUTPUT_DIR := doxygen
73 export $(COREBOOT_EXPORTS)
75 all: real-all
77 help_coreboot help::
78 @echo '*** coreboot platform targets ***'
79 @echo ' Use "make [target] V=1" for extra build debug information'
80 @echo ' all - Build coreboot'
81 @echo ' clean - Remove coreboot build artifacts'
82 @echo ' distclean - Remove build artifacts and config files'
83 @echo ' doxygen - Build doxygen documentation for coreboot'
84 @echo ' doxyplatform - Build doxygen documentation for the current platform'
85 @echo ' sphinx - Build sphinx documentation for coreboot'
86 @echo ' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
87 @echo ' filelist - Show files used in current build'
88 @echo ' printall - print makefile info for debugging'
89 @echo ' gitconfig - set up git to submit patches to coreboot'
90 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
91 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
92 @echo
94 # This include must come _before_ the pattern rules below!
95 # Order _does_ matter for pattern rules.
96 include $(srck)/Makefile.inc
98 # Three cases where we don't need fully populated $(obj) lists:
99 # 1. when no .config exists
100 # 2. when make config (in any flavour) is run
101 # 3. when make distclean is run
102 # Don't waste time on reading all Makefile.incs in these cases
103 ifeq ($(strip $(HAVE_DOTCONFIG)),)
104 NOCOMPILE:=1
105 endif
106 ifneq ($(MAKECMDGOALS),)
107 ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
108 NOCOMPILE:=1
109 endif
110 ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
111 NOMKDIR:=1
112 endif
113 endif
115 ifneq ($(filter %-test %-tests,$(MAKECMDGOALS)),)
116 ifneq ($(filter-out %-test %-tests, $(MAKECMDGOALS)),)
117 $(error Cannot mix unit-tests targets with other targets)
118 endif
119 UNIT_TEST:=1
120 NOCOMPILE:=
121 endif
123 $(xcompile): util/xcompile/xcompile
124 rm -f $@
125 $< $(XGCCPATH) > $@.tmp
126 \mv -f $@.tmp $@ 2> /dev/null
127 rm -f $@.tmp
129 ifeq ($(NOCOMPILE),1)
130 # We also don't use .xcompile in the no-compile situations, so
131 # provide some reasonable defaults.
132 HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
133 HOSTCXX ?= g++
135 include $(TOPLEVEL)/Makefile.inc
136 include $(TOPLEVEL)/payloads/Makefile.inc
137 include $(TOPLEVEL)/util/testing/Makefile.inc
138 -include $(TOPLEVEL)/site-local/Makefile.inc
139 real-all:
140 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
141 @echo "Please specify a config file or run 'make menuconfig' to" >&2
142 @echo "generate a new config file." >&2
143 @exit 1
144 else
146 ifneq ($(UNIT_TEST),1)
147 include $(DOTCONFIG)
148 endif
150 # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
151 # wait for make to generate the file.
152 $(if $(wildcard $(xcompile)),, $(shell \
153 mkdir -p $(dir $(xcompile)) && \
154 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
156 include $(xcompile)
158 ifneq ($(XCOMPILE_COMPLETE),1)
159 $(shell rm -f $(xcompile))
160 $(error $(xcompile) deleted because it's invalid. \
161 Restarting the build should fix that, or explain the problem)
162 endif
164 ifneq ($(CONFIG_MMX),y)
165 CFLAGS_x86_32 += -mno-mmx
166 endif
168 ifneq ($(UNIT_TEST),1)
169 include toolchain.inc
170 endif
172 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
173 # fix makefile syntax highlighting after strip macro \" "))
175 # The primary target needs to be here before we include the
176 # other files
178 real-all: real-target
180 # must come rather early
181 .SECONDEXPANSION:
182 .DELETE_ON_ERROR:
184 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
185 +$(MAKE) oldconfig
187 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
188 true
190 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
191 $(objutil)/kconfig/toada CB.Config <$< >$@
193 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
194 cp $< $@
196 # Add a new class of source/object files to the build system
197 add-class= \
198 $(eval $(1)-srcs:=) \
199 $(eval $(1)-objs:=) \
200 $(eval classes+=$(1))
202 # Special classes are managed types with special behaviour
203 # On parse time, for each entry in variable $(1)-y
204 # a handler $(1)-handler is executed with the arguments:
205 # * $(1): directory the parser is in
206 # * $(2): current entry
207 add-special-class= \
208 $(eval $(1):=) \
209 $(eval special-classes+=$(1))
211 # Converts one or more source file paths to their corresponding build/ paths.
212 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
213 # their name.
214 # $1 stage name
215 # $2 file path (list)
216 src-to-obj=\
217 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
218 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
219 $(patsubst 3rdparty/%,$(obj)/%,\
220 $(patsubst src/%,$(obj)/%,\
221 $(patsubst %.ads,%.o,\
222 $(patsubst %.adb,%.o,\
223 $(patsubst %.c,%.o,\
224 $(patsubst %.S,%.o,\
225 $(subst .$(1),,$(2))))))))))
227 # Converts one or more source file paths to the corresponding build/ paths
228 # of their Ada library information (.ali) files.
229 # $1 stage name
230 # $2 file path (list)
231 src-to-ali=\
232 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
233 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
234 $(patsubst 3rdparty/%,$(obj)/%,\
235 $(patsubst src/%,$(obj)/%,\
236 $(patsubst %.ads,%.ali,\
237 $(patsubst %.adb,%.ali,\
238 $(subst .$(1),,\
239 $(filter %.ads %.adb,$(2)))))))))
241 # Clean -y variables, include Makefile.inc
242 # Add paths to files in X-y to X-srcs
243 # Add subdirs-y to subdirs
244 includemakefiles= \
245 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
246 $(eval -include $(1)) \
247 $(foreach class,$(classes-y), $(call add-class,$(class))) \
248 $(foreach special,$(special-classes), \
249 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
250 $(foreach class,$(classes), \
251 $(eval $(class)-srcs+= \
252 $$(subst $(absobj)/,$(obj)/, \
253 $$(subst $(top)/,, \
254 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
255 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
257 # For each path in $(subdirs) call includemakefiles
258 # Repeat until subdirs is empty
259 evaluate_subdirs= \
260 $(eval cursubdirs:=$(subdirs)) \
261 $(eval subdirs:=) \
262 $(foreach dir,$(cursubdirs), \
263 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
264 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
266 # collect all object files eligible for building
267 subdirs:=$(TOPLEVEL)
268 postinclude-hooks :=
270 # Don't iterate through Makefile.incs under src/ when building tests
271 ifneq ($(UNIT_TEST),1)
272 $(eval $(call evaluate_subdirs))
273 else
274 include $(TOPLEVEL)/tests/Makefile.inc
275 endif
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 sphinx:
431 $(MAKE) -C Documentation -f Makefile.sphinx html
433 sphinx-lint:
434 $(MAKE) SPHINXOPTS=-W -C Documentation -f Makefile.sphinx html
436 doxy: doxygen
437 doxygen:
438 $(DOXYGEN) Documentation/Doxyfile.coreboot
440 doxygen_simple:
441 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
443 doxyplatform doxygen_platform: $(obj)/project_filelist.txt
444 echo
445 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
446 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' )"; \
447 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
448 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
449 export DOXYGEN_PLATFORM="$(call strip_quotes, $(CONFIG_MAINBOARD_DIR)) \($(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER))\) version $(KERNELVERSION)"; \
450 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
452 doxyclean: doxygen-clean
453 doxygen-clean:
454 rm -rf $(DOXYGEN_OUTPUT_DIR)
456 clean-for-update: doxygen-clean clean-for-update-target
457 rm -rf $(obj) .xcompile
459 clean: clean-for-update clean-target clean-utils
460 rm -f .ccwrap
462 clean-cscope:
463 rm -f cscope.out
465 clean-ctags:
466 rm -f tags
468 clean-utils:
469 $(foreach tool, $(TOOLLIST), \
470 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
472 distclean-utils:
473 $(foreach tool, $(TOOLLIST), \
474 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
475 rm -f /util/$(tool)/junit.xml;)
477 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
478 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
479 rm -rf coreboot-builds coreboot-builds-chromeos
480 rm -f abuild*.xml junit.xml* util/lint/junit.xml
482 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple sphinx sphinx-lint
483 .PHONY: ctags-project cscope-project clean-ctags