vendorcode/amd: Remove duplicate assignment
[coreboot.git] / Makefile
blob2bc2a6fe6364a8290d3f9f40b043e42120278640
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 ' filelist - Show files used in current build'
87 @echo ' printall - print makefile info for debugging'
88 @echo ' gitconfig - set up git to submit patches to coreboot'
89 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
90 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
91 @echo
93 # This include must come _before_ the pattern rules below!
94 # Order _does_ matter for pattern rules.
95 include $(srck)/Makefile.inc
97 # Three cases where we don't need fully populated $(obj) lists:
98 # 1. when no .config exists
99 # 2. when make config (in any flavour) is run
100 # 3. when make distclean is run
101 # Don't waste time on reading all Makefile.incs in these cases
102 ifeq ($(strip $(HAVE_DOTCONFIG)),)
103 NOCOMPILE:=1
104 endif
105 ifneq ($(MAKECMDGOALS),)
106 ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
107 NOCOMPILE:=1
108 endif
109 ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
110 NOMKDIR:=1
111 endif
112 endif
114 ifneq ($(filter %-test %-tests,$(MAKECMDGOALS)),)
115 ifneq ($(filter-out %-test %-tests, $(MAKECMDGOALS)),)
116 $(error Cannot mix unit-tests targets with other targets)
117 endif
118 UNIT_TEST:=1
119 NOCOMPILE:=
120 endif
122 .xcompile: util/xcompile/xcompile
123 rm -f $@
124 $< $(XGCCPATH) > $@.tmp
125 \mv -f $@.tmp $@ 2> /dev/null
126 rm -f $@.tmp
128 ifeq ($(NOCOMPILE),1)
129 include $(TOPLEVEL)/Makefile.inc
130 include $(TOPLEVEL)/payloads/Makefile.inc
131 include $(TOPLEVEL)/util/testing/Makefile.inc
132 -include $(TOPLEVEL)/site-local/Makefile.inc
133 real-all:
134 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
135 @echo "Please specify a config file or run 'make menuconfig' to" >&2
136 @echo "generate a new config file." >&2
137 @exit 1
138 else
140 ifneq ($(UNIT_TEST),1)
141 include $(DOTCONFIG)
142 endif
144 # in addition to the dependency below, create the file if it doesn't exist
145 # to silence stupid warnings about a file that would be generated anyway.
146 $(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
148 -include .xcompile
150 ifneq ($(XCOMPILE_COMPLETE),1)
151 $(shell rm -f .xcompile)
152 $(error .xcompile deleted because it's invalid. \
153 Restarting the build should fix that, or explain the problem)
154 endif
156 ifneq ($(CONFIG_MMX),y)
157 CFLAGS_x86_32 += -mno-mmx
158 endif
160 ifneq ($(UNIT_TEST),1)
161 include toolchain.inc
162 endif
164 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
165 # fix makefile syntax highlighting after strip macro \" "))
167 # The primary target needs to be here before we include the
168 # other files
170 real-all: real-target
172 # must come rather early
173 .SECONDEXPANSION:
174 .DELETE_ON_ERROR:
176 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
177 +$(MAKE) oldconfig
179 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
180 true
182 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
183 $(objutil)/kconfig/toada CB.Config <$< >$@
185 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
186 cp $< $@
188 # Add a new class of source/object files to the build system
189 add-class= \
190 $(eval $(1)-srcs:=) \
191 $(eval $(1)-objs:=) \
192 $(eval classes+=$(1))
194 # Special classes are managed types with special behaviour
195 # On parse time, for each entry in variable $(1)-y
196 # a handler $(1)-handler is executed with the arguments:
197 # * $(1): directory the parser is in
198 # * $(2): current entry
199 add-special-class= \
200 $(eval $(1):=) \
201 $(eval special-classes+=$(1))
203 # Converts one or more source file paths to their corresponding build/ paths.
204 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
205 # their name.
206 # $1 stage name
207 # $2 file path (list)
208 src-to-obj=\
209 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
210 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
211 $(patsubst 3rdparty/%,$(obj)/%,\
212 $(patsubst src/%,$(obj)/%,\
213 $(patsubst %.ads,%.o,\
214 $(patsubst %.adb,%.o,\
215 $(patsubst %.c,%.o,\
216 $(patsubst %.S,%.o,\
217 $(subst .$(1),,$(2))))))))))
219 # Converts one or more source file paths to the corresponding build/ paths
220 # of their Ada library information (.ali) files.
221 # $1 stage name
222 # $2 file path (list)
223 src-to-ali=\
224 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
225 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
226 $(patsubst 3rdparty/%,$(obj)/%,\
227 $(patsubst src/%,$(obj)/%,\
228 $(patsubst %.ads,%.ali,\
229 $(patsubst %.adb,%.ali,\
230 $(subst .$(1),,\
231 $(filter %.ads %.adb,$(2)))))))))
233 # Clean -y variables, include Makefile.inc
234 # Add paths to files in X-y to X-srcs
235 # Add subdirs-y to subdirs
236 includemakefiles= \
237 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
238 $(eval -include $(1)) \
239 $(foreach class,$(classes-y), $(call add-class,$(class))) \
240 $(foreach special,$(special-classes), \
241 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
242 $(foreach class,$(classes), \
243 $(eval $(class)-srcs+= \
244 $$(subst $(absobj)/,$(obj)/, \
245 $$(subst $(top)/,, \
246 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
247 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
249 # For each path in $(subdirs) call includemakefiles
250 # Repeat until subdirs is empty
251 evaluate_subdirs= \
252 $(eval cursubdirs:=$(subdirs)) \
253 $(eval subdirs:=) \
254 $(foreach dir,$(cursubdirs), \
255 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
256 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
258 # collect all object files eligible for building
259 subdirs:=$(TOPLEVEL)
260 postinclude-hooks :=
262 # Don't iterate through Makefile.incs under src/ when building tests
263 ifneq ($(UNIT_TEST),1)
264 $(eval $(call evaluate_subdirs))
265 else
266 include $(TOPLEVEL)/tests/Makefile.inc
267 endif
269 ifeq ($(FAILBUILD),1)
270 $(error cannot continue build)
271 endif
273 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
274 $(eval $(postinclude-hooks))
276 # Eliminate duplicate mentions of source files in a class
277 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
279 # Build Kconfig .ads if necessary
280 ifeq ($(CONFIG_RAMSTAGE_ADA),y)
281 ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
282 endif
284 # To track dependencies, we need all Ada specification (.ads) files in
285 # *-srcs. Extract / filter all specification files that have a matching
286 # body (.adb) file here (specifications without a body are valid sources
287 # in Ada).
288 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
289 $(filter \
290 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
291 $(filter %.ads,$($(class)-srcs)))))
292 $(foreach class,$(classes),$(eval $(class)-srcs := \
293 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
295 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
296 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
298 # For Ada includes
299 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
301 # Save all objs before processing them (for dependency inclusion)
302 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
304 # Call post-processors if they're defined
305 $(foreach class,$(classes),\
306 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
308 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
309 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
310 alldirs:=$(sort $(abspath $(dir $(allobjs))))
312 # Reads dependencies from an Ada library information (.ali) file
313 # Only basenames (with suffix) are preserved so we have to look the
314 # paths up in $($(stage)-srcs).
315 # $1 stage name
316 # $2 ali file
317 create_ada_deps=$$(if $(2),\
318 gnat.adc \
319 $$(filter \
320 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
321 $$($(1)-srcs) $$($(1)-extra-specs)))
323 # macro to define template macros that are used by use_template macro
324 define create_cc_template
325 # $1 obj class
326 # $2 source suffix (c, S, ld, ...)
327 # $3 additional compiler flags
328 # $4 additional dependencies
329 ifn$(EMPTY)def $(1)-objs_$(2)_template
330 de$(EMPTY)fine $(1)-objs_$(2)_template
331 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
332 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
333 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
334 $(GCC_$(1)) \
335 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
336 $(3) -c -o $$$$@ $$$$<
337 el$(EMPTY)se
338 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
339 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
340 $(CC_$(1)) \
341 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
342 $(3) -c -o $$$$@ $$$$<
343 end$(EMPTY)if
344 en$(EMPTY)def
345 end$(EMPTY)if
346 endef
348 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
349 $(foreach class,$(classes), \
350 $(foreach type,$(call filetypes-of-class,$(class)), \
351 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
352 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
353 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
355 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
356 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
358 # To supported complex package initializations, we need to call the
359 # emitted code explicitly. gnatbind gathers all the calls for us
360 # and exports them as a procedure $(stage)_adainit(). Every stage that
361 # uses Ada code has to call it!
362 define gnatbind_template
363 # $1 class
364 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
365 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
366 # We have to give gnatbind a simple filename (without leading
367 # path components) so just cd there.
368 cd $$(dir $$@) && \
369 $$(GNATBIND_$(1)) -a -n \
370 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
371 -L$(1)_ada -o $$(notdir $$@) \
372 $$(subst $$(dir $$@),,$$^)
373 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
374 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
375 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
376 $(1)-objs += $$(obj)/$(1)/b__$(1).o
377 $($(1)-alis): %.ali: %.o ;
378 endef
380 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
381 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
383 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
384 -include $(DEPENDENCIES)
386 printall:
387 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
388 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
389 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
390 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
391 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
392 endif
394 ifndef NOMKDIR
395 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
396 endif
398 $(obj)/project_filelist.txt:
399 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
400 echo "*** Error: Project must be built before generating file list ***"; \
401 exit 1; \
403 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
404 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
405 grep -v '\.o$$' > $(obj)/project_filelist.txt
407 filelist: $(obj)/project_filelist.txt
408 printf "\nFiles used in build:\n"
409 cat $(obj)/project_filelist.txt
411 #works with either exuberant ctags or ctags.emacs
412 ctags-project: clean-ctags $(obj)/project_filelist.txt
413 cat $(obj)/project_filelist.txt | \
414 xargs ctags -o tags
416 cscope-project: clean-cscope $(obj)/project_filelist.txt
417 cat $(obj)/project_filelist.txt | xargs cscope -b
419 cscope:
420 cscope -bR
422 doxy: doxygen
423 doxygen:
424 $(DOXYGEN) Documentation/Doxyfile.coreboot
426 doxygen_simple:
427 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
429 doxyplatform doxygen_platform: $(obj)/project_filelist.txt
430 echo
431 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
432 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
433 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
434 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
435 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
436 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
438 doxyclean: doxygen-clean
439 doxygen-clean:
440 rm -rf $(DOXYGEN_OUTPUT_DIR)
442 clean-for-update: doxygen-clean clean-for-update-target
443 rm -rf $(obj) .xcompile
445 clean: clean-for-update clean-target clean-utils
446 rm -f .ccwrap
448 clean-cscope:
449 rm -f cscope.out
451 clean-ctags:
452 rm -f tags
454 clean-utils:
455 $(foreach tool, $(TOOLLIST), \
456 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
458 distclean-utils:
459 $(foreach tool, $(TOOLLIST), \
460 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
461 rm -f /util/$(tool)/junit.xml;)
463 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
464 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
465 rm -rf coreboot-builds coreboot-builds-chromeos
466 rm -f abuild*.xml junit.xml* util/lint/junit.xml
468 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
469 .PHONY: ctags-project cscope-project clean-ctags