Revert "i82371eb: Drop support for older PIIX chips"
[coreboot.git] / Makefile
blob3f60493314eb0e5a3956278def6d2be8f5dcb3fb
1 ##
2 ## This file is part of the coreboot project.
3 ##
4 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
5 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
6 ## Copyright (C) 2009-2010 coresystems GmbH
7 ## Copyright (C) 2011 secunet Security Networks AG
8 ##
9 ## Redistribution and use in source and binary forms, with or without
10 ## modification, are permitted provided that the following conditions
11 ## are met:
12 ## 1. Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## 2. Redistributions in binary form must reproduce the above copyright
15 ## notice, this list of conditions and the following disclaimer in the
16 ## documentation and/or other materials provided with the distribution.
17 ## 3. The name of the author may not be used to endorse or promote products
18 ## derived from this software without specific prior written permission.
20 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 ## SUCH DAMAGE.
33 ifneq ($(words $(CURDIR)),1)
34 $(error Error: Path to the main directory cannot contain spaces)
35 endif
36 top := $(CURDIR)
37 src := src
38 srck := $(top)/util/kconfig
39 obj ?= build
40 override obj := $(subst $(top)/,,$(abspath $(obj)))
41 objutil ?= $(obj)/util
42 objk := $(objutil)/kconfig
43 absobj := $(abspath $(obj))
45 COREBOOT_EXPORTS := COREBOOT_EXPORTS
46 COREBOOT_EXPORTS += top src srck obj objutil objk
48 # reproducible builds
49 LANG:=C
50 LC_ALL:=C
51 TZ:=UTC0
52 COREBOOT_EXPORTS += LANG LC_ALL TZ
54 DOTCONFIG ?= $(top)/.config
55 KCONFIG_CONFIG = $(DOTCONFIG)
56 KCONFIG_AUTOADS := $(obj)/cb-config.ads
57 KCONFIG_AUTOHEADER := $(obj)/config.h
58 KCONFIG_AUTOCONFIG := $(obj)/auto.conf
59 KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
60 KCONFIG_SPLITCONFIG := $(obj)/config
61 KCONFIG_TRISTATE := $(obj)/tristate.conf
62 KCONFIG_NEGATIVES := 1
63 KCONFIG_STRICT := 1
64 KCONFIG_PACKAGE := CB.Config
66 COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
67 COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
68 COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
69 COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
71 # directory containing the toplevel Makefile.inc
72 TOPLEVEL := .
74 CONFIG_SHELL := sh
75 KBUILD_DEFCONFIG := configs/defconfig
76 UNAME_RELEASE := $(shell uname -r)
77 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
78 MAKEFLAGS += -rR --no-print-directory
80 # Make is silent per default, but 'make V=1' will show all compiler calls.
81 Q:=@
82 ifneq ($(V),1)
83 ifneq ($(Q),)
84 .SILENT:
85 MAKEFLAGS += -s
86 endif
87 endif
89 # Disable implicit/built-in rules to make Makefile errors fail fast.
90 .SUFFIXES:
92 HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
93 HOSTCXX = g++
94 HOSTCFLAGS := -g
95 HOSTCXXFLAGS := -g
97 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
99 DOXYGEN := doxygen
100 DOXYGEN_OUTPUT_DIR := doxygen
102 export $(COREBOOT_EXPORTS)
104 all: real-all
106 help_coreboot help::
107 @echo '*** coreboot platform targets ***'
108 @echo ' Use "make [target] V=1" for extra build debug information'
109 @echo ' all - Build coreboot'
110 @echo ' clean - Remove coreboot build artifacts'
111 @echo ' distclean - Remove build artifacts and config files'
112 @echo ' doxygen - Build doxygen documentation for coreboot'
113 @echo ' doxyplatform - Build doxygen documentation for the current platform'
114 @echo ' filelist - Show files used in current build'
115 @echo ' printall - print makefile info for debugging'
116 @echo ' gitconfig - set up git to submit patches to coreboot'
117 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
118 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
119 @echo
121 # This include must come _before_ the pattern rules below!
122 # Order _does_ matter for pattern rules.
123 include $(srck)/Makefile.inc
125 # Three cases where we don't need fully populated $(obj) lists:
126 # 1. when no .config exists
127 # 2. when make config (in any flavour) is run
128 # 3. when make distclean is run
129 # Don't waste time on reading all Makefile.incs in these cases
130 ifeq ($(strip $(HAVE_DOTCONFIG)),)
131 NOCOMPILE:=1
132 endif
133 ifneq ($(MAKECMDGOALS),)
134 ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
135 NOCOMPILE:=1
136 endif
137 ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
138 NOMKDIR:=1
139 endif
140 endif
142 .xcompile: util/xcompile/xcompile
143 rm -f $@
144 $< $(XGCCPATH) > $@.tmp
145 \mv -f $@.tmp $@ 2> /dev/null
146 rm -f $@.tmp
148 ifeq ($(NOCOMPILE),1)
149 include $(TOPLEVEL)/Makefile.inc
150 include $(TOPLEVEL)/payloads/Makefile.inc
151 include $(TOPLEVEL)/util/testing/Makefile.inc
152 -include $(TOPLEVEL)/site-local/Makefile.inc
153 real-all:
154 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
155 @echo "Please specify a config file or run 'make menuconfig' to" >&2
156 @echo "generate a new config file." >&2
157 @exit 1
158 else
160 include $(DOTCONFIG)
162 # in addition to the dependency below, create the file if it doesn't exist
163 # to silence stupid warnings about a file that would be generated anyway.
164 $(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
166 -include .xcompile
168 ifneq ($(XCOMPILE_COMPLETE),1)
169 $(shell rm -f .xcompile)
170 $(error .xcompile deleted because it's invalid. \
171 Restarting the build should fix that, or explain the problem)
172 endif
174 ifneq ($(CONFIG_MMX),y)
175 CFLAGS_x86_32 += -mno-mmx
176 endif
178 include toolchain.inc
180 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
181 # fix makefile syntax highlighting after strip macro \" "))
183 # The primary target needs to be here before we include the
184 # other files
186 real-all: real-target
188 # must come rather early
189 .SECONDEXPANSION:
190 .DELETE_ON_ERROR:
192 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
193 +$(MAKE) oldconfig
195 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
196 true
198 $(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
199 $(objutil)/kconfig/toada CB.Config <$< >$@
201 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
202 cp $< $@
204 # Add a new class of source/object files to the build system
205 add-class= \
206 $(eval $(1)-srcs:=) \
207 $(eval $(1)-objs:=) \
208 $(eval classes+=$(1))
210 # Special classes are managed types with special behaviour
211 # On parse time, for each entry in variable $(1)-y
212 # a handler $(1)-handler is executed with the arguments:
213 # * $(1): directory the parser is in
214 # * $(2): current entry
215 add-special-class= \
216 $(eval $(1):=) \
217 $(eval special-classes+=$(1))
219 # Converts one or more source file paths to their corresponding build/ paths.
220 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
221 # their name.
222 # $1 stage name
223 # $2 file path (list)
224 src-to-obj=\
225 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
226 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
227 $(patsubst 3rdparty/%,$(obj)/%,\
228 $(patsubst src/%,$(obj)/%,\
229 $(patsubst %.ads,%.o,\
230 $(patsubst %.adb,%.o,\
231 $(patsubst %.c,%.o,\
232 $(patsubst %.S,%.o,\
233 $(subst .$(1),,$(2))))))))))
235 # Converts one or more source file paths to the corresponding build/ paths
236 # of their Ada library information (.ali) files.
237 # $1 stage name
238 # $2 file path (list)
239 src-to-ali=\
240 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
241 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
242 $(patsubst 3rdparty/%,$(obj)/%,\
243 $(patsubst src/%,$(obj)/%,\
244 $(patsubst %.ads,%.ali,\
245 $(patsubst %.adb,%.ali,\
246 $(subst .$(1),,\
247 $(filter %.ads %.adb,$(2)))))))))
249 # Clean -y variables, include Makefile.inc
250 # Add paths to files in X-y to X-srcs
251 # Add subdirs-y to subdirs
252 includemakefiles= \
253 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
254 $(eval -include $(1)) \
255 $(foreach class,$(classes-y), $(call add-class,$(class))) \
256 $(foreach special,$(special-classes), \
257 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
258 $(foreach class,$(classes), \
259 $(eval $(class)-srcs+= \
260 $$(subst $(absobj)/,$(obj)/, \
261 $$(subst $(top)/,, \
262 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
263 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
265 # For each path in $(subdirs) call includemakefiles
266 # Repeat until subdirs is empty
267 evaluate_subdirs= \
268 $(eval cursubdirs:=$(subdirs)) \
269 $(eval subdirs:=) \
270 $(foreach dir,$(cursubdirs), \
271 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
272 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
274 # collect all object files eligible for building
275 subdirs:=$(TOPLEVEL)
276 postinclude-hooks :=
277 $(eval $(call evaluate_subdirs))
278 ifeq ($(FAILBUILD),1)
279 $(error cannot continue build)
280 endif
282 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
283 $(eval $(postinclude-hooks))
285 # Eliminate duplicate mentions of source files in a class
286 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
288 # Build Kconfig .ads if necessary
289 ifeq ($(CONFIG_RAMSTAGE_ADA),y)
290 ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
291 endif
293 # To track dependencies, we need all Ada specification (.ads) files in
294 # *-srcs. Extract / filter all specification files that have a matching
295 # body (.adb) file here (specifications without a body are valid sources
296 # in Ada).
297 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
298 $(filter \
299 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
300 $(filter %.ads,$($(class)-srcs)))))
301 $(foreach class,$(classes),$(eval $(class)-srcs := \
302 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
304 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
305 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
307 # For Ada includes
308 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
310 # Save all objs before processing them (for dependency inclusion)
311 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
313 # Call post-processors if they're defined
314 $(foreach class,$(classes),\
315 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
317 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
318 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
319 alldirs:=$(sort $(abspath $(dir $(allobjs))))
321 # Reads dependencies from an Ada library information (.ali) file
322 # Only basenames (with suffix) are preserved so we have to look the
323 # paths up in $($(stage)-srcs).
324 # $1 stage name
325 # $2 ali file
326 create_ada_deps=$$(if $(2),\
327 gnat.adc \
328 $$(filter \
329 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
330 $$($(1)-srcs) $$($(1)-extra-specs)))
332 # macro to define template macros that are used by use_template macro
333 define create_cc_template
334 # $1 obj class
335 # $2 source suffix (c, S, ld, ...)
336 # $3 additional compiler flags
337 # $4 additional dependencies
338 ifn$(EMPTY)def $(1)-objs_$(2)_template
339 de$(EMPTY)fine $(1)-objs_$(2)_template
340 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
341 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
342 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
343 $(GCC_$(1)) \
344 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
345 $(3) -c -o $$$$@ $$$$<
346 el$(EMPTY)se
347 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
348 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
349 $(CC_$(1)) \
350 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
351 $(3) -c -o $$$$@ $$$$<
352 end$(EMPTY)if
353 en$(EMPTY)def
354 end$(EMPTY)if
355 endef
357 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
358 $(foreach class,$(classes), \
359 $(foreach type,$(call filetypes-of-class,$(class)), \
360 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
361 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
362 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
364 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
365 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
367 # To supported complex package initializations, we need to call the
368 # emitted code explicitly. gnatbind gathers all the calls for us
369 # and exports them as a procedure $(stage)_adainit(). Every stage that
370 # uses Ada code has to call it!
371 define gnatbind_template
372 # $1 class
373 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
374 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
375 # We have to give gnatbind a simple filename (without leading
376 # path components) so just cd there.
377 cd $$(dir $$@) && \
378 $$(GNATBIND_$(1)) -a -n \
379 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
380 -L$(1)_ada -o $$(notdir $$@) \
381 $$(subst $$(dir $$@),,$$^)
382 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
383 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
384 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
385 $(1)-objs += $$(obj)/$(1)/b__$(1).o
386 $($(1)-alis): %.ali: %.o ;
387 endef
389 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
390 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
392 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
393 -include $(DEPENDENCIES)
395 printall:
396 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
397 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
398 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
399 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
400 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
401 endif
403 ifndef NOMKDIR
404 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
405 endif
407 $(obj)/project_filelist.txt:
408 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
409 echo "*** Error: Project must be built before generating file list ***"; \
410 exit 1; \
412 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
413 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
414 grep -v '\.o$$' > $(obj)/project_filelist.txt
416 filelist: $(obj)/project_filelist.txt
417 printf "\nFiles used in build:\n"
418 cat $(obj)/project_filelist.txt
420 #works with either exuberant ctags or ctags.emacs
421 ctags-project: clean-ctags $(obj)/project_filelist.txt
422 cat $(obj)/project_filelist.txt | \
423 xargs ctags -o tags
425 cscope-project: clean-cscope $(obj)/project_filelist.txt
426 cat $(obj)/project_filelist.txt | xargs cscope -b
428 cscope:
429 cscope -bR
431 doxy: doxygen
432 doxygen:
433 $(DOXYGEN) Documentation/Doxyfile.coreboot
435 doxygen_simple:
436 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
438 doxyplatform doxygen_platform: $(obj)/project_filelist.txt
439 echo
440 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
441 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
442 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
443 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
444 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
445 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
447 doxyclean: doxygen-clean
448 doxygen-clean:
449 rm -rf $(DOXYGEN_OUTPUT_DIR)
451 clean-for-update: doxygen-clean clean-for-update-target
452 rm -rf $(obj) .xcompile
454 clean: clean-for-update clean-target clean-utils
455 rm -f .ccwrap
457 clean-cscope:
458 rm -f cscope.out
460 clean-ctags:
461 rm -f tags
463 clean-utils:
464 $(foreach tool, $(TOOLLIST), \
465 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
467 distclean-utils:
468 $(foreach tool, $(TOOLLIST), \
469 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
470 rm -f /util/$(tool)/junit.xml;)
472 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
473 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
474 rm -rf coreboot-builds coreboot-builds-chromeos
475 rm -f abuild*.xml junit.xml* util/lint/junit.xml
477 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
478 .PHONY: ctags-project cscope-project clean-ctags