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