xref: /openbmc/linux/Makefile (revision 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2)
1*1da177e4SLinus TorvaldsVERSION = 2
2*1da177e4SLinus TorvaldsPATCHLEVEL = 6
3*1da177e4SLinus TorvaldsSUBLEVEL = 12
4*1da177e4SLinus TorvaldsEXTRAVERSION =-rc2
5*1da177e4SLinus TorvaldsNAME=Woozy Numbat
6*1da177e4SLinus Torvalds
7*1da177e4SLinus Torvalds# *DOCUMENTATION*
8*1da177e4SLinus Torvalds# To see a list of typical targets execute "make help"
9*1da177e4SLinus Torvalds# More info can be located in ./README
10*1da177e4SLinus Torvalds# Comments in this file are targeted only to the developer, do not
11*1da177e4SLinus Torvalds# expect to learn how to build the kernel reading this file.
12*1da177e4SLinus Torvalds
13*1da177e4SLinus Torvalds# Do not print "Entering directory ..."
14*1da177e4SLinus TorvaldsMAKEFLAGS += --no-print-directory
15*1da177e4SLinus Torvalds
16*1da177e4SLinus Torvalds# We are using a recursive build, so we need to do a little thinking
17*1da177e4SLinus Torvalds# to get the ordering right.
18*1da177e4SLinus Torvalds#
19*1da177e4SLinus Torvalds# Most importantly: sub-Makefiles should only ever modify files in
20*1da177e4SLinus Torvalds# their own directory. If in some directory we have a dependency on
21*1da177e4SLinus Torvalds# a file in another dir (which doesn't happen often, but it's often
22*1da177e4SLinus Torvalds# unavoidable when linking the built-in.o targets which finally
23*1da177e4SLinus Torvalds# turn into vmlinux), we will call a sub make in that other dir, and
24*1da177e4SLinus Torvalds# after that we are sure that everything which is in that other dir
25*1da177e4SLinus Torvalds# is now up to date.
26*1da177e4SLinus Torvalds#
27*1da177e4SLinus Torvalds# The only cases where we need to modify files which have global
28*1da177e4SLinus Torvalds# effects are thus separated out and done before the recursive
29*1da177e4SLinus Torvalds# descending is started. They are now explicitly listed as the
30*1da177e4SLinus Torvalds# prepare rule.
31*1da177e4SLinus Torvalds
32*1da177e4SLinus Torvalds# To put more focus on warnings, be less verbose as default
33*1da177e4SLinus Torvalds# Use 'make V=1' to see the full commands
34*1da177e4SLinus Torvalds
35*1da177e4SLinus Torvaldsifdef V
36*1da177e4SLinus Torvalds  ifeq ("$(origin V)", "command line")
37*1da177e4SLinus Torvalds    KBUILD_VERBOSE = $(V)
38*1da177e4SLinus Torvalds  endif
39*1da177e4SLinus Torvaldsendif
40*1da177e4SLinus Torvaldsifndef KBUILD_VERBOSE
41*1da177e4SLinus Torvalds  KBUILD_VERBOSE = 0
42*1da177e4SLinus Torvaldsendif
43*1da177e4SLinus Torvalds
44*1da177e4SLinus Torvalds# Call sparse as part of compilation of C files
45*1da177e4SLinus Torvalds# Use 'make C=1' to enable sparse checking
46*1da177e4SLinus Torvalds
47*1da177e4SLinus Torvaldsifdef C
48*1da177e4SLinus Torvalds  ifeq ("$(origin C)", "command line")
49*1da177e4SLinus Torvalds    KBUILD_CHECKSRC = $(C)
50*1da177e4SLinus Torvalds  endif
51*1da177e4SLinus Torvaldsendif
52*1da177e4SLinus Torvaldsifndef KBUILD_CHECKSRC
53*1da177e4SLinus Torvalds  KBUILD_CHECKSRC = 0
54*1da177e4SLinus Torvaldsendif
55*1da177e4SLinus Torvalds
56*1da177e4SLinus Torvalds# Use make M=dir to specify directory of external module to build
57*1da177e4SLinus Torvalds# Old syntax make ... SUBDIRS=$PWD is still supported
58*1da177e4SLinus Torvalds# Setting the environment variable KBUILD_EXTMOD take precedence
59*1da177e4SLinus Torvaldsifdef SUBDIRS
60*1da177e4SLinus Torvalds  KBUILD_EXTMOD ?= $(SUBDIRS)
61*1da177e4SLinus Torvaldsendif
62*1da177e4SLinus Torvaldsifdef M
63*1da177e4SLinus Torvalds  ifeq ("$(origin M)", "command line")
64*1da177e4SLinus Torvalds    KBUILD_EXTMOD := $(M)
65*1da177e4SLinus Torvalds  endif
66*1da177e4SLinus Torvaldsendif
67*1da177e4SLinus Torvalds
68*1da177e4SLinus Torvalds
69*1da177e4SLinus Torvalds# kbuild supports saving output files in a separate directory.
70*1da177e4SLinus Torvalds# To locate output files in a separate directory two syntaxes are supported.
71*1da177e4SLinus Torvalds# In both cases the working directory must be the root of the kernel src.
72*1da177e4SLinus Torvalds# 1) O=
73*1da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/"
74*1da177e4SLinus Torvalds#
75*1da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT
76*1da177e4SLinus Torvalds# Set the environment variable KBUILD_OUTPUT to point to the directory
77*1da177e4SLinus Torvalds# where the output files shall be placed.
78*1da177e4SLinus Torvalds# export KBUILD_OUTPUT=dir/to/store/output/files/
79*1da177e4SLinus Torvalds# make
80*1da177e4SLinus Torvalds#
81*1da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment
82*1da177e4SLinus Torvalds# variable.
83*1da177e4SLinus Torvalds
84*1da177e4SLinus Torvalds
85*1da177e4SLinus Torvalds# KBUILD_SRC is set on invocation of make in OBJ directory
86*1da177e4SLinus Torvalds# KBUILD_SRC is not intended to be used by the regular user (for now)
87*1da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),)
88*1da177e4SLinus Torvalds
89*1da177e4SLinus Torvalds# OK, Make called in directory where kernel src resides
90*1da177e4SLinus Torvalds# Do we want to locate output files in a separate directory?
91*1da177e4SLinus Torvaldsifdef O
92*1da177e4SLinus Torvalds  ifeq ("$(origin O)", "command line")
93*1da177e4SLinus Torvalds    KBUILD_OUTPUT := $(O)
94*1da177e4SLinus Torvalds  endif
95*1da177e4SLinus Torvaldsendif
96*1da177e4SLinus Torvalds
97*1da177e4SLinus Torvalds# That's our default target when none is given on the command line
98*1da177e4SLinus Torvalds.PHONY: _all
99*1da177e4SLinus Torvalds_all:
100*1da177e4SLinus Torvalds
101*1da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
102*1da177e4SLinus Torvalds# Invoke a second make in the output directory, passing relevant variables
103*1da177e4SLinus Torvalds# check that the output directory actually exists
104*1da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
105*1da177e4SLinus TorvaldsKBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
106*1da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
107*1da177e4SLinus Torvalds     $(error output directory "$(saved-output)" does not exist))
108*1da177e4SLinus Torvalds
109*1da177e4SLinus Torvalds.PHONY: $(MAKECMDGOALS)
110*1da177e4SLinus Torvalds
111*1da177e4SLinus Torvalds$(filter-out _all,$(MAKECMDGOALS)) _all:
112*1da177e4SLinus Torvalds	$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT)		\
113*1da177e4SLinus Torvalds	KBUILD_SRC=$(CURDIR)	     KBUILD_VERBOSE=$(KBUILD_VERBOSE)	\
114*1da177e4SLinus Torvalds	KBUILD_CHECK=$(KBUILD_CHECK) KBUILD_EXTMOD="$(KBUILD_EXTMOD)"	\
115*1da177e4SLinus Torvalds        -f $(CURDIR)/Makefile $@
116*1da177e4SLinus Torvalds
117*1da177e4SLinus Torvalds# Leave processing to above invocation of make
118*1da177e4SLinus Torvaldsskip-makefile := 1
119*1da177e4SLinus Torvaldsendif # ifneq ($(KBUILD_OUTPUT),)
120*1da177e4SLinus Torvaldsendif # ifeq ($(KBUILD_SRC),)
121*1da177e4SLinus Torvalds
122*1da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
123*1da177e4SLinus Torvaldsifeq ($(skip-makefile),)
124*1da177e4SLinus Torvalds
125*1da177e4SLinus Torvalds# If building an external module we do not care about the all: rule
126*1da177e4SLinus Torvalds# but instead _all depend on modules
127*1da177e4SLinus Torvalds.PHONY: all
128*1da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
129*1da177e4SLinus Torvalds_all: all
130*1da177e4SLinus Torvaldselse
131*1da177e4SLinus Torvalds_all: modules
132*1da177e4SLinus Torvaldsendif
133*1da177e4SLinus Torvalds
134*1da177e4SLinus Torvaldssrctree		:= $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
135*1da177e4SLinus TorvaldsTOPDIR		:= $(srctree)
136*1da177e4SLinus Torvalds# FIXME - TOPDIR is obsolete, use srctree/objtree
137*1da177e4SLinus Torvaldsobjtree		:= $(CURDIR)
138*1da177e4SLinus Torvaldssrc		:= $(srctree)
139*1da177e4SLinus Torvaldsobj		:= $(objtree)
140*1da177e4SLinus Torvalds
141*1da177e4SLinus TorvaldsVPATH		:= $(srctree)
142*1da177e4SLinus Torvalds
143*1da177e4SLinus Torvaldsexport srctree objtree VPATH TOPDIR
144*1da177e4SLinus Torvalds
145*1da177e4SLinus Torvaldsnullstring :=
146*1da177e4SLinus Torvaldsspace      := $(nullstring) # end of line
147*1da177e4SLinus Torvalds
148*1da177e4SLinus Torvalds# Take the contents of any files called localversion* and the config
149*1da177e4SLinus Torvalds# variable CONFIG_LOCALVERSION and append them to KERNELRELEASE. Be
150*1da177e4SLinus Torvalds# careful not to include files twice if building in the source
151*1da177e4SLinus Torvalds# directory. LOCALVERSION from the command line override all of this
152*1da177e4SLinus Torvalds
153*1da177e4SLinus Torvaldslocalver := $(objtree)/localversion* $(srctree)/localversion*
154*1da177e4SLinus Torvaldslocalver := $(sort $(wildcard $(localver)))
155*1da177e4SLinus Torvalds# skip backup files (containing '~')
156*1da177e4SLinus Torvaldslocalver := $(foreach f, $(localver), $(if $(findstring ~, $(f)),,$(f)))
157*1da177e4SLinus Torvalds
158*1da177e4SLinus TorvaldsLOCALVERSION = $(subst $(space),, \
159*1da177e4SLinus Torvalds	       $(shell cat /dev/null $(localver)) \
160*1da177e4SLinus Torvalds	       $(patsubst "%",%,$(CONFIG_LOCALVERSION)))
161*1da177e4SLinus Torvalds
162*1da177e4SLinus TorvaldsKERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(LOCALVERSION)
163*1da177e4SLinus Torvalds
164*1da177e4SLinus Torvalds# SUBARCH tells the usermode build what the underlying arch is.  That is set
165*1da177e4SLinus Torvalds# first, and if a usermode build is happening, the "ARCH=um" on the command
166*1da177e4SLinus Torvalds# line overrides the setting of ARCH below.  If a native build is happening,
167*1da177e4SLinus Torvalds# then ARCH is assigned, getting whatever value it gets normally, and
168*1da177e4SLinus Torvalds# SUBARCH is subsequently ignored.
169*1da177e4SLinus Torvalds
170*1da177e4SLinus TorvaldsSUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
171*1da177e4SLinus Torvalds				  -e s/arm.*/arm/ -e s/sa110/arm/ \
172*1da177e4SLinus Torvalds				  -e s/s390x/s390/ -e s/parisc64/parisc/ )
173*1da177e4SLinus Torvalds
174*1da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
175*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
176*1da177e4SLinus Torvalds#
177*1da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
178*1da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
179*1da177e4SLinus Torvalds# ARCH can be set during invocation of make:
180*1da177e4SLinus Torvalds# make ARCH=ia64
181*1da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
182*1da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
183*1da177e4SLinus Torvalds
184*1da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
185*1da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
186*1da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
187*1da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
188*1da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
189*1da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
190*1da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
191*1da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
192*1da177e4SLinus Torvalds
193*1da177e4SLinus TorvaldsARCH		?= $(SUBARCH)
194*1da177e4SLinus TorvaldsCROSS_COMPILE	?=
195*1da177e4SLinus Torvalds
196*1da177e4SLinus Torvalds# Architecture as present in compile.h
197*1da177e4SLinus TorvaldsUTS_MACHINE := $(ARCH)
198*1da177e4SLinus Torvalds
199*1da177e4SLinus Torvalds# SHELL used by kbuild
200*1da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
201*1da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
202*1da177e4SLinus Torvalds	  else echo sh; fi ; fi)
203*1da177e4SLinus Torvalds
204*1da177e4SLinus TorvaldsHOSTCC  	= gcc
205*1da177e4SLinus TorvaldsHOSTCXX  	= g++
206*1da177e4SLinus TorvaldsHOSTCFLAGS	= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
207*1da177e4SLinus TorvaldsHOSTCXXFLAGS	= -O2
208*1da177e4SLinus Torvalds
209*1da177e4SLinus Torvalds# 	Decide whether to build built-in, modular, or both.
210*1da177e4SLinus Torvalds#	Normally, just do built-in.
211*1da177e4SLinus Torvalds
212*1da177e4SLinus TorvaldsKBUILD_MODULES :=
213*1da177e4SLinus TorvaldsKBUILD_BUILTIN := 1
214*1da177e4SLinus Torvalds
215*1da177e4SLinus Torvalds#	If we have only "make modules", don't compile built-in objects.
216*1da177e4SLinus Torvalds#	When we're building modules with modversions, we need to consider
217*1da177e4SLinus Torvalds#	the built-in objects during the descend as well, in order to
218*1da177e4SLinus Torvalds#	make sure the checksums are uptodate before we record them.
219*1da177e4SLinus Torvalds
220*1da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),modules)
221*1da177e4SLinus Torvalds  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
222*1da177e4SLinus Torvaldsendif
223*1da177e4SLinus Torvalds
224*1da177e4SLinus Torvalds#	If we have "make <whatever> modules", compile modules
225*1da177e4SLinus Torvalds#	in addition to whatever we do anyway.
226*1da177e4SLinus Torvalds#	Just "make" or "make all" shall build modules as well
227*1da177e4SLinus Torvalds
228*1da177e4SLinus Torvaldsifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
229*1da177e4SLinus Torvalds  KBUILD_MODULES := 1
230*1da177e4SLinus Torvaldsendif
231*1da177e4SLinus Torvalds
232*1da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),)
233*1da177e4SLinus Torvalds  KBUILD_MODULES := 1
234*1da177e4SLinus Torvaldsendif
235*1da177e4SLinus Torvalds
236*1da177e4SLinus Torvaldsexport KBUILD_MODULES KBUILD_BUILTIN KBUILD_VERBOSE
237*1da177e4SLinus Torvaldsexport KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
238*1da177e4SLinus Torvalds
239*1da177e4SLinus Torvalds# Beautify output
240*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
241*1da177e4SLinus Torvalds#
242*1da177e4SLinus Torvalds# Normally, we echo the whole command before executing it. By making
243*1da177e4SLinus Torvalds# that echo $($(quiet)$(cmd)), we now have the possibility to set
244*1da177e4SLinus Torvalds# $(quiet) to choose other forms of output instead, e.g.
245*1da177e4SLinus Torvalds#
246*1da177e4SLinus Torvalds#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
247*1da177e4SLinus Torvalds#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
248*1da177e4SLinus Torvalds#
249*1da177e4SLinus Torvalds# If $(quiet) is empty, the whole command will be printed.
250*1da177e4SLinus Torvalds# If it is set to "quiet_", only the short version will be printed.
251*1da177e4SLinus Torvalds# If it is set to "silent_", nothing wil be printed at all, since
252*1da177e4SLinus Torvalds# the variable $(silent_cmd_cc_o_c) doesn't exist.
253*1da177e4SLinus Torvalds#
254*1da177e4SLinus Torvalds# A simple variant is to prefix commands with $(Q) - that's usefull
255*1da177e4SLinus Torvalds# for commands that shall be hidden in non-verbose mode.
256*1da177e4SLinus Torvalds#
257*1da177e4SLinus Torvalds#	$(Q)ln $@ :<
258*1da177e4SLinus Torvalds#
259*1da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
260*1da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 1 then the above command is displayed.
261*1da177e4SLinus Torvalds
262*1da177e4SLinus Torvaldsifeq ($(KBUILD_VERBOSE),1)
263*1da177e4SLinus Torvalds  quiet =
264*1da177e4SLinus Torvalds  Q =
265*1da177e4SLinus Torvaldselse
266*1da177e4SLinus Torvalds  quiet=quiet_
267*1da177e4SLinus Torvalds  Q = @
268*1da177e4SLinus Torvaldsendif
269*1da177e4SLinus Torvalds
270*1da177e4SLinus Torvalds# If the user is running make -s (silent mode), suppress echoing of
271*1da177e4SLinus Torvalds# commands
272*1da177e4SLinus Torvalds
273*1da177e4SLinus Torvaldsifneq ($(findstring s,$(MAKEFLAGS)),)
274*1da177e4SLinus Torvalds  quiet=silent_
275*1da177e4SLinus Torvaldsendif
276*1da177e4SLinus Torvalds
277*1da177e4SLinus Torvaldsexport quiet Q KBUILD_VERBOSE
278*1da177e4SLinus Torvalds
279*1da177e4SLinus Torvalds######
280*1da177e4SLinus Torvalds# cc support functions to be used (only) in arch/$(ARCH)/Makefile
281*1da177e4SLinus Torvalds# See documentation in Documentation/kbuild/makefiles.txt
282*1da177e4SLinus Torvalds
283*1da177e4SLinus Torvalds# cc-option
284*1da177e4SLinus Torvalds# Usage: cflags-y += $(call gcc-option, -march=winchip-c6, -march=i586)
285*1da177e4SLinus Torvalds
286*1da177e4SLinus Torvaldscc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
287*1da177e4SLinus Torvalds             > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
288*1da177e4SLinus Torvalds
289*1da177e4SLinus Torvalds# For backward compatibility
290*1da177e4SLinus Torvaldscheck_gcc = $(warning check_gcc is deprecated - use cc-option) \
291*1da177e4SLinus Torvalds            $(call cc-option, $(1),$(2))
292*1da177e4SLinus Torvalds
293*1da177e4SLinus Torvalds# cc-option-yn
294*1da177e4SLinus Torvalds# Usage: flag := $(call cc-option-yn, -march=winchip-c6)
295*1da177e4SLinus Torvaldscc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
296*1da177e4SLinus Torvalds                > /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
297*1da177e4SLinus Torvalds
298*1da177e4SLinus Torvalds# cc-option-align
299*1da177e4SLinus Torvalds# Prefix align with either -falign or -malign
300*1da177e4SLinus Torvaldscc-option-align = $(subst -functions=0,,\
301*1da177e4SLinus Torvalds	$(call cc-option,-falign-functions=0,-malign-functions=0))
302*1da177e4SLinus Torvalds
303*1da177e4SLinus Torvalds# cc-version
304*1da177e4SLinus Torvalds# Usage gcc-ver := $(call cc-version $(CC))
305*1da177e4SLinus Torvaldscc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \
306*1da177e4SLinus Torvalds              $(if $(1), $(1), $(CC)))
307*1da177e4SLinus Torvalds
308*1da177e4SLinus Torvalds
309*1da177e4SLinus Torvalds# Look for make include files relative to root of kernel src
310*1da177e4SLinus TorvaldsMAKEFLAGS += --include-dir=$(srctree)
311*1da177e4SLinus Torvalds
312*1da177e4SLinus Torvalds# For maximum performance (+ possibly random breakage, uncomment
313*1da177e4SLinus Torvalds# the following)
314*1da177e4SLinus Torvalds
315*1da177e4SLinus Torvalds#MAKEFLAGS += -rR
316*1da177e4SLinus Torvalds
317*1da177e4SLinus Torvalds# Make variables (CC, etc...)
318*1da177e4SLinus Torvalds
319*1da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
320*1da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
321*1da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
322*1da177e4SLinus TorvaldsCPP		= $(CC) -E
323*1da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
324*1da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
325*1da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
326*1da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
327*1da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
328*1da177e4SLinus TorvaldsAWK		= awk
329*1da177e4SLinus TorvaldsGENKSYMS	= scripts/genksyms/genksyms
330*1da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
331*1da177e4SLinus TorvaldsKALLSYMS	= scripts/kallsyms
332*1da177e4SLinus TorvaldsPERL		= perl
333*1da177e4SLinus TorvaldsCHECK		= sparse
334*1da177e4SLinus Torvalds
335*1da177e4SLinus TorvaldsNOSTDINC_FLAGS  = -nostdinc -isystem $(shell $(CC) -print-file-name=include)
336*1da177e4SLinus TorvaldsCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__
337*1da177e4SLinus TorvaldsCHECKFLAGS     += $(NOSTDINC_FLAGS)
338*1da177e4SLinus TorvaldsMODFLAGS	= -DMODULE
339*1da177e4SLinus TorvaldsCFLAGS_MODULE   = $(MODFLAGS)
340*1da177e4SLinus TorvaldsAFLAGS_MODULE   = $(MODFLAGS)
341*1da177e4SLinus TorvaldsLDFLAGS_MODULE  = -r
342*1da177e4SLinus TorvaldsCFLAGS_KERNEL	=
343*1da177e4SLinus TorvaldsAFLAGS_KERNEL	=
344*1da177e4SLinus Torvalds
345*1da177e4SLinus Torvalds
346*1da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
347*1da177e4SLinus Torvalds# Needed to be compatible with the O= option
348*1da177e4SLinus TorvaldsLINUXINCLUDE    := -Iinclude \
349*1da177e4SLinus Torvalds                   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include)
350*1da177e4SLinus Torvalds
351*1da177e4SLinus TorvaldsCPPFLAGS        := -D__KERNEL__ $(LINUXINCLUDE)
352*1da177e4SLinus Torvalds
353*1da177e4SLinus TorvaldsCFLAGS 		:= -Wall -Wstrict-prototypes -Wno-trigraphs \
354*1da177e4SLinus Torvalds	  	   -fno-strict-aliasing -fno-common \
355*1da177e4SLinus Torvalds		   -ffreestanding
356*1da177e4SLinus TorvaldsAFLAGS		:= -D__ASSEMBLY__
357*1da177e4SLinus Torvalds
358*1da177e4SLinus Torvaldsexport	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION LOCALVERSION KERNELRELEASE \
359*1da177e4SLinus Torvalds	ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
360*1da177e4SLinus Torvalds	CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
361*1da177e4SLinus Torvalds	HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
362*1da177e4SLinus Torvalds
363*1da177e4SLinus Torvaldsexport CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
364*1da177e4SLinus Torvaldsexport CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
365*1da177e4SLinus Torvaldsexport AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
366*1da177e4SLinus Torvalds
367*1da177e4SLinus Torvalds# When compiling out-of-tree modules, put MODVERDIR in the module
368*1da177e4SLinus Torvalds# tree rather than in the kernel tree. The kernel tree might
369*1da177e4SLinus Torvalds# even be read-only.
370*1da177e4SLinus Torvaldsexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
371*1da177e4SLinus Torvalds
372*1da177e4SLinus Torvalds# The temporary file to save gcc -MD generated dependencies must not
373*1da177e4SLinus Torvalds# contain a comma
374*1da177e4SLinus Torvaldscomma := ,
375*1da177e4SLinus Torvaldsdepfile = $(subst $(comma),_,$(@D)/.$(@F).d)
376*1da177e4SLinus Torvalds
377*1da177e4SLinus Torvalds# Files to ignore in find ... statements
378*1da177e4SLinus Torvalds
379*1da177e4SLinus TorvaldsRCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS -o -name .pc \) -prune -o
380*1da177e4SLinus TorvaldsRCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc
381*1da177e4SLinus Torvalds
382*1da177e4SLinus Torvalds# ===========================================================================
383*1da177e4SLinus Torvalds# Rules shared between *config targets and build targets
384*1da177e4SLinus Torvalds
385*1da177e4SLinus Torvalds# Basic helpers built in scripts/
386*1da177e4SLinus Torvalds.PHONY: scripts_basic
387*1da177e4SLinus Torvaldsscripts_basic:
388*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/basic
389*1da177e4SLinus Torvalds
390*1da177e4SLinus Torvalds.PHONY: outputmakefile
391*1da177e4SLinus Torvalds# outputmakefile generate a Makefile to be placed in output directory, if
392*1da177e4SLinus Torvalds# using a seperate output directory. This allows convinient use
393*1da177e4SLinus Torvalds# of make in output directory
394*1da177e4SLinus Torvaldsoutputmakefile:
395*1da177e4SLinus Torvalds	$(Q)if test ! $(srctree) -ef $(objtree); then \
396*1da177e4SLinus Torvalds	$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile              \
397*1da177e4SLinus Torvalds	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)         \
398*1da177e4SLinus Torvalds	    > $(objtree)/Makefile;                                 \
399*1da177e4SLinus Torvalds	    echo '  GEN    $(objtree)/Makefile';                   \
400*1da177e4SLinus Torvalds	fi
401*1da177e4SLinus Torvalds
402*1da177e4SLinus Torvalds# To make sure we do not include .config for any of the *config targets
403*1da177e4SLinus Torvalds# catch them early, and hand them over to scripts/kconfig/Makefile
404*1da177e4SLinus Torvalds# It is allowed to specify more targets when calling make, including
405*1da177e4SLinus Torvalds# mixing *config targets and build targets.
406*1da177e4SLinus Torvalds# For example 'make oldconfig all'.
407*1da177e4SLinus Torvalds# Detect when mixed targets is specified, and make a second invocation
408*1da177e4SLinus Torvalds# of make so .config is not included in this case either (for *config).
409*1da177e4SLinus Torvalds
410*1da177e4SLinus Torvaldsno-dot-config-targets := clean mrproper distclean \
411*1da177e4SLinus Torvalds			 cscope TAGS tags help %docs check%
412*1da177e4SLinus Torvalds
413*1da177e4SLinus Torvaldsconfig-targets := 0
414*1da177e4SLinus Torvaldsmixed-targets  := 0
415*1da177e4SLinus Torvaldsdot-config     := 1
416*1da177e4SLinus Torvalds
417*1da177e4SLinus Torvaldsifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
418*1da177e4SLinus Torvalds	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
419*1da177e4SLinus Torvalds		dot-config := 0
420*1da177e4SLinus Torvalds	endif
421*1da177e4SLinus Torvaldsendif
422*1da177e4SLinus Torvalds
423*1da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
424*1da177e4SLinus Torvalds        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
425*1da177e4SLinus Torvalds                config-targets := 1
426*1da177e4SLinus Torvalds                ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
427*1da177e4SLinus Torvalds                        mixed-targets := 1
428*1da177e4SLinus Torvalds                endif
429*1da177e4SLinus Torvalds        endif
430*1da177e4SLinus Torvaldsendif
431*1da177e4SLinus Torvalds
432*1da177e4SLinus Torvaldsifeq ($(mixed-targets),1)
433*1da177e4SLinus Torvalds# ===========================================================================
434*1da177e4SLinus Torvalds# We're called with mixed targets (*config and build targets).
435*1da177e4SLinus Torvalds# Handle them one by one.
436*1da177e4SLinus Torvalds
437*1da177e4SLinus Torvalds%:: FORCE
438*1da177e4SLinus Torvalds	$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
439*1da177e4SLinus Torvalds
440*1da177e4SLinus Torvaldselse
441*1da177e4SLinus Torvaldsifeq ($(config-targets),1)
442*1da177e4SLinus Torvalds# ===========================================================================
443*1da177e4SLinus Torvalds# *config targets only - make sure prerequisites are updated, and descend
444*1da177e4SLinus Torvalds# in scripts/kconfig to make the *config target
445*1da177e4SLinus Torvalds
446*1da177e4SLinus Torvalds# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
447*1da177e4SLinus Torvalds# KBUILD_DEFCONFIG may point out an alternative default configuration
448*1da177e4SLinus Torvalds# used for 'make defconfig'
449*1da177e4SLinus Torvaldsinclude $(srctree)/arch/$(ARCH)/Makefile
450*1da177e4SLinus Torvaldsexport KBUILD_DEFCONFIG
451*1da177e4SLinus Torvalds
452*1da177e4SLinus Torvaldsconfig: scripts_basic outputmakefile FORCE
453*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/kconfig $@
454*1da177e4SLinus Torvalds%config: scripts_basic outputmakefile FORCE
455*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/kconfig $@
456*1da177e4SLinus Torvalds
457*1da177e4SLinus Torvaldselse
458*1da177e4SLinus Torvalds# ===========================================================================
459*1da177e4SLinus Torvalds# Build targets only - this includes vmlinux, arch specific targets, clean
460*1da177e4SLinus Torvalds# targets and others. In general all targets except *config targets.
461*1da177e4SLinus Torvalds
462*1da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
463*1da177e4SLinus Torvalds# Additional helpers built in scripts/
464*1da177e4SLinus Torvalds# Carefully list dependencies so we do not try to build scripts twice
465*1da177e4SLinus Torvalds# in parrallel
466*1da177e4SLinus Torvalds.PHONY: scripts
467*1da177e4SLinus Torvaldsscripts: scripts_basic include/config/MARKER
468*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@)
469*1da177e4SLinus Torvalds
470*1da177e4SLinus Torvaldsscripts_basic: include/linux/autoconf.h
471*1da177e4SLinus Torvalds
472*1da177e4SLinus Torvalds# Objects we will link into vmlinux / subdirs we need to visit
473*1da177e4SLinus Torvaldsinit-y		:= init/
474*1da177e4SLinus Torvaldsdrivers-y	:= drivers/ sound/
475*1da177e4SLinus Torvaldsnet-y		:= net/
476*1da177e4SLinus Torvaldslibs-y		:= lib/
477*1da177e4SLinus Torvaldscore-y		:= usr/
478*1da177e4SLinus Torvaldsendif # KBUILD_EXTMOD
479*1da177e4SLinus Torvalds
480*1da177e4SLinus Torvaldsifeq ($(dot-config),1)
481*1da177e4SLinus Torvalds# In this section, we need .config
482*1da177e4SLinus Torvalds
483*1da177e4SLinus Torvalds# Read in dependencies to all Kconfig* files, make sure to run
484*1da177e4SLinus Torvalds# oldconfig if changes are detected.
485*1da177e4SLinus Torvalds-include .config.cmd
486*1da177e4SLinus Torvalds
487*1da177e4SLinus Torvaldsinclude .config
488*1da177e4SLinus Torvalds
489*1da177e4SLinus Torvalds# If .config needs to be updated, it will be done via the dependency
490*1da177e4SLinus Torvalds# that autoconf has on .config.
491*1da177e4SLinus Torvalds# To avoid any implicit rule to kick in, define an empty command
492*1da177e4SLinus Torvalds.config: ;
493*1da177e4SLinus Torvalds
494*1da177e4SLinus Torvalds# If .config is newer than include/linux/autoconf.h, someone tinkered
495*1da177e4SLinus Torvalds# with it and forgot to run make oldconfig
496*1da177e4SLinus Torvaldsinclude/linux/autoconf.h: .config
497*1da177e4SLinus Torvalds	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
498*1da177e4SLinus Torvaldselse
499*1da177e4SLinus Torvalds# Dummy target needed, because used as prerequisite
500*1da177e4SLinus Torvaldsinclude/linux/autoconf.h: ;
501*1da177e4SLinus Torvaldsendif
502*1da177e4SLinus Torvalds
503*1da177e4SLinus Torvalds# The all: target is the default when no target is given on the
504*1da177e4SLinus Torvalds# command line.
505*1da177e4SLinus Torvalds# This allow a user to issue only 'make' to build a kernel including modules
506*1da177e4SLinus Torvalds# Defaults vmlinux but it is usually overriden in the arch makefile
507*1da177e4SLinus Torvaldsall: vmlinux
508*1da177e4SLinus Torvalds
509*1da177e4SLinus Torvaldsifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
510*1da177e4SLinus TorvaldsCFLAGS		+= -Os
511*1da177e4SLinus Torvaldselse
512*1da177e4SLinus TorvaldsCFLAGS		+= -O2
513*1da177e4SLinus Torvaldsendif
514*1da177e4SLinus Torvalds
515*1da177e4SLinus Torvalds#Add align options if CONFIG_CC_* is not equal to 0
516*1da177e4SLinus Torvaldsadd-align = $(if $(filter-out 0,$($(1))),$(cc-option-align)$(2)=$($(1)))
517*1da177e4SLinus TorvaldsCFLAGS		+= $(call add-align,CONFIG_CC_ALIGN_FUNCTIONS,-functions)
518*1da177e4SLinus TorvaldsCFLAGS		+= $(call add-align,CONFIG_CC_ALIGN_LABELS,-labels)
519*1da177e4SLinus TorvaldsCFLAGS		+= $(call add-align,CONFIG_CC_ALIGN_LOOPS,-loops)
520*1da177e4SLinus TorvaldsCFLAGS		+= $(call add-align,CONFIG_CC_ALIGN_JUMPS,-jumps)
521*1da177e4SLinus Torvalds
522*1da177e4SLinus Torvaldsifdef CONFIG_FRAME_POINTER
523*1da177e4SLinus TorvaldsCFLAGS		+= -fno-omit-frame-pointer
524*1da177e4SLinus Torvaldselse
525*1da177e4SLinus TorvaldsCFLAGS		+= -fomit-frame-pointer
526*1da177e4SLinus Torvaldsendif
527*1da177e4SLinus Torvalds
528*1da177e4SLinus Torvaldsifdef CONFIG_DEBUG_INFO
529*1da177e4SLinus TorvaldsCFLAGS		+= -g
530*1da177e4SLinus Torvaldsendif
531*1da177e4SLinus Torvalds
532*1da177e4SLinus Torvaldsinclude $(srctree)/arch/$(ARCH)/Makefile
533*1da177e4SLinus Torvalds
534*1da177e4SLinus Torvalds# warn about C99 declaration after statement
535*1da177e4SLinus TorvaldsCFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
536*1da177e4SLinus Torvalds
537*1da177e4SLinus Torvalds# disable pointer signedness warnings in gcc 4.0
538*1da177e4SLinus TorvaldsCFLAGS += $(call cc-option,-Wno-pointer-sign,)
539*1da177e4SLinus Torvalds
540*1da177e4SLinus Torvalds# Default kernel image to build when no specific target is given.
541*1da177e4SLinus Torvalds# KBUILD_IMAGE may be overruled on the commandline or
542*1da177e4SLinus Torvalds# set in the environment
543*1da177e4SLinus Torvalds# Also any assignments in arch/$(ARCH)/Makefile take precedence over
544*1da177e4SLinus Torvalds# this default value
545*1da177e4SLinus Torvaldsexport KBUILD_IMAGE ?= vmlinux
546*1da177e4SLinus Torvalds
547*1da177e4SLinus Torvalds#
548*1da177e4SLinus Torvalds# INSTALL_PATH specifies where to place the updated kernel and system map
549*1da177e4SLinus Torvalds# images. Default is /boot, but you can set it to other values
550*1da177e4SLinus Torvaldsexport	INSTALL_PATH ?= /boot
551*1da177e4SLinus Torvalds
552*1da177e4SLinus Torvalds#
553*1da177e4SLinus Torvalds# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
554*1da177e4SLinus Torvalds# relocations required by build roots.  This is not defined in the
555*1da177e4SLinus Torvalds# makefile but the arguement can be passed to make if needed.
556*1da177e4SLinus Torvalds#
557*1da177e4SLinus Torvalds
558*1da177e4SLinus TorvaldsMODLIB	:= $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
559*1da177e4SLinus Torvaldsexport MODLIB
560*1da177e4SLinus Torvalds
561*1da177e4SLinus Torvalds
562*1da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
563*1da177e4SLinus Torvaldscore-y		+= kernel/ mm/ fs/ ipc/ security/ crypto/
564*1da177e4SLinus Torvalds
565*1da177e4SLinus Torvaldsvmlinux-dirs	:= $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
566*1da177e4SLinus Torvalds		     $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
567*1da177e4SLinus Torvalds		     $(net-y) $(net-m) $(libs-y) $(libs-m)))
568*1da177e4SLinus Torvalds
569*1da177e4SLinus Torvaldsvmlinux-alldirs	:= $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \
570*1da177e4SLinus Torvalds		     $(init-n) $(init-) \
571*1da177e4SLinus Torvalds		     $(core-n) $(core-) $(drivers-n) $(drivers-) \
572*1da177e4SLinus Torvalds		     $(net-n)  $(net-)  $(libs-n)    $(libs-))))
573*1da177e4SLinus Torvalds
574*1da177e4SLinus Torvaldsinit-y		:= $(patsubst %/, %/built-in.o, $(init-y))
575*1da177e4SLinus Torvaldscore-y		:= $(patsubst %/, %/built-in.o, $(core-y))
576*1da177e4SLinus Torvaldsdrivers-y	:= $(patsubst %/, %/built-in.o, $(drivers-y))
577*1da177e4SLinus Torvaldsnet-y		:= $(patsubst %/, %/built-in.o, $(net-y))
578*1da177e4SLinus Torvaldslibs-y1		:= $(patsubst %/, %/lib.a, $(libs-y))
579*1da177e4SLinus Torvaldslibs-y2		:= $(patsubst %/, %/built-in.o, $(libs-y))
580*1da177e4SLinus Torvaldslibs-y		:= $(libs-y1) $(libs-y2)
581*1da177e4SLinus Torvalds
582*1da177e4SLinus Torvalds# Build vmlinux
583*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
584*1da177e4SLinus Torvalds# vmlinux is build from the objects selected by $(vmlinux-init) and
585*1da177e4SLinus Torvalds# $(vmlinux-main). Most are built-in.o files from top-level directories
586*1da177e4SLinus Torvalds# in the kernel tree, others are specified in arch/$(ARCH)Makefile.
587*1da177e4SLinus Torvalds# Ordering when linking is important, and $(vmlinux-init) must be first.
588*1da177e4SLinus Torvalds#
589*1da177e4SLinus Torvalds# vmlinux
590*1da177e4SLinus Torvalds#   ^
591*1da177e4SLinus Torvalds#   |
592*1da177e4SLinus Torvalds#   +-< $(vmlinux-init)
593*1da177e4SLinus Torvalds#   |   +--< init/version.o + more
594*1da177e4SLinus Torvalds#   |
595*1da177e4SLinus Torvalds#   +--< $(vmlinux-main)
596*1da177e4SLinus Torvalds#   |    +--< driver/built-in.o mm/built-in.o + more
597*1da177e4SLinus Torvalds#   |
598*1da177e4SLinus Torvalds#   +-< kallsyms.o (see description in CONFIG_KALLSYMS section)
599*1da177e4SLinus Torvalds#
600*1da177e4SLinus Torvalds# vmlinux version (uname -v) cannot be updated during normal
601*1da177e4SLinus Torvalds# descending-into-subdirs phase since we do not yet know if we need to
602*1da177e4SLinus Torvalds# update vmlinux.
603*1da177e4SLinus Torvalds# Therefore this step is delayed until just before final link of vmlinux -
604*1da177e4SLinus Torvalds# except in the kallsyms case where it is done just before adding the
605*1da177e4SLinus Torvalds# symbols to the kernel.
606*1da177e4SLinus Torvalds#
607*1da177e4SLinus Torvalds# System.map is generated to document addresses of all kernel symbols
608*1da177e4SLinus Torvalds
609*1da177e4SLinus Torvaldsvmlinux-init := $(head-y) $(init-y)
610*1da177e4SLinus Torvaldsvmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)
611*1da177e4SLinus Torvaldsvmlinux-all  := $(vmlinux-init) $(vmlinux-main)
612*1da177e4SLinus Torvaldsvmlinux-lds  := arch/$(ARCH)/kernel/vmlinux.lds
613*1da177e4SLinus Torvalds
614*1da177e4SLinus Torvalds# Rule to link vmlinux - also used during CONFIG_KALLSYMS
615*1da177e4SLinus Torvalds# May be overridden by arch/$(ARCH)/Makefile
616*1da177e4SLinus Torvaldsquiet_cmd_vmlinux__ ?= LD      $@
617*1da177e4SLinus Torvalds      cmd_vmlinux__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) -o $@ \
618*1da177e4SLinus Torvalds      -T $(vmlinux-lds) $(vmlinux-init)                          \
619*1da177e4SLinus Torvalds      --start-group $(vmlinux-main) --end-group                  \
620*1da177e4SLinus Torvalds      $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) FORCE ,$^)
621*1da177e4SLinus Torvalds
622*1da177e4SLinus Torvalds# Generate new vmlinux version
623*1da177e4SLinus Torvaldsquiet_cmd_vmlinux_version = GEN     .version
624*1da177e4SLinus Torvalds      cmd_vmlinux_version = set -e;                     \
625*1da177e4SLinus Torvalds	. $(srctree)/scripts/mkversion > .tmp_version;	\
626*1da177e4SLinus Torvalds	mv -f .tmp_version .version;			\
627*1da177e4SLinus Torvalds	$(MAKE) $(build)=init
628*1da177e4SLinus Torvalds
629*1da177e4SLinus Torvalds# Generate System.map
630*1da177e4SLinus Torvaldsquiet_cmd_sysmap = SYSMAP
631*1da177e4SLinus Torvalds      cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
632*1da177e4SLinus Torvalds
633*1da177e4SLinus Torvalds# Link of vmlinux
634*1da177e4SLinus Torvalds# If CONFIG_KALLSYMS is set .version is already updated
635*1da177e4SLinus Torvalds# Generate System.map and verify that the content is consistent
636*1da177e4SLinus Torvalds
637*1da177e4SLinus Torvaldsdefine rule_vmlinux__
638*1da177e4SLinus Torvalds	$(if $(CONFIG_KALLSYMS),,+$(call cmd,vmlinux_version))
639*1da177e4SLinus Torvalds
640*1da177e4SLinus Torvalds	$(call cmd,vmlinux__)
641*1da177e4SLinus Torvalds	$(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
642*1da177e4SLinus Torvalds
643*1da177e4SLinus Torvalds	$(Q)$(if $($(quiet)cmd_sysmap),                 \
644*1da177e4SLinus Torvalds	  echo '  $($(quiet)cmd_sysmap) System.map' &&) \
645*1da177e4SLinus Torvalds	$(cmd_sysmap) $@ System.map;                    \
646*1da177e4SLinus Torvalds	if [ $$? -ne 0 ]; then                          \
647*1da177e4SLinus Torvalds		rm -f $@;                               \
648*1da177e4SLinus Torvalds		/bin/false;                             \
649*1da177e4SLinus Torvalds	fi;
650*1da177e4SLinus Torvalds	$(verify_kallsyms)
651*1da177e4SLinus Torvaldsendef
652*1da177e4SLinus Torvalds
653*1da177e4SLinus Torvalds
654*1da177e4SLinus Torvaldsifdef CONFIG_KALLSYMS
655*1da177e4SLinus Torvalds# Generate section listing all symbols and add it into vmlinux $(kallsyms.o)
656*1da177e4SLinus Torvalds# It's a three stage process:
657*1da177e4SLinus Torvalds# o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
658*1da177e4SLinus Torvalds#   empty
659*1da177e4SLinus Torvalds#   Running kallsyms on that gives us .tmp_kallsyms1.o with
660*1da177e4SLinus Torvalds#   the right size - vmlinux version (uname -v) is updated during this step
661*1da177e4SLinus Torvalds# o .tmp_vmlinux2 now has a __kallsyms section of the right size,
662*1da177e4SLinus Torvalds#   but due to the added section, some addresses have shifted.
663*1da177e4SLinus Torvalds#   From here, we generate a correct .tmp_kallsyms2.o
664*1da177e4SLinus Torvalds# o The correct .tmp_kallsyms2.o is linked into the final vmlinux.
665*1da177e4SLinus Torvalds# o Verify that the System.map from vmlinux matches the map from
666*1da177e4SLinus Torvalds#   .tmp_vmlinux2, just in case we did not generate kallsyms correctly.
667*1da177e4SLinus Torvalds# o If CONFIG_KALLSYMS_EXTRA_PASS is set, do an extra pass using
668*1da177e4SLinus Torvalds#   .tmp_vmlinux3 and .tmp_kallsyms3.o.  This is only meant as a
669*1da177e4SLinus Torvalds#   temporary bypass to allow the kernel to be built while the
670*1da177e4SLinus Torvalds#   maintainers work out what went wrong with kallsyms.
671*1da177e4SLinus Torvalds
672*1da177e4SLinus Torvaldsifdef CONFIG_KALLSYMS_EXTRA_PASS
673*1da177e4SLinus Torvaldslast_kallsyms := 3
674*1da177e4SLinus Torvaldselse
675*1da177e4SLinus Torvaldslast_kallsyms := 2
676*1da177e4SLinus Torvaldsendif
677*1da177e4SLinus Torvalds
678*1da177e4SLinus Torvaldskallsyms.o := .tmp_kallsyms$(last_kallsyms).o
679*1da177e4SLinus Torvalds
680*1da177e4SLinus Torvaldsdefine verify_kallsyms
681*1da177e4SLinus Torvalds	$(Q)$(if $($(quiet)cmd_sysmap),                       \
682*1da177e4SLinus Torvalds	  echo '  $($(quiet)cmd_sysmap) .tmp_System.map' &&)  \
683*1da177e4SLinus Torvalds	  $(cmd_sysmap) .tmp_vmlinux$(last_kallsyms) .tmp_System.map
684*1da177e4SLinus Torvalds	$(Q)cmp -s System.map .tmp_System.map ||              \
685*1da177e4SLinus Torvalds		(echo Inconsistent kallsyms data;             \
686*1da177e4SLinus Torvalds		 echo Try setting CONFIG_KALLSYMS_EXTRA_PASS; \
687*1da177e4SLinus Torvalds		 rm .tmp_kallsyms* ; /bin/false )
688*1da177e4SLinus Torvaldsendef
689*1da177e4SLinus Torvalds
690*1da177e4SLinus Torvalds# Update vmlinux version before link
691*1da177e4SLinus Torvalds# Use + in front of this rule to silent warning about make -j1
692*1da177e4SLinus Torvaldscmd_ksym_ld = $(cmd_vmlinux__)
693*1da177e4SLinus Torvaldsdefine rule_ksym_ld
694*1da177e4SLinus Torvalds	+$(call cmd,vmlinux_version)
695*1da177e4SLinus Torvalds	$(call cmd,vmlinux__)
696*1da177e4SLinus Torvalds	$(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
697*1da177e4SLinus Torvaldsendef
698*1da177e4SLinus Torvalds
699*1da177e4SLinus Torvalds# Generate .S file with all kernel symbols
700*1da177e4SLinus Torvaldsquiet_cmd_kallsyms = KSYM    $@
701*1da177e4SLinus Torvalds      cmd_kallsyms = $(NM) -n $< | $(KALLSYMS) \
702*1da177e4SLinus Torvalds                     $(if $(CONFIG_KALLSYMS_ALL),--all-symbols) > $@
703*1da177e4SLinus Torvalds
704*1da177e4SLinus Torvalds.tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms3.o: %.o: %.S scripts FORCE
705*1da177e4SLinus Torvalds	$(call if_changed_dep,as_o_S)
706*1da177e4SLinus Torvalds
707*1da177e4SLinus Torvalds.tmp_kallsyms%.S: .tmp_vmlinux% $(KALLSYMS)
708*1da177e4SLinus Torvalds	$(call cmd,kallsyms)
709*1da177e4SLinus Torvalds
710*1da177e4SLinus Torvalds# .tmp_vmlinux1 must be complete except kallsyms, so update vmlinux version
711*1da177e4SLinus Torvalds.tmp_vmlinux1: $(vmlinux-lds) $(vmlinux-all) FORCE
712*1da177e4SLinus Torvalds	$(call if_changed_rule,ksym_ld)
713*1da177e4SLinus Torvalds
714*1da177e4SLinus Torvalds.tmp_vmlinux2: $(vmlinux-lds) $(vmlinux-all) .tmp_kallsyms1.o FORCE
715*1da177e4SLinus Torvalds	$(call if_changed,vmlinux__)
716*1da177e4SLinus Torvalds
717*1da177e4SLinus Torvalds.tmp_vmlinux3: $(vmlinux-lds) $(vmlinux-all) .tmp_kallsyms2.o FORCE
718*1da177e4SLinus Torvalds	$(call if_changed,vmlinux__)
719*1da177e4SLinus Torvalds
720*1da177e4SLinus Torvalds# Needs to visit scripts/ before $(KALLSYMS) can be used.
721*1da177e4SLinus Torvalds$(KALLSYMS): scripts ;
722*1da177e4SLinus Torvalds
723*1da177e4SLinus Torvaldsendif # ifdef CONFIG_KALLSYMS
724*1da177e4SLinus Torvalds
725*1da177e4SLinus Torvalds# vmlinux image - including updated kernel symbols
726*1da177e4SLinus Torvaldsvmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) $(kallsyms.o) FORCE
727*1da177e4SLinus Torvalds	$(call if_changed_rule,vmlinux__)
728*1da177e4SLinus Torvalds
729*1da177e4SLinus Torvalds# The actual objects are generated when descending,
730*1da177e4SLinus Torvalds# make sure no implicit rule kicks in
731*1da177e4SLinus Torvalds$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
732*1da177e4SLinus Torvalds
733*1da177e4SLinus Torvalds# Handle descending into subdirectories listed in $(vmlinux-dirs)
734*1da177e4SLinus Torvalds# Preset locale variables to speed up the build process. Limit locale
735*1da177e4SLinus Torvalds# tweaks to this spot to avoid wrong language settings when running
736*1da177e4SLinus Torvalds# make menuconfig etc.
737*1da177e4SLinus Torvalds# Error messages still appears in the original language
738*1da177e4SLinus Torvalds
739*1da177e4SLinus Torvalds.PHONY: $(vmlinux-dirs)
740*1da177e4SLinus Torvalds$(vmlinux-dirs): prepare-all scripts
741*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$@
742*1da177e4SLinus Torvalds
743*1da177e4SLinus Torvalds# Things we need to do before we recursively start building the kernel
744*1da177e4SLinus Torvalds# or the modules are listed in "prepare-all".
745*1da177e4SLinus Torvalds# A multi level approach is used. prepare1 is updated first, then prepare0.
746*1da177e4SLinus Torvalds# prepare-all is the collection point for the prepare targets.
747*1da177e4SLinus Torvalds
748*1da177e4SLinus Torvalds.PHONY: prepare-all prepare prepare0 prepare1 prepare2
749*1da177e4SLinus Torvalds
750*1da177e4SLinus Torvalds# prepare2 is used to check if we are building in a separate output directory,
751*1da177e4SLinus Torvalds# and if so do:
752*1da177e4SLinus Torvalds# 1) Check that make has not been executed in the kernel src $(srctree)
753*1da177e4SLinus Torvalds# 2) Create the include2 directory, used for the second asm symlink
754*1da177e4SLinus Torvalds
755*1da177e4SLinus Torvaldsprepare2:
756*1da177e4SLinus Torvaldsifneq ($(KBUILD_SRC),)
757*1da177e4SLinus Torvalds	@echo '  Using $(srctree) as source for kernel'
758*1da177e4SLinus Torvalds	$(Q)if [ -h $(srctree)/include/asm -o -f $(srctree)/.config ]; then \
759*1da177e4SLinus Torvalds		echo "  $(srctree) is not clean, please run 'make mrproper'";\
760*1da177e4SLinus Torvalds		echo "  in the '$(srctree)' directory.";\
761*1da177e4SLinus Torvalds		/bin/false; \
762*1da177e4SLinus Torvalds	fi;
763*1da177e4SLinus Torvalds	$(Q)if [ ! -d include2 ]; then mkdir -p include2; fi;
764*1da177e4SLinus Torvalds	$(Q)ln -fsn $(srctree)/include/asm-$(ARCH) include2/asm
765*1da177e4SLinus Torvaldsendif
766*1da177e4SLinus Torvalds
767*1da177e4SLinus Torvalds# prepare1 creates a makefile if using a separate output directory
768*1da177e4SLinus Torvaldsprepare1: prepare2 outputmakefile
769*1da177e4SLinus Torvalds
770*1da177e4SLinus Torvaldsprepare0: prepare1 include/linux/version.h include/asm include/config/MARKER
771*1da177e4SLinus Torvaldsifneq ($(KBUILD_MODULES),)
772*1da177e4SLinus Torvalds	$(Q)rm -rf $(MODVERDIR)
773*1da177e4SLinus Torvalds	$(Q)mkdir -p $(MODVERDIR)
774*1da177e4SLinus Torvaldsendif
775*1da177e4SLinus Torvalds
776*1da177e4SLinus Torvalds# All the preparing..
777*1da177e4SLinus Torvaldsprepare-all: prepare0 prepare
778*1da177e4SLinus Torvalds
779*1da177e4SLinus Torvalds#	Leave this as default for preprocessing vmlinux.lds.S, which is now
780*1da177e4SLinus Torvalds#	done in arch/$(ARCH)/kernel/Makefile
781*1da177e4SLinus Torvalds
782*1da177e4SLinus Torvaldsexport CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
783*1da177e4SLinus Torvalds
784*1da177e4SLinus Torvalds# Single targets
785*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
786*1da177e4SLinus Torvalds
787*1da177e4SLinus Torvalds%.s: %.c scripts FORCE
788*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@D) $@
789*1da177e4SLinus Torvalds%.i: %.c scripts FORCE
790*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@D) $@
791*1da177e4SLinus Torvalds%.o: %.c scripts FORCE
792*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@D) $@
793*1da177e4SLinus Torvalds%/:      scripts prepare FORCE
794*1da177e4SLinus Torvalds	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) $(build)=$(@D)
795*1da177e4SLinus Torvalds%.lst: %.c scripts FORCE
796*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@D) $@
797*1da177e4SLinus Torvalds%.s: %.S scripts FORCE
798*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@D) $@
799*1da177e4SLinus Torvalds%.o: %.S scripts FORCE
800*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@D) $@
801*1da177e4SLinus Torvalds
802*1da177e4SLinus Torvalds# 	FIXME: The asm symlink changes when $(ARCH) changes. That's
803*1da177e4SLinus Torvalds#	hard to detect, but I suppose "make mrproper" is a good idea
804*1da177e4SLinus Torvalds#	before switching between archs anyway.
805*1da177e4SLinus Torvalds
806*1da177e4SLinus Torvaldsinclude/asm:
807*1da177e4SLinus Torvalds	@echo '  SYMLINK $@ -> include/asm-$(ARCH)'
808*1da177e4SLinus Torvalds	$(Q)if [ ! -d include ]; then mkdir -p include; fi;
809*1da177e4SLinus Torvalds	@ln -fsn asm-$(ARCH) $@
810*1da177e4SLinus Torvalds
811*1da177e4SLinus Torvalds# 	Split autoconf.h into include/linux/config/*
812*1da177e4SLinus Torvalds
813*1da177e4SLinus Torvaldsinclude/config/MARKER: include/linux/autoconf.h
814*1da177e4SLinus Torvalds	@echo '  SPLIT   include/linux/autoconf.h -> include/config/*'
815*1da177e4SLinus Torvalds	@scripts/basic/split-include include/linux/autoconf.h include/config
816*1da177e4SLinus Torvalds	@touch $@
817*1da177e4SLinus Torvalds
818*1da177e4SLinus Torvalds# Generate some files
819*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
820*1da177e4SLinus Torvalds
821*1da177e4SLinus Torvalds# KERNELRELEASE can change from a few different places, meaning version.h
822*1da177e4SLinus Torvalds# needs to be updated, so this check is forced on all builds
823*1da177e4SLinus Torvalds
824*1da177e4SLinus Torvaldsuts_len := 64
825*1da177e4SLinus Torvalds
826*1da177e4SLinus Torvaldsdefine filechk_version.h
827*1da177e4SLinus Torvalds	if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
828*1da177e4SLinus Torvalds	  echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
829*1da177e4SLinus Torvalds	  exit 1; \
830*1da177e4SLinus Torvalds	fi; \
831*1da177e4SLinus Torvalds	(echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"; \
832*1da177e4SLinus Torvalds	  echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)`; \
833*1da177e4SLinus Torvalds	 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'; \
834*1da177e4SLinus Torvalds	)
835*1da177e4SLinus Torvaldsendef
836*1da177e4SLinus Torvalds
837*1da177e4SLinus Torvaldsinclude/linux/version.h: $(srctree)/Makefile FORCE
838*1da177e4SLinus Torvalds	$(call filechk,version.h)
839*1da177e4SLinus Torvalds
840*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
841*1da177e4SLinus Torvalds
842*1da177e4SLinus Torvalds.PHONY: depend dep
843*1da177e4SLinus Torvaldsdepend dep:
844*1da177e4SLinus Torvalds	@echo '*** Warning: make $@ is unnecessary now.'
845*1da177e4SLinus Torvalds
846*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
847*1da177e4SLinus Torvalds# Modules
848*1da177e4SLinus Torvalds
849*1da177e4SLinus Torvaldsifdef CONFIG_MODULES
850*1da177e4SLinus Torvalds
851*1da177e4SLinus Torvalds# 	By default, build modules as well
852*1da177e4SLinus Torvalds
853*1da177e4SLinus Torvaldsall: modules
854*1da177e4SLinus Torvalds
855*1da177e4SLinus Torvalds#	Build modules
856*1da177e4SLinus Torvalds
857*1da177e4SLinus Torvalds.PHONY: modules
858*1da177e4SLinus Torvaldsmodules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
859*1da177e4SLinus Torvalds	@echo '  Building modules, stage 2.';
860*1da177e4SLinus Torvalds	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
861*1da177e4SLinus Torvalds
862*1da177e4SLinus Torvalds
863*1da177e4SLinus Torvalds# Target to prepare building external modules
864*1da177e4SLinus Torvalds.PHONY: modules_prepare
865*1da177e4SLinus Torvaldsmodules_prepare: prepare-all scripts
866*1da177e4SLinus Torvalds
867*1da177e4SLinus Torvalds# Target to install modules
868*1da177e4SLinus Torvalds.PHONY: modules_install
869*1da177e4SLinus Torvaldsmodules_install: _modinst_ _modinst_post
870*1da177e4SLinus Torvalds
871*1da177e4SLinus Torvalds.PHONY: _modinst_
872*1da177e4SLinus Torvalds_modinst_:
873*1da177e4SLinus Torvalds	@if [ -z "`$(DEPMOD) -V | grep module-init-tools`" ]; then \
874*1da177e4SLinus Torvalds		echo "Warning: you may need to install module-init-tools"; \
875*1da177e4SLinus Torvalds		echo "See http://www.codemonkey.org.uk/docs/post-halloween-2.6.txt";\
876*1da177e4SLinus Torvalds		sleep 1; \
877*1da177e4SLinus Torvalds	fi
878*1da177e4SLinus Torvalds	@rm -rf $(MODLIB)/kernel
879*1da177e4SLinus Torvalds	@rm -f $(MODLIB)/source
880*1da177e4SLinus Torvalds	@mkdir -p $(MODLIB)/kernel
881*1da177e4SLinus Torvalds	@ln -s $(srctree) $(MODLIB)/source
882*1da177e4SLinus Torvalds	@if [ ! $(objtree) -ef  $(MODLIB)/build ]; then \
883*1da177e4SLinus Torvalds		rm -f $(MODLIB)/build ; \
884*1da177e4SLinus Torvalds		ln -s $(objtree) $(MODLIB)/build ; \
885*1da177e4SLinus Torvalds	fi
886*1da177e4SLinus Torvalds	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst
887*1da177e4SLinus Torvalds
888*1da177e4SLinus Torvalds# If System.map exists, run depmod.  This deliberately does not have a
889*1da177e4SLinus Torvalds# dependency on System.map since that would run the dependency tree on
890*1da177e4SLinus Torvalds# vmlinux.  This depmod is only for convenience to give the initial
891*1da177e4SLinus Torvalds# boot a modules.dep even before / is mounted read-write.  However the
892*1da177e4SLinus Torvalds# boot script depmod is the master version.
893*1da177e4SLinus Torvaldsifeq "$(strip $(INSTALL_MOD_PATH))" ""
894*1da177e4SLinus Torvaldsdepmod_opts	:=
895*1da177e4SLinus Torvaldselse
896*1da177e4SLinus Torvaldsdepmod_opts	:= -b $(INSTALL_MOD_PATH) -r
897*1da177e4SLinus Torvaldsendif
898*1da177e4SLinus Torvalds.PHONY: _modinst_post
899*1da177e4SLinus Torvalds_modinst_post: _modinst_
900*1da177e4SLinus Torvalds	if [ -r System.map -a -x $(DEPMOD) ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi
901*1da177e4SLinus Torvalds
902*1da177e4SLinus Torvaldselse # CONFIG_MODULES
903*1da177e4SLinus Torvalds
904*1da177e4SLinus Torvalds# Modules not configured
905*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
906*1da177e4SLinus Torvalds
907*1da177e4SLinus Torvaldsmodules modules_install: FORCE
908*1da177e4SLinus Torvalds	@echo
909*1da177e4SLinus Torvalds	@echo "The present kernel configuration has modules disabled."
910*1da177e4SLinus Torvalds	@echo "Type 'make config' and enable loadable module support."
911*1da177e4SLinus Torvalds	@echo "Then build a kernel with module support enabled."
912*1da177e4SLinus Torvalds	@echo
913*1da177e4SLinus Torvalds	@exit 1
914*1da177e4SLinus Torvalds
915*1da177e4SLinus Torvaldsendif # CONFIG_MODULES
916*1da177e4SLinus Torvalds
917*1da177e4SLinus Torvalds# Generate asm-offsets.h
918*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
919*1da177e4SLinus Torvalds
920*1da177e4SLinus Torvaldsdefine filechk_gen-asm-offsets
921*1da177e4SLinus Torvalds	(set -e; \
922*1da177e4SLinus Torvalds	 echo "#ifndef __ASM_OFFSETS_H__"; \
923*1da177e4SLinus Torvalds	 echo "#define __ASM_OFFSETS_H__"; \
924*1da177e4SLinus Torvalds	 echo "/*"; \
925*1da177e4SLinus Torvalds	 echo " * DO NOT MODIFY."; \
926*1da177e4SLinus Torvalds	 echo " *"; \
927*1da177e4SLinus Torvalds	 echo " * This file was generated by arch/$(ARCH)/Makefile"; \
928*1da177e4SLinus Torvalds	 echo " *"; \
929*1da177e4SLinus Torvalds	 echo " */"; \
930*1da177e4SLinus Torvalds	 echo ""; \
931*1da177e4SLinus Torvalds	 sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
932*1da177e4SLinus Torvalds	 echo ""; \
933*1da177e4SLinus Torvalds	 echo "#endif" )
934*1da177e4SLinus Torvaldsendef
935*1da177e4SLinus Torvalds
936*1da177e4SLinus Torvalds
937*1da177e4SLinus Torvalds###
938*1da177e4SLinus Torvalds# Cleaning is done on three levels.
939*1da177e4SLinus Torvalds# make clean     Delete most generated files
940*1da177e4SLinus Torvalds#                Leave enough to build external modules
941*1da177e4SLinus Torvalds# make mrproper  Delete the current configuration, and all generated files
942*1da177e4SLinus Torvalds# make distclean Remove editor backup files, patch leftover files and the like
943*1da177e4SLinus Torvalds
944*1da177e4SLinus Torvalds# Directories & files removed with 'make clean'
945*1da177e4SLinus TorvaldsCLEAN_DIRS  += $(MODVERDIR)
946*1da177e4SLinus TorvaldsCLEAN_FILES +=	vmlinux System.map \
947*1da177e4SLinus Torvalds                .tmp_kallsyms* .tmp_version .tmp_vmlinux* .tmp_System.map
948*1da177e4SLinus Torvalds
949*1da177e4SLinus Torvalds# Directories & files removed with 'make mrproper'
950*1da177e4SLinus TorvaldsMRPROPER_DIRS  += include/config include2
951*1da177e4SLinus TorvaldsMRPROPER_FILES += .config .config.old include/asm .version \
952*1da177e4SLinus Torvalds                  include/linux/autoconf.h include/linux/version.h \
953*1da177e4SLinus Torvalds                  Module.symvers tags TAGS cscope*
954*1da177e4SLinus Torvalds
955*1da177e4SLinus Torvalds# clean - Delete most, but leave enough to build external modules
956*1da177e4SLinus Torvalds#
957*1da177e4SLinus Torvaldsclean: rm-dirs  := $(CLEAN_DIRS)
958*1da177e4SLinus Torvaldsclean: rm-files := $(CLEAN_FILES)
959*1da177e4SLinus Torvaldsclean-dirs      := $(addprefix _clean_,$(vmlinux-alldirs))
960*1da177e4SLinus Torvalds
961*1da177e4SLinus Torvalds.PHONY: $(clean-dirs) clean archclean
962*1da177e4SLinus Torvalds$(clean-dirs):
963*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
964*1da177e4SLinus Torvalds
965*1da177e4SLinus Torvaldsclean: archclean $(clean-dirs)
966*1da177e4SLinus Torvalds	$(call cmd,rmdirs)
967*1da177e4SLinus Torvalds	$(call cmd,rmfiles)
968*1da177e4SLinus Torvalds	@find . $(RCS_FIND_IGNORE) \
969*1da177e4SLinus Torvalds	 	\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
970*1da177e4SLinus Torvalds		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
971*1da177e4SLinus Torvalds		-type f -print | xargs rm -f
972*1da177e4SLinus Torvalds
973*1da177e4SLinus Torvalds# mrproper - Delete all generated files, including .config
974*1da177e4SLinus Torvalds#
975*1da177e4SLinus Torvaldsmrproper: rm-dirs  := $(wildcard $(MRPROPER_DIRS))
976*1da177e4SLinus Torvaldsmrproper: rm-files := $(wildcard $(MRPROPER_FILES))
977*1da177e4SLinus Torvaldsmrproper-dirs      := $(addprefix _mrproper_,Documentation/DocBook scripts)
978*1da177e4SLinus Torvalds
979*1da177e4SLinus Torvalds.PHONY: $(mrproper-dirs) mrproper archmrproper
980*1da177e4SLinus Torvalds$(mrproper-dirs):
981*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
982*1da177e4SLinus Torvalds
983*1da177e4SLinus Torvaldsmrproper: clean archmrproper $(mrproper-dirs)
984*1da177e4SLinus Torvalds	$(call cmd,rmdirs)
985*1da177e4SLinus Torvalds	$(call cmd,rmfiles)
986*1da177e4SLinus Torvalds
987*1da177e4SLinus Torvalds# distclean
988*1da177e4SLinus Torvalds#
989*1da177e4SLinus Torvalds.PHONY: distclean
990*1da177e4SLinus Torvalds
991*1da177e4SLinus Torvaldsdistclean: mrproper
992*1da177e4SLinus Torvalds	@find $(srctree) $(RCS_FIND_IGNORE) \
993*1da177e4SLinus Torvalds	 	\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
994*1da177e4SLinus Torvalds		-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
995*1da177e4SLinus Torvalds	 	-o -name '.*.rej' -o -size 0 \
996*1da177e4SLinus Torvalds		-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
997*1da177e4SLinus Torvalds		-type f -print | xargs rm -f
998*1da177e4SLinus Torvalds
999*1da177e4SLinus Torvalds
1000*1da177e4SLinus Torvalds# Packaging of the kernel to various formats
1001*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
1002*1da177e4SLinus Torvalds# rpm target kept for backward compatibility
1003*1da177e4SLinus Torvaldspackage-dir	:= $(srctree)/scripts/package
1004*1da177e4SLinus Torvalds
1005*1da177e4SLinus Torvalds.PHONY: %-pkg rpm
1006*1da177e4SLinus Torvalds
1007*1da177e4SLinus Torvalds%pkg: FORCE
1008*1da177e4SLinus Torvalds	$(Q)$(MAKE) -f $(package-dir)/Makefile $@
1009*1da177e4SLinus Torvaldsrpm: FORCE
1010*1da177e4SLinus Torvalds	$(Q)$(MAKE) -f $(package-dir)/Makefile $@
1011*1da177e4SLinus Torvalds
1012*1da177e4SLinus Torvalds
1013*1da177e4SLinus Torvalds# Brief documentation of the typical targets used
1014*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
1015*1da177e4SLinus Torvalds
1016*1da177e4SLinus Torvaldsboards := $(wildcard $(srctree)/arch/$(ARCH)/configs/*_defconfig)
1017*1da177e4SLinus Torvaldsboards := $(notdir $(boards))
1018*1da177e4SLinus Torvalds
1019*1da177e4SLinus Torvaldshelp:
1020*1da177e4SLinus Torvalds	@echo  'Cleaning targets:'
1021*1da177e4SLinus Torvalds	@echo  '  clean		  - remove most generated files but keep the config'
1022*1da177e4SLinus Torvalds	@echo  '  mrproper	  - remove all generated files + config + various backup files'
1023*1da177e4SLinus Torvalds	@echo  ''
1024*1da177e4SLinus Torvalds	@echo  'Configuration targets:'
1025*1da177e4SLinus Torvalds	@$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1026*1da177e4SLinus Torvalds	@echo  ''
1027*1da177e4SLinus Torvalds	@echo  'Other generic targets:'
1028*1da177e4SLinus Torvalds	@echo  '  all		  - Build all targets marked with [*]'
1029*1da177e4SLinus Torvalds	@echo  '* vmlinux	  - Build the bare kernel'
1030*1da177e4SLinus Torvalds	@echo  '* modules	  - Build all modules'
1031*1da177e4SLinus Torvalds	@echo  '  modules_install - Install all modules'
1032*1da177e4SLinus Torvalds	@echo  '  dir/            - Build all files in dir and below'
1033*1da177e4SLinus Torvalds	@echo  '  dir/file.[ois]  - Build specified target only'
1034*1da177e4SLinus Torvalds	@echo  '  rpm		  - Build a kernel as an RPM package'
1035*1da177e4SLinus Torvalds	@echo  '  tags/TAGS	  - Generate tags file for editors'
1036*1da177e4SLinus Torvalds	@echo  '  cscope	  - Generate cscope index'
1037*1da177e4SLinus Torvalds	@echo  ''
1038*1da177e4SLinus Torvalds	@echo  'Static analysers'
1039*1da177e4SLinus Torvalds	@echo  '  buildcheck      - List dangling references to vmlinux discarded sections'
1040*1da177e4SLinus Torvalds	@echo  '                    and init sections from non-init sections'
1041*1da177e4SLinus Torvalds	@echo  '  checkstack      - Generate a list of stack hogs'
1042*1da177e4SLinus Torvalds	@echo  '  namespacecheck  - Name space analysis on compiled kernel'
1043*1da177e4SLinus Torvalds	@echo  ''
1044*1da177e4SLinus Torvalds	@echo  'Kernel packaging:'
1045*1da177e4SLinus Torvalds	@$(MAKE) -f $(package-dir)/Makefile help
1046*1da177e4SLinus Torvalds	@echo  ''
1047*1da177e4SLinus Torvalds	@echo  'Documentation targets:'
1048*1da177e4SLinus Torvalds	@$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp
1049*1da177e4SLinus Torvalds	@echo  ''
1050*1da177e4SLinus Torvalds	@echo  'Architecture specific targets ($(ARCH)):'
1051*1da177e4SLinus Torvalds	@$(if $(archhelp),$(archhelp),\
1052*1da177e4SLinus Torvalds		echo '  No architecture specific help defined for $(ARCH)')
1053*1da177e4SLinus Torvalds	@echo  ''
1054*1da177e4SLinus Torvalds	@$(if $(boards), \
1055*1da177e4SLinus Torvalds		$(foreach b, $(boards), \
1056*1da177e4SLinus Torvalds		printf "  %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
1057*1da177e4SLinus Torvalds		echo '')
1058*1da177e4SLinus Torvalds
1059*1da177e4SLinus Torvalds	@echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
1060*1da177e4SLinus Torvalds	@echo  '  make O=dir [targets] Locate all output files in "dir", including .config'
1061*1da177e4SLinus Torvalds	@echo  '  make C=1   [targets] Check all c source with $$CHECK (sparse)'
1062*1da177e4SLinus Torvalds	@echo  '  make C=2   [targets] Force check of all c source with $$CHECK (sparse)'
1063*1da177e4SLinus Torvalds	@echo  ''
1064*1da177e4SLinus Torvalds	@echo  'Execute "make" or "make all" to build all targets marked with [*] '
1065*1da177e4SLinus Torvalds	@echo  'For further info see the ./README file'
1066*1da177e4SLinus Torvalds
1067*1da177e4SLinus Torvalds
1068*1da177e4SLinus Torvalds# Documentation targets
1069*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
1070*1da177e4SLinus Torvalds%docs: scripts_basic FORCE
1071*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=Documentation/DocBook $@
1072*1da177e4SLinus Torvalds
1073*1da177e4SLinus Torvaldselse # KBUILD_EXTMOD
1074*1da177e4SLinus Torvalds
1075*1da177e4SLinus Torvalds###
1076*1da177e4SLinus Torvalds# External module support.
1077*1da177e4SLinus Torvalds# When building external modules the kernel used as basis is considered
1078*1da177e4SLinus Torvalds# read-only, and no consistency checks are made and the make
1079*1da177e4SLinus Torvalds# system is not used on the basis kernel. If updates are required
1080*1da177e4SLinus Torvalds# in the basis kernel ordinary make commands (without M=...) must
1081*1da177e4SLinus Torvalds# be used.
1082*1da177e4SLinus Torvalds#
1083*1da177e4SLinus Torvalds# The following are the only valid targets when building external
1084*1da177e4SLinus Torvalds# modules.
1085*1da177e4SLinus Torvalds# make M=dir clean     Delete all automatically generated files
1086*1da177e4SLinus Torvalds# make M=dir modules   Make all modules in specified dir
1087*1da177e4SLinus Torvalds# make M=dir	       Same as 'make M=dir modules'
1088*1da177e4SLinus Torvalds# make M=dir modules_install
1089*1da177e4SLinus Torvalds#                      Install the modules build in the module directory
1090*1da177e4SLinus Torvalds#                      Assumes install directory is already created
1091*1da177e4SLinus Torvalds
1092*1da177e4SLinus Torvalds# We are always building modules
1093*1da177e4SLinus TorvaldsKBUILD_MODULES := 1
1094*1da177e4SLinus Torvalds.PHONY: crmodverdir
1095*1da177e4SLinus Torvaldscrmodverdir:
1096*1da177e4SLinus Torvalds	$(Q)mkdir -p $(MODVERDIR)
1097*1da177e4SLinus Torvalds
1098*1da177e4SLinus Torvalds.PHONY: $(objtree)/Module.symvers
1099*1da177e4SLinus Torvalds$(objtree)/Module.symvers:
1100*1da177e4SLinus Torvalds	@test -e $(objtree)/Module.symvers || ( \
1101*1da177e4SLinus Torvalds	echo; \
1102*1da177e4SLinus Torvalds	echo "  WARNING: Symbol version dump $(objtree)/Module.symvers"; \
1103*1da177e4SLinus Torvalds	echo "           is missing; modules will have no dependencies and modversions."; \
1104*1da177e4SLinus Torvalds	echo )
1105*1da177e4SLinus Torvalds
1106*1da177e4SLinus Torvaldsmodule-dirs := $(addprefix _module_,$(KBUILD_EXTMOD))
1107*1da177e4SLinus Torvalds.PHONY: $(module-dirs) modules
1108*1da177e4SLinus Torvalds$(module-dirs): crmodverdir $(objtree)/Module.symvers
1109*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
1110*1da177e4SLinus Torvalds
1111*1da177e4SLinus Torvaldsmodules: $(module-dirs)
1112*1da177e4SLinus Torvalds	@echo '  Building modules, stage 2.';
1113*1da177e4SLinus Torvalds	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
1114*1da177e4SLinus Torvalds
1115*1da177e4SLinus Torvalds.PHONY: modules_install
1116*1da177e4SLinus Torvaldsmodules_install:
1117*1da177e4SLinus Torvalds	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst
1118*1da177e4SLinus Torvalds
1119*1da177e4SLinus Torvaldsclean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD))
1120*1da177e4SLinus Torvalds
1121*1da177e4SLinus Torvalds.PHONY: $(clean-dirs) clean
1122*1da177e4SLinus Torvalds$(clean-dirs):
1123*1da177e4SLinus Torvalds	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1124*1da177e4SLinus Torvalds
1125*1da177e4SLinus Torvaldsclean:	rm-dirs := $(MODVERDIR)
1126*1da177e4SLinus Torvaldsclean: $(clean-dirs)
1127*1da177e4SLinus Torvalds	$(call cmd,rmdirs)
1128*1da177e4SLinus Torvalds	@find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \
1129*1da177e4SLinus Torvalds	 	\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
1130*1da177e4SLinus Torvalds		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
1131*1da177e4SLinus Torvalds		-type f -print | xargs rm -f
1132*1da177e4SLinus Torvalds
1133*1da177e4SLinus Torvaldshelp:
1134*1da177e4SLinus Torvalds	@echo  '  Building external modules.'
1135*1da177e4SLinus Torvalds	@echo  '  Syntax: make -C path/to/kernel/src M=$$PWD target'
1136*1da177e4SLinus Torvalds	@echo  ''
1137*1da177e4SLinus Torvalds	@echo  '  modules         - default target, build the module(s)'
1138*1da177e4SLinus Torvalds	@echo  '  modules_install - install the module'
1139*1da177e4SLinus Torvalds	@echo  '  clean           - remove generated files in module directory only'
1140*1da177e4SLinus Torvalds	@echo  ''
1141*1da177e4SLinus Torvaldsendif # KBUILD_EXTMOD
1142*1da177e4SLinus Torvalds
1143*1da177e4SLinus Torvalds# Generate tags for editors
1144*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
1145*1da177e4SLinus Torvalds
1146*1da177e4SLinus Torvalds#We want __srctree to totally vanish out when KBUILD_OUTPUT is not set
1147*1da177e4SLinus Torvalds#(which is the most common case IMHO) to avoid unneeded clutter in the big tags file.
1148*1da177e4SLinus Torvalds#Adding $(srctree) adds about 20M on i386 to the size of the output file!
1149*1da177e4SLinus Torvalds
1150*1da177e4SLinus Torvaldsifeq ($(KBUILD_OUTPUT),)
1151*1da177e4SLinus Torvalds__srctree =
1152*1da177e4SLinus Torvaldselse
1153*1da177e4SLinus Torvalds__srctree = $(srctree)/
1154*1da177e4SLinus Torvaldsendif
1155*1da177e4SLinus Torvalds
1156*1da177e4SLinus Torvaldsdefine all-sources
1157*1da177e4SLinus Torvalds	( find $(__srctree) $(RCS_FIND_IGNORE) \
1158*1da177e4SLinus Torvalds	       \( -name include -o -name arch \) -prune -o \
1159*1da177e4SLinus Torvalds	       -name '*.[chS]' -print; \
1160*1da177e4SLinus Torvalds	  find $(__srctree)arch/$(ARCH) $(RCS_FIND_IGNORE) \
1161*1da177e4SLinus Torvalds	       -name '*.[chS]' -print; \
1162*1da177e4SLinus Torvalds	  find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \
1163*1da177e4SLinus Torvalds	       -name '*.[chS]' -print; \
1164*1da177e4SLinus Torvalds	  find $(__srctree)include $(RCS_FIND_IGNORE) \
1165*1da177e4SLinus Torvalds	       \( -name config -o -name 'asm-*' \) -prune \
1166*1da177e4SLinus Torvalds	       -o -name '*.[chS]' -print; \
1167*1da177e4SLinus Torvalds	  find $(__srctree)include/asm-$(ARCH) $(RCS_FIND_IGNORE) \
1168*1da177e4SLinus Torvalds	       -name '*.[chS]' -print; \
1169*1da177e4SLinus Torvalds	  find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \
1170*1da177e4SLinus Torvalds	       -name '*.[chS]' -print )
1171*1da177e4SLinus Torvaldsendef
1172*1da177e4SLinus Torvalds
1173*1da177e4SLinus Torvaldsquiet_cmd_cscope-file = FILELST cscope.files
1174*1da177e4SLinus Torvalds      cmd_cscope-file = $(all-sources) > cscope.files
1175*1da177e4SLinus Torvalds
1176*1da177e4SLinus Torvaldsquiet_cmd_cscope = MAKE    cscope.out
1177*1da177e4SLinus Torvalds      cmd_cscope = cscope -k -b -q
1178*1da177e4SLinus Torvalds
1179*1da177e4SLinus Torvaldscscope: FORCE
1180*1da177e4SLinus Torvalds	$(call cmd,cscope-file)
1181*1da177e4SLinus Torvalds	$(call cmd,cscope)
1182*1da177e4SLinus Torvalds
1183*1da177e4SLinus Torvaldsquiet_cmd_TAGS = MAKE   $@
1184*1da177e4SLinus Torvaldscmd_TAGS = $(all-sources) | etags -
1185*1da177e4SLinus Torvalds
1186*1da177e4SLinus Torvalds# 	Exuberant ctags works better with -I
1187*1da177e4SLinus Torvalds
1188*1da177e4SLinus Torvaldsquiet_cmd_tags = MAKE   $@
1189*1da177e4SLinus Torvaldsdefine cmd_tags
1190*1da177e4SLinus Torvalds	rm -f $@; \
1191*1da177e4SLinus Torvalds	CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_GPL"`; \
1192*1da177e4SLinus Torvalds	$(all-sources) | xargs ctags $$CTAGSF -a --extra=+f
1193*1da177e4SLinus Torvaldsendef
1194*1da177e4SLinus Torvalds
1195*1da177e4SLinus TorvaldsTAGS: FORCE
1196*1da177e4SLinus Torvalds	$(call cmd,TAGS)
1197*1da177e4SLinus Torvalds
1198*1da177e4SLinus Torvaldstags: FORCE
1199*1da177e4SLinus Torvalds	$(call cmd,tags)
1200*1da177e4SLinus Torvalds
1201*1da177e4SLinus Torvalds
1202*1da177e4SLinus Torvalds# Scripts to check various things for consistency
1203*1da177e4SLinus Torvalds# ---------------------------------------------------------------------------
1204*1da177e4SLinus Torvalds
1205*1da177e4SLinus Torvaldsconfigcheck:
1206*1da177e4SLinus Torvalds	find * $(RCS_FIND_IGNORE) \
1207*1da177e4SLinus Torvalds		-name '*.[hcS]' -type f -print | sort \
1208*1da177e4SLinus Torvalds		| xargs $(PERL) -w scripts/checkconfig.pl
1209*1da177e4SLinus Torvalds
1210*1da177e4SLinus Torvaldsincludecheck:
1211*1da177e4SLinus Torvalds	find * $(RCS_FIND_IGNORE) \
1212*1da177e4SLinus Torvalds		-name '*.[hcS]' -type f -print | sort \
1213*1da177e4SLinus Torvalds		| xargs $(PERL) -w scripts/checkincludes.pl
1214*1da177e4SLinus Torvalds
1215*1da177e4SLinus Torvaldsversioncheck:
1216*1da177e4SLinus Torvalds	find * $(RCS_FIND_IGNORE) \
1217*1da177e4SLinus Torvalds		-name '*.[hcS]' -type f -print | sort \
1218*1da177e4SLinus Torvalds		| xargs $(PERL) -w scripts/checkversion.pl
1219*1da177e4SLinus Torvalds
1220*1da177e4SLinus Torvaldsbuildcheck:
1221*1da177e4SLinus Torvalds	$(PERL) $(srctree)/scripts/reference_discarded.pl
1222*1da177e4SLinus Torvalds	$(PERL) $(srctree)/scripts/reference_init.pl
1223*1da177e4SLinus Torvalds
1224*1da177e4SLinus Torvaldsnamespacecheck:
1225*1da177e4SLinus Torvalds	$(PERL) $(srctree)/scripts/namespace.pl
1226*1da177e4SLinus Torvalds
1227*1da177e4SLinus Torvaldsendif #ifeq ($(config-targets),1)
1228*1da177e4SLinus Torvaldsendif #ifeq ($(mixed-targets),1)
1229*1da177e4SLinus Torvalds
1230*1da177e4SLinus Torvalds.PHONY: checkstack
1231*1da177e4SLinus Torvaldscheckstack:
1232*1da177e4SLinus Torvalds	$(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
1233*1da177e4SLinus Torvalds	$(PERL) $(src)/scripts/checkstack.pl $(ARCH)
1234*1da177e4SLinus Torvalds
1235*1da177e4SLinus Torvaldskernelrelease:
1236*1da177e4SLinus Torvalds	@echo $(KERNELRELEASE)
1237*1da177e4SLinus Torvalds
1238*1da177e4SLinus Torvalds# FIXME Should go into a make.lib or something
1239*1da177e4SLinus Torvalds# ===========================================================================
1240*1da177e4SLinus Torvalds
1241*1da177e4SLinus Torvaldsquiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN   $(wildcard $(rm-dirs)))
1242*1da177e4SLinus Torvalds      cmd_rmdirs = rm -rf $(rm-dirs)
1243*1da177e4SLinus Torvalds
1244*1da177e4SLinus Torvaldsquiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files)))
1245*1da177e4SLinus Torvalds      cmd_rmfiles = rm -f $(rm-files)
1246*1da177e4SLinus Torvalds
1247*1da177e4SLinus Torvalds
1248*1da177e4SLinus Torvaldsa_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
1249*1da177e4SLinus Torvalds	  $(NOSTDINC_FLAGS) $(CPPFLAGS) \
1250*1da177e4SLinus Torvalds	  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
1251*1da177e4SLinus Torvalds
1252*1da177e4SLinus Torvaldsquiet_cmd_as_o_S = AS      $@
1253*1da177e4SLinus Torvaldscmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
1254*1da177e4SLinus Torvalds
1255*1da177e4SLinus Torvalds# read all saved command lines
1256*1da177e4SLinus Torvalds
1257*1da177e4SLinus Torvaldstargets := $(wildcard $(sort $(targets)))
1258*1da177e4SLinus Torvaldscmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
1259*1da177e4SLinus Torvalds
1260*1da177e4SLinus Torvaldsifneq ($(cmd_files),)
1261*1da177e4SLinus Torvalds  $(cmd_files): ;	# Do not try to update included dependency files
1262*1da177e4SLinus Torvalds  include $(cmd_files)
1263*1da177e4SLinus Torvaldsendif
1264*1da177e4SLinus Torvalds
1265*1da177e4SLinus Torvalds# Execute command and generate cmd file
1266*1da177e4SLinus Torvaldsif_changed = $(if $(strip $? \
1267*1da177e4SLinus Torvalds		          $(filter-out $(cmd_$(1)),$(cmd_$@))\
1268*1da177e4SLinus Torvalds			  $(filter-out $(cmd_$@),$(cmd_$(1)))),\
1269*1da177e4SLinus Torvalds	@set -e; \
1270*1da177e4SLinus Torvalds	$(if $($(quiet)cmd_$(1)),echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';) \
1271*1da177e4SLinus Torvalds	$(cmd_$(1)); \
1272*1da177e4SLinus Torvalds	echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd)
1273*1da177e4SLinus Torvalds
1274*1da177e4SLinus Torvalds
1275*1da177e4SLinus Torvalds# execute the command and also postprocess generated .d dependencies
1276*1da177e4SLinus Torvalds# file
1277*1da177e4SLinus Torvaldsif_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
1278*1da177e4SLinus Torvalds		          $(filter-out $(cmd_$(1)),$(cmd_$@))\
1279*1da177e4SLinus Torvalds			  $(filter-out $(cmd_$@),$(cmd_$(1)))),\
1280*1da177e4SLinus Torvalds	$(Q)set -e; \
1281*1da177e4SLinus Torvalds	$(if $($(quiet)cmd_$(1)),echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';) \
1282*1da177e4SLinus Torvalds	$(cmd_$(1)); \
1283*1da177e4SLinus Torvalds	scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
1284*1da177e4SLinus Torvalds	rm -f $(depfile); \
1285*1da177e4SLinus Torvalds	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
1286*1da177e4SLinus Torvalds
1287*1da177e4SLinus Torvalds# Usage: $(call if_changed_rule,foo)
1288*1da177e4SLinus Torvalds# will check if $(cmd_foo) changed, or any of the prequisites changed,
1289*1da177e4SLinus Torvalds# and if so will execute $(rule_foo)
1290*1da177e4SLinus Torvalds
1291*1da177e4SLinus Torvaldsif_changed_rule = $(if $(strip $? \
1292*1da177e4SLinus Torvalds		               $(filter-out $(cmd_$(1)),$(cmd_$(@F)))\
1293*1da177e4SLinus Torvalds			       $(filter-out $(cmd_$(@F)),$(cmd_$(1)))),\
1294*1da177e4SLinus Torvalds	               $(Q)$(rule_$(1)))
1295*1da177e4SLinus Torvalds
1296*1da177e4SLinus Torvalds# If quiet is set, only print short version of command
1297*1da177e4SLinus Torvalds
1298*1da177e4SLinus Torvaldscmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
1299*1da177e4SLinus Torvalds
1300*1da177e4SLinus Torvalds# filechk is used to check if the content of a generated file is updated.
1301*1da177e4SLinus Torvalds# Sample usage:
1302*1da177e4SLinus Torvalds# define filechk_sample
1303*1da177e4SLinus Torvalds#	echo $KERNELRELEASE
1304*1da177e4SLinus Torvalds# endef
1305*1da177e4SLinus Torvalds# version.h : Makefile
1306*1da177e4SLinus Torvalds#	$(call filechk,sample)
1307*1da177e4SLinus Torvalds# The rule defined shall write to stdout the content of the new file.
1308*1da177e4SLinus Torvalds# The existing file will be compared with the new one.
1309*1da177e4SLinus Torvalds# - If no file exist it is created
1310*1da177e4SLinus Torvalds# - If the content differ the new file is used
1311*1da177e4SLinus Torvalds# - If they are equal no change, and no timestamp update
1312*1da177e4SLinus Torvalds
1313*1da177e4SLinus Torvaldsdefine filechk
1314*1da177e4SLinus Torvalds	@set -e;				\
1315*1da177e4SLinus Torvalds	echo '  CHK     $@';			\
1316*1da177e4SLinus Torvalds	mkdir -p $(dir $@);			\
1317*1da177e4SLinus Torvalds	$(filechk_$(1)) < $< > $@.tmp;		\
1318*1da177e4SLinus Torvalds	if [ -r $@ ] && cmp -s $@ $@.tmp; then	\
1319*1da177e4SLinus Torvalds		rm -f $@.tmp;			\
1320*1da177e4SLinus Torvalds	else					\
1321*1da177e4SLinus Torvalds		echo '  UPD     $@';		\
1322*1da177e4SLinus Torvalds		mv -f $@.tmp $@;		\
1323*1da177e4SLinus Torvalds	fi
1324*1da177e4SLinus Torvaldsendef
1325*1da177e4SLinus Torvalds
1326*1da177e4SLinus Torvalds# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=dir
1327*1da177e4SLinus Torvalds# Usage:
1328*1da177e4SLinus Torvalds# $(Q)$(MAKE) $(build)=dir
1329*1da177e4SLinus Torvaldsbuild := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
1330*1da177e4SLinus Torvalds
1331*1da177e4SLinus Torvalds# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
1332*1da177e4SLinus Torvalds# Usage:
1333*1da177e4SLinus Torvalds# $(Q)$(MAKE) $(clean)=dir
1334*1da177e4SLinus Torvaldsclean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
1335*1da177e4SLinus Torvalds
1336*1da177e4SLinus Torvalds#	$(call descend,<dir>,<target>)
1337*1da177e4SLinus Torvalds#	Recursively call a sub-make in <dir> with target <target>
1338*1da177e4SLinus Torvalds# Usage is deprecated, because make does not see this as an invocation of make.
1339*1da177e4SLinus Torvaldsdescend =$(Q)$(MAKE) -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj=$(1) $(2)
1340*1da177e4SLinus Torvalds
1341*1da177e4SLinus Torvaldsendif	# skip-makefile
1342*1da177e4SLinus Torvalds
1343*1da177e4SLinus TorvaldsFORCE:
1344