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 # from-one-* recipes make a thing from one source file, so they use $<. Others
42 # use $(MODULE_something) instead of $^
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
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 $@
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 $@
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 $@
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 $@
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)
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)
88 define target-executable-from-o
89 $(if $(V),,@echo " LD " $(call relative-to-top,$@))
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)
96 define target-executable-cxx-from-o
97 $(if $(V),,@echo " LD " $(call relative-to-top,$@))
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)
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)
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)
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)
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)
138 define host-copy-debug-information
139 $(HOST_OBJCOPY) --only-keep-debug $@ $(basename $@).dbg
142 define host-strip-debug-information
143 $(HOST_STRIP) --strip-unneeded $@
146 define host-add-debuglink
147 $(if $(V),,@echo " DBGLINK " $(call relative-to-top,$(basename $@).dbg))
148 $(HOST_OBJCOPY) --add-gnu-debuglink=$(basename $@).dbg $@
151 define target-copy-debug-information
152 $(OBJCOPY) --only-keep-debug $@ $(basename $@).dbg
155 define target-strip-debug-information
156 $(STRIP) --strip-unneeded $@
159 define target-add-debuglink
160 $(if $(V),,@echo " DBGLINK " $(call relative-to-top,$(basename $@).dbg))
161 $(OBJCOPY) --add-gnu-debuglink=$(basename $@).dbg $@
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))
169 define target-static-library-from-o
170 $(if $(V),,@echo " AR " $(call relative-to-top,$@))
171 $(AR) cru $@ $(sort $(MODULE_ALL_OBJECTS))
175 $(if $(V),,@echo " BISON " $(call relative-to-top,$<))
176 $(BISON) $(MODULE_BISON_FLAGS) -o $@ -d $<
180 $(if $(V),,@echo " FLEX " $(call relative-to-top,$<))
181 $(FLEX) $(MODULE_FLEX_FLAGS) -o$@ $<
185 $(if $(V),,@echo " FLEXXX " $(call relative-to-top,$<))
186 $(FLEXXX) $(MODULE_FLEXXX_FLAGS) -o$@ $<
190 $(if $(V),,@echo " RM " $(call relative-to-top,$(MODULE_DIRS_TO_REMOVE)))
191 $(RM) -rf $(MODULE_DIRS_TO_REMOVE)
194 define make-directory
198 ifeq ($(DISABLE_CHECK_EXPORTS),)
206 # Check a source file with the program specified in $(CHECK).
207 # If $(CHECK) is empty, don't do anything.
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)) \
218 # If CHECK_ONLY is set, only check files matching a Make pattern.
219 # e.g. CHECK_ONLY=opengles1/%.c
221 $(if $(and $(if $(CHECK_ONLY),$(filter $(CHECK_ONLY),$<),true), \
222 $(if $(CHECK_EXCLUDE),$(filter-out $(CHECK_EXCLUDE),$<),true)),$(check-src-1),@:)
226 # Programs used in recipes
230 CC_SECONDARY ?= $(CC)
231 CROSS_COMPILE_SECONDARY ?= $(CROSS_COMPILE)
233 CXX_SECONDARY ?= $(CXX)
242 ifeq ($(USE_CCACHE),1)
245 ifeq ($(USE_DISTCC),1)
249 # Define CHMOD and CC_CHECK first so we can use cc-is-clang
251 override CHMOD := $(if $(V),,@)chmod
252 override CC_CHECK := $(if $(V),,@)$(MAKE_TOP)/tools/cc-check.sh
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.
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).
263 # Set the secondary compiler first before we overwrite $(CC).
266 ifneq ($(CROSS_COMPILE_SECONDARY),)
267 ifeq ($(cc-is-clang),true)
268 override CC_SECONDARY := \
270 -target $(patsubst %-,%,$(CROSS_COMPILE_SECONDARY)) \
271 -B$(dir $(shell which $(CROSS_COMPILE_SECONDARY)gcc))
272 override CXX_SECONDARY := \
274 -target $(patsubst %-,%,$(CROSS_COMPILE_SECONDARY)) \
275 -B$(dir $(shell which $(CROSS_COMPILE_SECONDARY)gcc))
277 ifeq ($(origin CC_SECONDARY),file)
278 override CC_SECONDARY := $(CROSS_COMPILE_SECONDARY)$(CC_SECONDARY)
280 ifeq ($(origin CXX_SECONDARY),file)
281 override CXX_SECONDARY := $(CROSS_COMPILE_SECONDARY)$(CXX_SECONDARY)
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)
290 ifneq ($(CROSS_COMPILE),)
291 ifeq ($(cc-is-clang),true)
294 -target $(patsubst %-,%,$(CROSS_COMPILE)) \
295 -B$(dir $(shell which $(CROSS_COMPILE)gcc))
298 -target $(patsubst %-,%,$(CROSS_COMPILE)) \
299 -B$(dir $(shell which $(CROSS_COMPILE)gcc))
301 ifeq ($(origin CC),file)
302 override CC := $(CROSS_COMPILE)$(CC)
304 ifeq ($(origin CXX),file)
305 override CXX := $(CROSS_COMPILE)$(CXX)
309 $(if $(CROSS_COMPILE_SECONDARY),$(error CROSS_COMPILE_SECONDARY is set but CROSS_COMPILE is empty))
312 # Apply compiler wrappers and V=1 handling
313 override CC := $(if $(V),,@)$(CCACHE)$(DISTCC) $(CC)
314 override CXX := $(if $(V),,@)$(CCACHE)$(DISTCC) $(CXX)
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)
355 ifeq ($(SUPPORT_NEUTRINO_PLATFORM),1)
356 include $(MAKE_TOP)/common/neutrino/commands_neutrino.mk