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 ifeq ($(SUPPORT_NEUTRINO_PLATFORM),1)
131 include $(MAKE_TOP)/common/neutrino/subst_makefiles.mk
134 unexport ALL_MAKEFILES
136 REMAINING_MAKEFILES := $(ALL_MAKEFILES)
138 INTERNAL_INCLUDED_ALL_MAKEFILES :=
142 # Please do not change the format of the following lines
143 -include $(CONFIG_MK)
144 -include $(CONFIG_KERNEL_MK)
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
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
169 # Mark subdirectories of $(OUT) as secondary, and provide rules to create
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)
177 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
178 -include $(MAKE_TOP)/pvrversion.mk
179 ifeq ($(SUPPORT_BUILD_LWS),1)
180 -include $(MAKE_TOP)/lwsconf.mk
182 -include $(MAKE_TOP)/llvm.mk
183 -include $(MAKE_TOP)/common/bridges.mk
186 include $(MAKE_TOP)/commands.mk
187 include $(MAKE_TOP)/buildvars.mk
189 HOST_INTERMEDIATES := $(HOST_OUT)/intermediates
190 TARGET_INTERMEDIATES := $(TARGET_OUT)/intermediates
192 ifneq ($(KERNEL_COMPONENTS),)
196 # "make bridges" makes all the modules which are bridges. This is used by
197 # builds which ship pregenerated bridge headers.
201 # Include each Linux.mk, then include modules.mk to save some information
203 include $(foreach _Linux.mk,$(ALL_MAKEFILES),$(MAKE_TOP)/this_makefile.mk $(_Linux.mk) $(MAKE_TOP)/modules.mk)
205 ifeq ($(strip $(REMAINING_MAKEFILES)),)
206 INTERNAL_INCLUDED_ALL_MAKEFILES := true
208 $(error Impossible: $(words $(REMAINING_MAKEFILES)) makefiles were mysteriously ignored when reading $$(ALL_MAKEFILES))
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))))
215 .PHONY: kbuild install
218 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
219 -include $(MAKE_TOP)/scripts.mk
220 -include $(MAKE_TOP)/kbuild/kbuild.mk
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
226 @if [ ! -d "$(DISCIMAGE)" ]; then \
228 echo "** DISCIMAGE was not set or does not point to a valid directory."; \
229 echo "** Cannot continue with install."; \
233 @if [ ! -f $(RELATIVE_OUT)/install.sh ]; then \
235 echo "** install.sh not found in $(RELATIVE_OUT)."; \
236 echo "** Cannot continue with install."; \
240 @cd $(RELATIVE_OUT) && ./install.sh
243 uninstall: install_script
245 @if [ ! -d "$(DISCIMAGE)" ]; then \
247 echo "** DISCIMAGE was not set or does not point to a valid directory."; \
248 echo "** Cannot continue with uninstall."; \
252 @if [ ! -f $(RELATIVE_OUT)/install.sh ]; then \
254 echo "** install.sh not found in $(RELATIVE_OUT)."; \
255 echo "** Cannot continue with uninstall."; \
259 @cd $(RELATIVE_OUT) && ./install.sh -u
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)
267 components: $(COMPONENTS)
270 .PHONY: clean clobber
271 clean: MODULE_DIRS_TO_REMOVE := $(OUT_SUBDIRS)
274 clobber: MODULE_DIRS_TO_REMOVE := $(OUT)
278 # Saying 'make clean-MODULE' removes the intermediates for MODULE.
279 # clobber-MODULE deletes the output files as well
281 $(if $(V),,@echo " RM " $(call relative-to-top,$(INTERNAL_CLEAN_TARGETS_FOR_$*)))
282 $(RM) -rf $(INTERNAL_CLEAN_TARGETS_FOR_$*)
284 $(if $(V),,@echo " RM " $(call relative-to-top,$(INTERNAL_CLOBBER_TARGETS_FOR_$*)))
285 $(RM) -rf $(INTERNAL_CLOBBER_TARGETS_FOR_$*)
287 include $(MAKE_TOP)/bits.mk
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),)