bootblock: Guard CMOS rewrite in disable/enable RTC
[coreboot.git] / Makefile
blobb40574b75a6ba2d87addf4abe77e08894f1fca9e
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 ifeq ($(INNER_SCANBUILD),y)
34 CC_real:=$(CC)
35 endif
37 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile $(XGCCPATH) > .xcompile)))
38 include .xcompile
40 ifeq ($(INNER_SCANBUILD),y)
41 CC:=$(CC_real)
42 HOSTCC:=$(CC_real) --hostcc
43 HOSTCXX:=$(CC_real) --hostcxx
44 endif
46 export top := $(CURDIR)
47 export src := src
48 export srck := $(top)/util/kconfig
49 export obj ?= build
50 export objutil ?= $(obj)/util
51 export objk := $(objutil)/kconfig
54 export KCONFIG_AUTOHEADER := $(obj)/config.h
55 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
57 # directory containing the toplevel Makefile.inc
58 TOPLEVEL := .
60 CONFIG_SHELL := sh
61 KBUILD_DEFCONFIG := configs/defconfig
62 UNAME_RELEASE := $(shell uname -r)
63 DOTCONFIG ?= .config
64 KCONFIG_CONFIG = $(DOTCONFIG)
65 export KCONFIG_CONFIG
66 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
67 MAKEFLAGS += -rR --no-print-directory
69 # Make is silent per default, but 'make V=1' will show all compiler calls.
70 Q:=@
71 ifneq ($(V),1)
72 ifneq ($(Q),)
73 .SILENT:
74 endif
75 endif
77 HOSTCC = gcc
78 HOSTCXX = g++
79 HOSTCFLAGS := -g
80 HOSTCXXFLAGS := -g
81 LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && $(CC) -print-libgcc-file-name)
83 DOXYGEN := doxygen
84 DOXYGEN_OUTPUT_DIR := doxygen
86 all: real-all
88 # This include must come _before_ the pattern rules below!
89 # Order _does_ matter for pattern rules.
90 include util/kconfig/Makefile
92 # Three cases where we don't need fully populated $(obj) lists:
93 # 1. when no .config exists
94 # 2. when make config (in any flavour) is run
95 # 3. when make distclean is run
96 # Don't waste time on reading all Makefile.incs in these cases
97 ifeq ($(strip $(HAVE_DOTCONFIG)),)
98 NOCOMPILE:=1
99 endif
100 ifneq ($(MAKECMDGOALS),)
101 ifneq ($(filter %config distclean,$(MAKECMDGOALS)),)
102 NOCOMPILE:=1
103 endif
104 ifeq ($(MAKECMDGOALS), distclean)
105 NOMKDIR:=1
106 endif
107 endif
109 ifeq ($(NOCOMPILE),1)
110 include $(TOPLEVEL)/Makefile.inc
111 real-all: config
113 else
115 include $(HAVE_DOTCONFIG)
117 ifneq ($(INNER_SCANBUILD),y)
118 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
119 CC:=clang -m32 -mno-mmx -mno-sse
120 HOSTCC:=clang
121 endif
122 endif
124 ifeq ($(CONFIG_CCACHE),y)
125 CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
126 ifeq ($(CCACHE),)
127 $(error ccache selected, but not found in PATH)
128 endif
129 CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
130 CC := $(CCACHE) $(CC)
131 HOSTCC := $(CCACHE) $(HOSTCC)
132 HOSTCXX := $(CCACHE) $(HOSTCXX)
133 ROMCC := $(CCACHE) $(ROMCC)
134 endif
136 strip_quotes = $(subst ",,$(subst \",,$(1)))
138 # The primary target needs to be here before we include the
139 # other files
141 ifeq ($(INNER_SCANBUILD),y)
142 CONFIG_SCANBUILD_ENABLE:=
143 endif
145 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
146 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
147 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
148 endif
149 real-all:
150 echo '#!/bin/sh' > .ccwrap
151 echo 'CC="$(CC)"' >> .ccwrap
152 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
153 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
154 echo 'eval $$CC $$*' >> .ccwrap
155 chmod +x .ccwrap
156 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
157 else
158 real-all: real-target
159 endif
161 # must come rather early
162 .SECONDEXPANSION:
164 $(obj)/config.h:
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 $(top)/,, \
192 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
193 $(foreach special,$(special-classes), \
194 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
195 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
197 # For each path in $(subdirs) call includemakefiles
198 # Repeat until subdirs is empty
199 evaluate_subdirs= \
200 $(eval cursubdirs:=$(subdirs)) \
201 $(eval subdirs:=) \
202 $(foreach dir,$(cursubdirs), \
203 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
204 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
206 # collect all object files eligible for building
207 subdirs:=$(TOPLEVEL)
208 $(eval $(call evaluate_subdirs))
210 # Eliminate duplicate mentions of source files in a class
211 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
213 src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
214 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
216 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
217 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
218 alldirs:=$(sort $(abspath $(dir $(allobjs))))
220 # macro to define template macros that are used by use_template macro
221 define create_cc_template
222 # $1 obj class
223 # $2 source suffix (c, S)
224 # $3 additional compiler flags
225 # $4 additional dependencies
226 ifn$(EMPTY)def $(1)-objs_$(2)_template
227 de$(EMPTY)fine $(1)-objs_$(2)_template
228 $(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
229 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
230 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
231 en$(EMPTY)def
232 end$(EMPTY)if
233 endef
235 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
236 $(foreach class,$(classes), \
237 $(foreach type,$(call filetypes-of-class,$(class)), \
238 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
240 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
241 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
243 DEPENDENCIES = $(allobjs:.o=.d)
244 -include $(DEPENDENCIES)
246 printall:
247 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
248 @echo alldirs:=$(alldirs)
249 @echo allsrcs=$(allsrcs)
250 @echo DEPENDENCIES=$(DEPENDENCIES)
251 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
252 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
254 endif
256 ifndef NOMKDIR
257 $(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
258 endif
260 cscope:
261 cscope -bR
263 doxy: doxygen
264 doxygen:
265 $(DOXYGEN) documentation/Doxyfile.coreboot
267 doxyclean: doxygen-clean
268 doxygen-clean:
269 rm -rf $(DOXYGEN_OUTPUT_DIR)
271 clean-for-update: doxygen-clean clean-for-update-target
272 rm -f $(allobjs) .xcompile
273 rm -f $(DEPENDENCIES)
274 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
276 clean: clean-for-update clean-target
277 rm -f .ccwrap
279 clean-cscope:
280 rm -f cscope.out
282 distclean:
283 rm -rf $(obj)
284 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
286 .PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy .xcompile