1 ########################################################################### ###
2 #@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
3 #@License Dual MIT/GPLv2
5 # The contents of this file are subject to the MIT license as set out below.
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
17 # Alternatively, the contents of this file may be used under the terms of
18 # the GNU General Public License Version 2 ("GPL") in which case the provisions
19 # of GPL are applicable instead of those above.
21 # If you wish to allow use of your version of this file only under the terms of
22 # GPL, and not to allow others to use your version of this file under the terms
23 # of the MIT license, indicate your decision by deleting the provisions above
24 # and replace them with the notice and other provisions required by GPL as set
25 # out in the file called "GPL-COPYING" included in this distribution. If you do
26 # not delete the provisions above, a recipient may use your version of this file
27 # under the terms of either the MIT license or GPL.
29 # This License is also included in this distribution in the file called
32 # EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
33 # PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
34 # BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 # PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
36 # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
37 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
38 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 ### ###########################################################################
41 define must-be-defined
42 $(if $(filter undefined,$(origin $(1))),$(error In makefile $(THIS_MAKEFILE): $$($(1)) must be defined),)
45 define must-be-nonempty
46 $(if $(strip $($(1))),,$(error In makefile $(THIS_MAKEFILE): $$($(1)) must contain a value))
49 define directory-must-exist
50 $(if $(wildcard $(abspath $(1)/)),,$(error Directory $(1) must exist))
54 $(if $(filter-out $(firstword $($(1))),$($(1))),$(error In makefile $(THIS_MAKEFILE): $$($(1)) must contain only one word),)
58 $(patsubst lib%.so,%,$(if $($(1)_target),$($(1)_target),$(1).so))
61 # This is done to allow module type makefiles to use $(THIS_MAKEFILE)
62 define register-module
63 INTERNAL_MAKEFILE_FOR_MODULE_$(1) := $(THIS_MAKEFILE)
66 define process-module-arch
67 MODULE_ARCH := $$(strip $(2))
68 include $$(MAKE_TOP)/moduledefs_common.mk
69 include $$(MAKE_TOP)/moduledefs/$$(MODULE_ARCH).mk
70 include $$(MAKE_TOP)/modules/$$(strip $$($$(THIS_MODULE)_type)).mk
71 .SECONDARY: $$(MODULE_INTERMEDIATES_DIR)
72 $$(MODULE_INTERMEDIATES_DIR):
74 MODULE_CLEAN_TARGETS += $$(MODULE_INTERMEDIATES_DIR)
75 INTERNAL_TARGETS_FOR_$(1) += $$(MODULE_TARGETS)
76 INTERNAL_CLEAN_TARGETS_FOR_$(1) += $$(MODULE_CLEAN_TARGETS)
77 INTERNAL_CLOBBER_TARGETS_FOR_$(1) += $$(MODULE_CLEAN_TARGETS) $$(MODULE_CLOBBER_TARGETS) $$(MODULE_TARGETS)
80 target_neutral_types := \
105 define calculate-arch-list
106 # Work out the target platforms for this module
107 MODULE_ARCH_LIST := $(2)
108 ifeq ($$(MODULE_ARCH_LIST),)
109 ifneq ($$(filter $(1),$(doc_types)),)
110 MODULE_ARCH_LIST := doc
112 ifneq ($$(filter $(1),$(target_neutral_types)),)
113 MODULE_ARCH_LIST := target_neutral
115 ifneq ($$(filter $(1),kernel_module),)
116 MODULE_ARCH_LIST := $(TARGET_PRIMARY_ARCH)
118 MODULE_ARCH_LIST := $(TARGET_ALL_ARCH)
125 define process-module
127 THIS_MAKEFILE := $(INTERNAL_MAKEFILE_FOR_MODULE_$(1))
128 INTERNAL_TARGETS_FOR_$(1) :=
129 INTERNAL_CLEAN_TARGETS_FOR_$(1) :=
130 INTERNAL_CLOBBER_TARGETS_FOR_$(1) :=
131 include $$(MAKE_TOP)/this_makefile.mk
132 $$(call must-be-nonempty,THIS_MAKEFILE)
133 $$(call must-be-nonempty,$(1)_type)
134 $$(eval $$(call calculate-arch-list,$$($(1)_type),$$($(1)_arch)))
135 INTERNAL_ARCH_LIST_FOR_$(1) := $$(MODULE_ARCH_LIST)
136 $$(foreach _m,$$(MODULE_ARCH_LIST),$$(eval $$(call process-module-arch,$(1),$$(_m))))
139 # This can be used by module_type.mk files to indicate that they can't be
140 # built as host_module_type
141 define target-build-only
142 $(if $(filter true,$(MODULE_HOST_BUILD)),$(error In makefile $(THIS_MAKEFILE): Module $(THIS_MODULE) attempted to build a host $(1), which is not supported))
145 define relative-to-top
146 $(patsubst $(TOP)/%,%,$(1))
151 CC_CHECK=$(patsubst @%,%,$(CC_CHECK)) && \
152 $(patsubst @%,%,$(CHMOD)) +x $$CC_CHECK && \
153 $$CC_CHECK --cc "$(1)" --out "$(2)" $(3))
157 $(call cc-check,$(patsubst @%,%,$(CC)),$(OUT),--clang)
161 $(call cc-check,$(patsubst @%,%,$(CC)),$(OUT),$(1))
165 $(call cc-check,$(patsubst @%,%,$(CXX)),$(OUT),$(1))
168 define host-cc-option
169 $(call cc-check,$(patsubst @%,%,$(HOST_CC)),$(OUT),$(1))
172 define host-cxx-option
173 $(call cc-check,$(patsubst @%,%,$(HOST_CXX)),$(OUT),$(1))
176 define kernel-cc-option
177 $(call cc-check,$(KERNEL_CROSS_COMPILE)gcc,$(OUT),$(1))
180 # Turn a particular warning on, or explicitly turn it off, depending on
181 # the value of W. The "-W" or "-Wno-" part of the warning need not be
183 define cc-optional-warning
184 $(call cc-option,-W$(if $(W),,no-)$(patsubst -W%,%,$(patsubst -Wno-%,%,$(1))))
187 define host-cc-optional-warning
188 $(call host-cc-option,-W$(if $(W),,no-)$(patsubst -W%,%,$(patsubst -Wno-%,%,$(1))))
191 define kernel-cc-optional-warning
192 $(call kernel-cc-option,-W$(if $(W),,no-)$(patsubst -W%,%,$(patsubst -Wno-%,%,$(1))))
195 define module-info-line
196 $(if $(filter modules,$(D)),$(info [$(THIS_MODULE)] <$(MODULE_ARCH)> $(1)),)
199 # $(call if-exists,A,B) => A if A is a file which exists, otherwise B
201 $(if $(wildcard $(1)),$(1),$(2))
205 # Joins a given list of strings together with the given separator.
207 # (1): the list of strings to join
208 # (2): the separator to use for joining
211 SPACE=$(NOOP) $(NOOP)
213 $(subst $(SPACE),$(2),$(strip $(1)))
217 # Check if a given path is absolute
219 # $(1): path to check
220 # $(2): return when true
221 # $(3): return when false
224 $(if $(filter /%,$(1)),$(2),$(3))
228 # Add a prefix to every path in a list, when the path isn't absolute.
230 # $(1): prefix to add
231 # $(2): list of paths
233 define addprefix-ifnot-abs
234 $(foreach _path,$(2),$(call if-abs-path,$(_path),$(_path),$(1)$(_path)))
238 # Return the directory part of a path normalized (without trailing slashes)
240 # $(1): Path to normalize
242 define normalized-dir
243 $(if $(filter /,$(dir $(1))),$(dir $(1)),$(if $(findstring /,$(dir $(1))),$(patsubst %/,%,$(dir $(1))),$(dir $(1))))
246 # Definitions to handle the various suffixes allowed for C++ files.
247 INTERNAL_CXX_SUFFIXES := .cc .cxx .cpp .c++
248 define filter-cxx-files
249 $(filter $(addprefix %,$(INTERNAL_CXX_SUFFIXES)),$(1))
252 define filter-out-cxx-files
253 $(filter-out $(addprefix %,$(INTERNAL_CXX_SUFFIXES)),$(1))
256 define objects-from-cxx-files
257 $(foreach _suffix,$(INTERNAL_CXX_SUFFIXES),$(patsubst %$(_suffix),%.o,$(filter %$(_suffix),$(1))))
260 define unsupported-module-var
261 $(if $(strip $($(THIS_MODULE)_$(1))),$(error In makefile $(THIS_MAKEFILE): Setting '$(THIS_MODULE)_$(1)' has no effect, because $(THIS_MODULE) has type $($(THIS_MODULE)_type)))