RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / build / linux / defs.mk
1 ########################################################################### ###
2 #@Copyright     Copyright (c) Imagination Technologies Ltd. All Rights Reserved
3 #@License       Dual MIT/GPLv2
4
5 # The contents of this file are subject to the MIT license as set out below.
6
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:
13
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
16
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.
20
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.
28
29 # This License is also included in this distribution in the file called
30 # "MIT-COPYING".
31
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 ### ###########################################################################
40
41 define must-be-defined
42 $(if $(filter undefined,$(origin $(1))),$(error In makefile $(THIS_MAKEFILE): $$($(1)) must be defined),)
43 endef
44
45 define must-be-nonempty
46 $(if $(strip $($(1))),,$(error In makefile $(THIS_MAKEFILE): $$($(1)) must contain a value))
47 endef
48
49 define directory-must-exist
50 $(if $(wildcard $(abspath $(1)/)),,$(error Directory $(1) must exist))
51 endef
52
53 define one-word-only
54 $(if $(filter-out $(firstword $($(1))),$($(1))),$(error In makefile $(THIS_MAKEFILE): $$($(1)) must contain only one word),)
55 endef
56
57 define module-library
58 $(patsubst lib%.so,%,$(if $($(1)_target),$($(1)_target),$(1).so))
59 endef
60
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)
64 endef
65
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):
73         $$(make-directory)
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)
78 endef
79
80 target_neutral_types := \
81  apk \
82  bison_parser \
83  bridge \
84  copy_files \
85  custom \
86  flex_lexer \
87  flexxx_lexer \
88  gen_dispatch \
89  rsc_scriptc \
90  image_header \
91  inline_shaders \
92  java_archive \
93  module_group \
94  pds_header \
95  rgxfw \
96  test_image \
97  usc_header \
98  rscbitcode_header \
99  yuv_test_image
100
101 doc_types := \
102  doc \
103  doxygen
104
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
111 else
112 ifneq ($$(filter $(1),$(target_neutral_types)),)
113 MODULE_ARCH_LIST := target_neutral
114 else
115 ifneq ($$(filter $(1),kernel_module),)
116 MODULE_ARCH_LIST := $(TARGET_PRIMARY_ARCH)
117 else
118 MODULE_ARCH_LIST := $(TARGET_ALL_ARCH)
119 endif
120 endif
121 endif
122 endif
123 endef
124
125 define process-module
126 THIS_MODULE := $(1)
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))))
137 endef
138
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))
143 endef
144
145 define relative-to-top
146 $(patsubst $(TOP)/%,%,$(1))
147 endef
148
149 define cc-check
150 $(shell \
151         CC_CHECK=$(patsubst @%,%,$(CC_CHECK)) && \
152         $(patsubst @%,%,$(CHMOD)) +x $$CC_CHECK && \
153         $$CC_CHECK --cc "$(1)" --out "$(2)" $(3))
154 endef
155
156 define cc-is-clang
157 $(call cc-check,$(patsubst @%,%,$(CC)),$(OUT),--clang)
158 endef
159
160 define cc-option
161 $(call cc-check,$(patsubst @%,%,$(CC)),$(OUT),$(1))
162 endef
163
164 define cxx-option
165 $(call cc-check,$(patsubst @%,%,$(CXX)),$(OUT),$(1))
166 endef
167
168 define host-cc-option
169 $(call cc-check,$(patsubst @%,%,$(HOST_CC)),$(OUT),$(1))
170 endef
171
172 define host-cxx-option
173 $(call cc-check,$(patsubst @%,%,$(HOST_CXX)),$(OUT),$(1))
174 endef
175
176 define kernel-cc-option
177 $(call cc-check,$(KERNEL_CROSS_COMPILE)gcc,$(OUT),$(1))
178 endef
179
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
182 # specified.
183 define cc-optional-warning
184 $(call cc-option,-W$(if $(W),,no-)$(patsubst -W%,%,$(patsubst -Wno-%,%,$(1))))
185 endef
186
187 define host-cc-optional-warning
188 $(call host-cc-option,-W$(if $(W),,no-)$(patsubst -W%,%,$(patsubst -Wno-%,%,$(1))))
189 endef
190
191 define kernel-cc-optional-warning
192 $(call kernel-cc-option,-W$(if $(W),,no-)$(patsubst -W%,%,$(patsubst -Wno-%,%,$(1))))
193 endef
194
195 define module-info-line
196 $(if $(filter modules,$(D)),$(info [$(THIS_MODULE)] <$(MODULE_ARCH)> $(1)),)
197 endef
198
199 # $(call if-exists,A,B) => A if A is a file which exists, otherwise B
200 define if-exists
201 $(if $(wildcard $(1)),$(1),$(2))
202 endef
203
204 #
205 # Joins a given list of strings together with the given separator.
206 #
207 # (1): the list of strings to join
208 # (2): the separator to use for joining
209 #
210 NOOP=
211 SPACE=$(NOOP) $(NOOP)
212 define list-join
213 $(subst $(SPACE),$(2),$(strip $(1)))
214 endef
215
216
217 # Check if a given path is absolute
218 #
219 # $(1): path to check
220 # $(2): return when true
221 # $(3): return when false
222 #
223 define if-abs-path
224 $(if $(filter /%,$(1)),$(2),$(3))
225 endef
226
227
228 # Add a prefix to every path in a list, when the path isn't absolute.
229 #
230 # $(1): prefix to add
231 # $(2): list of paths
232 #
233 define addprefix-ifnot-abs
234 $(foreach _path,$(2),$(call if-abs-path,$(_path),$(_path),$(1)$(_path)))
235 endef
236
237 #
238 # Return the directory part of a path normalized (without trailing slashes)
239 #
240 # $(1): Path to normalize
241 #
242 define normalized-dir
243 $(if $(filter /,$(dir $(1))),$(dir $(1)),$(if $(findstring /,$(dir $(1))),$(patsubst %/,%,$(dir $(1))),$(dir $(1))))
244 endef
245
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))
250 endef
251
252 define filter-out-cxx-files
253 $(filter-out $(addprefix %,$(INTERNAL_CXX_SUFFIXES)),$(1))
254 endef
255
256 define objects-from-cxx-files
257 $(foreach _suffix,$(INTERNAL_CXX_SUFFIXES),$(patsubst %$(_suffix),%.o,$(filter %$(_suffix),$(1))))
258 endef
259
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)))
262 endef