1 ########################################################################### ###
3 #@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 #@License Dual MIT/GPLv2
6 # The contents of this file are subject to the MIT license as set out below.
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:
15 # The above copyright notice and this permission notice shall be included in
16 # all copies or substantial portions of the Software.
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.
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.
30 # This License is also included in this distribution in the file called
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 ### ###########################################################################
42 # Define the default goal. This masks a previous definition of the default
43 # goal in config/core.mk, which must match this one
47 MAKE_TOP := build/linux
48 THIS_MAKEFILE := (top-level makefiles)
50 include $(MAKE_TOP)/defs.mk
53 $(error Must specify output directory with OUT=)
57 $(error Must specify root of source tree with TOP=)
59 $(call directory-must-exist,$(TOP))
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
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))
73 space := $(empty) $(empty)
74 override D := $(subst $(comma),$(space),$(D))
76 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
77 # Create the out directory
79 $(shell mkdir -p $(OUT))
81 # If these generated files differ from any pre-existing ones,
82 # replace them, causing affected parts of the driver to rebuild.
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 \
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)
101 ifneq ($(_freeze_config),)
102 $(if $(_updated_config_files),$(error Configuration change in $(RELATIVE_OUT) prevented by D=freeze-config),)
105 # Update the config, if changed
106 $(foreach _f,$(_updated_config_files), \
107 $(shell mv -f $(_f).new $(_f) >/dev/null 2>/dev/null))
109 endif # INTERNAL_CLOBBER_ONLY
111 MAKEFLAGS := -Rr --no-print-directory
113 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
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)
130 unexport ALL_MAKEFILES
132 REMAINING_MAKEFILES := $(ALL_MAKEFILES)
134 INTERNAL_INCLUDED_ALL_MAKEFILES :=
138 # Please do not change the format of the following lines
139 -include $(CONFIG_MK)
140 -include $(CONFIG_KERNEL_MK)
143 # If we haven't set host/target archs, set some sensible defaults now.
144 # This allows things like prune.sh to work
145 ifeq ($(HOST_PRIMARY_ARCH),)
146 ifneq ($(FORCE_ARCH),)
147 HOST_PRIMARY_ARCH := host_x86_64
148 HOST_32BIT_ARCH := host_i386
151 $(filter-out %target_neutral.mk,$(wildcard $(MAKE_TOP)/moduledefs/target_*.mk))
152 TARGET_PRIMARY_ARCH := \
153 $(patsubst $(MAKE_TOP)/moduledefs/%.mk,%,$(word 1, $(_ALL_ARCHS)))
155 TARGET_ALL_ARCH := $(TARGET_PRIMARY_ARCH)
159 # Output directory for configuration, object code,
160 # final programs/libraries, and install/rc scripts.
161 HOST_OUT := $(RELATIVE_OUT)/$(HOST_PRIMARY_ARCH)
162 HOST_32BIT_OUT := $(RELATIVE_OUT)/$(HOST_32BIT_ARCH)
163 TARGET_OUT := $(RELATIVE_OUT)/$(TARGET_PRIMARY_ARCH)
164 TARGET_PRIMARY_OUT := $(RELATIVE_OUT)/$(TARGET_PRIMARY_ARCH)
165 TARGET_NEUTRAL_OUT := $(RELATIVE_OUT)/target_neutral
166 BRIDGE_SOURCE_ROOT := $(call if-exists,$(TOP)/generated,$(TARGET_NEUTRAL_OUT)/intermediates)
167 GENERATED_CODE_OUT := $(TARGET_NEUTRAL_OUT)/intermediates
168 DOCS_OUT := $(RELATIVE_OUT)/doc
171 # neutrino/subst_makefiles.mk must be included after Output directories have been defined,
172 # because it overrides BRIDGE_SOURCE_ROOT of bridges to be built. If we include this makefile
173 # earlier, the value of BRIDGE_SOURCE_ROOT set in neutrino/subst_makefiles.mk will be overwritten.
174 ifeq ($(SUPPORT_NEUTRINO_PLATFORM),1)
175 include $(MAKE_TOP)/common/neutrino/subst_makefiles.mk
176 # neutrino/subst_makefiles.mk overrides ALL_MAKEFILES.
177 # Set REMAINING_MAKEFILES to the new value of ALL_MAKEFILES
178 REMAINING_MAKEFILES := $(ALL_MAKEFILES)
181 # Mark subdirectories of $(OUT) as secondary, and provide rules to create
183 OUT_SUBDIRS := $(addprefix $(RELATIVE_OUT)/,$(TARGET_ALL_ARCH)) \
184 $(TARGET_NEUTRAL_OUT) $(DOCS_OUT) $(if $(HOST_PRIMARY_ARCH),$(sort $(HOST_OUT) $(HOST_32BIT_OUT)))
185 .SECONDARY: $(OUT_SUBDIRS)
189 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
190 -include $(MAKE_TOP)/pvrversion.mk
191 ifeq ($(SUPPORT_BUILD_LWS),1)
192 -include $(MAKE_TOP)/lwsconf.mk
194 -include $(MAKE_TOP)/llvm.mk
195 -include $(MAKE_TOP)/common/bridges.mk
198 include $(MAKE_TOP)/commands.mk
199 include $(MAKE_TOP)/buildvars.mk
201 HOST_INTERMEDIATES := $(HOST_OUT)/intermediates
202 TARGET_INTERMEDIATES := $(TARGET_OUT)/intermediates
204 ifneq ($(KERNEL_COMPONENTS),)
208 # "make bridges" makes all the modules which are bridges. This is used by
209 # builds which ship pregenerated bridge headers.
211 bridges: $(BRIDGES) $(DIRECT_BRIDGES)
213 # Include each Linux.mk, then include modules.mk to save some information
215 include $(foreach _Linux.mk,$(ALL_MAKEFILES),$(MAKE_TOP)/this_makefile.mk $(_Linux.mk) $(MAKE_TOP)/modules.mk)
217 ifeq ($(strip $(REMAINING_MAKEFILES)),)
218 INTERNAL_INCLUDED_ALL_MAKEFILES := true
220 $(error Impossible: $(words $(REMAINING_MAKEFILES)) makefiles were mysteriously ignored when reading $$(ALL_MAKEFILES))
223 # At this point, all Linux.mks have been included. Now generate rules to build
224 # each module: for each module in $(ALL_MODULES), set per-makefile variables
225 $(foreach _m,$(ALL_MODULES),$(eval $(call process-module,$(_m))))
227 .PHONY: kbuild install
230 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
231 -include $(MAKE_TOP)/scripts.mk
232 -include $(MAKE_TOP)/kbuild/kbuild.mk
234 # We won't depend on 'build' here so that people can build subsets of
235 # components and still have the install script attempt to install the
238 @if [ ! -d "$(DISCIMAGE)" ]; then \
240 echo "** DISCIMAGE was not set or does not point to a valid directory."; \
241 echo "** Cannot continue with install."; \
245 @if [ ! -f $(RELATIVE_OUT)/install.sh ]; then \
247 echo "** install.sh not found in $(RELATIVE_OUT)."; \
248 echo "** Cannot continue with install."; \
252 @cd $(RELATIVE_OUT) && ./install.sh
255 uninstall: install_script
257 @if [ ! -d "$(DISCIMAGE)" ]; then \
259 echo "** DISCIMAGE was not set or does not point to a valid directory."; \
260 echo "** Cannot continue with uninstall."; \
264 @if [ ! -f $(RELATIVE_OUT)/install.sh ]; then \
266 echo "** install.sh not found in $(RELATIVE_OUT)."; \
267 echo "** Cannot continue with uninstall."; \
271 @cd $(RELATIVE_OUT) && ./install.sh -u
273 # You can say 'make all_modules' to attempt to make everything, or 'make
274 # components' to only make the things which are listed (in the per-build
275 # makefiles) as components of the build.
276 .PHONY: all_modules all_docs components
277 all_modules: $(ALL_MODULES)
279 components: $(COMPONENTS)
282 .PHONY: clean clobber
283 clean: MODULE_DIRS_TO_REMOVE := $(OUT_SUBDIRS)
286 clobber: MODULE_DIRS_TO_REMOVE := $(OUT)
290 # Saying 'make clean-MODULE' removes the intermediates for MODULE.
291 # clobber-MODULE deletes the output files as well
293 $(if $(V),,@echo " RM " $(call relative-to-top,$(INTERNAL_CLEAN_TARGETS_FOR_$*)))
294 $(RM) -rf $(INTERNAL_CLEAN_TARGETS_FOR_$*)
296 $(if $(V),,@echo " RM " $(call relative-to-top,$(INTERNAL_CLOBBER_TARGETS_FOR_$*)))
297 $(RM) -rf $(INTERNAL_CLOBBER_TARGETS_FOR_$*)
299 include $(MAKE_TOP)/bits.mk
301 # D=nobuild stops the build before any recipes are run. This line should
302 # come at the end of this makefile.
303 $(if $(filter nobuild,$(D)),$(error D=nobuild given),)