Merge branch develop-3.10-next
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue / build / linux / toplevel.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 # Define the default goal. This masks a previous definition of the default
43 # goal in config/core.mk, which must match this one
44 .PHONY: build
45 build: components
46
47 MAKE_TOP      := build/linux
48 THIS_MAKEFILE := (top-level makefiles)
49
50 include $(MAKE_TOP)/defs.mk
51
52 ifeq ($(OUT),)
53 $(error Must specify output directory with OUT=)
54 endif
55
56 ifeq ($(TOP),)
57 $(error Must specify root of source tree with TOP=)
58 endif
59 $(call directory-must-exist,$(TOP))
60
61 # RELATIVE_OUT is relative only if it's under $(TOP)
62 RELATIVE_OUT       := $(patsubst $(TOP)/%,%,$(OUT))
63 CONFIG_MK          := $(RELATIVE_OUT)/config.mk
64 CONFIG_H           := $(RELATIVE_OUT)/config.h
65 CONFIG_KERNEL_MK   := $(RELATIVE_OUT)/config_kernel.mk
66 CONFIG_KERNEL_H    := $(RELATIVE_OUT)/config_kernel.h
67
68 # Convert commas to spaces in $(D). This is so you can say "make
69 # D=config-changes,freeze-config" and have $(filter config-changes,$(D))
70 # still work.
71 comma := ,
72 empty :=
73 space := $(empty) $(empty)
74 override D := $(subst $(comma),$(space),$(D))
75
76 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
77 # Create the out directory
78 #
79 $(shell mkdir -p $(OUT))
80
81 # If these generated files differ from any pre-existing ones,
82 # replace them, causing affected parts of the driver to rebuild.
83 #
84 _want_config_diff := $(filter config-changes,$(D))
85 _freeze_config := $(strip $(filter freeze-config,$(D)))
86 _updated_config_files := $(shell \
87     $(if $(_want_config_diff),rm -f $(OUT)/config.diff;,) \
88         for file in $(CONFIG_MK) $(CONFIG_H) \
89                                 $(CONFIG_KERNEL_MK) $(CONFIG_KERNEL_H); do \
90                 diff -U 0 $$file $$file.new \
91                         >>$(if $(_want_config_diff),$(OUT)/config.diff,/dev/null) 2>/dev/null \
92                 && rm -f $$file.new \
93                 || echo $$file; \
94         done)
95
96 ifneq ($(_want_config_diff),)
97 # We send the diff to stderr so it isn't captured by $(shell)
98 $(shell [ -s $(OUT)/config.diff ] && echo >&2 "Configuration changed in $(RELATIVE_OUT):" && cat >&2 $(OUT)/config.diff)
99 endif
100
101 ifneq ($(_freeze_config),)
102 $(if $(_updated_config_files),$(error Configuration change in $(RELATIVE_OUT) prevented by D=freeze-config),)
103 endif
104
105 # Update the config, if changed
106 $(foreach _f,$(_updated_config_files), \
107         $(shell mv -f $(_f).new $(_f) >/dev/null 2>/dev/null))
108
109 endif # INTERNAL_CLOBBER_ONLY
110
111 MAKEFLAGS := -Rr --no-print-directory
112
113 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
114
115 # This is so you can say "find $(TOP) -name Linux.mk > /tmp/something; export
116 # ALL_MAKEFILES=/tmp/something; make" and avoid having to run find. This is
117 # handy if your source tree is mounted over NFS or something
118 override ALL_MAKEFILES := $(call relative-to-top,$(if $(strip $(ALL_MAKEFILES)),$(shell cat $(ALL_MAKEFILES)),$(shell find $(TOP) -type f -name Linux.mk -print -o -type d -name '.*' -prune)))
119 ifeq ($(strip $(ALL_MAKEFILES)),)
120 $(info ** Unable to find any Linux.mk files under $$(TOP). This could mean that)
121 $(info ** there are no makefiles, or that ALL_MAKEFILES is set in the environment)
122 $(info ** and points to a nonexistent or empty file.)
123 $(error No makefiles)
124 endif
125
126 else # clobber-only
127 ALL_MAKEFILES :=
128 endif
129
130 ifeq ($(SUPPORT_NEUTRINO_PLATFORM),1)
131 include $(MAKE_TOP)/common/neutrino/subst_makefiles.mk
132 endif
133
134 unexport ALL_MAKEFILES
135
136 REMAINING_MAKEFILES := $(ALL_MAKEFILES)
137 ALL_MODULES :=
138 INTERNAL_INCLUDED_ALL_MAKEFILES :=
139
140 ALL_LDFLAGS :=
141
142 # Please do not change the format of the following lines
143 -include $(CONFIG_MK)
144 -include $(CONFIG_KERNEL_MK)
145 # OK to change now
146
147 # If we haven't set host/target archs, set some sensible defaults now.
148 # This allows things like prune.sh to work
149 ifeq ($(HOST_PRIMARY_ARCH),)
150 ifneq ($(FORCE_ARCH),)
151 HOST_PRIMARY_ARCH := host_i386
152 HOST_32BIT_ARCH := host_i386
153 TARGET_PRIMARY_ARCH := target_i686
154 TARGET_ALL_ARCH := target_i686
155 endif
156 endif
157
158 # Output directory for configuration, object code,
159 # final programs/libraries, and install/rc scripts.
160 HOST_OUT             := $(RELATIVE_OUT)/$(HOST_PRIMARY_ARCH)
161 HOST_32BIT_OUT       := $(RELATIVE_OUT)/$(HOST_32BIT_ARCH)
162 TARGET_OUT           := $(RELATIVE_OUT)/$(TARGET_PRIMARY_ARCH)
163 TARGET_PRIMARY_OUT   := $(RELATIVE_OUT)/$(TARGET_PRIMARY_ARCH)
164 TARGET_NEUTRAL_OUT   := $(RELATIVE_OUT)/target_neutral
165 BRIDGE_SOURCE_ROOT   := $(call if-exists,$(TOP)/generated,$(TARGET_NEUTRAL_OUT)/intermediates)
166 GENERATED_CODE_OUT   := $(TARGET_NEUTRAL_OUT)/intermediates
167 DOCS_OUT             := $(RELATIVE_OUT)/doc
168
169 # Mark subdirectories of $(OUT) as secondary, and provide rules to create
170 # them.
171 OUT_SUBDIRS := $(addprefix $(RELATIVE_OUT)/,$(TARGET_ALL_ARCH)) \
172  $(TARGET_NEUTRAL_OUT) $(DOCS_OUT) $(if $(HOST_PRIMARY_ARCH),$(sort $(HOST_OUT) $(HOST_32BIT_OUT)))
173 .SECONDARY: $(OUT_SUBDIRS)
174 $(OUT_SUBDIRS):
175         $(make-directory)
176
177 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
178 -include $(MAKE_TOP)/pvrversion.mk
179 ifeq ($(SUPPORT_BUILD_LWS),1)
180 -include $(MAKE_TOP)/lwsconf.mk
181 endif
182 -include $(MAKE_TOP)/llvm.mk
183 -include $(MAKE_TOP)/common/bridges.mk
184 endif
185
186 include $(MAKE_TOP)/commands.mk
187 include $(MAKE_TOP)/buildvars.mk
188
189 HOST_INTERMEDIATES := $(HOST_OUT)/intermediates
190 TARGET_INTERMEDIATES := $(TARGET_OUT)/intermediates
191
192 ifneq ($(KERNEL_COMPONENTS),)
193 build: kbuild
194 endif
195
196 # "make bridges" makes all the modules which are bridges. This is used by
197 # builds which ship pregenerated bridge headers.
198 .PHONY: bridges
199 bridges: 
200
201 # Include each Linux.mk, then include modules.mk to save some information
202 # about each module
203 include $(foreach _Linux.mk,$(ALL_MAKEFILES),$(MAKE_TOP)/this_makefile.mk $(_Linux.mk) $(MAKE_TOP)/modules.mk)
204
205 ifeq ($(strip $(REMAINING_MAKEFILES)),)
206 INTERNAL_INCLUDED_ALL_MAKEFILES := true
207 else
208 $(error Impossible: $(words $(REMAINING_MAKEFILES)) makefiles were mysteriously ignored when reading $$(ALL_MAKEFILES))
209 endif
210
211 # At this point, all Linux.mks have been included. Now generate rules to build
212 # each module: for each module in $(ALL_MODULES), set per-makefile variables
213 $(foreach _m,$(ALL_MODULES),$(eval $(call process-module,$(_m))))
214
215 .PHONY: kbuild install
216 kbuild install:
217
218 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
219 -include $(MAKE_TOP)/scripts.mk
220 -include $(MAKE_TOP)/kbuild/kbuild.mk
221 endif
222 # We won't depend on 'build' here so that people can build subsets of
223 # components and still have the install script attempt to install the
224 # subset.
225 install:
226         @if [ ! -d "$(DISCIMAGE)" ]; then \
227                 echo; \
228                 echo "** DISCIMAGE was not set or does not point to a valid directory."; \
229                 echo "** Cannot continue with install."; \
230                 echo; \
231                 exit 1; \
232         fi
233         @if [ ! -f $(RELATIVE_OUT)/install.sh ]; then \
234                 echo; \
235                 echo "** install.sh not found in $(RELATIVE_OUT)."; \
236                 echo "** Cannot continue with install."; \
237                 echo; \
238                 exit 1; \
239         fi
240         @cd $(RELATIVE_OUT) && ./install.sh
241
242 .PHONY: uninstall
243 uninstall: install_script
244 uninstall:
245         @if [ ! -d "$(DISCIMAGE)" ]; then \
246                 echo; \
247                 echo "** DISCIMAGE was not set or does not point to a valid directory."; \
248                 echo "** Cannot continue with uninstall."; \
249                 echo; \
250                 exit 1; \
251         fi
252         @if [ ! -f $(RELATIVE_OUT)/install.sh ]; then \
253                 echo; \
254                 echo "** install.sh not found in $(RELATIVE_OUT)."; \
255                 echo "** Cannot continue with uninstall."; \
256                 echo; \
257                 exit 1; \
258         fi
259         @cd $(RELATIVE_OUT) && ./install.sh -u
260
261 # You can say 'make all_modules' to attempt to make everything, or 'make
262 # components' to only make the things which are listed (in the per-build
263 # makefiles) as components of the build.
264 .PHONY: all_modules all_docs components
265 all_modules: $(ALL_MODULES)
266 all_docs: ;
267 components: $(COMPONENTS)
268
269 # Cleaning
270 .PHONY: clean clobber
271 clean: MODULE_DIRS_TO_REMOVE := $(OUT_SUBDIRS)
272 clean:
273         $(clean-dirs)
274 clobber: MODULE_DIRS_TO_REMOVE := $(OUT)
275 clobber:
276         $(clean-dirs)
277
278 # Saying 'make clean-MODULE' removes the intermediates for MODULE.
279 # clobber-MODULE deletes the output files as well
280 clean-%:
281         $(if $(V),,@echo "  RM      " $(call relative-to-top,$(INTERNAL_CLEAN_TARGETS_FOR_$*)))
282         $(RM) -rf $(INTERNAL_CLEAN_TARGETS_FOR_$*)
283 clobber-%:
284         $(if $(V),,@echo "  RM      " $(call relative-to-top,$(INTERNAL_CLOBBER_TARGETS_FOR_$*)))
285         $(RM) -rf $(INTERNAL_CLOBBER_TARGETS_FOR_$*)
286
287 include $(MAKE_TOP)/bits.mk
288
289 # D=nobuild stops the build before any recipes are run. This line should
290 # come at the end of this makefile.
291 $(if $(filter nobuild,$(D)),$(error D=nobuild given),)