Makefile revision d746d647
11da177e4SLinus TorvaldsVERSION = 2
21da177e4SLinus TorvaldsPATCHLEVEL = 6
3c9927c2bSLinus TorvaldsSUBLEVEL = 24
4dbeeb816SLinus TorvaldsEXTRAVERSION = -rc2
581cfe79bSLinus TorvaldsNAME = Arr Matey! A Hairy Bilge Rat!
61da177e4SLinus Torvalds
71da177e4SLinus Torvalds# *DOCUMENTATION*
81da177e4SLinus Torvalds# To see a list of typical targets execute "make help"
91da177e4SLinus Torvalds# More info can be located in ./README
101da177e4SLinus Torvalds# Comments in this file are targeted only to the developer, do not
111da177e4SLinus Torvalds# expect to learn how to build the kernel reading this file.
121da177e4SLinus Torvalds
1315964864SOleg Verych# Do not:
1415964864SOleg Verych# o  use make's built-in rules and variables
1515964864SOleg Verych#    (this increases performance and avoid hard-to-debug behavour);
1615964864SOleg Verych# o  print "Entering directory ...";
1715964864SOleg VerychMAKEFLAGS += -rR --no-print-directory
181da177e4SLinus Torvalds
191da177e4SLinus Torvalds# We are using a recursive build, so we need to do a little thinking
201da177e4SLinus Torvalds# to get the ordering right.
211da177e4SLinus Torvalds#
221da177e4SLinus Torvalds# Most importantly: sub-Makefiles should only ever modify files in
231da177e4SLinus Torvalds# their own directory. If in some directory we have a dependency on
241da177e4SLinus Torvalds# a file in another dir (which doesn't happen often, but it's often
251da177e4SLinus Torvalds# unavoidable when linking the built-in.o targets which finally
261da177e4SLinus Torvalds# turn into vmlinux), we will call a sub make in that other dir, and
271da177e4SLinus Torvalds# after that we are sure that everything which is in that other dir
281da177e4SLinus Torvalds# is now up to date.
291da177e4SLinus Torvalds#
301da177e4SLinus Torvalds# The only cases where we need to modify files which have global
311da177e4SLinus Torvalds# effects are thus separated out and done before the recursive
321da177e4SLinus Torvalds# descending is started. They are now explicitly listed as the
331da177e4SLinus Torvalds# prepare rule.
341da177e4SLinus Torvalds
351da177e4SLinus Torvalds# To put more focus on warnings, be less verbose as default
361da177e4SLinus Torvalds# Use 'make V=1' to see the full commands
371da177e4SLinus Torvalds
381da177e4SLinus Torvaldsifdef V
391da177e4SLinus Torvalds  ifeq ("$(origin V)", "command line")
401da177e4SLinus Torvalds    KBUILD_VERBOSE = $(V)
411da177e4SLinus Torvalds  endif
421da177e4SLinus Torvaldsendif
431da177e4SLinus Torvaldsifndef KBUILD_VERBOSE
441da177e4SLinus Torvalds  KBUILD_VERBOSE = 0
451da177e4SLinus Torvaldsendif
461da177e4SLinus Torvalds
471c7bafe7SRobert P. J. Day# Call a source code checker (by default, "sparse") as part of the
481c7bafe7SRobert P. J. Day# C compilation.
491c7bafe7SRobert P. J. Day#
501c7bafe7SRobert P. J. Day# Use 'make C=1' to enable checking of only re-compiled files.
511c7bafe7SRobert P. J. Day# Use 'make C=2' to enable checking of *all* source files, regardless
521c7bafe7SRobert P. J. Day# of whether they are re-compiled or not.
531c7bafe7SRobert P. J. Day#
541c7bafe7SRobert P. J. Day# See the file "Documentation/sparse.txt" for more details, including
551c7bafe7SRobert P. J. Day# where to get the "sparse" utility.
561da177e4SLinus Torvalds
571da177e4SLinus Torvaldsifdef C
581da177e4SLinus Torvalds  ifeq ("$(origin C)", "command line")
591da177e4SLinus Torvalds    KBUILD_CHECKSRC = $(C)
601da177e4SLinus Torvalds  endif
611da177e4SLinus Torvaldsendif
621da177e4SLinus Torvaldsifndef KBUILD_CHECKSRC
631da177e4SLinus Torvalds  KBUILD_CHECKSRC = 0
641da177e4SLinus Torvaldsendif
651da177e4SLinus Torvalds
661da177e4SLinus Torvalds# Use make M=dir to specify directory of external module to build
671da177e4SLinus Torvalds# Old syntax make ... SUBDIRS=$PWD is still supported
681da177e4SLinus Torvalds# Setting the environment variable KBUILD_EXTMOD take precedence
691da177e4SLinus Torvaldsifdef SUBDIRS
701da177e4SLinus Torvalds  KBUILD_EXTMOD ?= $(SUBDIRS)
711da177e4SLinus Torvaldsendif
721da177e4SLinus Torvaldsifdef M
731da177e4SLinus Torvalds  ifeq ("$(origin M)", "command line")
741da177e4SLinus Torvalds    KBUILD_EXTMOD := $(M)
751da177e4SLinus Torvalds  endif
761da177e4SLinus Torvaldsendif
771da177e4SLinus Torvalds
781da177e4SLinus Torvalds
791da177e4SLinus Torvalds# kbuild supports saving output files in a separate directory.
801da177e4SLinus Torvalds# To locate output files in a separate directory two syntaxes are supported.
811da177e4SLinus Torvalds# In both cases the working directory must be the root of the kernel src.
821da177e4SLinus Torvalds# 1) O=
831da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/"
84070b98bfSSam Ravnborg#
851da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT
861da177e4SLinus Torvalds# Set the environment variable KBUILD_OUTPUT to point to the directory
871da177e4SLinus Torvalds# where the output files shall be placed.
881da177e4SLinus Torvalds# export KBUILD_OUTPUT=dir/to/store/output/files/
891da177e4SLinus Torvalds# make
901da177e4SLinus Torvalds#
911da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment
921da177e4SLinus Torvalds# variable.
931da177e4SLinus Torvalds
941da177e4SLinus Torvalds
951da177e4SLinus Torvalds# KBUILD_SRC is set on invocation of make in OBJ directory
961da177e4SLinus Torvalds# KBUILD_SRC is not intended to be used by the regular user (for now)
971da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),)
981da177e4SLinus Torvalds
991da177e4SLinus Torvalds# OK, Make called in directory where kernel src resides
1001da177e4SLinus Torvalds# Do we want to locate output files in a separate directory?
1011da177e4SLinus Torvaldsifdef O
1021da177e4SLinus Torvalds  ifeq ("$(origin O)", "command line")
1031da177e4SLinus Torvalds    KBUILD_OUTPUT := $(O)
1041da177e4SLinus Torvalds  endif
1051da177e4SLinus Torvaldsendif
1061da177e4SLinus Torvalds
1071da177e4SLinus Torvalds# That's our default target when none is given on the command line
1084f193362SPaul SmithPHONY := _all
1091da177e4SLinus Torvalds_all:
1101da177e4SLinus Torvalds
1111da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
1121da177e4SLinus Torvalds# Invoke a second make in the output directory, passing relevant variables
1131da177e4SLinus Torvalds# check that the output directory actually exists
1141da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
1151da177e4SLinus TorvaldsKBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
1161da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1171da177e4SLinus Torvalds     $(error output directory "$(saved-output)" does not exist))
1184f1127e2SSam Ravnborg# Check that OUTPUT directory is not the same as where we have kernel src
1194f1127e2SSam Ravnborg$(if $(filter-out $(KBUILD_OUTPUT),$(shell /bin/pwd)),, \
1204f1127e2SSam Ravnborg     $(error Output directory (O=...) specifies kernel src dir))
1211da177e4SLinus Torvalds
1220b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1230b35786dSMilton Miller
1240b35786dSMilton Miller$(filter-out _all sub-make,$(MAKECMDGOALS)) _all: sub-make
1250b35786dSMilton Miller	$(Q)@:
1260b35786dSMilton Miller
1270b35786dSMilton Millersub-make: FORCE
12823a45e2cSSam Ravnborg	$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
12923a45e2cSSam Ravnborg	KBUILD_SRC=$(CURDIR) \
1300b35786dSMilton Miller	KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile \
1310b35786dSMilton Miller	$(filter-out _all sub-make,$(MAKECMDGOALS))
1321da177e4SLinus Torvalds
1331da177e4SLinus Torvalds# Leave processing to above invocation of make
1341da177e4SLinus Torvaldsskip-makefile := 1
1351da177e4SLinus Torvaldsendif # ifneq ($(KBUILD_OUTPUT),)
1361da177e4SLinus Torvaldsendif # ifeq ($(KBUILD_SRC),)
1371da177e4SLinus Torvalds
1381da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
1391da177e4SLinus Torvaldsifeq ($(skip-makefile),)
1401da177e4SLinus Torvalds
1411da177e4SLinus Torvalds# If building an external module we do not care about the all: rule
1421da177e4SLinus Torvalds# but instead _all depend on modules
1434f193362SPaul SmithPHONY += all
1441da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
1451da177e4SLinus Torvalds_all: all
1461da177e4SLinus Torvaldselse
1471da177e4SLinus Torvalds_all: modules
1481da177e4SLinus Torvaldsendif
1491da177e4SLinus Torvalds
1501da177e4SLinus Torvaldssrctree		:= $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
1511da177e4SLinus TorvaldsTOPDIR		:= $(srctree)
1521da177e4SLinus Torvalds# FIXME - TOPDIR is obsolete, use srctree/objtree
1531da177e4SLinus Torvaldsobjtree		:= $(CURDIR)
1541da177e4SLinus Torvaldssrc		:= $(srctree)
1551da177e4SLinus Torvaldsobj		:= $(objtree)
1561da177e4SLinus Torvalds
1570f558c33SMattia DongiliVPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
1581da177e4SLinus Torvalds
1591da177e4SLinus Torvaldsexport srctree objtree VPATH TOPDIR
1601da177e4SLinus Torvalds
1611da177e4SLinus Torvalds
1621da177e4SLinus Torvalds# SUBARCH tells the usermode build what the underlying arch is.  That is set
1631da177e4SLinus Torvalds# first, and if a usermode build is happening, the "ARCH=um" on the command
1641da177e4SLinus Torvalds# line overrides the setting of ARCH below.  If a native build is happening,
1651da177e4SLinus Torvalds# then ARCH is assigned, getting whatever value it gets normally, and 
1661da177e4SLinus Torvalds# SUBARCH is subsequently ignored.
1671da177e4SLinus Torvalds
1681da177e4SLinus TorvaldsSUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
1691da177e4SLinus Torvalds				  -e s/arm.*/arm/ -e s/sa110/arm/ \
17039990b5eSLinus Torvalds				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
171236b1957SPaul Mundt				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
172236b1957SPaul Mundt				  -e s/sh[234].*/sh/ )
1731da177e4SLinus Torvalds
1741da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
1751da177e4SLinus Torvalds# ---------------------------------------------------------------------------
1761da177e4SLinus Torvalds#
1771da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
1781da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
1791da177e4SLinus Torvalds# ARCH can be set during invocation of make:
1801da177e4SLinus Torvalds# make ARCH=ia64
1811da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
1821da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
1831da177e4SLinus Torvalds
1841da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
1851da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
1861da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
1871da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
1881da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
1891da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
1901da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
1911da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
1921da177e4SLinus Torvalds
1931da177e4SLinus TorvaldsARCH		?= $(SUBARCH)
1941da177e4SLinus TorvaldsCROSS_COMPILE	?=
1951da177e4SLinus Torvalds
1961da177e4SLinus Torvalds# Architecture as present in compile.h
1976752ed90SThomas GleixnerUTS_MACHINE 	:= $(ARCH)
1986752ed90SThomas GleixnerSRCARCH 	:= $(ARCH)
1991da177e4SLinus Torvalds
200d746d647SSam Ravnborg# Additional ARCH settings for x86
201d746d647SSam Ravnborgifeq ($(ARCH),i386)
202d746d647SSam Ravnborg        SRCARCH := x86
203d746d647SSam Ravnborgendif
204d746d647SSam Ravnborgifeq ($(ARCH),x86_64)
205d746d647SSam Ravnborg        SRCARCH := x86
206d746d647SSam Ravnborgendif
20774b469f2SSam Ravnborg
20814cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
20914cdd3c4SRoman Zippel
2101da177e4SLinus Torvalds# SHELL used by kbuild
2111da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
2121da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
2131da177e4SLinus Torvalds	  else echo sh; fi ; fi)
2141da177e4SLinus Torvalds
215070b98bfSSam RavnborgHOSTCC       = gcc
216070b98bfSSam RavnborgHOSTCXX      = g++
217070b98bfSSam RavnborgHOSTCFLAGS   = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
218070b98bfSSam RavnborgHOSTCXXFLAGS = -O2
2191da177e4SLinus Torvalds
220070b98bfSSam Ravnborg# Decide whether to build built-in, modular, or both.
221070b98bfSSam Ravnborg# Normally, just do built-in.
2221da177e4SLinus Torvalds
2231da177e4SLinus TorvaldsKBUILD_MODULES :=
2241da177e4SLinus TorvaldsKBUILD_BUILTIN := 1
2251da177e4SLinus Torvalds
2261da177e4SLinus Torvalds#	If we have only "make modules", don't compile built-in objects.
2271da177e4SLinus Torvalds#	When we're building modules with modversions, we need to consider
2281da177e4SLinus Torvalds#	the built-in objects during the descend as well, in order to
229070b98bfSSam Ravnborg#	make sure the checksums are up to date before we record them.
2301da177e4SLinus Torvalds
2311da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),modules)
2321da177e4SLinus Torvalds  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
2331da177e4SLinus Torvaldsendif
2341da177e4SLinus Torvalds
2351da177e4SLinus Torvalds#	If we have "make <whatever> modules", compile modules
2361da177e4SLinus Torvalds#	in addition to whatever we do anyway.
2371da177e4SLinus Torvalds#	Just "make" or "make all" shall build modules as well
2381da177e4SLinus Torvalds
2391da177e4SLinus Torvaldsifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
2401da177e4SLinus Torvalds  KBUILD_MODULES := 1
2411da177e4SLinus Torvaldsendif
2421da177e4SLinus Torvalds
2431da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),)
2441da177e4SLinus Torvalds  KBUILD_MODULES := 1
2451da177e4SLinus Torvaldsendif
2461da177e4SLinus Torvalds
247e579d351SSam Ravnborgexport KBUILD_MODULES KBUILD_BUILTIN
2491da177e4SLinus Torvalds
2501da177e4SLinus Torvalds# Beautify output
2511da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2521da177e4SLinus Torvalds#
2531da177e4SLinus Torvalds# Normally, we echo the whole command before executing it. By making
2541da177e4SLinus Torvalds# that echo $($(quiet)$(cmd)), we now have the possibility to set
2551da177e4SLinus Torvalds# $(quiet) to choose other forms of output instead, e.g.
2561da177e4SLinus Torvalds#
2571da177e4SLinus Torvalds#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
2581da177e4SLinus Torvalds#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
2591da177e4SLinus Torvalds#
2601da177e4SLinus Torvalds# If $(quiet) is empty, the whole command will be printed.
2611da177e4SLinus Torvalds# If it is set to "quiet_", only the short version will be printed. 
262070b98bfSSam Ravnborg# If it is set to "silent_", nothing will be printed at all, since
2631da177e4SLinus Torvalds# the variable $(silent_cmd_cc_o_c) doesn't exist.
2641da177e4SLinus Torvalds#
265a58a414fSAdrian Bunk# A simple variant is to prefix commands with $(Q) - that's useful
2661da177e4SLinus Torvalds# for commands that shall be hidden in non-verbose mode.
2671da177e4SLinus Torvalds#
2681da177e4SLinus Torvalds#	$(Q)ln $@ :<
2691da177e4SLinus Torvalds#
2701da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
2711da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 1 then the above command is displayed.
2721da177e4SLinus Torvalds
2731da177e4SLinus Torvaldsifeq ($(KBUILD_VERBOSE),1)
2741da177e4SLinus Torvalds  quiet =
2751da177e4SLinus Torvalds  Q =
2761da177e4SLinus Torvaldselse
2771da177e4SLinus Torvalds  quiet=quiet_
2781da177e4SLinus Torvalds  Q = @
2791da177e4SLinus Torvaldsendif
2801da177e4SLinus Torvalds
2811da177e4SLinus Torvalds# If the user is running make -s (silent mode), suppress echoing of
2821da177e4SLinus Torvalds# commands
2831da177e4SLinus Torvalds
2841da177e4SLinus Torvaldsifneq ($(findstring s,$(MAKEFLAGS)),)
2851da177e4SLinus Torvalds  quiet=silent_
2861da177e4SLinus Torvaldsendif
2871da177e4SLinus Torvalds
2881da177e4SLinus Torvaldsexport quiet Q KBUILD_VERBOSE
2891da177e4SLinus Torvalds
2901da177e4SLinus Torvalds
2911da177e4SLinus Torvalds# Look for make include files relative to root of kernel src
2921da177e4SLinus TorvaldsMAKEFLAGS += --include-dir=$(srctree)
2931da177e4SLinus Torvalds
29415964864SOleg Verych# We need some generic definitions.
29515964864SOleg Verychinclude $(srctree)/scripts/Kbuild.include
2961da177e4SLinus Torvalds
2971da177e4SLinus Torvalds# Make variables (CC, etc...)
2981da177e4SLinus Torvalds
2991da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
3001da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
3011da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
3021da177e4SLinus TorvaldsCPP		= $(CC) -E
3031da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
3041da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
3051da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
3061da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
3071da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
3081da177e4SLinus TorvaldsAWK		= awk
3091da177e4SLinus TorvaldsGENKSYMS	= scripts/genksyms/genksyms
3101da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
3111da177e4SLinus TorvaldsKALLSYMS	= scripts/kallsyms
3121da177e4SLinus TorvaldsPERL		= perl
3131da177e4SLinus TorvaldsCHECK		= sparse
3141da177e4SLinus Torvalds
315af4ca457SAl ViroCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF)
3161da177e4SLinus TorvaldsMODFLAGS	= -DMODULE
3171da177e4SLinus TorvaldsCFLAGS_MODULE   = $(MODFLAGS)
3181da177e4SLinus TorvaldsAFLAGS_MODULE   = $(MODFLAGS)
319114f5157SRoland McGrathLDFLAGS_MODULE  =
3201da177e4SLinus TorvaldsCFLAGS_KERNEL	=
3211da177e4SLinus TorvaldsAFLAGS_KERNEL	=
3221da177e4SLinus Torvalds
3231da177e4SLinus Torvalds
3241da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
3251da177e4SLinus Torvalds# Needed to be compatible with the O= option
3261da177e4SLinus TorvaldsLINUXINCLUDE    := -Iinclude \
3272dd34b48SRussell King                   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \
328e623a3b8SZachary Amsden		   -include include/linux/autoconf.h
3291da177e4SLinus Torvalds
3311da177e4SLinus Torvalds
332a0f97e06SSam RavnborgKBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
33394bed2a9SDave Jones		   -fno-strict-aliasing -fno-common \
33494bed2a9SDave Jones		   -Werror-implicit-function-declaration
335222d394dSSam RavnborgKBUILD_AFLAGS   := -D__ASSEMBLY__
3361da177e4SLinus Torvalds
337f1d28fb0SRoman Zippel# Read KERNELRELEASE from include/config/kernel.release (if it exists)
338f1d28fb0SRoman ZippelKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
340cb58455cSSam Ravnborg
3451da177e4SLinus Torvalds
3491da177e4SLinus Torvalds
3501da177e4SLinus Torvalds# When compiling out-of-tree modules, put MODVERDIR in the module
3511da177e4SLinus Torvalds# tree rather than in the kernel tree. The kernel tree might
3521da177e4SLinus Torvalds# even be read-only.
3531da177e4SLinus Torvaldsexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
3541da177e4SLinus Torvalds
3551da177e4SLinus Torvalds# Files to ignore in find ... statements
3561da177e4SLinus Torvalds
357406119f4STrond MyklebustRCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS -o -name .pc -o -name .hg -o -name .git \) -prune -o
358406119f4STrond Myklebustexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc --exclude .hg --exclude .git
3591da177e4SLinus Torvalds
3601da177e4SLinus Torvalds# ===========================================================================
3611da177e4SLinus Torvalds# Rules shared between *config targets and build targets
3621da177e4SLinus Torvalds
3631da177e4SLinus Torvalds# Basic helpers built in scripts/
3644f193362SPaul SmithPHONY += scripts_basic
3651da177e4SLinus Torvaldsscripts_basic:
3661da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/basic
3671da177e4SLinus Torvalds
368cd05e6bdSJan Beulich# To avoid any implicit rule to kick in, define an empty command.
369cd05e6bdSJan Beulichscripts/basic/%: scripts_basic ;
370cd05e6bdSJan Beulich
3714f193362SPaul SmithPHONY += outputmakefile
372fd5f0cd6SJan Beulich# outputmakefile generates a Makefile in the output directory, if using a
373fd5f0cd6SJan Beulich# separate output directory. This allows convenient use of make in the
374fd5f0cd6SJan Beulich# output directory.
3751da177e4SLinus Torvaldsoutputmakefile:
376fd5f0cd6SJan Beulichifneq ($(KBUILD_SRC),)
377fd5f0cd6SJan Beulich	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
378fd5f0cd6SJan Beulich	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
379fd5f0cd6SJan Beulichendif
3801da177e4SLinus Torvalds
3811da177e4SLinus Torvalds# To make sure we do not include .config for any of the *config targets
3821da177e4SLinus Torvalds# catch them early, and hand them over to scripts/kconfig/Makefile
3831da177e4SLinus Torvalds# It is allowed to specify more targets when calling make, including
3841da177e4SLinus Torvalds# mixing *config targets and build targets.
385070b98bfSSam Ravnborg# For example 'make oldconfig all'.
3861da177e4SLinus Torvalds# Detect when mixed targets is specified, and make a second invocation
3871da177e4SLinus Torvalds# of make so .config is not included in this case either (for *config).
3881da177e4SLinus Torvalds
3893eb3c740SRoman Zippelno-dot-config-targets := clean mrproper distclean \
390c30a02e0SRoman Zippel			 cscope TAGS tags help %docs check% \
3913eb3c740SRoman Zippel			 include/linux/version.h headers_% \
3923eb3c740SRoman Zippel			 kernelrelease kernelversion
3931da177e4SLinus Torvalds
3941da177e4SLinus Torvaldsconfig-targets := 0
3951da177e4SLinus Torvaldsmixed-targets  := 0
3961da177e4SLinus Torvaldsdot-config     := 1
3971da177e4SLinus Torvalds
3981da177e4SLinus Torvaldsifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
3991da177e4SLinus Torvalds	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
4001da177e4SLinus Torvalds		dot-config := 0
4011da177e4SLinus Torvalds	endif
4021da177e4SLinus Torvaldsendif
4031da177e4SLinus Torvalds
4041da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
4051da177e4SLinus Torvalds        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
4061da177e4SLinus Torvalds                config-targets := 1
4071da177e4SLinus Torvalds                ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
4081da177e4SLinus Torvalds                        mixed-targets := 1
4091da177e4SLinus Torvalds                endif
4101da177e4SLinus Torvalds        endif
4111da177e4SLinus Torvaldsendif
4121da177e4SLinus Torvalds
4131da177e4SLinus Torvaldsifeq ($(mixed-targets),1)
4141da177e4SLinus Torvalds# ===========================================================================
4151da177e4SLinus Torvalds# We're called with mixed targets (*config and build targets).
4161da177e4SLinus Torvalds# Handle them one by one.
4171da177e4SLinus Torvalds
4181da177e4SLinus Torvalds%:: FORCE
4191da177e4SLinus Torvalds	$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
4201da177e4SLinus Torvalds
4211da177e4SLinus Torvaldselse
4221da177e4SLinus Torvaldsifeq ($(config-targets),1)
4231da177e4SLinus Torvalds# ===========================================================================
4241da177e4SLinus Torvalds# *config targets only - make sure prerequisites are updated, and descend
4251da177e4SLinus Torvalds# in scripts/kconfig to make the *config target
4261da177e4SLinus Torvalds
4271da177e4SLinus Torvalds# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
4281da177e4SLinus Torvalds# KBUILD_DEFCONFIG may point out an alternative default configuration
4291da177e4SLinus Torvalds# used for 'make defconfig'
43074b469f2SSam Ravnborginclude $(srctree)/arch/$(SRCARCH)/Makefile
4311da177e4SLinus Torvaldsexport KBUILD_DEFCONFIG
4321da177e4SLinus Torvalds
433cd05e6bdSJan Beulichconfig %config: scripts_basic outputmakefile FORCE
434c955ccafSRoman Zippel	$(Q)mkdir -p include/linux include/config
4351da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/kconfig $@
4361da177e4SLinus Torvalds
4371da177e4SLinus Torvaldselse
4381da177e4SLinus Torvalds# ===========================================================================
4391da177e4SLinus Torvalds# Build targets only - this includes vmlinux, arch specific targets, clean
4401da177e4SLinus Torvalds# targets and others. In general all targets except *config targets.
4411da177e4SLinus Torvalds
4421da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
4431da177e4SLinus Torvalds# Additional helpers built in scripts/
4441da177e4SLinus Torvalds# Carefully list dependencies so we do not try to build scripts twice
445070b98bfSSam Ravnborg# in parallel
4464f193362SPaul SmithPHONY += scripts
4472e3646e5SRoman Zippelscripts: scripts_basic include/config/auto.conf
4481da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@)
4491da177e4SLinus Torvalds
4501da177e4SLinus Torvalds# Objects we will link into vmlinux / subdirs we need to visit
4511da177e4SLinus Torvaldsinit-y		:= init/
4521da177e4SLinus Torvaldsdrivers-y	:= drivers/ sound/
4531da177e4SLinus Torvaldsnet-y		:= net/
4541da177e4SLinus Torvaldslibs-y		:= lib/
4551da177e4SLinus Torvaldscore-y		:= usr/
4561da177e4SLinus Torvaldsendif # KBUILD_EXTMOD
4571da177e4SLinus Torvalds
4581da177e4SLinus Torvaldsifeq ($(dot-config),1)
4599ee4e336SSam Ravnborg# Read in config
4609ee4e336SSam Ravnborg-include include/config/auto.conf
4611da177e4SLinus Torvalds
4629ee4e336SSam Ravnborgifeq ($(KBUILD_EXTMOD),)
4631da177e4SLinus Torvalds# Read in dependencies to all Kconfig* files, make sure to run
4641da177e4SLinus Torvalds# oldconfig if changes are detected.
465c955ccafSRoman Zippel-include include/config/auto.conf.cmd
4661da177e4SLinus Torvalds
4671da177e4SLinus Torvalds# To avoid any implicit rule to kick in, define an empty command
46814cdd3c4SRoman Zippel$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
4691da177e4SLinus Torvalds
470c955ccafSRoman Zippel# If .config is newer than include/config/auto.conf, someone tinkered
471752625cfSSam Ravnborg# with it and forgot to run make oldconfig.
472070b98bfSSam Ravnborg# if auto.conf.cmd is missing then we are probably in a cleaned tree so
473752625cfSSam Ravnborg# we execute the config step to be sure to catch updated Kconfig files
47414cdd3c4SRoman Zippelinclude/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
4751da177e4SLinus Torvalds	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
4763041e47eSRoman Zippelelse
4779ee4e336SSam Ravnborg# external modules needs include/linux/autoconf.h and include/config/auto.conf
4789ee4e336SSam Ravnborg# but do not care if they are up-to-date. Use auto.conf to trigger the test
4799ee4e336SSam RavnborgPHONY += include/config/auto.conf
4809ee4e336SSam Ravnborg
4819ee4e336SSam Ravnborginclude/config/auto.conf:
4829ee4e336SSam Ravnborg	$(Q)test -e include/linux/autoconf.h -a -e $@ || (		\
4839ee4e336SSam Ravnborg	echo;								\
4849ee4e336SSam Ravnborg	echo "  ERROR: Kernel configuration is invalid.";		\
4859ee4e336SSam Ravnborg	echo "         include/linux/autoconf.h or $@ are missing.";	\
4869ee4e336SSam Ravnborg	echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";	\
4879ee4e336SSam Ravnborg	echo;								\
4889ee4e336SSam Ravnborg	/bin/false)
4899ee4e336SSam Ravnborg
4909ee4e336SSam Ravnborgendif # KBUILD_EXTMOD
491c955ccafSRoman Zippel
4921da177e4SLinus Torvaldselse
4931da177e4SLinus Torvalds# Dummy target needed, because used as prerequisite
494c955ccafSRoman Zippelinclude/config/auto.conf: ;
4959ee4e336SSam Ravnborgendif # $(dot-config)
4961da177e4SLinus Torvalds
4971da177e4SLinus Torvalds# The all: target is the default when no target is given on the
4981da177e4SLinus Torvalds# command line.
4991da177e4SLinus Torvalds# This allow a user to issue only 'make' to build a kernel including modules
500070b98bfSSam Ravnborg# Defaults vmlinux but it is usually overridden in the arch makefile
5011da177e4SLinus Torvaldsall: vmlinux
5021da177e4SLinus Torvalds
5031da177e4SLinus Torvaldsifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
504a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -Os
5051da177e4SLinus Torvaldselse
506a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -O2
5071da177e4SLinus Torvaldsendif
5081da177e4SLinus Torvalds
50974b469f2SSam Ravnborginclude $(srctree)/arch/$(SRCARCH)/Makefile
510c9eca0b9SSam Ravnborg
5111da177e4SLinus Torvaldsifdef CONFIG_FRAME_POINTER
512a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls
5131da177e4SLinus Torvaldselse
514a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -fomit-frame-pointer
5151da177e4SLinus Torvaldsendif
5161da177e4SLinus Torvalds
5171da177e4SLinus Torvaldsifdef CONFIG_DEBUG_INFO
518a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -g
519222d394dSSam RavnborgKBUILD_AFLAGS	+= -gdwarf-2
5201da177e4SLinus Torvaldsendif
5211da177e4SLinus Torvalds
522c9eca0b9SSam Ravnborg# Force gcc to behave correct even for buggy distributions
523a0f97e06SSam RavnborgKBUILD_CFLAGS         += $(call cc-option, -fno-stack-protector)
5241da177e4SLinus Torvalds
525e8e69931SSam Ravnborg# arch Makefile may override CC so keep this after arch Makefile is included
526e8f5bdb0SRik van RielNOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
527e8e69931SSam RavnborgCHECKFLAGS     += $(NOSTDINC_FLAGS)
528e8e69931SSam Ravnborg
5291da177e4SLinus Torvalds# warn about C99 declaration after statement
530a0f97e06SSam RavnborgKBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
5311da177e4SLinus Torvalds
532070b98bfSSam Ravnborg# disable pointer signed / unsigned warnings in gcc 4.0
533a0f97e06SSam RavnborgKBUILD_CFLAGS += $(call cc-option,-Wno-pointer-sign,)
5341da177e4SLinus Torvalds
53506c5040cSSam Ravnborg# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
53669ee0b35SSam Ravnborg# But warn user when we do so
53769ee0b35SSam Ravnborgwarn-assign = \
53869ee0b35SSam Ravnborg$(warning "WARNING: Appending $$K$(1) ($(K$(1))) from $(origin K$(1)) to kernel $$$(1)")
53969ee0b35SSam Ravnborg
54069ee0b35SSam Ravnborgifneq ($(KCPPFLAGS),)
54169ee0b35SSam Ravnborg        $(call warn-assign,CPPFLAGS)
54269ee0b35SSam Ravnborg        KBUILD_CPPFLAGS += $(KCPPFLAGS)
54369ee0b35SSam Ravnborgendif
54469ee0b35SSam Ravnborgifneq ($(KAFLAGS),)
54569ee0b35SSam Ravnborg        $(call warn-assign,AFLAGS)
54669ee0b35SSam Ravnborg        KBUILD_AFLAGS += $(KAFLAGS)
54769ee0b35SSam Ravnborgendif
54869ee0b35SSam Ravnborgifneq ($(KCFLAGS),)
54969ee0b35SSam Ravnborg        $(call warn-assign,CFLAGS)
55069ee0b35SSam Ravnborg        KBUILD_CFLAGS += $(KCFLAGS)
55169ee0b35SSam Ravnborgendif
55252bcc330SSam Ravnborg
55318991197SRoland McGrath# Use --build-id when available.
55418991197SRoland McGrathLDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\
55518991197SRoland McGrath			      $(call ld-option, -Wl$(comma)--build-id,))
55618991197SRoland McGrathLDFLAGS_MODULE += $(LDFLAGS_BUILD_ID)
55718991197SRoland McGrathLDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID)
55818991197SRoland McGrath
5591da177e4SLinus Torvalds# Default kernel image to build when no specific target is given.
560070b98bfSSam Ravnborg# KBUILD_IMAGE may be overruled on the command line or
5611da177e4SLinus Torvalds# set in the environment
5621da177e4SLinus Torvalds# Also any assignments in arch/$(ARCH)/Makefile take precedence over
5631da177e4SLinus Torvalds# this default value
5641da177e4SLinus Torvaldsexport KBUILD_IMAGE ?= vmlinux
5651da177e4SLinus Torvalds
5661da177e4SLinus Torvalds#
5671da177e4SLinus Torvalds# INSTALL_PATH specifies where to place the updated kernel and system map
5681da177e4SLinus Torvalds# images. Default is /boot, but you can set it to other values
5691da177e4SLinus Torvaldsexport	INSTALL_PATH ?= /boot
5701da177e4SLinus Torvalds
5711da177e4SLinus Torvalds#
5721da177e4SLinus Torvalds# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
5731da177e4SLinus Torvalds# relocations required by build roots.  This is not defined in the
574070b98bfSSam Ravnborg# makefile but the argument can be passed to make if needed.
5751da177e4SLinus Torvalds#
5761da177e4SLinus Torvalds
577df9df036SSam RavnborgMODLIB	= $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
5781da177e4SLinus Torvaldsexport MODLIB
5791da177e4SLinus Torvalds
580ac031f26STheodore Ts'o#
581ac031f26STheodore Ts'o#  INSTALL_MOD_STRIP, if defined, will cause modules to be