RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / build / linux / commands.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 # from-one-* recipes make a thing from one source file, so they use $<. Others
42 # use $(MODULE_something) instead of $^
43
44 # We expect that MODULE_*FLAGS contains all the flags we need, including the
45 # flags for all modules (like $(ALL_CFLAGS) and $(ALL_HOST_CFLAGS)), and
46 # excluding flags for include search dirs or for linking libraries. The
47 # exceptions are ALL_EXE_LDFLAGS and ALL_LIB_LDFLAGS, since they depend on the
48 # type of thing being linked, so they appear in the commands below
49
50 define host-o-from-one-c
51 $(if $(V),,@echo "  HOST_CC " $(call relative-to-top,$<))
52 $(MODULE_CC) -MD -MF $(patsubst %.o,%.d,$@) -c $(MODULE_CFLAGS) \
53         $(MODULE_INCLUDE_FLAGS) -include $(CONFIG_H) $< -o $@
54 endef
55
56 define target-o-from-one-c
57 $(if $(V),,@echo "  CC      " $(call relative-to-top,$<))
58 $(MODULE_CC) -MD -MF $(patsubst %.o,%.d,$@) -c $(MODULE_CFLAGS) \
59         $(MODULE_INCLUDE_FLAGS) -include $(CONFIG_H) $< -o $@
60 endef
61
62 define host-o-from-one-cxx
63 $(if $(V),,@echo "  HOST_CXX" $(call relative-to-top,$<))
64 $(MODULE_CXX) -MD -MF $(patsubst %.o,%.d,$@) -c $(MODULE_CXXFLAGS) \
65         $(MODULE_INCLUDE_FLAGS) -include $(CONFIG_H) $< -o $@
66 endef
67
68 define target-o-from-one-cxx
69 $(if $(V),,@echo "  CXX     " $(call relative-to-top,$<))
70 $(MODULE_CXX) -MD -MF $(patsubst %.o,%.d,$@) -c $(MODULE_CXXFLAGS) \
71         $(MODULE_INCLUDE_FLAGS) -include $(CONFIG_H) $< -o $@
72 endef
73
74 define host-executable-from-o
75 $(if $(V),,@echo "  HOST_LD " $(call relative-to-top,$@))
76 $(MODULE_CC) $(MODULE_LDFLAGS) \
77         -o $@ $(sort $(MODULE_ALL_OBJECTS)) $(MODULE_LIBRARY_DIR_FLAGS) \
78         $(MODULE_LIBRARY_FLAGS)
79 endef
80
81 define host-executable-cxx-from-o
82 $(if $(V),,@echo "  HOST_LD " $(call relative-to-top,$@))
83 $(MODULE_CXX) $(MODULE_LDFLAGS) \
84         -o $@ $(sort $(MODULE_ALL_OBJECTS)) $(MODULE_LIBRARY_DIR_FLAGS) \
85         $(MODULE_LIBRARY_FLAGS)
86 endef
87
88 define target-executable-from-o
89 $(if $(V),,@echo "  LD      " $(call relative-to-top,$@))
90 $(MODULE_CC) \
91         $(MODULE_EXE_LDFLAGS) $(MODULE_LDFLAGS) -o $@ \
92         $(MODULE_EXE_CRTBEGIN) $(MODULE_ALL_OBJECTS) $(MODULE_EXE_CRTEND) \
93         $(MODULE_LIBRARY_DIR_FLAGS) $(MODULE_LIBRARY_FLAGS) $(MODULE_LIBGCC)
94 endef
95
96 define target-executable-cxx-from-o
97 $(if $(V),,@echo "  LD      " $(call relative-to-top,$@))
98 $(MODULE_CXX) \
99         $(MODULE_EXE_LDFLAGS) $(MODULE_LDFLAGS) -o $@ \
100         $(MODULE_EXE_CRTBEGIN) $(MODULE_ALL_OBJECTS) $(MODULE_EXE_CRTEND) \
101         $(MODULE_LIBRARY_DIR_FLAGS) $(MODULE_LIBRARY_FLAGS) $(MODULE_LIBGCC)
102 endef
103
104 define target-shared-library-from-o
105 $(if $(V),,@echo "  LD      " $(call relative-to-top,$@))
106 $(MODULE_CC) -shared -Wl,-Bsymbolic \
107         $(MODULE_LIB_LDFLAGS) $(MODULE_LDFLAGS) -o $@ \
108         $(MODULE_LIB_CRTBEGIN) $(MODULE_ALL_OBJECTS) $(MODULE_LIB_CRTEND) \
109         $(MODULE_LIBRARY_DIR_FLAGS) $(MODULE_LIBRARY_FLAGS) $(MODULE_LIBGCC)
110 endef
111
112 define host-shared-library-from-o
113 $(if $(V),,@echo "  HOST_LD " $(call relative-to-top,$@))
114 $(MODULE_CC) -shared -Wl,-Bsymbolic \
115         $(MODULE_LDFLAGS) -o $@ \
116         $(sort $(MODULE_ALL_OBJECTS)) \
117         $(MODULE_LIBRARY_DIR_FLAGS) $(MODULE_LIBRARY_FLAGS)
118 endef
119
120 # If there were any C++ source files in a shared library, we use one of
121 # these recipes, which run the C++ compiler to link the final library
122 define target-shared-library-cxx-from-o
123 $(if $(V),,@echo "  LD      " $(call relative-to-top,$@))
124 $(MODULE_CXX) -shared -Wl,-Bsymbolic \
125         $(MODULE_LIB_LDFLAGS) $(MODULE_LDFLAGS) -o $@ \
126         $(MODULE_LIB_CRTBEGIN) $(MODULE_ALL_OBJECTS) $(MODULE_LIB_CRTEND) \
127         $(MODULE_LIBRARY_DIR_FLAGS) $(MODULE_LIBRARY_FLAGS) $(MODULE_LIBGCC)
128 endef
129
130 define host-shared-library-cxx-from-o
131 $(if $(V),,@echo "  HOST_LD " $(call relative-to-top,$@))
132 $(MODULE_CXX) -shared -Wl,-Bsymbolic \
133         $(MODULE_LDFLAGS) -o $@ \
134         $(sort $(MODULE_ALL_OBJECTS)) \
135         $(MODULE_LIBRARY_DIR_FLAGS) $(MODULE_LIBRARY_FLAGS)
136 endef
137
138 define host-copy-debug-information
139 $(HOST_OBJCOPY) --only-keep-debug $@ $(basename $@).dbg
140 endef
141
142 define host-strip-debug-information
143 $(HOST_STRIP) --strip-unneeded $@
144 endef
145
146 define host-add-debuglink
147 $(if $(V),,@echo "  DBGLINK " $(call relative-to-top,$(basename $@).dbg))
148 $(HOST_OBJCOPY) --add-gnu-debuglink=$(basename $@).dbg $@
149 endef
150
151 define target-copy-debug-information
152 $(OBJCOPY) --only-keep-debug $@ $(basename $@).dbg
153 endef
154
155 define target-strip-debug-information
156 $(STRIP) --strip-unneeded $@
157 endef
158
159 define target-add-debuglink
160 $(if $(V),,@echo "  DBGLINK " $(call relative-to-top,$(basename $@).dbg))
161 $(OBJCOPY) --add-gnu-debuglink=$(basename $@).dbg $@
162 endef
163
164 define host-static-library-from-o
165 $(if $(V),,@echo "  HOST_AR " $(call relative-to-top,$@))
166 $(HOST_AR) cru $@ $(sort $(MODULE_ALL_OBJECTS))
167 endef
168
169 define target-static-library-from-o
170 $(if $(V),,@echo "  AR      " $(call relative-to-top,$@))
171 $(AR) cru $@ $(sort $(MODULE_ALL_OBJECTS))
172 endef
173
174 define tab-c-from-y
175 $(if $(V),,@echo "  BISON   " $(call relative-to-top,$<))
176 $(BISON) $(MODULE_BISON_FLAGS) -o $@ -d $<
177 endef
178
179 define l-c-from-l
180 $(if $(V),,@echo "  FLEX    " $(call relative-to-top,$<))
181 $(FLEX) $(MODULE_FLEX_FLAGS) -o$@ $<
182 endef
183
184 define l-cc-from-l
185 $(if $(V),,@echo "  FLEXXX  " $(call relative-to-top,$<))
186 $(FLEXXX) $(MODULE_FLEXXX_FLAGS) -o$@ $<
187 endef
188
189 define clean-dirs
190 $(if $(V),,@echo "  RM      " $(call relative-to-top,$(MODULE_DIRS_TO_REMOVE)))
191 $(RM) -rf $(MODULE_DIRS_TO_REMOVE)
192 endef
193
194 define make-directory
195 $(MKDIR) -p $@
196 endef
197
198 ifeq ($(DISABLE_CHECK_EXPORTS),)
199 define check-exports
200 endef
201 else
202 define check-exports
203 endef
204 endif
205
206 # Check a source file with the program specified in $(CHECK).
207 # If $(CHECK) is empty, don't do anything.
208 ifeq ($(CHECK),)
209 check-src :=
210 else
211 define check-src-1
212 $(if $(V),,@echo "  CHECK   " $(call relative-to-top,$<))
213 $(if $(IGNORE_CHECK_ERRORS),-,)$(CHECK) $(MODULE_INCLUDE_FLAGS) \
214         $(if $(CHECK_NO_CONFIG_H),,-include $(CONFIG_H)) \
215         $(filter -D%,$(MODULE_CFLAGS)) \
216         $(CHECKFLAGS) $<
217 endef
218 # If CHECK_ONLY is set, only check files matching a Make pattern.
219 # e.g. CHECK_ONLY=opengles1/%.c
220 define check-src
221 $(if $(and $(if $(CHECK_ONLY),$(filter $(CHECK_ONLY),$<),true), \
222                 $(if $(CHECK_EXCLUDE),$(filter-out $(CHECK_EXCLUDE),$<),true)),$(check-src-1),@:)
223 endef
224 endif
225
226 # Programs used in recipes
227
228 BISON ?= bison
229 CC ?= gcc
230 CC_SECONDARY ?= $(CC)
231 CROSS_COMPILE_SECONDARY ?= $(CROSS_COMPILE)
232 CXX ?= g++
233 CXX_SECONDARY ?= $(CXX)
234 HOST_CC ?= gcc
235 HOST_CXX ?= g++
236 JAR ?= jar
237 JAVA ?= java
238 JAVAC ?= javac
239 PYTHON ?= python
240 ZIP ?= zip
241
242 ifeq ($(USE_CCACHE),1)
243 CCACHE ?= ccache
244 endif
245 ifeq ($(USE_DISTCC),1)
246 DISTCC ?= distcc
247 endif
248
249 # Define CHMOD and CC_CHECK first so we can use cc-is-clang
250 #
251 override CHMOD          := $(if $(V),,@)chmod
252 override CC_CHECK       := $(if $(V),,@)$(MAKE_TOP)/tools/cc-check.sh
253
254 # If clang is detected, the compiler name is invariant but CROSS_COMPILE
255 # is reflected in the use of -target. For GCC this is always encoded into
256 # the binary. If CROSS_COMPILE is not set we can skip this.
257 #
258 # If we're doing a build with multiple target architectures, we might need
259 # two separate compilers to build binaries for each architecture. In this
260 # case, CROSS_COMPILE and CROSS_COMPILE_SECONDARY are the cross compiler
261 # prefix for the two compilers - $(CC) and $(CC_SECONDARY).
262 #
263 # Set the secondary compiler first before we overwrite $(CC).
264 #
265
266 ifneq ($(CROSS_COMPILE_SECONDARY),)
267  ifeq ($(cc-is-clang),true)
268   override CC_SECONDARY   := \
269    $(CC_SECONDARY) \
270    -target $(patsubst %-,%,$(CROSS_COMPILE_SECONDARY)) \
271    -B$(dir $(shell which $(CROSS_COMPILE_SECONDARY)gcc))
272   override CXX_SECONDARY  := \
273    $(CXX_SECONDARY) \
274    -target $(patsubst %-,%,$(CROSS_COMPILE_SECONDARY)) \
275    -B$(dir $(shell which $(CROSS_COMPILE_SECONDARY)gcc))
276  else
277   ifeq ($(origin CC_SECONDARY),file)
278    override CC_SECONDARY  := $(CROSS_COMPILE_SECONDARY)$(CC_SECONDARY)
279   endif
280   ifeq ($(origin CXX_SECONDARY),file)
281    override CXX_SECONDARY := $(CROSS_COMPILE_SECONDARY)$(CXX_SECONDARY)
282   endif
283  endif
284 endif
285
286 # Apply compiler wrappers and V=1 handling
287 override CC_SECONDARY     := $(if $(V),,@)$(CCACHE)$(DISTCC) $(CC_SECONDARY)
288 override CXX_SECONDARY    := $(if $(V),,@)$(CCACHE)$(DISTCC) $(CXX_SECONDARY)
289
290 ifneq ($(CROSS_COMPILE),)
291  ifeq ($(cc-is-clang),true)
292   override CC   := \
293    $(CC) \
294    -target $(patsubst %-,%,$(CROSS_COMPILE)) \
295    -B$(dir $(shell which $(CROSS_COMPILE)gcc))
296   override CXX  := \
297    $(CXX) \
298    -target $(patsubst %-,%,$(CROSS_COMPILE)) \
299    -B$(dir $(shell which $(CROSS_COMPILE)gcc))
300  else
301   ifeq ($(origin CC),file)
302    override CC  := $(CROSS_COMPILE)$(CC)
303   endif
304   ifeq ($(origin CXX),file)
305    override CXX := $(CROSS_COMPILE)$(CXX)
306   endif
307  endif
308 else
309  $(if $(CROSS_COMPILE_SECONDARY),$(error CROSS_COMPILE_SECONDARY is set but CROSS_COMPILE is empty))
310 endif
311
312 # Apply compiler wrappers and V=1 handling
313 override CC     := $(if $(V),,@)$(CCACHE)$(DISTCC) $(CC)
314 override CXX    := $(if $(V),,@)$(CCACHE)$(DISTCC) $(CXX)
315
316 override AR                             := $(if $(V),,@)$(CROSS_COMPILE)ar
317 override BISON                  := $(if $(V),,@)$(BISON)
318 override BZIP2                  := $(if $(V),,@)bzip2 -9
319 override CAT                    := $(if $(V),,@)cat
320 override CHECK                  := $(if $(CHECK),$(if $(V),,@)$(CHECK),)
321 override CP                             := $(if $(V),,@)cp
322 override ECHO                   := $(if $(V),,@)echo
323 override FLEX                   := $(if $(V),,@)flex
324 override FLEXXX                 := $(if $(V),,@)flex++
325 override GREP                   := $(if $(V),,@)grep
326 override HOST_AR                := $(if $(V),,@)ar
327 override HOST_CC                := $(if $(V),,@)$(CCACHE) $(HOST_CC)
328 override HOST_CXX               := $(if $(V),,@)$(CCACHE) $(HOST_CXX)
329 override HOST_OBJCOPY   := $(if $(V),,@)objcopy
330 override HOST_STRIP             := $(if $(V),,@)strip
331 override INSTALL                := $(if $(V),,@)install
332 override JAR                    := $(if $(V),,@)$(JAR)
333 override JAVA                   := $(if $(V),,@)$(JAVA)
334 override JAVAC                  := $(if $(V),,@)$(JAVAC)
335 override LN                             := $(if $(V),,@)ln -f -s
336 override M4                             := $(if $(V),,@)m4
337 override MKDIR                  := $(if $(V),,@)mkdir
338 override MV                             := $(if $(V),,@)mv
339 override OBJCOPY                := $(if $(V),,@)$(CROSS_COMPILE)objcopy
340 override PERL                   := $(if $(V),,@)perl
341 override PSC                    := $(if $(V),,@)$(HOST_OUT)/psc_standalone
342 override PYTHON                 := $(if $(V),,@)$(PYTHON)
343 override RANLIB                 := $(if $(V),,@)$(CROSS_COMPILE)ranlib
344 override RM                             := $(if $(V),,@)rm -f
345 override ROGUEASM               := $(if $(V),,@)$(HOST_OUT)/rogueasm
346 override SED                    := $(if $(V),,@)sed
347 override STRIP                  := $(if $(V),,@)$(CROSS_COMPILE)strip
348 override TAR                    := $(if $(V),,@)tar
349 override TOUCH                  := $(if $(V),,@)touch
350 override TEST                   := $(if $(V),,@)test
351 override VHD2INC                := $(if $(V),,@)$(HOST_OUT)/vhd2inc
352 override XXD            := $(if $(V),,@)xxd
353 override ZIP                    := $(if $(V),,@)$(ZIP)
354
355 ifeq ($(SUPPORT_NEUTRINO_PLATFORM),1)
356 include $(MAKE_TOP)/common/neutrino/commands_neutrino.mk
357 endif