RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / build / linux / config / compiler.mk
1 ########################################################################### ###
2 #@File
3 #@Copyright     Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 #@License       Dual MIT/GPLv2
5
6 # The contents of this file are subject to the MIT license as set out below.
7
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to deal
10 # in the Software without restriction, including without limitation the rights
11 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 # copies of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
14
15 # The above copyright notice and this permission notice shall be included in
16 # all copies or substantial portions of the Software.
17
18 # Alternatively, the contents of this file may be used under the terms of
19 # the GNU General Public License Version 2 ("GPL") in which case the provisions
20 # of GPL are applicable instead of those above.
21
22 # If you wish to allow use of your version of this file only under the terms of
23 # GPL, and not to allow others to use your version of this file under the terms
24 # of the MIT license, indicate your decision by deleting the provisions above
25 # and replace them with the notice and other provisions required by GPL as set
26 # out in the file called "GPL-COPYING" included in this distribution. If you do
27 # not delete the provisions above, a recipient may use your version of this file
28 # under the terms of either the MIT license or GPL.
29
30 # This License is also included in this distribution in the file called
31 # "MIT-COPYING".
32
33 # EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
34 # PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
35 # BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 # PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
37 # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 ### ###########################################################################
41
42 # Check for valid values of $(MULTIARCH).
43 ifeq ($(strip $(MULTIARCH)),0)
44 $(error MULTIARCH must be empty to disable multiarch)
45 endif
46
47 define calculate-compiler-preferred-target
48  ifeq ($(2),qcc)
49   $(1)_compiler_preferred_target := qcc
50  else
51   $(1)_compiler_preferred_target := $$(shell $(2) -dumpmachine)
52   ifeq ($$($(1)_compiler_preferred_target),)
53    $$(warning No output from '$(2) -dumpmachine')
54    $$(warning Check that the compiler is in your PATH and CROSS_COMPILE is)
55    $$(warning set correctly.)
56    $$(error Unable to run compiler '$(2)')
57   endif
58   ifneq ($$(filter x86_64-%,$$($(1)_compiler_preferred_target)),)
59    $(1)_compiler_preferred_target := x86_64-linux-gnu
60   endif
61   ifneq ($$(filter i386-% i486-% i686-%,$$($(1)_compiler_preferred_target)),)
62    $(1)_compiler_preferred_target := i386-linux-gnu
63   endif
64   ifneq ($$(filter armv7a-cros-linux-gnueabi,$$($(1)_compiler_preferred_target)),)
65    $(1)_compiler_preferred_target := arm-linux-gnueabi
66   endif
67  endif
68 endef
69
70 define cross-compiler-name
71  ifeq ($$(origin CC),file)
72   $(1) := $(2)$(3)
73  else
74   ifeq ($$(_CLANG),true)
75    $(1) := $(3) -target $$(patsubst %-,%,$(2))
76   else
77    $(1) := $(3)
78   endif
79  endif
80 endef
81
82 # Work out the host compiler architecture
83 $(eval $(call calculate-compiler-preferred-target,host,$(HOST_CC)))
84
85 ifeq ($(host_compiler_preferred_target),x86_64-linux-gnu)
86  HOST_PRIMARY_ARCH := host_x86_64
87  HOST_32BIT_ARCH   := host_i386
88  HOST_FORCE_32BIT  := -m32
89 else
90 ifeq ($(host_compiler_preferred_target),i386-linux-gnu)
91  HOST_PRIMARY_ARCH := host_i386
92  HOST_32BIT_ARCH   := host_i386
93 else
94  $(error Unknown host compiler target architecture $(host_compiler_preferred_target))
95 endif
96 endif
97
98 # Workaround our lack of support for non-Linux HOST_CCs
99 ifneq ($(HOST_CC_IS_LINUX),1)
100  $(warning $$(HOST_CC) is non-Linux. Trying to work around.)
101  override HOST_CC := $(HOST_CC) -D__linux__
102  $(eval $(call BothConfigMake,HOST_CC,$(HOST_CC)))
103 endif
104
105 $(eval $(call BothConfigMake,HOST_PRIMARY_ARCH,$(HOST_PRIMARY_ARCH)))
106 $(eval $(call BothConfigMake,HOST_32BIT_ARCH,$(HOST_32BIT_ARCH)))
107 $(eval $(call BothConfigMake,HOST_FORCE_32BIT,$(HOST_FORCE_32BIT)))
108
109 TARGET_ALL_ARCH := 
110 TARGET_PRIMARY_ARCH :=
111 TARGET_SECONDARY_ARCH :=
112
113 # Work out the target compiler cross triple, and include the corresponding
114 # compilers/*.mk file, which sets TARGET_PRIMARY_ARCH and
115 # TARGET_SECONDARY_ARCH for that compiler.
116 #
117 compilers := ../config/compilers
118 define include-compiler-file
119  ifeq ($(strip $(1)),)
120   $$(error empty arg passed to include-compiler-file)
121  endif
122  ifeq ($$(wildcard $$(compilers)/$(1).mk),)
123   $$(warning ******************************************************)
124   $$(warning Compiler target '$(1)' not recognised)
125   $$(warning (missing $$(compilers)/$(1).mk file))
126   $$(warning ******************************************************)
127   $$(error Compiler '$(1)' not recognised)
128  endif
129  include $$(compilers)/$(1).mk
130 endef
131
132 # Check the kernel cross compiler to work out which architecture it targets.
133 # We can then tell if CROSS_COMPILE targets a different architecture.
134 ifneq ($(origin KERNEL_CROSS_COMPILE),undefined)
135  # First, calculate the value of KERNEL_CROSS_COMPILE as it would be seen by
136  # the main build, so we can check it here in the config stage.
137  $(call one-word-only,KERNEL_CROSS_COMPILE)
138  _kernel_cross_compile := $(if $(filter undef,$(KERNEL_CROSS_COMPILE)),,$(KERNEL_CROSS_COMPILE))
139  # We can take shortcuts with KERNEL_CROSS_COMPILE, as we don't want to
140  # respect CC and we don't support clang in that part currently.
141  _kernel_cross_compile := $(_kernel_cross_compile)gcc
142  # Then check the compiler.
143  $(eval $(call calculate-compiler-preferred-target,target,$(_kernel_cross_compile)))
144  $(eval $(call include-compiler-file,$(target_compiler_preferred_target)))
145  _kernel_primary_arch := $(TARGET_PRIMARY_ARCH)
146 else
147  # We can take shortcuts with KERNEL_CROSS_COMPILE, as we don't want to
148  # respect CC and we don't support clang in that part currently.
149  _kernel_cross_compile := $(CROSS_COMPILE)gcc
150  # KERNEL_CROSS_COMPILE will be the same as CROSS_COMPILE, so we don't need
151  # to do the compatibility check.
152  _kernel_primary_arch :=
153 endif
154
155 $(eval $(call cross-compiler-name,_cc,$(CROSS_COMPILE),$(CC)))
156 $(eval $(call cross-compiler-name,_cc_secondary,$(if $(CROSS_COMPILE_SECONDARY),$(CROSS_COMPILE_SECONDARY),$(CROSS_COMPILE)),$(CC_SECONDARY)))
157 $(eval $(call calculate-compiler-preferred-target,target,$(_cc)))
158 $(eval $(call include-compiler-file,$(target_compiler_preferred_target)))
159
160 # Sanity check: if KERNEL_CROSS_COMPILE was set, it has to target the same
161 # architecture as CROSS_COMPILE.
162 ifneq ($(_kernel_primary_arch),)
163  ifneq ($(TARGET_PRIMARY_ARCH),$(_kernel_primary_arch))
164   $(warning ********************************************************)
165   $(warning Error: Kernel and user-mode cross compilers build for)
166   $(warning different targets)
167   $(warning $(space)$(space)CROSS_COMPILE=$(CROSS_COMPILE))
168   $(warning $(space)$(space)$(space)builds for $(TARGET_PRIMARY_ARCH))
169   $(warning $(space)$(space)KERNEL_CROSS_COMPILE=$(KERNEL_CROSS_COMPILE))
170   $(warning $(space)$(space)$(space)builds for $(_kernel_primary_arch))
171   $(warning ********************************************************)
172   $(error Mismatching kernel and user-mode cross compilers)
173  endif
174 endif
175
176 ifneq ($(MULTIARCH),32only)
177 TARGET_ALL_ARCH += $(TARGET_PRIMARY_ARCH)
178 endif
179 ifneq ($(MULTIARCH),64only)
180 TARGET_ALL_ARCH += $(TARGET_SECONDARY_ARCH)
181 endif
182
183 $(eval $(call BothConfigMake,TARGET_PRIMARY_ARCH,$(TARGET_PRIMARY_ARCH)))
184 $(eval $(call BothConfigMake,TARGET_SECONDARY_ARCH,$(TARGET_SECONDARY_ARCH)))
185 $(eval $(call BothConfigMake,TARGET_ALL_ARCH,$(TARGET_ALL_ARCH)))
186 $(eval $(call BothConfigMake,TARGET_FORCE_32BIT,$(TARGET_FORCE_32BIT)))
187
188 $(info ******* Multiarch build: $(if $(MULTIARCH),yes,no))
189 $(info ******* Primary arch:    $(if $(TARGET_PRIMARY_ARCH),$(TARGET_PRIMARY_ARCH),none))
190 $(info ******* Secondary arch:  $(if $(TARGET_SECONDARY_ARCH),$(TARGET_SECONDARY_ARCH),none))
191
192 # Find the paths to libgcc for the primary and secondary architectures.
193 LIBGCC := $(shell $(_cc) -print-libgcc-file-name)
194 LIBGCC_SECONDARY := $(shell $(_cc_secondary) $(TARGET_FORCE_32BIT) -print-libgcc-file-name)