Documentation: Fix sphinx configuration
[coreboot.git] / payloads / libpayload / Makefile
blobb5687c3859b439574b4fe4704442effbe14119ec
1 ##
2 ##
3 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
4 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
5 ## Copyright (C) 2009-2010 coresystems GmbH
6 ## Copyright (C) 2011 secunet Security Networks AG
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted provided that the following conditions
10 ## are met:
11 ## 1. Redistributions of source code must retain the above copyright
12 ## notice, this list of conditions and the following disclaimer.
13 ## 2. Redistributions in binary form must reproduce the above copyright
14 ## notice, this list of conditions and the following disclaimer in the
15 ## documentation and/or other materials provided with the distribution.
16 ## 3. The name of the author may not be used to endorse or promote products
17 ## derived from this software without specific prior written permission.
19 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 ## SUCH DAMAGE.
32 ifeq ($(INNER_SCANBUILD),y)
33 CC_real:=$(CC)
34 endif
36 export top := $(CURDIR)
37 export src := src
38 export srck := $(abspath $(top)/../../util/kconfig)
39 export obj ?= build
40 export objutil ?= $(obj)/util
41 export objk := $(objutil)/lp_kconfig
43 export KCONFIG_AUTOHEADER := $(obj)/config.h
44 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
45 export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
46 export KCONFIG_SPLITCONFIG := $(obj)/config
47 export KCONFIG_TRISTATE := $(obj)/tristate.conf
48 export KCONFIG_NEGATIVES := 1
49 export Kconfig := Kconfig
50 export CONFIG_ := CONFIG_LP_
52 # directory containing the toplevel Makefile.inc
53 TOPLEVEL := .
55 CONFIG_LP_SHELL := sh
56 KBUILD_DEFCONFIG ?= configs/defconfig
57 UNAME_RELEASE := $(shell uname -r)
58 DOTCONFIG ?= .config
59 KCONFIG_CONFIG = $(DOTCONFIG)
60 export KCONFIG_CONFIG
61 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
62 MAKEFLAGS += -rR --no-print-directory
64 # Make is silent per default, but 'make V=1' will show all compiler calls.
65 Q:=@
66 ifneq ($(V),1)
67 ifneq ($(Q),)
68 .SILENT:
69 endif
70 endif
72 CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
73 HOSTCC = gcc
74 HOSTCXX = g++
75 HOSTCFLAGS := -I$(srck) -I$(objk) -g
76 HOSTCXXFLAGS := -I$(srck) -I$(objk)
78 DOXYGEN := doxygen
79 DOXYGEN_OUTPUT_DIR := doxygen
81 all: real-all
83 ifeq ($(INNER_SCANBUILD),y)
84 CC:=$(CC_real)
85 HOSTCC:=$(CC_real) --hostcc
86 HOSTCXX:=$(CC_real) --hostcxx
87 endif
89 # This include must come _before_ the pattern rules below!
90 # Order _does_ matter for pattern rules.
91 include $(srck)/Makefile
93 include $(HAVE_DOTCONFIG)
95 ARCHDIR-$(CONFIG_LP_ARCH_ARM) := arm
96 ARCHDIR-$(CONFIG_LP_ARCH_ARM64) := arm64
97 ARCHDIR-$(CONFIG_LP_ARCH_X86) := x86
99 ARCH-y := $(ARCHDIR-y)
101 # If architecture folder name is different from xcompile architecture name,
102 # override here.
103 ARCH-$(CONFIG_LP_ARCH_ARM) := arm
104 ARCH-$(CONFIG_LP_ARCH_ARM64) := arm64
105 ARCH-$(CONFIG_LP_ARCH_X86) := x86_32
107 # Three cases where we don't need fully populated $(obj) lists:
108 # 1. when no .config exists
109 # 2. when make config (in any flavour) is run
110 # 3. when make distclean is run
111 # Don't waste time on reading all Makefile.incs in these cases
112 ifeq ($(strip $(HAVE_DOTCONFIG)),)
113 NOCOMPILE:=1
114 endif
115 ifneq ($(MAKECMDGOALS),)
116 ifneq ($(filter %config %clean,$(MAKECMDGOALS)),)
117 NOCOMPILE:=1
118 endif
119 endif
121 ifeq ($(NOCOMPILE),1)
122 include $(TOPLEVEL)/Makefile.inc
123 real-all: config
125 else
127 # in addition to the dependency below, create the file if it doesn't exist
128 # to silence stupid warnings about a file that would be generated anyway.
129 $(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell $(top)/../../util/xcompile/xcompile $(XGCCPATH) > .xcompile)))
131 .xcompile: $(top)/../../util/xcompile/xcompile
132 $< $(XGCCPATH) > $@.tmp
133 \mv -f $@.tmp $@ 2> /dev/null
135 -include .xcompile
137 CC := $(CC_$(ARCH-y))
138 AS := $(AS_$(ARCH-y))
139 LD := $(LD_$(ARCH-y))
140 NM := $(NM_$(ARCH-y))
141 OBJCOPY := $(OBJCOPY_$(ARCH-y))
142 OBJDUMP := $(OBJDUMP_$(ARCH-y))
143 READELF := $(READELF_$(ARCH-y))
144 STRIP := $(STRIP_$(ARCH-y))
145 AR := $(AR_$(ARCH-y))
147 CFLAGS += -std=gnu11 $(CFLAGS_$(ARCH-y))
149 ifneq ($(INNER_SCANBUILD),y)
150 ifeq ($(CONFIG_LP_COMPILER_LLVM_CLANG),y)
151 CC:=clang -m32
152 HOSTCC:=clang
153 endif
154 endif
156 ifeq ($(CONFIG_LP_CCACHE),y)
157 CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
158 ifeq ($(CCACHE),)
159 $(error ccache selected, but not found in PATH)
160 endif
161 CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
162 CC := $(CCACHE) $(CC)
163 HOSTCC := $(CCACHE) $(HOSTCC)
164 HOSTCXX := $(CCACHE) $(HOSTCXX)
165 endif
167 strip_quotes = $(subst ",,$(subst \",,$(1)))
169 # The primary target needs to be here before we include the
170 # other files
172 ifeq ($(INNER_SCANBUILD),y)
173 CONFIG_LP_SCANBUILD_ENABLE:=
174 endif
176 ifeq ($(CONFIG_LP_SCANBUILD_ENABLE),y)
177 ifneq ($(CONFIG_LP_SCANBUILD_REPORT_LOCATION),)
178 CONFIG_LP_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_LP_SCANBUILD_REPORT_LOCATION)
179 endif
180 real-all:
181 echo '#!/bin/sh' > .ccwrap
182 echo 'CC="$(CC)"' >> .ccwrap
183 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
184 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
185 echo 'eval $$CC $$*' >> .ccwrap
186 chmod +x .ccwrap
187 scan-build $(CONFIG_LP_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
188 else
189 real-all: real-target
190 endif
192 # must come rather early
193 .SECONDEXPANSION:
195 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
196 $(MAKE) oldconfig
198 # Add a new class of source/object files to the build system
199 add-class= \
200 $(eval $(1)-srcs:=) \
201 $(eval $(1)-objs:=) \
202 $(eval classes+=$(1))
204 # Special classes are managed types with special behaviour
205 # On parse time, for each entry in variable $(1)-y
206 # a handler $(1)-handler is executed with the arguments:
207 # * $(1): directory the parser is in
208 # * $(2): current entry
209 add-special-class= \
210 $(eval $(1):=) \
211 $(eval special-classes+=$(1))
213 # Clean -y variables, include Makefile.inc
214 # Add paths to files in X-y to X-srcs
215 # Add subdirs-y to subdirs
216 includemakefiles= \
217 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
218 $(eval -include $(1)) \
219 $(foreach class,$(classes-y), $(call add-class,$(class))) \
220 $(foreach special,$(special-classes), \
221 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
222 $(foreach class,$(classes), \
223 $(eval $(class)-srcs+= \
224 $$(subst $(top)/,, \
225 $$(abspath $$(addprefix $(dir $(1)),$$($(class)-y)))))) \
226 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
228 # For each path in $(subdirs) call includemakefiles
229 # Repeat until subdirs is empty
230 evaluate_subdirs= \
231 $(eval cursubdirs:=$(subdirs)) \
232 $(eval subdirs:=) \
233 $(foreach dir,$(cursubdirs), \
234 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
235 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
237 # collect all object files eligible for building
238 subdirs:=$(TOPLEVEL)
239 $(eval $(call evaluate_subdirs))
241 src-to-obj=$(addsuffix .$(1).o, $(basename $(addprefix $(obj)/, $($(1)-srcs))))
242 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
244 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
245 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
246 alldirs:=$(sort $(abspath $(dir $(allobjs))))
248 # macro to define template macros that are used by use_template macro
249 define create_cc_template
250 # $1 obj class
251 # $2 source suffix (c, S)
252 # $3 additional compiler flags
253 # $4 additional dependencies
254 ifn$(EMPTY)def $(1)-objs_$(2)_template
255 de$(EMPTY)fine $(1)-objs_$(2)_template
256 $(obj)/$$(1).$(1).o: $$(1).$(2) $(obj)/libpayload-config.h $(4)
257 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
258 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
259 en$(EMPTY)def
260 end$(EMPTY)if
261 endef
263 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
264 $(foreach class,$(classes), \
265 $(foreach type,$(call filetypes-of-class,$(class)), \
266 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
268 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
269 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
271 DEPENDENCIES = $(allobjs:.o=.d)
272 -include $(DEPENDENCIES)
274 printall:
275 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
276 @echo alldirs:=$(alldirs)
277 @echo allsrcs=$(allsrcs)
278 @echo DEPENDENCIES=$(DEPENDENCIES)
279 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
281 endif
283 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(obj) $(objk)/lxdialog $(additional-dirs) $(alldirs))
285 cscope:
286 cscope -bR
288 doxy: doxygen
289 doxygen:
290 $(DOXYGEN) Doxyfile
292 doxyclean: doxygen-clean
293 doxygen-clean:
294 rm -rf $(DOXYGEN_OUTPUT_DIR)
296 clean-for-update: doxygen-clean clean-for-update-target
297 rm -f $(allobjs) .xcompile
298 rm -f $(DEPENDENCIES)
299 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
301 clean: clean-for-update clean-target
302 rm -f .ccwrap junit_config junit_config.old
303 rm -rf $(obj)
305 clean-cscope:
306 rm -f cscope.out
308 distclean: clean-cscope clean
309 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile junit.xml
311 .PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy