Remove #ifdef checks on Kconfig symbols
[coreboot.git] / Makefile
blob99d71395ede1b6fc305a2beef74281e91ef9dd36
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 # in addition to the dependency below, create the file if it doesn't exist
34 # to silence stupid warnings about a file that would be generated anyway.
35 $(if $(wildcard .xcompile),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
37 .xcompile: util/xcompile/xcompile
38 rm -f $@
39 $< $(XGCCPATH) > $@.tmp
40 \mv -f $@.tmp $@ 2> /dev/null
41 rm -f $@.tmp
43 export top := $(CURDIR)
44 export src := src
45 export srck := $(top)/util/kconfig
46 obj ?= build
47 override obj := $(subst $(top)/,,$(abspath $(obj)))
48 export obj
49 export objutil ?= $(obj)/util
50 export objk := $(objutil)/kconfig
51 absobj := $(abspath $(obj))
54 export KCONFIG_AUTOHEADER := $(obj)/config.h
55 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
56 export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
57 export KCONFIG_SPLITCONFIG := $(obj)/config
58 export KCONFIG_TRISTATE := $(obj)/tristate.conf
59 export KCONFIG_NEGATIVES := 1
61 # directory containing the toplevel Makefile.inc
62 TOPLEVEL := .
64 CONFIG_SHELL := sh
65 KBUILD_DEFCONFIG := configs/defconfig
66 UNAME_RELEASE := $(shell uname -r)
67 DOTCONFIG ?= .config
68 KCONFIG_CONFIG = $(DOTCONFIG)
69 export KCONFIG_CONFIG
70 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
71 MAKEFLAGS += -rR --no-print-directory
73 # Make is silent per default, but 'make V=1' will show all compiler calls.
74 Q:=@
75 ifneq ($(V),1)
76 ifneq ($(Q),)
77 .SILENT:
78 endif
79 endif
81 # Disable implicit/built-in rules to make Makefile errors fail fast.
82 .SUFFIXES:
84 HOSTCC := $(if $(shell type gcc 2>/dev/null), gcc, cc)
85 HOSTCXX = g++
86 HOSTCFLAGS := -g
87 HOSTCXXFLAGS := -g
89 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
91 DOXYGEN := doxygen
92 DOXYGEN_OUTPUT_DIR := doxygen
94 all: real-all
96 help_coreboot help::
97 @echo '*** coreboot platform targets ***'
98 @echo ' Use "make [target] V=1" for extra build debug information'
99 @echo ' all - Build coreboot'
100 @echo ' clean - Remove coreboot build artifacts'
101 @echo ' distclean - Remove build artifacts and config files'
102 @echo ' doxygen - Build doxygen documentation for coreboot'
103 @echo ' what-jenkins-does - Run platform build tests (Use CPUS=# for more cores)'
104 @echo ' printall - print makefile info for debugging'
105 @echo ' lint / lint-stable - run coreboot lint tools (all / minimal)'
106 @echo ' gitconfig - set up git to subnit patches to coreboot'
107 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
108 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
109 @echo
111 # This include must come _before_ the pattern rules below!
112 # Order _does_ matter for pattern rules.
113 include $(srck)/Makefile
115 # Three cases where we don't need fully populated $(obj) lists:
116 # 1. when no .config exists
117 # 2. when make config (in any flavour) is run
118 # 3. when make distclean is run
119 # Don't waste time on reading all Makefile.incs in these cases
120 ifeq ($(strip $(HAVE_DOTCONFIG)),)
121 NOCOMPILE:=1
122 endif
123 ifneq ($(MAKECMDGOALS),)
124 ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
125 NOCOMPILE:=1
126 endif
127 ifeq ($(MAKECMDGOALS), %clean)
128 NOMKDIR:=1
129 endif
130 endif
132 ifeq ($(NOCOMPILE),1)
133 include $(TOPLEVEL)/Makefile.inc
134 real-all: config
136 else
138 include $(HAVE_DOTCONFIG)
140 -include .xcompile
142 ifneq ($(XCOMPILE_COMPLETE),1)
143 $(shell rm -f .xcompile)
144 $(error .xcompile deleted because it's invalid. \
145 Restarting the build should fix that, or explain the problem)
146 endif
148 ifneq ($(CONFIG_MMX),y)
149 CFLAGS_x86_32 += -mno-mmx
150 endif
152 include toolchain.inc
154 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
156 # The primary target needs to be here before we include the
157 # other files
159 real-all: real-target
161 # must come rather early
162 .SECONDEXPANSION:
164 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
165 $(MAKE) oldconfig
167 # Add a new class of source/object files to the build system
168 add-class= \
169 $(eval $(1)-srcs:=) \
170 $(eval $(1)-objs:=) \
171 $(eval classes+=$(1))
173 # Special classes are managed types with special behaviour
174 # On parse time, for each entry in variable $(1)-y
175 # a handler $(1)-handler is executed with the arguments:
176 # * $(1): directory the parser is in
177 # * $(2): current entry
178 add-special-class= \
179 $(eval $(1):=) \
180 $(eval special-classes+=$(1))
182 # Clean -y variables, include Makefile.inc
183 # Add paths to files in X-y to X-srcs
184 # Add subdirs-y to subdirs
185 includemakefiles= \
186 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
187 $(eval -include $(1)) \
188 $(foreach class,$(classes-y), $(call add-class,$(class))) \
189 $(foreach class,$(classes), \
190 $(eval $(class)-srcs+= \
191 $$(subst $(absobj)/,$(obj)/, \
192 $$(subst $(top)/,, \
193 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
194 $(foreach special,$(special-classes), \
195 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
196 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
198 # For each path in $(subdirs) call includemakefiles
199 # Repeat until subdirs is empty
200 evaluate_subdirs= \
201 $(eval cursubdirs:=$(subdirs)) \
202 $(eval subdirs:=) \
203 $(foreach dir,$(cursubdirs), \
204 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
205 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
207 # collect all object files eligible for building
208 subdirs:=$(TOPLEVEL)
209 $(eval $(call evaluate_subdirs))
210 ifeq ($(FAILBUILD),1)
211 $(error cannot continue build)
212 endif
214 # Eliminate duplicate mentions of source files in a class
215 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
217 # Converts one or more source file paths to their corresponding build/ paths.
218 # Only .c and .S get converted to .o, other files (like .ld) keep their name.
219 # $1 stage name
220 # $2 file path (list)
221 src-to-obj=$(foreach file,$(2),$(subst .$(1),,$(basename $(patsubst src/%,$(obj)/%,$(file)))).$(1)$(patsubst %.c,%.o,$(patsubst %.S,%.o,$(suffix $(file)))))
223 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
225 # Save all objs before processing them (for dependency inclusion)
226 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
228 # Call post-processors if they're defined
229 $(foreach class,$(classes),\
230 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
232 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
233 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
234 alldirs:=$(sort $(abspath $(dir $(allobjs))))
236 # macro to define template macros that are used by use_template macro
237 define create_cc_template
238 # $1 obj class
239 # $2 source suffix (c, S, ld, ...)
240 # $3 additional compiler flags
241 # $4 additional dependencies
242 ifn$(EMPTY)def $(1)-objs_$(2)_template
243 de$(EMPTY)fine $(1)-objs_$(2)_template
244 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
245 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
246 $(CC_$(1)) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) $(3) -c -o $$$$@ $$$$<
247 en$(EMPTY)def
248 end$(EMPTY)if
249 endef
251 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
252 $(foreach class,$(classes), \
253 $(foreach type,$(call filetypes-of-class,$(class)), \
254 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
255 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
256 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
258 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
259 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
261 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
262 -include $(DEPENDENCIES)
264 printall:
265 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
266 @echo alldirs:=$(alldirs)
267 @echo allsrcs=$(allsrcs)
268 @echo DEPENDENCIES=$(DEPENDENCIES)
269 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
271 endif
273 ifndef NOMKDIR
274 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
275 endif
277 $(obj)/project_filelist.txt: all
278 find $(obj) -name "*.d" -exec cat {} \; | \
279 sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
280 grep -v '\.o$$' > $(obj)/project_filelist.txt
282 #works with either exuberant ctags or ctags.emacs
283 ctags-project: clean-ctags $(obj)/project_filelist.txt
284 cat $(obj)/project_filelist.txt | \
285 xargs ctags -o tags
287 cscope-project: clean-cscope $(obj)/project_filelist.txt
288 cat $(obj)/project_filelist.txt | xargs cscope -b
290 cscope:
291 cscope -bR
293 doxy: doxygen
294 doxygen:
295 $(DOXYGEN) Documentation/Doxyfile.coreboot
297 doxygen_simple:
298 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
300 doxyclean: doxygen-clean
301 doxygen-clean:
302 rm -rf $(DOXYGEN_OUTPUT_DIR)
304 clean-for-update: doxygen-clean clean-for-update-target
305 rm -rf $(obj) .xcompile
307 clean: clean-for-update clean-target
308 rm -f .ccwrap
310 clean-cscope:
311 rm -f cscope.out
313 clean-ctags:
314 rm -f tags
316 distclean: clean clean-ctags clean-cscope
317 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
319 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
320 .PHONY: ctags-project cscope-project clean-ctags