Documentation: Fix spelling of "Supermicro"
[coreboot.git] / Makefile
blob82f64583c55e88c705a3ec156d8c8b8fa083ef8e
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 DOXYGEN := doxygen
68 DOXYGEN_OUTPUT_DIR := doxygen
70 export $(COREBOOT_EXPORTS)
72 all: real-all
74 help_coreboot help::
75 @echo '*** coreboot platform targets ***'
76 @echo ' Use "make [target] V=1" for extra build debug information'
77 @echo ' all - Build coreboot'
78 @echo ' clean - Remove coreboot build artifacts'
79 @echo ' distclean - Remove build artifacts and config files'
80 @echo ' doxygen - Build doxygen documentation for coreboot'
81 @echo ' doxyplatform - Build doxygen documentation for the current platform'
82 @echo ' sphinx - Build sphinx documentation for coreboot'
83 @echo ' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
84 @echo ' filelist - Show files used in current build'
85 @echo ' printall - print makefile info for debugging'
86 @echo ' gitconfig - set up git to submit patches to coreboot'
87 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
88 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
89 @echo
91 # This include must come _before_ the pattern rules below!
92 # Order _does_ matter for pattern rules.
93 include $(srck)/Makefile.inc
95 # Three cases where we don't need fully populated $(obj) lists:
96 # 1. when no .config exists
97 # 2. when make config (in any flavour) is run
98 # 3. when make distclean is run
99 # Don't waste time on reading all Makefile.incs in these cases
100 ifeq ($(strip $(HAVE_DOTCONFIG)),)
101 NOCOMPILE:=1
102 endif
103 ifneq ($(MAKECMDGOALS),)
104 ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
105 NOCOMPILE:=1
106 endif
107 ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
108 NOMKDIR:=1
109 UNIT_TEST:=1
110 endif
111 endif
113 ifneq ($(filter help%, $(MAKECMDGOALS)), )
114 NOCOMPILE:=1
115 UNIT_TEST:=1
116 else
117 ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
118 ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
119 $(error Cannot mix unit-tests targets with other targets)
120 endif
121 UNIT_TEST:=1
122 NOCOMPILE:=
123 endif
124 endif
126 $(xcompile): util/xcompile/xcompile
127 rm -f $@
128 $< $(XGCCPATH) > $@.tmp
129 \mv -f $@.tmp $@ 2> /dev/null
130 rm -f $@.tmp
132 ifeq ($(NOCOMPILE),1)
133 # We also don't use .xcompile in the no-compile situations, so
134 # provide some reasonable defaults.
135 HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
136 HOSTCXX ?= g++
138 include $(TOPLEVEL)/Makefile.inc
139 include $(TOPLEVEL)/payloads/Makefile.inc
140 include $(TOPLEVEL)/util/testing/Makefile.inc
141 -include $(TOPLEVEL)/site-local/Makefile.inc
142 include $(TOPLEVEL)/tests/Makefile.inc
143 real-all:
144 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
145 @echo "Please specify a config file or run 'make menuconfig' to" >&2
146 @echo "generate a new config file." >&2
147 @exit 1
148 else
150 ifneq ($(UNIT_TEST),1)
151 include $(DOTCONFIG)
152 endif
154 # The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
155 # wait for make to generate the file.
156 $(if $(wildcard $(xcompile)),, $(shell \
157 mkdir -p $(dir $(xcompile)) && \
158 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
160 include $(xcompile)
162 ifneq ($(XCOMPILE_COMPLETE),1)
163 $(shell rm -f $(xcompile))
164 $(error $(xcompile) deleted because it's invalid. \
165 Restarting the build should fix that, or explain the problem)
166 endif
168 # reproducible builds
169 LANG:=C
170 LC_ALL:=C
171 TZ:=UTC0
172 ifneq ($(NOCOMPILE),1)
173 SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
174 endif
175 # don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
176 # are reproducible
177 export LANG LC_ALL TZ SOURCE_DATE_EPOCH
179 ifneq ($(CONFIG_MMX),y)
180 CFLAGS_x86_32 += -mno-mmx
181 endif
183 ifneq ($(UNIT_TEST),1)
184 include toolchain.inc
185 endif
187 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
188 # fix makefile syntax highlighting after strip macro \" "))
190 # The primary target needs to be here before we include the
191 # other files
193 real-all: real-target
195 # must come rather early
196 .SECONDARY:
197 .SECONDEXPANSION:
198 .DELETE_ON_ERROR:
200 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
201 $(MAKE) olddefconfig
202 $(MAKE) syncconfig
204 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
205 true
207 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
208 $(objutil)/kconfig/toada CB.Config <$< >$@
210 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
211 cp $< $@
213 # Add a new class of source/object files to the build system
214 add-class= \
215 $(eval $(1)-srcs:=) \
216 $(eval $(1)-objs:=) \
217 $(eval classes+=$(1))
219 # Special classes are managed types with special behaviour
220 # On parse time, for each entry in variable $(1)-y
221 # a handler $(1)-handler is executed with the arguments:
222 # * $(1): directory the parser is in
223 # * $(2): current entry
224 add-special-class= \
225 $(eval $(1):=) \
226 $(eval special-classes+=$(1))
228 # Converts one or more source file paths to their corresponding build/ paths.
229 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
230 # their name.
231 # $1 stage name
232 # $2 file path (list)
233 src-to-obj=\
234 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
235 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
236 $(patsubst 3rdparty/%,$(obj)/%,\
237 $(patsubst src/%,$(obj)/%,\
238 $(patsubst %.ads,%.o,\
239 $(patsubst %.adb,%.o,\
240 $(patsubst %.c,%.o,\
241 $(patsubst %.S,%.o,\
242 $(subst .$(1),,$(2))))))))))
244 # Converts one or more source file paths to the corresponding build/ paths
245 # of their Ada library information (.ali) files.
246 # $1 stage name
247 # $2 file path (list)
248 src-to-ali=\
249 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
250 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
251 $(patsubst 3rdparty/%,$(obj)/%,\
252 $(patsubst src/%,$(obj)/%,\
253 $(patsubst %.ads,%.ali,\
254 $(patsubst %.adb,%.ali,\
255 $(subst .$(1),,\
256 $(filter %.ads %.adb,$(2)))))))))
258 # Clean -y variables, include Makefile.inc
259 # Add paths to files in X-y to X-srcs
260 # Add subdirs-y to subdirs
261 includemakefiles= \
262 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
263 $(eval -include $(1)) \
264 $(foreach class,$(classes-y), $(call add-class,$(class))) \
265 $(foreach special,$(special-classes), \
266 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
267 $(foreach class,$(classes), \
268 $(eval $(class)-srcs+= \
269 $$(subst $(absobj)/,$(obj)/, \
270 $$(subst $(top)/,, \
271 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
272 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
274 # For each path in $(subdirs) call includemakefiles
275 # Repeat until subdirs is empty
276 evaluate_subdirs= \
277 $(eval cursubdirs:=$(subdirs)) \
278 $(eval subdirs:=) \
279 $(foreach dir,$(cursubdirs), \
280 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
281 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
283 # collect all object files eligible for building
284 subdirs:=$(TOPLEVEL)
285 postinclude-hooks :=
287 # Don't iterate through Makefile.incs under src/ when building tests
288 ifneq ($(UNIT_TEST),1)
289 $(eval $(call evaluate_subdirs))
290 else
291 include $(TOPLEVEL)/tests/Makefile.inc
292 endif
294 ifeq ($(FAILBUILD),1)
295 $(error cannot continue build)
296 endif
298 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
299 $(eval $(postinclude-hooks))
301 # Eliminate duplicate mentions of source files in a class
302 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
304 # Build Kconfig .ads if necessary
305 ifeq ($(CONFIG_RAMSTAGE_ADA),y)
306 ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
307 endif
309 # To track dependencies, we need all Ada specification (.ads) files in
310 # *-srcs. Extract / filter all specification files that have a matching
311 # body (.adb) file here (specifications without a body are valid sources
312 # in Ada).
313 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
314 $(filter \
315 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
316 $(filter %.ads,$($(class)-srcs)))))
317 $(foreach class,$(classes),$(eval $(class)-srcs := \
318 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
320 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
321 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
323 # For Ada includes
324 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
326 # Save all objs before processing them (for dependency inclusion)
327 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
329 # Call post-processors if they're defined
330 $(foreach class,$(classes),\
331 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
333 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
334 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
335 alldirs:=$(sort $(abspath $(dir $(allobjs))))
337 # Reads dependencies from an Ada library information (.ali) file
338 # Only basenames (with suffix) are preserved so we have to look the
339 # paths up in $($(stage)-srcs).
340 # $1 stage name
341 # $2 ali file
342 create_ada_deps=$$(if $(2),\
343 gnat.adc \
344 $$(filter \
345 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
346 $$($(1)-srcs) $$($(1)-extra-specs)))
348 # macro to define template macros that are used by use_template macro
349 define create_cc_template
350 # $1 obj class
351 # $2 source suffix (c, S, ld, ...)
352 # $3 additional compiler flags
353 # $4 additional dependencies
354 ifn$(EMPTY)def $(1)-objs_$(2)_template
355 de$(EMPTY)fine $(1)-objs_$(2)_template
356 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
357 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
358 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
359 $(GCC_$(1)) \
360 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
361 $(3) -c -o $$$$@ $$$$<
362 el$(EMPTY)se
363 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
364 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
365 $(CC_$(1)) \
366 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
367 $(3) -c -o $$$$@ $$$$<
368 end$(EMPTY)if
369 en$(EMPTY)def
370 end$(EMPTY)if
371 endef
373 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
374 $(foreach class,$(classes), \
375 $(foreach type,$(call filetypes-of-class,$(class)), \
376 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
377 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
378 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
380 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
381 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
383 # To supported complex package initializations, we need to call the
384 # emitted code explicitly. gnatbind gathers all the calls for us
385 # and exports them as a procedure $(stage)_adainit(). Every stage that
386 # uses Ada code has to call it!
387 define gnatbind_template
388 # $1 class
389 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
390 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
391 # We have to give gnatbind a simple filename (without leading
392 # path components) so just cd there.
393 cd $$(dir $$@) && \
394 $$(GNATBIND_$(1)) -a -n \
395 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
396 -L$(1)_ada -o $$(notdir $$@) \
397 $$(subst $$(dir $$@),,$$^)
398 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
399 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
400 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
401 $(1)-objs += $$(obj)/$(1)/b__$(1).o
402 $($(1)-alis): %.ali: %.o ;
403 endef
405 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
406 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
408 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
409 -include $(DEPENDENCIES)
411 printall:
412 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
413 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
414 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
415 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
416 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
417 endif
419 ifndef NOMKDIR
420 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
421 endif
423 $(obj)/project_filelist.txt:
424 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
425 echo "*** Error: Project must be built before generating file list ***"; \
426 exit 1; \
428 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
429 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
430 grep -v '\.o$$' > $(obj)/project_filelist.txt
432 filelist: $(obj)/project_filelist.txt
433 printf "\nFiles used in build:\n"
434 cat $(obj)/project_filelist.txt
436 #works with either exuberant ctags or ctags.emacs
437 ctags-project: clean-ctags $(obj)/project_filelist.txt
438 cat $(obj)/project_filelist.txt | \
439 xargs ctags -o tags
441 cscope-project: clean-cscope $(obj)/project_filelist.txt
442 cat $(obj)/project_filelist.txt | xargs cscope -b
444 cscope:
445 cscope -bR
447 sphinx:
448 $(MAKE) -C Documentation -f Makefile.sphinx html
450 sphinx-lint:
451 $(MAKE) SPHINXOPTS=-W -C Documentation -f Makefile.sphinx html
453 doxy: doxygen
454 doxygen:
455 $(DOXYGEN) Documentation/Doxyfile.coreboot
457 doxygen_simple:
458 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
460 doxyplatform doxygen_platform: $(obj)/project_filelist.txt
461 echo
462 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
463 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' )"; \
464 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
465 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
466 export DOXYGEN_PLATFORM="$(call strip_quotes, $(CONFIG_MAINBOARD_DIR)) \($(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER))\) version $(KERNELVERSION)"; \
467 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
469 doxyclean: doxygen-clean
470 doxygen-clean:
471 rm -rf $(DOXYGEN_OUTPUT_DIR)
473 clean-for-update: doxygen-clean clean-for-update-target
474 rm -rf $(obj) .xcompile
476 clean: clean-for-update clean-target clean-utils
477 rm -f .ccwrap
479 clean-cscope:
480 rm -f cscope.out
482 clean-ctags:
483 rm -f tags
485 clean-utils:
486 $(foreach tool, $(TOOLLIST), \
487 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
489 distclean-utils:
490 $(foreach tool, $(TOOLLIST), \
491 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
492 rm -f /util/$(tool)/junit.xml;)
494 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
495 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
496 rm -rf coreboot-builds coreboot-builds-chromeos
497 rm -f abuild*.xml junit.xml* util/lint/junit.xml
499 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple sphinx sphinx-lint
500 .PHONY: ctags-project cscope-project clean-ctags