blob: 383d5839a6720c623594f9767e95629acd71e0ad [file] [log] [blame]
Patrick Georgi0588d192009-08-12 15:00:51 +00001##
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>
Stefan Reinauer8ed1b6d2010-01-19 21:13:44 +00006## Copyright (C) 2009-2010 coresystems GmbH
Patrick Georgi71b84802011-02-22 14:35:05 +00007## Copyright (C) 2011 secunet Security Networks AG
Patrick Georgi0588d192009-08-12 15:00:51 +00008##
Patrick Georgi3bda0442011-06-30 15:48:57 +02009## 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.
Patrick Georgi0588d192009-08-12 15:00:51 +000019##
Patrick Georgi3bda0442011-06-30 15:48:57 +020020## 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.
Patrick Georgi0588d192009-08-12 15:00:51 +000031##
32
Nico Huber7a1fbdb2017-08-23 23:48:13 +020033top := $(CURDIR)
34src := src
35srck := $(top)/util/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070036obj ?= build
37override obj := $(subst $(top)/,,$(abspath $(obj)))
Nico Huber7a1fbdb2017-08-23 23:48:13 +020038objutil ?= $(obj)/util
39objk := $(objutil)/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070040absobj := $(abspath $(obj))
Patrick Georgi0588d192009-08-12 15:00:51 +000041
Nico Huber7a1fbdb2017-08-23 23:48:13 +020042COREBOOT_EXPORTS := COREBOOT_EXPORTS
43COREBOOT_EXPORTS += top src srck obj objutil objk
Patrick Georgi0588d192009-08-12 15:00:51 +000044
Nico Huber7a1fbdb2017-08-23 23:48:13 +020045DOTCONFIG ?= $(top)/.config
46KCONFIG_CONFIG = $(DOTCONFIG)
47KCONFIG_AUTOHEADER := $(obj)/config.h
48KCONFIG_AUTOCONFIG := $(obj)/auto.conf
49KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
50KCONFIG_SPLITCONFIG := $(obj)/config
51KCONFIG_TRISTATE := $(obj)/tristate.conf
52KCONFIG_NEGATIVES := 1
53KCONFIG_STRICT := 1
54
55COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
56COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
57COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
Patrick Georgi0588d192009-08-12 15:00:51 +000058
Patrick Georgie38d0a62011-03-01 08:09:22 +000059# directory containing the toplevel Makefile.inc
60TOPLEVEL := .
61
Patrick Georgi0588d192009-08-12 15:00:51 +000062CONFIG_SHELL := sh
63KBUILD_DEFCONFIG := configs/defconfig
64UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000065HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000066MAKEFLAGS += -rR --no-print-directory
67
68# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000069Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000070ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000071ifneq ($(Q),)
72.SILENT:
73endif
Patrick Georgi0588d192009-08-12 15:00:51 +000074endif
75
Julius Werner808a4292015-03-13 11:05:07 -070076# Disable implicit/built-in rules to make Makefile errors fail fast.
77.SUFFIXES:
78
Patrick Georgif92068d2016-02-01 12:02:29 +010079HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
Patrick Georgi0588d192009-08-12 15:00:51 +000080HOSTCXX = g++
Patrick Georgib3a18ac2012-09-13 22:13:33 +020081HOSTCFLAGS := -g
82HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000083
Patrick Georgi828e0e82015-04-04 15:50:20 +020084PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
85
Patrick Georgi0588d192009-08-12 15:00:51 +000086DOXYGEN := doxygen
87DOXYGEN_OUTPUT_DIR := doxygen
88
Nico Huber7a1fbdb2017-08-23 23:48:13 +020089export $(COREBOOT_EXPORTS)
90
Patrick Georgi71b84802011-02-22 14:35:05 +000091all: real-all
92
Martin Roth4eea1742015-11-25 11:50:04 -070093help_coreboot help::
94 @echo '*** coreboot platform targets ***'
Martin Roth76f14b22015-11-18 13:09:23 -070095 @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'
Martin Rothb1574e32016-07-07 15:50:28 -0600100 @echo ' doxyplatform - Build doxygen documentation for the current platform'
Martin Roth76f14b22015-11-18 13:09:23 -0700101 @echo ' printall - print makefile info for debugging'
Werner Zeh2de64102016-01-12 12:45:49 +0100102 @echo ' gitconfig - set up git to submit patches to coreboot'
Martin Roth76f14b22015-11-18 13:09:23 -0700103 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
104 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
105 @echo
106
Patrick Georgie38d0a62011-03-01 08:09:22 +0000107# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +0000108# Order _does_ matter for pattern rules.
Stefan Reinauerde60c882015-06-29 14:44:37 -0700109include $(srck)/Makefile
Patrick Georgi71b84802011-02-22 14:35:05 +0000110
Patrick Georgicf036d12010-04-21 06:36:20 +0000111# Three cases where we don't need fully populated $(obj) lists:
112# 1. when no .config exists
113# 2. when make config (in any flavour) is run
114# 3. when make distclean is run
115# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000116ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000117NOCOMPILE:=1
118endif
119ifneq ($(MAKECMDGOALS),)
Martin Roth109a7db2016-08-11 18:16:59 -0600120ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000121NOCOMPILE:=1
122endif
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100123ifeq ($(MAKECMDGOALS), %clean)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800124NOMKDIR:=1
125endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000126endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000127
Patrick Georgicf036d12010-04-21 06:36:20 +0000128ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000129include $(TOPLEVEL)/Makefile.inc
Martin Roth67975572016-03-07 16:38:52 -0700130include $(TOPLEVEL)/payloads/Makefile.inc
Martin Rothe624e272017-07-31 11:52:58 -0600131include $(TOPLEVEL)/util/testing/Makefile.inc
Naresh G Solanki57443692017-08-31 22:32:49 +0530132-include $(TOPLEVEL)/site-local/Makefile.inc
Martin Roth20aa0432017-01-26 10:51:43 -0700133real-all:
134 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
135 @echo "Please specify a config file or run 'make menuconfig' to" >&2
136 @echo "generate a new config file." >&2
137 @exit 1
Patrick Georgi0588d192009-08-12 15:00:51 +0000138else
139
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200140include $(DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000141
Patrick Georgi0ffef882017-01-19 23:20:14 +0100142# in addition to the dependency below, create the file if it doesn't exist
143# to silence stupid warnings about a file that would be generated anyway.
144$(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
145
146.xcompile: util/xcompile/xcompile
147 rm -f $@
148 $< $(XGCCPATH) > $@.tmp
149 \mv -f $@.tmp $@ 2> /dev/null
150 rm -f $@.tmp
151
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100152-include .xcompile
153
154ifneq ($(XCOMPILE_COMPLETE),1)
155$(shell rm -f .xcompile)
156$(error .xcompile deleted because it's invalid. \
157 Restarting the build should fix that, or explain the problem)
158endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200159
Patrick Georgicc84a002014-05-14 21:05:35 +0200160ifneq ($(CONFIG_MMX),y)
161CFLAGS_x86_32 += -mno-mmx
162endif
163
Patrick Georgicc84a002014-05-14 21:05:35 +0200164include toolchain.inc
165
Zheng Bao07648922015-11-13 10:42:27 +0800166strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700167# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000168
Patrick Georgi0588d192009-08-12 15:00:51 +0000169# The primary target needs to be here before we include the
170# other files
171
Patrick Georgi71b84802011-02-22 14:35:05 +0000172real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000173
Patrick Georgi51e142f2010-03-27 17:18:39 +0000174# must come rather early
175.SECONDEXPANSION:
176
Stefan Reinauer0d869ed2015-07-17 13:31:16 -0700177$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
Patrick Georgi78a5f222017-01-30 15:29:34 +0100178 +$(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000179
Patrick Georgi58262652011-02-17 20:47:49 +0000180# Add a new class of source/object files to the build system
181add-class= \
182 $(eval $(1)-srcs:=) \
183 $(eval $(1)-objs:=) \
184 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000185
Patrick Georgi58262652011-02-17 20:47:49 +0000186# Special classes are managed types with special behaviour
187# On parse time, for each entry in variable $(1)-y
188# a handler $(1)-handler is executed with the arguments:
189# * $(1): directory the parser is in
190# * $(2): current entry
191add-special-class= \
192 $(eval $(1):=) \
193 $(eval special-classes+=$(1))
194
Nico Huber81b09f42016-01-23 00:50:00 +0100195# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100196# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
197# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100198# $1 stage name
199# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100200src-to-obj=\
201 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
202 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200203 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100204 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100205 $(patsubst %.ads,%.o,\
206 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100207 $(patsubst %.c,%.o,\
208 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200209 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100210
211# Converts one or more source file paths to the corresponding build/ paths
212# of their Ada library information (.ali) files.
213# $1 stage name
214# $2 file path (list)
215src-to-ali=\
216 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
217 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200218 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100219 $(patsubst src/%,$(obj)/%,\
220 $(patsubst %.ads,%.ali,\
221 $(patsubst %.adb,%.ali,\
222 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200223 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100224
Patrick Georgi47d68d82010-03-06 21:18:43 +0000225# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000226# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000227# Add subdirs-y to subdirs
228includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000229 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000230 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000231 $(foreach class,$(classes-y), $(call add-class,$(class))) \
232 $(foreach class,$(classes), \
233 $(eval $(class)-srcs+= \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700234 $$(subst $(absobj)/,$(obj)/, \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000235 $$(subst $(top)/,, \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700236 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000237 $(foreach special,$(special-classes), \
238 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000239 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000240
Patrick Georgi8463dd92010-09-30 16:55:02 +0000241# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000242# Repeat until subdirs is empty
243evaluate_subdirs= \
244 $(eval cursubdirs:=$(subdirs)) \
245 $(eval subdirs:=) \
246 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000247 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000248 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000249
250# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000251subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700252postinclude-hooks :=
Patrick Georgi51e142f2010-03-27 17:18:39 +0000253$(eval $(call evaluate_subdirs))
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100254ifeq ($(FAILBUILD),1)
255$(error cannot continue build)
256endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000257
Julius Wernere91d1702017-03-20 15:32:15 -0700258# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
259$(eval $(postinclude-hooks))
260
Patrick Georgi94a45862011-10-25 14:32:21 -0700261# Eliminate duplicate mentions of source files in a class
262$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
263
Nico Huber2e09d2b2016-01-14 01:13:33 +0100264# To track dependencies, we need all Ada specification (.ads) files in
265# *-srcs. Extract / filter all specification files that have a matching
266# body (.adb) file here (specifications without a body are valid sources
267# in Ada).
268$(foreach class,$(classes),$(eval $(class)-extra-specs := \
269 $(filter \
270 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
271 $(filter %.ads,$($(class)-srcs)))))
272$(foreach class,$(classes),$(eval $(class)-srcs := \
273 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
274
Patrick Georgi10f86b02015-03-27 16:56:23 +0100275$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100276$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
277
278# For Ada includes
279$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000280
Nico Huber963bed52013-05-15 11:47:51 +0200281# Save all objs before processing them (for dependency inclusion)
282originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
283
Patrick Georgi79f90102012-11-25 14:31:08 +0100284# Call post-processors if they're defined
285$(foreach class,$(classes),\
286 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
287
Patrick Georgi58262652011-02-17 20:47:49 +0000288allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
289allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000290alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000291
Nico Huber2e09d2b2016-01-14 01:13:33 +0100292# Reads dependencies from an Ada library information (.ali) file
293# Only basenames (with suffix) are preserved so we have to look the
294# paths up in $($(stage)-srcs).
295# $1 stage name
296# $2 ali file
297create_ada_deps=$$(if $(2),\
298 gnat.adc \
299 $$(filter \
300 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
301 $$($(1)-srcs) $$($(1)-extra-specs)))
302
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000303# macro to define template macros that are used by use_template macro
304define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000305# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200306# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700307# $3 additional compiler flags
308# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000309ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000310de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber2e09d2b2016-01-14 01:13:33 +0100311$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000312 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100313 $(CC_$(1)) \
314 $$(if $$(filter-out ads adb,$(2)), \
315 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@), \
316 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs))) \
317 $(3) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000318en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000319end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000320endef
321
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000322filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
323$(foreach class,$(classes), \
324 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100325 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200326 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
327 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000328
Patrick Georgid69839b2015-04-03 10:32:17 +0200329foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000330$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000331
Nico Huber2e09d2b2016-01-14 01:13:33 +0100332# To supported complex package initializations, we need to call the
333# emitted code explicitly. gnatbind gathers all the calls for us
334# and exports them as a procedure $(stage)_adainit(). Every stage that
335# uses Ada code has to call it!
336define gnatbind_template
337# $1 class
338$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
339 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
340 # We have to give gnatbind a simple filename (without leading
341 # path components) so just cd there.
342 cd $$(dir $$@) && \
343 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200344 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100345 -L$(1)_ada -o $$(notdir $$@) \
346 $$(subst $$(dir $$@),,$$^)
347$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
348 @printf " CC $$(subst $$(obj)/,,$$@)\n"
349 $(CC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
350$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200351$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100352endef
353
Nico Huberbe5492a2015-09-29 16:41:19 +0200354$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100355 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
356
Julius Wernerf97b88b2014-12-05 12:32:09 -0800357DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000358-include $(DEPENDENCIES)
359
Patrick Georgi0588d192009-08-12 15:00:51 +0000360printall:
Martin Roth09b64442016-06-05 10:52:43 -0600361 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
362 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
363 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
364 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
365 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000366endif
367
Patrick Georgi40ad8422011-05-21 22:18:59 +0000368ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700369$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000370endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000371
Martin Roth9c1b33e2015-07-29 14:55:18 -0700372$(obj)/project_filelist.txt: all
373 find $(obj) -name "*.d" -exec cat {} \; | \
374 sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
375 grep -v '\.o$$' > $(obj)/project_filelist.txt
376
Martin Rotha18353d2017-06-06 06:44:46 -0600377filelist: clean
378 $(MAKE) $(obj)/project_filelist.txt
379 printf "\nFiles used in build:\n"
380 cat $(obj)/project_filelist.txt
381
Martin Roth9c1b33e2015-07-29 14:55:18 -0700382#works with either exuberant ctags or ctags.emacs
383ctags-project: clean-ctags $(obj)/project_filelist.txt
384 cat $(obj)/project_filelist.txt | \
385 xargs ctags -o tags
386
387cscope-project: clean-cscope $(obj)/project_filelist.txt
388 cat $(obj)/project_filelist.txt | xargs cscope -b
389
Warren Turkala9fc3302010-09-03 08:57:32 +0000390cscope:
391 cscope -bR
392
Patrick Georgi0588d192009-08-12 15:00:51 +0000393doxy: doxygen
394doxygen:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500395 $(DOXYGEN) Documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000396
Martin Rothd7689e42014-12-29 14:56:19 -0700397doxygen_simple:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500398 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
Martin Rothd7689e42014-12-29 14:56:19 -0700399
Martin Rothb1574e32016-07-07 15:50:28 -0600400doxyplatform doxygen_platform: $(obj)/project_filelist.txt
401 echo
402 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
403 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
404 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
405 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
406 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
407 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
408
Patrick Georgi0588d192009-08-12 15:00:51 +0000409doxyclean: doxygen-clean
410doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000411 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000412
Patrick Georgi71b84802011-02-22 14:35:05 +0000413clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100414 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000415
Martin Roth20cd54f2017-03-26 18:49:02 -0600416clean: clean-for-update clean-target clean-utils
Patrick Georgi71b84802011-02-22 14:35:05 +0000417 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000418
Warren Turkala9fc3302010-09-03 08:57:32 +0000419clean-cscope:
420 rm -f cscope.out
421
Martin Roth9c1b33e2015-07-29 14:55:18 -0700422clean-ctags:
423 rm -f tags
424
Martin Roth20cd54f2017-03-26 18:49:02 -0600425clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600426 $(foreach tool, $(TOOLLIST), \
427 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600428
429distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600430 $(foreach tool, $(TOOLLIST), \
431 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600432 rm -f /util/$(tool)/junit.xml;)
433
434distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200435 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600436 rm -rf coreboot-builds coreboot-builds-chromeos
437 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000438
Martin Rothd7689e42014-12-29 14:56:19 -0700439.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
Martin Roth9c1b33e2015-07-29 14:55:18 -0700440.PHONY: ctags-project cscope-project clean-ctags