mb/google/zork: Drop check for ENV_RAMSTAGE in mainboard_ec_init
[coreboot.git] / Makefile
blob6a96f9dee9b6bda4ccf1dcd810b9dc3bc27f4b08
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 objutil ?= $(obj)/util
12 objk := $(objutil)/kconfig
13 absobj := $(abspath $(obj))
15 VBOOT_HOST_BUILD ?= $(abspath $(objutil)/vboot_lib)
17 COREBOOT_EXPORTS := COREBOOT_EXPORTS
18 COREBOOT_EXPORTS += top src srck obj objutil objk
20 # reproducible builds
21 LANG:=C
22 LC_ALL:=C
23 TZ:=UTC0
24 COREBOOT_EXPORTS += LANG LC_ALL TZ
26 DOTCONFIG ?= $(top)/.config
27 KCONFIG_CONFIG = $(DOTCONFIG)
28 KCONFIG_AUTOADS := $(obj)/cb-config.ads
29 KCONFIG_AUTOHEADER := $(obj)/config.h
30 KCONFIG_AUTOCONFIG := $(obj)/auto.conf
31 KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
32 KCONFIG_SPLITCONFIG := $(obj)/config
33 KCONFIG_TRISTATE := $(obj)/tristate.conf
34 KCONFIG_NEGATIVES := 1
35 KCONFIG_STRICT := 1
36 KCONFIG_PACKAGE := CB.Config
38 COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
39 COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
40 COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
41 COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
43 # directory containing the toplevel Makefile.inc
44 TOPLEVEL := .
46 CONFIG_SHELL := sh
47 KBUILD_DEFCONFIG := configs/defconfig
48 UNAME_RELEASE := $(shell uname -r)
49 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
50 MAKEFLAGS += -rR --no-print-directory
52 # Make is silent per default, but 'make V=1' will show all compiler calls.
53 Q:=@
54 ifneq ($(V),1)
55 ifneq ($(Q),)
56 .SILENT:
57 MAKEFLAGS += -s
58 endif
59 endif
61 # Disable implicit/built-in rules to make Makefile errors fail fast.
62 .SUFFIXES:
64 HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
65 HOSTCXX = g++
66 HOSTCFLAGS := -g
67 HOSTCXXFLAGS := -g
69 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
71 DOXYGEN := doxygen
72 DOXYGEN_OUTPUT_DIR := doxygen
74 export $(COREBOOT_EXPORTS)
76 all: real-all
78 help_coreboot help::
79 @echo '*** coreboot platform targets ***'
80 @echo ' Use "make [target] V=1" for extra build debug information'
81 @echo ' all - Build coreboot'
82 @echo ' clean - Remove coreboot build artifacts'
83 @echo ' distclean - Remove build artifacts and config files'
84 @echo ' doxygen - Build doxygen documentation for coreboot'
85 @echo ' doxyplatform - Build doxygen documentation for the current platform'
86 @echo ' sphinx - Build sphinx documentation for coreboot'
87 @echo ' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
88 @echo ' filelist - Show files used in current build'
89 @echo ' printall - print makefile info for debugging'
90 @echo ' gitconfig - set up git to submit patches to coreboot'
91 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
92 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
93 @echo
95 # This include must come _before_ the pattern rules below!
96 # Order _does_ matter for pattern rules.
97 include $(srck)/Makefile.inc
99 # Three cases where we don't need fully populated $(obj) lists:
100 # 1. when no .config exists
101 # 2. when make config (in any flavour) is run
102 # 3. when make distclean is run
103 # Don't waste time on reading all Makefile.incs in these cases
104 ifeq ($(strip $(HAVE_DOTCONFIG)),)
105 NOCOMPILE:=1
106 endif
107 ifneq ($(MAKECMDGOALS),)
108 ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
109 NOCOMPILE:=1
110 endif
111 ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
112 NOMKDIR:=1
113 endif
114 endif
116 ifneq ($(filter %-test %-tests,$(MAKECMDGOALS)),)
117 ifneq ($(filter-out %-test %-tests, $(MAKECMDGOALS)),)
118 $(error Cannot mix unit-tests targets with other targets)
119 endif
120 UNIT_TEST:=1
121 NOCOMPILE:=
122 endif
124 .xcompile: util/xcompile/xcompile
125 rm -f $@
126 $< $(XGCCPATH) > $@.tmp
127 \mv -f $@.tmp $@ 2> /dev/null
128 rm -f $@.tmp
130 ifeq ($(NOCOMPILE),1)
131 include $(TOPLEVEL)/Makefile.inc
132 include $(TOPLEVEL)/payloads/Makefile.inc
133 include $(TOPLEVEL)/util/testing/Makefile.inc
134 -include $(TOPLEVEL)/site-local/Makefile.inc
135 real-all:
136 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
137 @echo "Please specify a config file or run 'make menuconfig' to" >&2
138 @echo "generate a new config file." >&2
139 @exit 1
140 else
142 ifneq ($(UNIT_TEST),1)
143 include $(DOTCONFIG)
144 endif
146 # in addition to the dependency below, create the file if it doesn't exist
147 # to silence stupid warnings about a file that would be generated anyway.
148 $(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
150 -include .xcompile
152 ifneq ($(XCOMPILE_COMPLETE),1)
153 $(shell rm -f .xcompile)
154 $(error .xcompile deleted because it's invalid. \
155 Restarting the build should fix that, or explain the problem)
156 endif
158 ifneq ($(CONFIG_MMX),y)
159 CFLAGS_x86_32 += -mno-mmx
160 endif
162 ifneq ($(UNIT_TEST),1)
163 include toolchain.inc
164 endif
166 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
167 # fix makefile syntax highlighting after strip macro \" "))
169 # The primary target needs to be here before we include the
170 # other files
172 real-all: real-target
174 # must come rather early
175 .SECONDEXPANSION:
176 .DELETE_ON_ERROR:
178 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
179 +$(MAKE) oldconfig
181 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
182 true
184 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
185 $(objutil)/kconfig/toada CB.Config <$< >$@
187 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
188 cp $< $@
190 # Add a new class of source/object files to the build system
191 add-class= \
192 $(eval $(1)-srcs:=) \
193 $(eval $(1)-objs:=) \
194 $(eval classes+=$(1))
196 # Special classes are managed types with special behaviour
197 # On parse time, for each entry in variable $(1)-y
198 # a handler $(1)-handler is executed with the arguments:
199 # * $(1): directory the parser is in
200 # * $(2): current entry
201 add-special-class= \
202 $(eval $(1):=) \
203 $(eval special-classes+=$(1))
205 # Converts one or more source file paths to their corresponding build/ paths.
206 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
207 # their name.
208 # $1 stage name
209 # $2 file path (list)
210 src-to-obj=\
211 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
212 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
213 $(patsubst 3rdparty/%,$(obj)/%,\
214 $(patsubst src/%,$(obj)/%,\
215 $(patsubst %.ads,%.o,\
216 $(patsubst %.adb,%.o,\
217 $(patsubst %.c,%.o,\
218 $(patsubst %.S,%.o,\
219 $(subst .$(1),,$(2))))))))))
221 # Converts one or more source file paths to the corresponding build/ paths
222 # of their Ada library information (.ali) files.
223 # $1 stage name
224 # $2 file path (list)
225 src-to-ali=\
226 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
227 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
228 $(patsubst 3rdparty/%,$(obj)/%,\
229 $(patsubst src/%,$(obj)/%,\
230 $(patsubst %.ads,%.ali,\
231 $(patsubst %.adb,%.ali,\
232 $(subst .$(1),,\
233 $(filter %.ads %.adb,$(2)))))))))
235 # Clean -y variables, include Makefile.inc
236 # Add paths to files in X-y to X-srcs
237 # Add subdirs-y to subdirs
238 includemakefiles= \
239 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
240 $(eval -include $(1)) \
241 $(foreach class,$(classes-y), $(call add-class,$(class))) \
242 $(foreach special,$(special-classes), \
243 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
244 $(foreach class,$(classes), \
245 $(eval $(class)-srcs+= \
246 $$(subst $(absobj)/,$(obj)/, \
247 $$(subst $(top)/,, \
248 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
249 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
251 # For each path in $(subdirs) call includemakefiles
252 # Repeat until subdirs is empty
253 evaluate_subdirs= \
254 $(eval cursubdirs:=$(subdirs)) \
255 $(eval subdirs:=) \
256 $(foreach dir,$(cursubdirs), \
257 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
258 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
260 # collect all object files eligible for building
261 subdirs:=$(TOPLEVEL)
262 postinclude-hooks :=
264 # Don't iterate through Makefile.incs under src/ when building tests
265 ifneq ($(UNIT_TEST),1)
266 $(eval $(call evaluate_subdirs))
267 else
268 include $(TOPLEVEL)/tests/Makefile.inc
269 endif
271 ifeq ($(FAILBUILD),1)
272 $(error cannot continue build)
273 endif
275 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
276 $(eval $(postinclude-hooks))
278 # Eliminate duplicate mentions of source files in a class
279 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
281 # Build Kconfig .ads if necessary
282 ifeq ($(CONFIG_RAMSTAGE_ADA),y)
283 ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
284 endif
286 # To track dependencies, we need all Ada specification (.ads) files in
287 # *-srcs. Extract / filter all specification files that have a matching
288 # body (.adb) file here (specifications without a body are valid sources
289 # in Ada).
290 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
291 $(filter \
292 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
293 $(filter %.ads,$($(class)-srcs)))))
294 $(foreach class,$(classes),$(eval $(class)-srcs := \
295 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
297 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
298 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
300 # For Ada includes
301 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
303 # Save all objs before processing them (for dependency inclusion)
304 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
306 # Call post-processors if they're defined
307 $(foreach class,$(classes),\
308 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
310 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
311 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
312 alldirs:=$(sort $(abspath $(dir $(allobjs))))
314 # Reads dependencies from an Ada library information (.ali) file
315 # Only basenames (with suffix) are preserved so we have to look the
316 # paths up in $($(stage)-srcs).
317 # $1 stage name
318 # $2 ali file
319 create_ada_deps=$$(if $(2),\
320 gnat.adc \
321 $$(filter \
322 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
323 $$($(1)-srcs) $$($(1)-extra-specs)))
325 # macro to define template macros that are used by use_template macro
326 define create_cc_template
327 # $1 obj class
328 # $2 source suffix (c, S, ld, ...)
329 # $3 additional compiler flags
330 # $4 additional dependencies
331 ifn$(EMPTY)def $(1)-objs_$(2)_template
332 de$(EMPTY)fine $(1)-objs_$(2)_template
333 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
334 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
335 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
336 $(GCC_$(1)) \
337 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
338 $(3) -c -o $$$$@ $$$$<
339 el$(EMPTY)se
340 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
341 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
342 $(CC_$(1)) \
343 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
344 $(3) -c -o $$$$@ $$$$<
345 end$(EMPTY)if
346 en$(EMPTY)def
347 end$(EMPTY)if
348 endef
350 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
351 $(foreach class,$(classes), \
352 $(foreach type,$(call filetypes-of-class,$(class)), \
353 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
354 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
355 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
357 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
358 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
360 # To supported complex package initializations, we need to call the
361 # emitted code explicitly. gnatbind gathers all the calls for us
362 # and exports them as a procedure $(stage)_adainit(). Every stage that
363 # uses Ada code has to call it!
364 define gnatbind_template
365 # $1 class
366 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
367 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
368 # We have to give gnatbind a simple filename (without leading
369 # path components) so just cd there.
370 cd $$(dir $$@) && \
371 $$(GNATBIND_$(1)) -a -n \
372 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
373 -L$(1)_ada -o $$(notdir $$@) \
374 $$(subst $$(dir $$@),,$$^)
375 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
376 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
377 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
378 $(1)-objs += $$(obj)/$(1)/b__$(1).o
379 $($(1)-alis): %.ali: %.o ;
380 endef
382 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
383 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
385 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
386 -include $(DEPENDENCIES)
388 printall:
389 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
390 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
391 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
392 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
393 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
394 endif
396 ifndef NOMKDIR
397 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
398 endif
400 $(obj)/project_filelist.txt:
401 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
402 echo "*** Error: Project must be built before generating file list ***"; \
403 exit 1; \
405 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
406 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
407 grep -v '\.o$$' > $(obj)/project_filelist.txt
409 filelist: $(obj)/project_filelist.txt
410 printf "\nFiles used in build:\n"
411 cat $(obj)/project_filelist.txt
413 #works with either exuberant ctags or ctags.emacs
414 ctags-project: clean-ctags $(obj)/project_filelist.txt
415 cat $(obj)/project_filelist.txt | \
416 xargs ctags -o tags
418 cscope-project: clean-cscope $(obj)/project_filelist.txt
419 cat $(obj)/project_filelist.txt | xargs cscope -b
421 cscope:
422 cscope -bR
424 sphinx:
425 $(MAKE) -C Documentation -f Makefile.sphinx html
427 sphinx-lint:
428 $(MAKE) SPHINXOPTS=-W -C Documentation -f Makefile.sphinx html
430 doxy: doxygen
431 doxygen:
432 $(DOXYGEN) Documentation/Doxyfile.coreboot
434 doxygen_simple:
435 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
437 doxyplatform doxygen_platform: $(obj)/project_filelist.txt
438 echo
439 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
440 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
441 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
442 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
443 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
444 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
446 doxyclean: doxygen-clean
447 doxygen-clean:
448 rm -rf $(DOXYGEN_OUTPUT_DIR)
450 clean-for-update: doxygen-clean clean-for-update-target
451 rm -rf $(obj) .xcompile
453 clean: clean-for-update clean-target clean-utils
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 doxygen doxy doxygen_simple sphinx sphinx-lint
477 .PHONY: ctags-project cscope-project clean-ctags