Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 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> |
Stefan Reinauer | 8ed1b6d | 2010-01-19 21:13:44 +0000 | [diff] [blame] | 6 | ## Copyright (C) 2009-2010 coresystems GmbH |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 7 | ## Copyright (C) 2011 secunet Security Networks AG |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 8 | ## |
Patrick Georgi | 3bda044 | 2011-06-30 15:48:57 +0200 | [diff] [blame] | 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. |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 19 | ## |
Patrick Georgi | 3bda044 | 2011-06-30 15:48:57 +0200 | [diff] [blame] | 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. |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 31 | ## |
| 32 | |
Jonathan Kollasch | 7ff5b44 | 2010-09-28 21:11:48 +0000 | [diff] [blame] | 33 | export top := $(CURDIR) |
Patrick Georgi | 51e142f | 2010-03-27 17:18:39 +0000 | [diff] [blame] | 34 | export src := src |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 35 | export srck := $(top)/util/kconfig |
Vadim Bendebury | 5f7e4f0 | 2015-05-06 21:00:10 -0700 | [diff] [blame] | 36 | obj ?= build |
| 37 | override obj := $(subst $(top)/,,$(abspath $(obj))) |
| 38 | export obj |
Patrick Georgi | a2acbc7 | 2010-04-16 22:48:57 +0000 | [diff] [blame] | 39 | export objutil ?= $(obj)/util |
| 40 | export objk := $(objutil)/kconfig |
Vadim Bendebury | 5f7e4f0 | 2015-05-06 21:00:10 -0700 | [diff] [blame] | 41 | absobj := $(abspath $(obj)) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 42 | |
| 43 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 44 | export KCONFIG_AUTOHEADER := $(obj)/config.h |
| 45 | export KCONFIG_AUTOCONFIG := $(obj)/auto.conf |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 46 | export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd |
| 47 | export KCONFIG_SPLITCONFIG := $(obj)/config |
| 48 | export KCONFIG_TRISTATE := $(obj)/tristate.conf |
| 49 | export KCONFIG_NEGATIVES := 1 |
Stefan Reinauer | d373a00 | 2015-07-17 17:29:19 -0700 | [diff] [blame] | 50 | export KCONFIG_STRICT := 1 |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 51 | |
Patrick Georgi | e38d0a6 | 2011-03-01 08:09:22 +0000 | [diff] [blame] | 52 | # directory containing the toplevel Makefile.inc |
| 53 | TOPLEVEL := . |
| 54 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 55 | CONFIG_SHELL := sh |
| 56 | KBUILD_DEFCONFIG := configs/defconfig |
| 57 | UNAME_RELEASE := $(shell uname -r) |
Paul Kocialkowski | fde3275 | 2016-07-24 12:25:07 +0200 | [diff] [blame] | 58 | DOTCONFIG ?= $(top)/.config |
Patrick Georgi | 89ec376 | 2010-12-08 19:58:30 +0000 | [diff] [blame] | 59 | KCONFIG_CONFIG = $(DOTCONFIG) |
| 60 | export KCONFIG_CONFIG |
| 61 | HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG)) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 62 | MAKEFLAGS += -rR --no-print-directory |
| 63 | |
| 64 | # Make is silent per default, but 'make V=1' will show all compiler calls. |
Patrick Georgi | 2b7418e | 2009-08-25 19:38:46 +0000 | [diff] [blame] | 65 | Q:=@ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 66 | ifneq ($(V),1) |
Patrick Georgi | 2b7418e | 2009-08-25 19:38:46 +0000 | [diff] [blame] | 67 | ifneq ($(Q),) |
| 68 | .SILENT: |
| 69 | endif |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 70 | endif |
| 71 | |
Julius Werner | 808a429 | 2015-03-13 11:05:07 -0700 | [diff] [blame] | 72 | # Disable implicit/built-in rules to make Makefile errors fail fast. |
| 73 | .SUFFIXES: |
| 74 | |
Patrick Georgi | f92068d | 2016-02-01 12:02:29 +0100 | [diff] [blame] | 75 | HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 76 | HOSTCXX = g++ |
Patrick Georgi | b3a18ac | 2012-09-13 22:13:33 +0200 | [diff] [blame] | 77 | HOSTCFLAGS := -g |
| 78 | HOSTCXXFLAGS := -g |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 79 | |
Patrick Georgi | 828e0e8 | 2015-04-04 15:50:20 +0200 | [diff] [blame] | 80 | PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I . |
| 81 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 82 | DOXYGEN := doxygen |
| 83 | DOXYGEN_OUTPUT_DIR := doxygen |
| 84 | |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 85 | all: real-all |
| 86 | |
Martin Roth | 4eea174 | 2015-11-25 11:50:04 -0700 | [diff] [blame] | 87 | help_coreboot help:: |
| 88 | @echo '*** coreboot platform targets ***' |
Martin Roth | 76f14b2 | 2015-11-18 13:09:23 -0700 | [diff] [blame] | 89 | @echo ' Use "make [target] V=1" for extra build debug information' |
| 90 | @echo ' all - Build coreboot' |
| 91 | @echo ' clean - Remove coreboot build artifacts' |
| 92 | @echo ' distclean - Remove build artifacts and config files' |
| 93 | @echo ' doxygen - Build doxygen documentation for coreboot' |
Martin Roth | b1574e3 | 2016-07-07 15:50:28 -0600 | [diff] [blame] | 94 | @echo ' doxyplatform - Build doxygen documentation for the current platform' |
Martin Roth | 76f14b2 | 2015-11-18 13:09:23 -0700 | [diff] [blame] | 95 | @echo ' what-jenkins-does - Run platform build tests (Use CPUS=# for more cores)' |
| 96 | @echo ' printall - print makefile info for debugging' |
| 97 | @echo ' lint / lint-stable - run coreboot lint tools (all / minimal)' |
Werner Zeh | 2de6410 | 2016-01-12 12:45:49 +0100 | [diff] [blame] | 98 | @echo ' gitconfig - set up git to submit patches to coreboot' |
Martin Roth | 76f14b2 | 2015-11-18 13:09:23 -0700 | [diff] [blame] | 99 | @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board' |
| 100 | @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board' |
| 101 | @echo |
| 102 | |
Patrick Georgi | e38d0a6 | 2011-03-01 08:09:22 +0000 | [diff] [blame] | 103 | # This include must come _before_ the pattern rules below! |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 104 | # Order _does_ matter for pattern rules. |
Stefan Reinauer | de60c88 | 2015-06-29 14:44:37 -0700 | [diff] [blame] | 105 | include $(srck)/Makefile |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 106 | |
Patrick Georgi | cf036d1 | 2010-04-21 06:36:20 +0000 | [diff] [blame] | 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 |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 112 | ifeq ($(strip $(HAVE_DOTCONFIG)),) |
Patrick Georgi | cf036d1 | 2010-04-21 06:36:20 +0000 | [diff] [blame] | 113 | NOCOMPILE:=1 |
| 114 | endif |
| 115 | ifneq ($(MAKECMDGOALS),) |
Martin Roth | 109a7db | 2016-08-11 18:16:59 -0600 | [diff] [blame] | 116 | ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),) |
Patrick Georgi | cf036d1 | 2010-04-21 06:36:20 +0000 | [diff] [blame] | 117 | NOCOMPILE:=1 |
| 118 | endif |
Patrick Georgi | 02ae0bf | 2013-02-09 15:45:02 +0100 | [diff] [blame] | 119 | ifeq ($(MAKECMDGOALS), %clean) |
Zheng Bao | 0fd93d6 | 2012-10-22 16:36:03 +0800 | [diff] [blame] | 120 | NOMKDIR:=1 |
| 121 | endif |
Patrick Georgi | cf036d1 | 2010-04-21 06:36:20 +0000 | [diff] [blame] | 122 | endif |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 123 | |
Patrick Georgi | cf036d1 | 2010-04-21 06:36:20 +0000 | [diff] [blame] | 124 | ifeq ($(NOCOMPILE),1) |
Patrick Georgi | e38d0a6 | 2011-03-01 08:09:22 +0000 | [diff] [blame] | 125 | include $(TOPLEVEL)/Makefile.inc |
Martin Roth | 6797557 | 2016-03-07 16:38:52 -0700 | [diff] [blame] | 126 | include $(TOPLEVEL)/payloads/Makefile.inc |
Martin Roth | 20aa043 | 2017-01-26 10:51:43 -0700 | [diff] [blame] | 127 | real-all: |
| 128 | @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2 |
| 129 | @echo "Please specify a config file or run 'make menuconfig' to" >&2 |
| 130 | @echo "generate a new config file." >&2 |
| 131 | @exit 1 |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 132 | else |
| 133 | |
Paul Kocialkowski | 585c781 | 2016-07-13 11:00:41 +0200 | [diff] [blame] | 134 | include $(DOTCONFIG) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 135 | |
Patrick Georgi | 0ffef88 | 2017-01-19 23:20:14 +0100 | [diff] [blame] | 136 | # in addition to the dependency below, create the file if it doesn't exist |
| 137 | # to silence stupid warnings about a file that would be generated anyway. |
| 138 | $(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile))) |
| 139 | |
| 140 | .xcompile: util/xcompile/xcompile |
| 141 | rm -f $@ |
| 142 | $< $(XGCCPATH) > $@.tmp |
| 143 | \mv -f $@.tmp $@ 2> /dev/null |
| 144 | rm -f $@.tmp |
| 145 | |
Patrick Georgi | 6dda31d | 2015-11-19 15:15:33 +0100 | [diff] [blame] | 146 | -include .xcompile |
| 147 | |
| 148 | ifneq ($(XCOMPILE_COMPLETE),1) |
| 149 | $(shell rm -f .xcompile) |
| 150 | $(error .xcompile deleted because it's invalid. \ |
| 151 | Restarting the build should fix that, or explain the problem) |
| 152 | endif |
Patrick Georgi | 7b9762f | 2015-06-04 13:18:11 +0200 | [diff] [blame] | 153 | |
Patrick Georgi | cc84a00 | 2014-05-14 21:05:35 +0200 | [diff] [blame] | 154 | ifneq ($(CONFIG_MMX),y) |
| 155 | CFLAGS_x86_32 += -mno-mmx |
| 156 | endif |
| 157 | |
Patrick Georgi | cc84a00 | 2014-05-14 21:05:35 +0200 | [diff] [blame] | 158 | include toolchain.inc |
| 159 | |
Zheng Bao | 0764892 | 2015-11-13 10:42:27 +0800 | [diff] [blame] | 160 | strip_quotes = $(strip $(subst ",,$(subst \",,$(1)))) |
Martin Roth | bbf1399 | 2016-01-25 15:59:24 -0700 | [diff] [blame] | 161 | # fix makefile syntax highlighting after strip macro \" ")) |
Patrick Georgi | a84e98b | 2010-03-16 19:01:32 +0000 | [diff] [blame] | 162 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 163 | # The primary target needs to be here before we include the |
| 164 | # other files |
| 165 | |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 166 | real-all: real-target |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 167 | |
Patrick Georgi | 51e142f | 2010-03-27 17:18:39 +0000 | [diff] [blame] | 168 | # must come rather early |
| 169 | .SECONDEXPANSION: |
| 170 | |
Stefan Reinauer | 0d869ed | 2015-07-17 13:31:16 -0700 | [diff] [blame] | 171 | $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) |
Patrick Georgi | 78a5f22 | 2017-01-30 15:29:34 +0100 | [diff] [blame] | 172 | +$(MAKE) oldconfig |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 173 | |
Patrick Georgi | 5826265 | 2011-02-17 20:47:49 +0000 | [diff] [blame] | 174 | # Add a new class of source/object files to the build system |
| 175 | add-class= \ |
| 176 | $(eval $(1)-srcs:=) \ |
| 177 | $(eval $(1)-objs:=) \ |
| 178 | $(eval classes+=$(1)) |
Patrick Georgi | 8463dd9 | 2010-09-30 16:55:02 +0000 | [diff] [blame] | 179 | |
Patrick Georgi | 5826265 | 2011-02-17 20:47:49 +0000 | [diff] [blame] | 180 | # Special classes are managed types with special behaviour |
| 181 | # On parse time, for each entry in variable $(1)-y |
| 182 | # a handler $(1)-handler is executed with the arguments: |
| 183 | # * $(1): directory the parser is in |
| 184 | # * $(2): current entry |
| 185 | add-special-class= \ |
| 186 | $(eval $(1):=) \ |
| 187 | $(eval special-classes+=$(1)) |
| 188 | |
Nico Huber | 81b09f4 | 2016-01-23 00:50:00 +0100 | [diff] [blame] | 189 | # Converts one or more source file paths to their corresponding build/ paths. |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 190 | # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep |
| 191 | # their name. |
Nico Huber | 81b09f4 | 2016-01-23 00:50:00 +0100 | [diff] [blame] | 192 | # $1 stage name |
| 193 | # $2 file path (list) |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 194 | src-to-obj=\ |
| 195 | $(patsubst $(obj)/%,$(obj)/$(1)/%,\ |
| 196 | $(patsubst $(obj)/$(1)/%,$(obj)/%,\ |
Nico Huber | d011b6b | 2016-10-05 17:41:31 +0200 | [diff] [blame] | 197 | $(patsubst 3rdparty/%,$(obj)/%,\ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 198 | $(patsubst src/%,$(obj)/%,\ |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 199 | $(patsubst %.ads,%.o,\ |
| 200 | $(patsubst %.adb,%.o,\ |
Nico Huber | 98fc426 | 2016-01-23 01:24:33 +0100 | [diff] [blame] | 201 | $(patsubst %.c,%.o,\ |
| 202 | $(patsubst %.S,%.o,\ |
Nico Huber | d011b6b | 2016-10-05 17:41:31 +0200 | [diff] [blame] | 203 | $(subst .$(1),,$(2)))))))))) |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 204 | |
| 205 | # Converts one or more source file paths to the corresponding build/ paths |
| 206 | # of their Ada library information (.ali) files. |
| 207 | # $1 stage name |
| 208 | # $2 file path (list) |
| 209 | src-to-ali=\ |
| 210 | $(patsubst $(obj)/%,$(obj)/$(1)/%,\ |
| 211 | $(patsubst $(obj)/$(1)/%,$(obj)/%,\ |
Nico Huber | d011b6b | 2016-10-05 17:41:31 +0200 | [diff] [blame] | 212 | $(patsubst 3rdparty/%,$(obj)/%,\ |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 213 | $(patsubst src/%,$(obj)/%,\ |
| 214 | $(patsubst %.ads,%.ali,\ |
| 215 | $(patsubst %.adb,%.ali,\ |
| 216 | $(subst .$(1),,\ |
Nico Huber | d011b6b | 2016-10-05 17:41:31 +0200 | [diff] [blame] | 217 | $(filter %.ads %.adb,$(2))))))))) |
Nico Huber | 81b09f4 | 2016-01-23 00:50:00 +0100 | [diff] [blame] | 218 | |
Patrick Georgi | 47d68d8 | 2010-03-06 21:18:43 +0000 | [diff] [blame] | 219 | # Clean -y variables, include Makefile.inc |
Patrick Georgi | 8463dd9 | 2010-09-30 16:55:02 +0000 | [diff] [blame] | 220 | # Add paths to files in X-y to X-srcs |
Patrick Georgi | 47d68d8 | 2010-03-06 21:18:43 +0000 | [diff] [blame] | 221 | # Add subdirs-y to subdirs |
| 222 | includemakefiles= \ |
Patrick Georgi | 5826265 | 2011-02-17 20:47:49 +0000 | [diff] [blame] | 223 | $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \ |
Patrick Georgi | 47d68d8 | 2010-03-06 21:18:43 +0000 | [diff] [blame] | 224 | $(eval -include $(1)) \ |
Patrick Georgi | 5826265 | 2011-02-17 20:47:49 +0000 | [diff] [blame] | 225 | $(foreach class,$(classes-y), $(call add-class,$(class))) \ |
| 226 | $(foreach class,$(classes), \ |
| 227 | $(eval $(class)-srcs+= \ |
Vadim Bendebury | 5f7e4f0 | 2015-05-06 21:00:10 -0700 | [diff] [blame] | 228 | $$(subst $(absobj)/,$(obj)/, \ |
Patrick Georgi | 51e142f | 2010-03-27 17:18:39 +0000 | [diff] [blame] | 229 | $$(subst $(top)/,, \ |
Vadim Bendebury | 5f7e4f0 | 2015-05-06 21:00:10 -0700 | [diff] [blame] | 230 | $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \ |
Patrick Georgi | 5826265 | 2011-02-17 20:47:49 +0000 | [diff] [blame] | 231 | $(foreach special,$(special-classes), \ |
| 232 | $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \ |
Jonathan Kollasch | 7ff5b44 | 2010-09-28 21:11:48 +0000 | [diff] [blame] | 233 | $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))) |
Patrick Georgi | 47d68d8 | 2010-03-06 21:18:43 +0000 | [diff] [blame] | 234 | |
Patrick Georgi | 8463dd9 | 2010-09-30 16:55:02 +0000 | [diff] [blame] | 235 | # For each path in $(subdirs) call includemakefiles |
Patrick Georgi | 47d68d8 | 2010-03-06 21:18:43 +0000 | [diff] [blame] | 236 | # Repeat until subdirs is empty |
| 237 | evaluate_subdirs= \ |
| 238 | $(eval cursubdirs:=$(subdirs)) \ |
| 239 | $(eval subdirs:=) \ |
| 240 | $(foreach dir,$(cursubdirs), \ |
Patrick Georgi | 5826265 | 2011-02-17 20:47:49 +0000 | [diff] [blame] | 241 | $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \ |
Patrick Georgi | 51e142f | 2010-03-27 17:18:39 +0000 | [diff] [blame] | 242 | $(if $(subdirs),$(eval $(call evaluate_subdirs))) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 243 | |
| 244 | # collect all object files eligible for building |
Patrick Georgi | e38d0a6 | 2011-03-01 08:09:22 +0000 | [diff] [blame] | 245 | subdirs:=$(TOPLEVEL) |
Julius Werner | e91d170 | 2017-03-20 15:32:15 -0700 | [diff] [blame] | 246 | postinclude-hooks := |
Patrick Georgi | 51e142f | 2010-03-27 17:18:39 +0000 | [diff] [blame] | 247 | $(eval $(call evaluate_subdirs)) |
Patrick Georgi | 70c85ea | 2013-02-16 01:06:57 +0100 | [diff] [blame] | 248 | ifeq ($(FAILBUILD),1) |
| 249 | $(error cannot continue build) |
| 250 | endif |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 251 | |
Julius Werner | e91d170 | 2017-03-20 15:32:15 -0700 | [diff] [blame] | 252 | # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed |
| 253 | $(eval $(postinclude-hooks)) |
| 254 | |
Patrick Georgi | 94a4586 | 2011-10-25 14:32:21 -0700 | [diff] [blame] | 255 | # Eliminate duplicate mentions of source files in a class |
| 256 | $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs)))) |
| 257 | |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 258 | # To track dependencies, we need all Ada specification (.ads) files in |
| 259 | # *-srcs. Extract / filter all specification files that have a matching |
| 260 | # body (.adb) file here (specifications without a body are valid sources |
| 261 | # in Ada). |
| 262 | $(foreach class,$(classes),$(eval $(class)-extra-specs := \ |
| 263 | $(filter \ |
| 264 | $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \ |
| 265 | $(filter %.ads,$($(class)-srcs))))) |
| 266 | $(foreach class,$(classes),$(eval $(class)-srcs := \ |
| 267 | $(filter-out $($(class)-extra-specs),$($(class)-srcs)))) |
| 268 | |
Patrick Georgi | 10f86b0 | 2015-03-27 16:56:23 +0100 | [diff] [blame] | 269 | $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs)))) |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 270 | $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs)))) |
| 271 | |
| 272 | # For Ada includes |
| 273 | $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs))))) |
Patrick Georgi | d3428b0 | 2010-02-24 13:18:01 +0000 | [diff] [blame] | 274 | |
Nico Huber | 963bed5 | 2013-05-15 11:47:51 +0200 | [diff] [blame] | 275 | # Save all objs before processing them (for dependency inclusion) |
| 276 | originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var))) |
| 277 | |
Patrick Georgi | 79f9010 | 2012-11-25 14:31:08 +0100 | [diff] [blame] | 278 | # Call post-processors if they're defined |
| 279 | $(foreach class,$(classes),\ |
| 280 | $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs))))) |
| 281 | |
Patrick Georgi | 5826265 | 2011-02-17 20:47:49 +0000 | [diff] [blame] | 282 | allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var))) |
| 283 | allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var))) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 284 | alldirs:=$(sort $(abspath $(dir $(allobjs)))) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 285 | |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 286 | # Reads dependencies from an Ada library information (.ali) file |
| 287 | # Only basenames (with suffix) are preserved so we have to look the |
| 288 | # paths up in $($(stage)-srcs). |
| 289 | # $1 stage name |
| 290 | # $2 ali file |
| 291 | create_ada_deps=$$(if $(2),\ |
| 292 | gnat.adc \ |
| 293 | $$(filter \ |
| 294 | $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \ |
| 295 | $$($(1)-srcs) $$($(1)-extra-specs))) |
| 296 | |
Patrick Georgi patrick.georgi | c5f773d | 2010-03-16 12:01:13 +0000 | [diff] [blame] | 297 | # macro to define template macros that are used by use_template macro |
| 298 | define create_cc_template |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 299 | # $1 obj class |
Patrick Georgi | 990e7c9 | 2015-04-03 10:47:15 +0200 | [diff] [blame] | 300 | # $2 source suffix (c, S, ld, ...) |
Marc Jones | a38ccfd | 2014-11-06 15:50:22 -0700 | [diff] [blame] | 301 | # $3 additional compiler flags |
| 302 | # $4 additional dependencies |
Patrick Georgi | b8cdd9b | 2011-02-17 20:48:45 +0000 | [diff] [blame] | 303 | ifn$(EMPTY)def $(1)-objs_$(2)_template |
Patrick Georgi | 8463dd9 | 2010-09-30 16:55:02 +0000 | [diff] [blame] | 304 | de$(EMPTY)fine $(1)-objs_$(2)_template |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 305 | $$(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 Georgi | 1cd76e7 | 2010-04-19 20:39:22 +0000 | [diff] [blame] | 306 | @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n" |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 307 | $(CC_$(1)) \ |
| 308 | $$(if $$(filter-out ads adb,$(2)), \ |
| 309 | -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@), \ |
| 310 | $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs))) \ |
| 311 | $(3) -c -o $$$$@ $$$$< |
Patrick Georgi patrick.georgi | c5f773d | 2010-03-16 12:01:13 +0000 | [diff] [blame] | 312 | en$(EMPTY)def |
Patrick Georgi | b8cdd9b | 2011-02-17 20:48:45 +0000 | [diff] [blame] | 313 | end$(EMPTY)if |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 314 | endef |
| 315 | |
Patrick Georgi | b8cdd9b | 2011-02-17 20:48:45 +0000 | [diff] [blame] | 316 | filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs)))) |
| 317 | $(foreach class,$(classes), \ |
| 318 | $(foreach type,$(call filetypes-of-class,$(class)), \ |
Patrick Georgi | 2459aee | 2015-03-27 15:27:21 +0100 | [diff] [blame] | 319 | $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \ |
Patrick Georgi | 416ab38 | 2015-04-03 10:19:38 +0200 | [diff] [blame] | 320 | $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\ |
| 321 | $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 322 | |
Patrick Georgi | d69839b | 2015-04-03 10:32:17 +0200 | [diff] [blame] | 323 | foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file))))) |
Patrick Georgi | 5826265 | 2011-02-17 20:47:49 +0000 | [diff] [blame] | 324 | $(eval $(foreach class,$(classes),$(call foreach-src,$(class)))) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 325 | |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 326 | # To supported complex package initializations, we need to call the |
| 327 | # emitted code explicitly. gnatbind gathers all the calls for us |
| 328 | # and exports them as a procedure $(stage)_adainit(). Every stage that |
| 329 | # uses Ada code has to call it! |
| 330 | define gnatbind_template |
| 331 | # $1 class |
| 332 | $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis)) |
| 333 | @printf " BIND $$(subst $$(obj)/,,$$@)\n" |
| 334 | # We have to give gnatbind a simple filename (without leading |
| 335 | # path components) so just cd there. |
| 336 | cd $$(dir $$@) && \ |
| 337 | $$(GNATBIND_$(1)) -a -n \ |
Nico Huber | be5492a | 2015-09-29 16:41:19 +0200 | [diff] [blame] | 338 | --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \ |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 339 | -L$(1)_ada -o $$(notdir $$@) \ |
| 340 | $$(subst $$(dir $$@),,$$^) |
| 341 | $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb |
| 342 | @printf " CC $$(subst $$(obj)/,,$$@)\n" |
| 343 | $(CC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$< |
| 344 | $(1)-objs += $$(obj)/$(1)/b__$(1).o |
Nico Huber | ddb2465 | 2016-09-19 11:50:04 +0200 | [diff] [blame] | 345 | $($(1)-alis): %.ali: %.o ; |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 346 | endef |
| 347 | |
Nico Huber | be5492a | 2015-09-29 16:41:19 +0200 | [diff] [blame] | 348 | $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \ |
Nico Huber | 2e09d2b | 2016-01-14 01:13:33 +0100 | [diff] [blame] | 349 | $(if $($(class)-alis),$(call gnatbind_template,$(class))))) |
| 350 | |
Julius Werner | f97b88b | 2014-12-05 12:32:09 -0800 | [diff] [blame] | 351 | DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs))) |
Stefan Reinauer | 6bee951 | 2010-03-24 15:51:48 +0000 | [diff] [blame] | 352 | -include $(DEPENDENCIES) |
| 353 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 354 | printall: |
Martin Roth | 09b6444 | 2016-06-05 10:52:43 -0600 | [diff] [blame] | 355 | @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; ) |
| 356 | @echo alldirs: $(alldirs) | tr ' ' '\n'; echo |
| 357 | @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo |
| 358 | @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo |
| 359 | @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; ) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 360 | endif |
| 361 | |
Patrick Georgi | 40ad842 | 2011-05-21 22:18:59 +0000 | [diff] [blame] | 362 | ifndef NOMKDIR |
Stefan Reinauer | de60c88 | 2015-06-29 14:44:37 -0700 | [diff] [blame] | 363 | $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs)) |
Patrick Georgi | 40ad842 | 2011-05-21 22:18:59 +0000 | [diff] [blame] | 364 | endif |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 365 | |
Martin Roth | 9c1b33e | 2015-07-29 14:55:18 -0700 | [diff] [blame] | 366 | $(obj)/project_filelist.txt: all |
| 367 | find $(obj) -name "*.d" -exec cat {} \; | \ |
| 368 | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \ |
| 369 | grep -v '\.o$$' > $(obj)/project_filelist.txt |
| 370 | |
| 371 | #works with either exuberant ctags or ctags.emacs |
| 372 | ctags-project: clean-ctags $(obj)/project_filelist.txt |
| 373 | cat $(obj)/project_filelist.txt | \ |
| 374 | xargs ctags -o tags |
| 375 | |
| 376 | cscope-project: clean-cscope $(obj)/project_filelist.txt |
| 377 | cat $(obj)/project_filelist.txt | xargs cscope -b |
| 378 | |
Warren Turkal | a9fc330 | 2010-09-03 08:57:32 +0000 | [diff] [blame] | 379 | cscope: |
| 380 | cscope -bR |
| 381 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 382 | doxy: doxygen |
| 383 | doxygen: |
Nicky Sielicki | e08a2a5 | 2015-06-06 08:55:16 -0500 | [diff] [blame] | 384 | $(DOXYGEN) Documentation/Doxyfile.coreboot |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 385 | |
Martin Roth | d7689e4 | 2014-12-29 14:56:19 -0700 | [diff] [blame] | 386 | doxygen_simple: |
Nicky Sielicki | e08a2a5 | 2015-06-06 08:55:16 -0500 | [diff] [blame] | 387 | $(DOXYGEN) Documentation/Doxyfile.coreboot_simple |
Martin Roth | d7689e4 | 2014-12-29 14:56:19 -0700 | [diff] [blame] | 388 | |
Martin Roth | b1574e3 | 2016-07-07 15:50:28 -0600 | [diff] [blame] | 389 | doxyplatform doxygen_platform: $(obj)/project_filelist.txt |
| 390 | echo |
| 391 | echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)" |
| 392 | export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \ |
| 393 | mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \ |
| 394 | export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \ |
| 395 | export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \ |
| 396 | $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform |
| 397 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 398 | doxyclean: doxygen-clean |
| 399 | doxygen-clean: |
Patrick Georgi | 2b7418e | 2009-08-25 19:38:46 +0000 | [diff] [blame] | 400 | rm -rf $(DOXYGEN_OUTPUT_DIR) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 401 | |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 402 | clean-for-update: doxygen-clean clean-for-update-target |
Patrick Georgi | 02ae0bf | 2013-02-09 15:45:02 +0100 | [diff] [blame] | 403 | rm -rf $(obj) .xcompile |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 404 | |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 405 | clean: clean-for-update clean-target |
| 406 | rm -f .ccwrap |
Warren Turkal | 0e8f204 | 2010-09-27 21:14:19 +0000 | [diff] [blame] | 407 | |
Warren Turkal | a9fc330 | 2010-09-03 08:57:32 +0000 | [diff] [blame] | 408 | clean-cscope: |
| 409 | rm -f cscope.out |
| 410 | |
Martin Roth | 9c1b33e | 2015-07-29 14:55:18 -0700 | [diff] [blame] | 411 | clean-ctags: |
| 412 | rm -f tags |
| 413 | |
Martin Roth | 6797557 | 2016-03-07 16:38:52 -0700 | [diff] [blame] | 414 | distclean: clean clean-ctags clean-cscope distclean-payloads |
Patrick Georgi | 80656af | 2017-04-26 11:58:44 +0200 | [diff] [blame] | 415 | rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 416 | |
Martin Roth | d7689e4 | 2014-12-29 14:56:19 -0700 | [diff] [blame] | 417 | .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple |
Martin Roth | 9c1b33e | 2015-07-29 14:55:18 -0700 | [diff] [blame] | 418 | .PHONY: ctags-project cscope-project clean-ctags |