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