Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 1 | ## |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 2 | ## |
| 3 | ## Copyright (C) 2008 Advanced Micro Devices, Inc. |
Uwe Hermann | e55b32a | 2008-08-08 07:56:07 +0000 | [diff] [blame] | 4 | ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de> |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 5 | ## Copyright (C) 2009-2010 coresystems GmbH |
| 6 | ## Copyright (C) 2011 secunet Security Networks AG |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 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. |
| 18 | ## |
| 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. |
| 30 | ## |
| 31 | |
Jakub Czapiga | 289e2f6 | 2021-12-02 15:29:18 +0000 | [diff] [blame] | 32 | ifneq ($(words $(CURDIR)),1) |
| 33 | $(error ERROR: Path to the main directory cannot contain spaces) |
| 34 | endif |
| 35 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 36 | ifeq ($(INNER_SCANBUILD),y) |
| 37 | CC_real:=$(CC) |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 38 | endif |
| 39 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 40 | export top := $(CURDIR) |
Jakub Czapiga | 39b2e7a | 2021-11-23 09:21:30 +0000 | [diff] [blame] | 41 | export coreboottop ?= $(abspath $(top)/../../) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 42 | export src := src |
Stefan Reinauer | 2551f59 | 2015-06-29 14:28:25 -0700 | [diff] [blame] | 43 | export srck := $(abspath $(top)/../../util/kconfig) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 44 | export obj ?= build |
| 45 | export objutil ?= $(obj)/util |
Nico Huber | 08c7018 | 2014-10-14 23:27:50 +0200 | [diff] [blame] | 46 | export objk := $(objutil)/lp_kconfig |
Jakub Czapiga | 289e2f6 | 2021-12-02 15:29:18 +0000 | [diff] [blame] | 47 | export absobj := $(abspath $(obj)) |
Jakub Czapiga | 395f5b3 | 2022-01-12 09:59:39 +0000 | [diff] [blame] | 48 | VBOOT_SOURCE ?= $(coreboottop)/3rdparty/vboot |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 49 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 50 | export KCONFIG_AUTOHEADER := $(obj)/config.h |
| 51 | export KCONFIG_AUTOCONFIG := $(obj)/auto.conf |
Stefan Reinauer | ed56499 | 2015-06-11 14:57:36 -0700 | [diff] [blame] | 52 | export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 53 | export KCONFIG_SPLITCONFIG := $(obj)/config/ |
Stefan Reinauer | ed56499 | 2015-06-11 14:57:36 -0700 | [diff] [blame] | 54 | export KCONFIG_TRISTATE := $(obj)/tristate.conf |
| 55 | export KCONFIG_NEGATIVES := 1 |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 56 | export KBUILD_KCONFIG := Kconfig |
Stefan Reinauer | ed56499 | 2015-06-11 14:57:36 -0700 | [diff] [blame] | 57 | export CONFIG_ := CONFIG_LP_ |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 58 | |
| 59 | # directory containing the toplevel Makefile.inc |
| 60 | TOPLEVEL := . |
| 61 | |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 62 | CONFIG_LP_SHELL := sh |
Paul Kocialkowski | db0c0c4 | 2015-08-03 14:05:33 +0200 | [diff] [blame] | 63 | KBUILD_DEFCONFIG ?= configs/defconfig |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 64 | UNAME_RELEASE := $(shell uname -r) |
| 65 | DOTCONFIG ?= .config |
| 66 | KCONFIG_CONFIG = $(DOTCONFIG) |
| 67 | export KCONFIG_CONFIG |
| 68 | HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG)) |
| 69 | MAKEFLAGS += -rR --no-print-directory |
| 70 | |
| 71 | # Make is silent per default, but 'make V=1' will show all compiler calls. |
| 72 | Q:=@ |
| 73 | ifneq ($(V),1) |
| 74 | ifneq ($(Q),) |
| 75 | .SILENT: |
| 76 | endif |
| 77 | endif |
| 78 | |
| 79 | CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E |
Uwe Hermann | e55b32a | 2008-08-08 07:56:07 +0000 | [diff] [blame] | 80 | HOSTCC = gcc |
| 81 | HOSTCXX = g++ |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 82 | HOSTCFLAGS := -I$(srck) -I$(objk) -g |
| 83 | HOSTCXXFLAGS := -I$(srck) -I$(objk) |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 84 | HOSTAS ?= as |
| 85 | HOSTLD ?= ld |
| 86 | HOSTNM ?= nm |
| 87 | HOSTOBJCOPY ?= objcopy |
| 88 | HOSTOBJDUMP ?= objdump |
| 89 | HOSTREADELF ?= readelf |
| 90 | HOSTSTRIP ?= strip |
| 91 | HOSTAR ?= ar |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 92 | |
Uwe Hermann | 3b64129 | 2008-08-27 12:53:47 +0000 | [diff] [blame] | 93 | DOXYGEN := doxygen |
| 94 | DOXYGEN_OUTPUT_DIR := doxygen |
| 95 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 96 | all: real-all |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 97 | |
Stefan Reinauer | f53dbfa | 2015-07-09 00:26:49 +0200 | [diff] [blame] | 98 | ifeq ($(INNER_SCANBUILD),y) |
| 99 | CC:=$(CC_real) |
| 100 | HOSTCC:=$(CC_real) --hostcc |
| 101 | HOSTCXX:=$(CC_real) --hostcxx |
| 102 | endif |
| 103 | |
Uwe Hermann | ea87245 | 2008-10-22 15:49:20 +0000 | [diff] [blame] | 104 | # This include must come _before_ the pattern rules below! |
| 105 | # Order _does_ matter for pattern rules. |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 106 | include $(srck)/Makefile.inc |
Uwe Hermann | ea87245 | 2008-10-22 15:49:20 +0000 | [diff] [blame] | 107 | |
Stefan Reinauer | 8af0d03 | 2012-12-14 13:05:21 -0800 | [diff] [blame] | 108 | include $(HAVE_DOTCONFIG) |
| 109 | |
Gabe Black | 51edd54 | 2013-09-30 23:00:33 -0700 | [diff] [blame] | 110 | ARCHDIR-$(CONFIG_LP_ARCH_ARM) := arm |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 111 | ARCHDIR-$(CONFIG_LP_ARCH_ARM64) := arm64 |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 112 | ARCHDIR-$(CONFIG_LP_ARCH_X86) := x86 |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 113 | ARCHDIR-$(CONFIG_LP_ARCH_MOCK) := mock |
Stefan Reinauer | 8af0d03 | 2012-12-14 13:05:21 -0800 | [diff] [blame] | 114 | |
| 115 | ARCH-y := $(ARCHDIR-y) |
| 116 | |
Patrick Georgi | 21fc58b | 2015-07-06 09:07:11 +0000 | [diff] [blame] | 117 | # If architecture folder name is different from xcompile architecture name, |
Stefan Reinauer | 8af0d03 | 2012-12-14 13:05:21 -0800 | [diff] [blame] | 118 | # override here. |
Gabe Black | 51edd54 | 2013-09-30 23:00:33 -0700 | [diff] [blame] | 119 | ARCH-$(CONFIG_LP_ARCH_ARM) := arm |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 120 | ARCH-$(CONFIG_LP_ARCH_ARM64) := arm64 |
Patrick Georgi | 21fc58b | 2015-07-06 09:07:11 +0000 | [diff] [blame] | 121 | ARCH-$(CONFIG_LP_ARCH_X86) := x86_32 |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 122 | ARCH-$(CONFIG_LP_ARCH_MOCK) := mock |
Stefan Reinauer | 8af0d03 | 2012-12-14 13:05:21 -0800 | [diff] [blame] | 123 | |
Jakub Czapiga | 12ae850 | 2021-10-08 09:57:14 +0000 | [diff] [blame] | 124 | # Five cases where we don't need fully populated $(obj) lists: |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 125 | # 1. when no .config exists |
| 126 | # 2. when make config (in any flavour) is run |
| 127 | # 3. when make distclean is run |
Jakub Czapiga | 12ae850 | 2021-10-08 09:57:14 +0000 | [diff] [blame] | 128 | # 4. when make help% or make clean% is run |
| 129 | # 5. when make %-test or make %-tests or make %coverage-report is run |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 130 | # Don't waste time on reading all Makefile.incs in these cases |
Uwe Hermann | ea87245 | 2008-10-22 15:49:20 +0000 | [diff] [blame] | 131 | ifeq ($(strip $(HAVE_DOTCONFIG)),) |
Jakub Czapiga | 12ae850 | 2021-10-08 09:57:14 +0000 | [diff] [blame] | 132 | NOCOMPILE := 1 |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 133 | endif |
| 134 | ifneq ($(MAKECMDGOALS),) |
Jakub Czapiga | 12ae850 | 2021-10-08 09:57:14 +0000 | [diff] [blame] | 135 | ifneq ($(filter %config %clean clean-% help%,$(MAKECMDGOALS)),) |
| 136 | NOCOMPILE := 1 |
| 137 | endif |
| 138 | ifneq ($(filter %clean help% clean%, $(MAKECMDGOALS)),) |
| 139 | UNIT_TEST := 1 |
| 140 | endif |
| 141 | endif |
| 142 | |
| 143 | ifneq ($(filter help%, $(MAKECMDGOALS)),) |
| 144 | NOCOMPILE := 1 |
| 145 | UNIT_TEST := 1 |
| 146 | else |
| 147 | ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),) |
| 148 | ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),) |
| 149 | $(error Cannot mix unit-tests targets with other targets) |
| 150 | endif |
| 151 | NOCOMPILE := |
| 152 | UNIT_TEST := 1 |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 153 | endif |
| 154 | endif |
| 155 | |
Nico Huber | 1823d53 | 2020-11-16 22:50:49 +0100 | [diff] [blame] | 156 | xcompile ?= $(obj)/xcompile |
| 157 | $(xcompile): $(top)/../../util/xcompile/xcompile |
| 158 | $< $(XGCCPATH) > $@.tmp |
| 159 | \mv -f $@.tmp $@ 2> /dev/null |
| 160 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 161 | ifeq ($(NOCOMPILE),1) |
| 162 | include $(TOPLEVEL)/Makefile.inc |
Jakub Czapiga | 12ae850 | 2021-10-08 09:57:14 +0000 | [diff] [blame] | 163 | include $(TOPLEVEL)/tests/Makefile.inc |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 164 | real-all: config |
| 165 | |
Uwe Hermann | ea87245 | 2008-10-22 15:49:20 +0000 | [diff] [blame] | 166 | else |
| 167 | |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 168 | ifeq ($(CONFIG_LP_ARCH_MOCK),y) |
| 169 | |
| 170 | # Create empty xcompile to satisfy install script |
| 171 | $(shell echo '' > $(xcompile)) |
| 172 | |
| 173 | CC := $(HOSTCC) |
| 174 | CC-mock := $(HOSTCC) |
| 175 | AS := $(HOSTAS) |
| 176 | AS-mock := $(HOSTAS) |
| 177 | LD := $(HOSTLD) |
| 178 | LD-mock := $(HOSTLD) |
| 179 | NM := $(HOSTNM) |
| 180 | NM-mock := $(HOSTNM) |
| 181 | OBJCOPY := $(HOSTOBJCOPY) |
| 182 | OBJCOPY-mock := $(HOSTOBJCOPY) |
| 183 | OBJDUMP := $(HOSTOBJDUMP) |
| 184 | OBJDUMP-mock := $(HOSTOBJDUMP) |
| 185 | READELF := $(HOSTREADELF) |
| 186 | READELF-mock := $(HOSTEADELF) |
| 187 | STRIP := $(HOSTSTRIP) |
| 188 | STRIP-mock := $(HOSTSTRIP) |
| 189 | AR := $(HOSTAR) |
| 190 | AR-mock := $(HOSTAR) |
| 191 | else |
| 192 | |
Patrick Georgi | 0ffef88 | 2017-01-19 23:20:14 +0100 | [diff] [blame] | 193 | # in addition to the dependency below, create the file if it doesn't exist |
| 194 | # to silence stupid warnings about a file that would be generated anyway. |
Nico Huber | 1823d53 | 2020-11-16 22:50:49 +0100 | [diff] [blame] | 195 | $(if $(wildcard $(xcompile)),,$(shell \ |
| 196 | mkdir -p $(dir $(xcompile)) && \ |
| 197 | $(top)/../../util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile))) |
Patrick Georgi | 0ffef88 | 2017-01-19 23:20:14 +0100 | [diff] [blame] | 198 | |
Nico Huber | 1823d53 | 2020-11-16 22:50:49 +0100 | [diff] [blame] | 199 | include $(xcompile) |
Patrick Georgi | 0ffef88 | 2017-01-19 23:20:14 +0100 | [diff] [blame] | 200 | |
Nico Huber | 1823d53 | 2020-11-16 22:50:49 +0100 | [diff] [blame] | 201 | ifneq ($(XCOMPILE_COMPLETE),1) |
| 202 | $(shell rm -f $(xcompile)) |
| 203 | $(error $(xcompile) deleted because it's invalid. \ |
| 204 | Restarting the build should fix that, or explain the problem) |
| 205 | endif |
Patrick Georgi | 0ffef88 | 2017-01-19 23:20:14 +0100 | [diff] [blame] | 206 | |
Patrick Georgi | b144a34 | 2017-01-25 14:21:12 +0100 | [diff] [blame] | 207 | CC := $(CC_$(ARCH-y)) |
| 208 | AS := $(AS_$(ARCH-y)) |
| 209 | LD := $(LD_$(ARCH-y)) |
| 210 | NM := $(NM_$(ARCH-y)) |
| 211 | OBJCOPY := $(OBJCOPY_$(ARCH-y)) |
| 212 | OBJDUMP := $(OBJDUMP_$(ARCH-y)) |
| 213 | READELF := $(READELF_$(ARCH-y)) |
| 214 | STRIP := $(STRIP_$(ARCH-y)) |
| 215 | AR := $(AR_$(ARCH-y)) |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 216 | endif |
Patrick Georgi | b144a34 | 2017-01-25 14:21:12 +0100 | [diff] [blame] | 217 | |
Raul E Rangel | 50a2a86 | 2018-07-13 15:16:58 -0600 | [diff] [blame] | 218 | CFLAGS += -std=gnu11 $(CFLAGS_$(ARCH-y)) |
Patrick Georgi | b144a34 | 2017-01-25 14:21:12 +0100 | [diff] [blame] | 219 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 220 | ifneq ($(INNER_SCANBUILD),y) |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 221 | ifeq ($(CONFIG_LP_COMPILER_LLVM_CLANG),y) |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 222 | CC:=clang |
| 223 | ifneq ($(CONFIG_LP_ARCH_MOCK),y) |
| 224 | CC += -m32 |
| 225 | endif |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 226 | HOSTCC:=clang |
| 227 | endif |
| 228 | endif |
| 229 | |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 230 | ifeq ($(CONFIG_LP_CCACHE),y) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 231 | CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH))))) |
| 232 | ifeq ($(CCACHE),) |
| 233 | $(error ccache selected, but not found in PATH) |
| 234 | endif |
| 235 | CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE) |
| 236 | CC := $(CCACHE) $(CC) |
| 237 | HOSTCC := $(CCACHE) $(HOSTCC) |
| 238 | HOSTCXX := $(CCACHE) $(HOSTCXX) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 239 | endif |
| 240 | |
| 241 | strip_quotes = $(subst ",,$(subst \",,$(1))) |
| 242 | |
| 243 | # The primary target needs to be here before we include the |
| 244 | # other files |
| 245 | |
| 246 | ifeq ($(INNER_SCANBUILD),y) |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 247 | CONFIG_LP_SCANBUILD_ENABLE:= |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 248 | endif |
| 249 | |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 250 | ifeq ($(CONFIG_LP_SCANBUILD_ENABLE),y) |
| 251 | ifneq ($(CONFIG_LP_SCANBUILD_REPORT_LOCATION),) |
| 252 | CONFIG_LP_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_LP_SCANBUILD_REPORT_LOCATION) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 253 | endif |
| 254 | real-all: |
| 255 | echo '#!/bin/sh' > .ccwrap |
| 256 | echo 'CC="$(CC)"' >> .ccwrap |
| 257 | echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap |
| 258 | echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap |
| 259 | echo 'eval $$CC $$*' >> .ccwrap |
| 260 | chmod +x .ccwrap |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 261 | scan-build $(CONFIG_LP_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 262 | else |
| 263 | real-all: real-target |
| 264 | endif |
| 265 | |
| 266 | # must come rather early |
| 267 | .SECONDEXPANSION: |
| 268 | |
Nico Huber | 602a82a | 2015-09-09 13:02:51 +0200 | [diff] [blame] | 269 | $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 270 | $(MAKE) CONFIG_=CONFIG_LP_ olddefconfig |
| 271 | $(MAKE) CONFIG_=CONFIG_LP_ syncconfig |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 272 | |
| 273 | # Add a new class of source/object files to the build system |
| 274 | add-class= \ |
| 275 | $(eval $(1)-srcs:=) \ |
| 276 | $(eval $(1)-objs:=) \ |
| 277 | $(eval classes+=$(1)) |
| 278 | |
| 279 | # Special classes are managed types with special behaviour |
| 280 | # On parse time, for each entry in variable $(1)-y |
| 281 | # a handler $(1)-handler is executed with the arguments: |
| 282 | # * $(1): directory the parser is in |
| 283 | # * $(2): current entry |
| 284 | add-special-class= \ |
| 285 | $(eval $(1):=) \ |
| 286 | $(eval special-classes+=$(1)) |
| 287 | |
| 288 | # Clean -y variables, include Makefile.inc |
| 289 | # Add paths to files in X-y to X-srcs |
| 290 | # Add subdirs-y to subdirs |
| 291 | includemakefiles= \ |
| 292 | $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \ |
| 293 | $(eval -include $(1)) \ |
| 294 | $(foreach class,$(classes-y), $(call add-class,$(class))) \ |
Arthur Heymans | 6c2324a | 2019-10-29 18:36:46 +0100 | [diff] [blame] | 295 | $(foreach special,$(special-classes), \ |
| 296 | $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \ |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 297 | $(foreach class,$(classes), \ |
| 298 | $(eval $(class)-srcs+= \ |
Jakub Czapiga | 289e2f6 | 2021-12-02 15:29:18 +0000 | [diff] [blame] | 299 | $$(subst $(absobj)/,$(obj)/, \ |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 300 | $$(subst $(top)/,, \ |
Jakub Czapiga | 289e2f6 | 2021-12-02 15:29:18 +0000 | [diff] [blame] | 301 | $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \ |
| 302 | $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))) |
| 303 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 304 | |
| 305 | # For each path in $(subdirs) call includemakefiles |
| 306 | # Repeat until subdirs is empty |
| 307 | evaluate_subdirs= \ |
| 308 | $(eval cursubdirs:=$(subdirs)) \ |
| 309 | $(eval subdirs:=) \ |
| 310 | $(foreach dir,$(cursubdirs), \ |
| 311 | $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \ |
| 312 | $(if $(subdirs),$(eval $(call evaluate_subdirs))) |
| 313 | |
Jakub Czapiga | 12ae850 | 2021-10-08 09:57:14 +0000 | [diff] [blame] | 314 | # collect all object files eligible for building or run unit-tests |
| 315 | ifneq ($(UNIT_TEST),1) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 316 | subdirs:=$(TOPLEVEL) |
| 317 | $(eval $(call evaluate_subdirs)) |
Jakub Czapiga | 12ae850 | 2021-10-08 09:57:14 +0000 | [diff] [blame] | 318 | else |
| 319 | include $(TOPLEVEL)/tests/Makefile.inc |
| 320 | endif |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 321 | |
Jakub Czapiga | 289e2f6 | 2021-12-02 15:29:18 +0000 | [diff] [blame] | 322 | # Converts one or more source file paths to the corresponding build/ paths. |
| 323 | # $1 lib name |
| 324 | # $2 file path (list) |
| 325 | src-to-obj=\ |
| 326 | $(addsuffix .$(1).o,\ |
| 327 | $(basename \ |
| 328 | $(addprefix $(obj)/,\ |
| 329 | $(subst $(coreboottop)/,coreboot/,$(2))))) |
Jakub Czapiga | 1fa3da4 | 2021-12-06 09:01:50 +0000 | [diff] [blame] | 330 | $(foreach class,$(classes),$(eval $(class)-objs+=$(call src-to-obj,$(class),$($(class)-srcs)))) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 331 | |
| 332 | allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var))) |
| 333 | allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var))) |
| 334 | alldirs:=$(sort $(abspath $(dir $(allobjs)))) |
| 335 | |
| 336 | # macro to define template macros that are used by use_template macro |
| 337 | define create_cc_template |
| 338 | # $1 obj class |
| 339 | # $2 source suffix (c, S) |
| 340 | # $3 additional compiler flags |
| 341 | # $4 additional dependencies |
| 342 | ifn$(EMPTY)def $(1)-objs_$(2)_template |
| 343 | de$(EMPTY)fine $(1)-objs_$(2)_template |
Jakub Czapiga | 289e2f6 | 2021-12-02 15:29:18 +0000 | [diff] [blame] | 344 | $$(call src-to-obj,$(1), $$(1).$(2)): $$(1).$(2) $(obj)/libpayload-config.h $(4) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 345 | @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n" |
Jakub Czapiga | c35659d | 2021-08-26 14:35:10 +0200 | [diff] [blame] | 346 | $(CC) $(3) -MMD $$$$(CFLAGS) $(EXTRA_CFLAGS) -c -o $$$$@ $$$$< |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 347 | en$(EMPTY)def |
| 348 | end$(EMPTY)if |
| 349 | endef |
| 350 | |
| 351 | filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs)))) |
| 352 | $(foreach class,$(classes), \ |
| 353 | $(foreach type,$(call filetypes-of-class,$(class)), \ |
| 354 | $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))) |
| 355 | |
| 356 | foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file))))) |
| 357 | $(eval $(foreach class,$(classes),$(call foreach-src,$(class)))) |
| 358 | |
Jakub Czapiga | 1fa3da4 | 2021-12-06 09:01:50 +0000 | [diff] [blame] | 359 | DEPENDENCIES = $($(filter %.o,%(allobjs)):.o=.d) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 360 | -include $(DEPENDENCIES) |
| 361 | |
| 362 | printall: |
| 363 | @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); ) |
| 364 | @echo alldirs:=$(alldirs) |
| 365 | @echo allsrcs=$(allsrcs) |
| 366 | @echo DEPENDENCIES=$(DEPENDENCIES) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 367 | @$(foreach class,$(special-classes),echo $(class):='$($(class))'; ) |
Uwe Hermann | ea87245 | 2008-10-22 15:49:20 +0000 | [diff] [blame] | 368 | |
| 369 | endif |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 370 | |
Stefan Reinauer | ed56499 | 2015-06-11 14:57:36 -0700 | [diff] [blame] | 371 | $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(obj) $(objk)/lxdialog $(additional-dirs) $(alldirs)) |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 372 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 373 | cscope: |
| 374 | cscope -bR |
| 375 | |
| 376 | doxy: doxygen |
| 377 | doxygen: |
| 378 | $(DOXYGEN) Doxyfile |
| 379 | |
| 380 | doxyclean: doxygen-clean |
| 381 | doxygen-clean: |
| 382 | rm -rf $(DOXYGEN_OUTPUT_DIR) |
| 383 | |
| 384 | clean-for-update: doxygen-clean clean-for-update-target |
Nico Huber | 1823d53 | 2020-11-16 22:50:49 +0100 | [diff] [blame] | 385 | rm -f $(allobjs) $(xcompile) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 386 | rm -f $(DEPENDENCIES) |
| 387 | rmdir -p $(alldirs) 2>/dev/null >/dev/null || true |
| 388 | |
| 389 | clean: clean-for-update clean-target |
Martin Roth | 6959f5c | 2016-03-23 16:07:54 -0600 | [diff] [blame] | 390 | rm -f .ccwrap junit_config junit_config.old |
Patrick Georgi | b144a34 | 2017-01-25 14:21:12 +0100 | [diff] [blame] | 391 | rm -rf $(obj) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 392 | |
| 393 | clean-cscope: |
| 394 | rm -f cscope.out |
| 395 | |
Patrick Georgi | b144a34 | 2017-01-25 14:21:12 +0100 | [diff] [blame] | 396 | distclean: clean-cscope clean |
Martin Roth | 6959f5c | 2016-03-23 16:07:54 -0600 | [diff] [blame] | 397 | rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile junit.xml |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 398 | |
Paul Kocialkowski | 5d5fcdd | 2015-08-03 16:44:01 +0200 | [diff] [blame] | 399 | .PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy |