Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 1 | ## |
Patrick Georgi | c0458e6 | 2011-07-02 00:29:09 +0200 | [diff] [blame] | 2 | ## This file is part of the libpayload project. |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 3 | ## |
| 4 | ## Copyright (C) 2008 Advanced Micro Devices, Inc. |
Uwe Hermann | e55b32a | 2008-08-08 07:56:07 +0000 | [diff] [blame] | 5 | ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de> |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 6 | ## Copyright (C) 2009-2010 coresystems GmbH |
| 7 | ## Copyright (C) 2011 secunet Security Networks AG |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 8 | ## |
| 9 | ## Redistribution and use in source and binary forms, with or without |
| 10 | ## modification, are permitted provided that the following conditions |
| 11 | ## are met: |
| 12 | ## 1. Redistributions of source code must retain the above copyright |
| 13 | ## notice, this list of conditions and the following disclaimer. |
| 14 | ## 2. Redistributions in binary form must reproduce the above copyright |
| 15 | ## notice, this list of conditions and the following disclaimer in the |
| 16 | ## documentation and/or other materials provided with the distribution. |
| 17 | ## 3. The name of the author may not be used to endorse or promote products |
| 18 | ## derived from this software without specific prior written permission. |
| 19 | ## |
| 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. |
| 31 | ## |
| 32 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 33 | ifeq ($(INNER_SCANBUILD),y) |
| 34 | CC_real:=$(CC) |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 35 | endif |
| 36 | |
Stefan Reinauer | 97f546c | 2010-04-20 17:19:20 +0000 | [diff] [blame] | 37 | $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile))) |
| 38 | include .xcompile |
| 39 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 40 | ifeq ($(INNER_SCANBUILD),y) |
| 41 | CC:=$(CC_real) |
| 42 | HOSTCC:=$(CC_real) --hostcc |
| 43 | HOSTCXX:=$(CC_real) --hostcxx |
| 44 | endif |
| 45 | |
| 46 | export top := $(CURDIR) |
| 47 | export src := src |
| 48 | export srck := $(top)/util/kconfig |
| 49 | export obj ?= build |
| 50 | export objutil ?= $(obj)/util |
Nico Huber | 08c7018 | 2014-10-14 23:27:50 +0200 | [diff] [blame] | 51 | export objk := $(objutil)/lp_kconfig |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 52 | |
| 53 | |
| 54 | export KCONFIG_AUTOHEADER := $(obj)/config.h |
| 55 | export KCONFIG_AUTOCONFIG := $(obj)/auto.conf |
| 56 | |
| 57 | # directory containing the toplevel Makefile.inc |
| 58 | TOPLEVEL := . |
| 59 | |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 60 | CONFIG_LP_SHELL := sh |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 61 | KBUILD_DEFCONFIG := configs/defconfig |
| 62 | UNAME_RELEASE := $(shell uname -r) |
| 63 | DOTCONFIG ?= .config |
| 64 | KCONFIG_CONFIG = $(DOTCONFIG) |
| 65 | export KCONFIG_CONFIG |
| 66 | HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG)) |
| 67 | MAKEFLAGS += -rR --no-print-directory |
| 68 | |
| 69 | # Make is silent per default, but 'make V=1' will show all compiler calls. |
| 70 | Q:=@ |
| 71 | ifneq ($(V),1) |
| 72 | ifneq ($(Q),) |
| 73 | .SILENT: |
| 74 | endif |
| 75 | endif |
| 76 | |
| 77 | CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E |
Uwe Hermann | e55b32a | 2008-08-08 07:56:07 +0000 | [diff] [blame] | 78 | HOSTCC = gcc |
| 79 | HOSTCXX = g++ |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 80 | HOSTCFLAGS := -I$(srck) -I$(objk) -g |
| 81 | HOSTCXXFLAGS := -I$(srck) -I$(objk) |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 82 | |
Uwe Hermann | 3b64129 | 2008-08-27 12:53:47 +0000 | [diff] [blame] | 83 | DOXYGEN := doxygen |
| 84 | DOXYGEN_OUTPUT_DIR := doxygen |
| 85 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 86 | all: real-all |
Jordan Crouse | c3e728f | 2008-04-09 23:05:59 +0000 | [diff] [blame] | 87 | |
Uwe Hermann | ea87245 | 2008-10-22 15:49:20 +0000 | [diff] [blame] | 88 | # This include must come _before_ the pattern rules below! |
| 89 | # Order _does_ matter for pattern rules. |
| 90 | include util/kconfig/Makefile |
| 91 | |
Stefan Reinauer | 8af0d03 | 2012-12-14 13:05:21 -0800 | [diff] [blame] | 92 | include $(HAVE_DOTCONFIG) |
| 93 | |
Gabe Black | 51edd54 | 2013-09-30 23:00:33 -0700 | [diff] [blame] | 94 | ARCHDIR-$(CONFIG_LP_ARCH_ARM) := arm |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 95 | ARCHDIR-$(CONFIG_LP_ARCH_X86) := x86 |
Stefan Reinauer | 8af0d03 | 2012-12-14 13:05:21 -0800 | [diff] [blame] | 96 | |
| 97 | ARCH-y := $(ARCHDIR-y) |
| 98 | |
| 99 | # If architecture folder name is different from GCC binutils architecture name, |
| 100 | # override here. |
Gabe Black | 51edd54 | 2013-09-30 23:00:33 -0700 | [diff] [blame] | 101 | ARCH-$(CONFIG_LP_ARCH_ARM) := arm |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 102 | ARCH-$(CONFIG_LP_ARCH_X86) := i386 |
Stefan Reinauer | 8af0d03 | 2012-12-14 13:05:21 -0800 | [diff] [blame] | 103 | |
| 104 | CC := $(CC_$(ARCH-y)) |
| 105 | AS := $(AS_$(ARCH-y)) |
| 106 | LD := $(LD_$(ARCH-y)) |
| 107 | NM := $(NM_$(ARCH-y)) |
| 108 | OBJCOPY := $(OBJCOPY_$(ARCH-y)) |
| 109 | OBJDUMP := $(OBJDUMP_$(ARCH-y)) |
| 110 | READELF := $(READELF_$(ARCH-y)) |
| 111 | STRIP := $(STRIP_$(ARCH-y)) |
| 112 | AR := $(AR_$(ARCH-y)) |
| 113 | |
| 114 | CFLAGS += $(CFLAGS_$(ARCH-y)) |
| 115 | |
| 116 | LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && \ |
| 117 | $(CC) -print-libgcc-file-name) |
| 118 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 119 | # Three cases where we don't need fully populated $(obj) lists: |
| 120 | # 1. when no .config exists |
| 121 | # 2. when make config (in any flavour) is run |
| 122 | # 3. when make distclean is run |
| 123 | # Don't waste time on reading all Makefile.incs in these cases |
Uwe Hermann | ea87245 | 2008-10-22 15:49:20 +0000 | [diff] [blame] | 124 | ifeq ($(strip $(HAVE_DOTCONFIG)),) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 125 | NOCOMPILE:=1 |
| 126 | endif |
| 127 | ifneq ($(MAKECMDGOALS),) |
| 128 | ifneq ($(filter %config distclean,$(MAKECMDGOALS)),) |
| 129 | NOCOMPILE:=1 |
| 130 | endif |
| 131 | endif |
| 132 | |
| 133 | ifeq ($(NOCOMPILE),1) |
| 134 | include $(TOPLEVEL)/Makefile.inc |
| 135 | real-all: config |
| 136 | |
Uwe Hermann | ea87245 | 2008-10-22 15:49:20 +0000 | [diff] [blame] | 137 | else |
| 138 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 139 | ifneq ($(INNER_SCANBUILD),y) |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 140 | ifeq ($(CONFIG_LP_COMPILER_LLVM_CLANG),y) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 141 | CC:=clang -m32 |
| 142 | HOSTCC:=clang |
| 143 | endif |
| 144 | endif |
| 145 | |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 146 | ifeq ($(CONFIG_LP_CCACHE),y) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 147 | CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH))))) |
| 148 | ifeq ($(CCACHE),) |
| 149 | $(error ccache selected, but not found in PATH) |
| 150 | endif |
| 151 | CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE) |
| 152 | CC := $(CCACHE) $(CC) |
| 153 | HOSTCC := $(CCACHE) $(HOSTCC) |
| 154 | HOSTCXX := $(CCACHE) $(HOSTCXX) |
| 155 | ROMCC := $(CCACHE) $(ROMCC) |
| 156 | endif |
| 157 | |
| 158 | strip_quotes = $(subst ",,$(subst \",,$(1))) |
| 159 | |
| 160 | # The primary target needs to be here before we include the |
| 161 | # other files |
| 162 | |
| 163 | ifeq ($(INNER_SCANBUILD),y) |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 164 | CONFIG_LP_SCANBUILD_ENABLE:= |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 165 | endif |
| 166 | |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 167 | ifeq ($(CONFIG_LP_SCANBUILD_ENABLE),y) |
| 168 | ifneq ($(CONFIG_LP_SCANBUILD_REPORT_LOCATION),) |
| 169 | CONFIG_LP_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_LP_SCANBUILD_REPORT_LOCATION) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 170 | endif |
| 171 | real-all: |
| 172 | echo '#!/bin/sh' > .ccwrap |
| 173 | echo 'CC="$(CC)"' >> .ccwrap |
| 174 | echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap |
| 175 | echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap |
| 176 | echo 'eval $$CC $$*' >> .ccwrap |
| 177 | chmod +x .ccwrap |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 178 | 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] | 179 | else |
| 180 | real-all: real-target |
| 181 | endif |
| 182 | |
| 183 | # must come rather early |
| 184 | .SECONDEXPANSION: |
| 185 | |
| 186 | $(obj)/config.h: |
| 187 | $(MAKE) oldconfig |
| 188 | |
| 189 | # Add a new class of source/object files to the build system |
| 190 | add-class= \ |
| 191 | $(eval $(1)-srcs:=) \ |
| 192 | $(eval $(1)-objs:=) \ |
| 193 | $(eval classes+=$(1)) |
| 194 | |
| 195 | # Special classes are managed types with special behaviour |
| 196 | # On parse time, for each entry in variable $(1)-y |
| 197 | # a handler $(1)-handler is executed with the arguments: |
| 198 | # * $(1): directory the parser is in |
| 199 | # * $(2): current entry |
| 200 | add-special-class= \ |
| 201 | $(eval $(1):=) \ |
| 202 | $(eval special-classes+=$(1)) |
| 203 | |
| 204 | # Clean -y variables, include Makefile.inc |
| 205 | # Add paths to files in X-y to X-srcs |
| 206 | # Add subdirs-y to subdirs |
| 207 | includemakefiles= \ |
| 208 | $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \ |
| 209 | $(eval -include $(1)) \ |
| 210 | $(foreach class,$(classes-y), $(call add-class,$(class))) \ |
| 211 | $(foreach class,$(classes), \ |
| 212 | $(eval $(class)-srcs+= \ |
| 213 | $$(subst $(top)/,, \ |
| 214 | $$(abspath $$(addprefix $(dir $(1)),$$($(class)-y)))))) \ |
| 215 | $(foreach special,$(special-classes), \ |
| 216 | $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \ |
| 217 | $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))) |
| 218 | |
| 219 | # For each path in $(subdirs) call includemakefiles |
| 220 | # Repeat until subdirs is empty |
| 221 | evaluate_subdirs= \ |
| 222 | $(eval cursubdirs:=$(subdirs)) \ |
| 223 | $(eval subdirs:=) \ |
| 224 | $(foreach dir,$(cursubdirs), \ |
| 225 | $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \ |
| 226 | $(if $(subdirs),$(eval $(call evaluate_subdirs))) |
| 227 | |
| 228 | # collect all object files eligible for building |
| 229 | subdirs:=$(TOPLEVEL) |
| 230 | $(eval $(call evaluate_subdirs)) |
| 231 | |
| 232 | src-to-obj=$(addsuffix .$(1).o, $(basename $(addprefix $(obj)/, $($(1)-srcs)))) |
| 233 | $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class)))) |
| 234 | |
| 235 | allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var))) |
| 236 | allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var))) |
| 237 | alldirs:=$(sort $(abspath $(dir $(allobjs)))) |
| 238 | |
| 239 | # macro to define template macros that are used by use_template macro |
| 240 | define create_cc_template |
| 241 | # $1 obj class |
| 242 | # $2 source suffix (c, S) |
| 243 | # $3 additional compiler flags |
| 244 | # $4 additional dependencies |
| 245 | ifn$(EMPTY)def $(1)-objs_$(2)_template |
| 246 | de$(EMPTY)fine $(1)-objs_$(2)_template |
Gabe Black | f06111a | 2013-03-12 15:50:08 -0700 | [diff] [blame] | 247 | $(obj)/$$(1).$(1).o: $$(1).$(2) $(obj)/libpayload-config.h $(4) |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 248 | @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n" |
| 249 | $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$< |
| 250 | en$(EMPTY)def |
| 251 | end$(EMPTY)if |
| 252 | endef |
| 253 | |
| 254 | filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs)))) |
| 255 | $(foreach class,$(classes), \ |
| 256 | $(foreach type,$(call filetypes-of-class,$(class)), \ |
| 257 | $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))) |
| 258 | |
| 259 | foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file))))) |
| 260 | $(eval $(foreach class,$(classes),$(call foreach-src,$(class)))) |
| 261 | |
| 262 | DEPENDENCIES = $(allobjs:.o=.d) |
| 263 | -include $(DEPENDENCIES) |
| 264 | |
| 265 | printall: |
| 266 | @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); ) |
| 267 | @echo alldirs:=$(alldirs) |
| 268 | @echo allsrcs=$(allsrcs) |
| 269 | @echo DEPENDENCIES=$(DEPENDENCIES) |
| 270 | @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME) |
| 271 | @$(foreach class,$(special-classes),echo $(class):='$($(class))'; ) |
Uwe Hermann | ea87245 | 2008-10-22 15:49:20 +0000 | [diff] [blame] | 272 | |
| 273 | endif |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 274 | |
Nico Huber | 08c7018 | 2014-10-14 23:27:50 +0200 | [diff] [blame] | 275 | $(shell mkdir -p $(obj) $(objk)/lxdialog $(additional-dirs) $(alldirs)) |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 276 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 277 | cscope: |
| 278 | cscope -bR |
| 279 | |
| 280 | doxy: doxygen |
| 281 | doxygen: |
| 282 | $(DOXYGEN) Doxyfile |
| 283 | |
| 284 | doxyclean: doxygen-clean |
| 285 | doxygen-clean: |
| 286 | rm -rf $(DOXYGEN_OUTPUT_DIR) |
| 287 | |
| 288 | clean-for-update: doxygen-clean clean-for-update-target |
| 289 | rm -f $(allobjs) .xcompile |
| 290 | rm -f $(DEPENDENCIES) |
| 291 | rmdir -p $(alldirs) 2>/dev/null >/dev/null || true |
| 292 | |
| 293 | clean: clean-for-update clean-target |
| 294 | rm -f .ccwrap |
| 295 | |
| 296 | clean-cscope: |
| 297 | rm -f cscope.out |
| 298 | |
| 299 | distclean: clean-cscope |
| 300 | rm -rf $(obj) |
| 301 | rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile |
| 302 | |
| 303 | .PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy .xcompile |