Makefile revision 2331d1a6
11da177e4SLinus TorvaldsVERSION = 2
21da177e4SLinus TorvaldsPATCHLEVEL = 6
317d857beSLinus TorvaldsSUBLEVEL = 32
4374576a8SLinus TorvaldsEXTRAVERSION = -rc3
559a3759dSLinus TorvaldsNAME = Man-Eating Seals of Antiquity
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
15d384e35aSLinus Nilsson#    (this increases performance and avoids hard-to-debug behaviour);
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
38b8b0618cSCheng Renquanifeq ("$(origin V)", "command line")
39b8b0618cSCheng Renquan  KBUILD_VERBOSE = $(V)
401da177e4SLinus Torvaldsendif
411da177e4SLinus Torvaldsifndef KBUILD_VERBOSE
421da177e4SLinus Torvalds  KBUILD_VERBOSE = 0
431da177e4SLinus Torvaldsendif
441da177e4SLinus Torvalds
451c7bafe7SRobert P. J. Day# Call a source code checker (by default, "sparse") as part of the
461c7bafe7SRobert P. J. Day# C compilation.
471c7bafe7SRobert P. J. Day#
481c7bafe7SRobert P. J. Day# Use 'make C=1' to enable checking of only re-compiled files.
491c7bafe7SRobert P. J. Day# Use 'make C=2' to enable checking of *all* source files, regardless
501c7bafe7SRobert P. J. Day# of whether they are re-compiled or not.
511c7bafe7SRobert P. J. Day#
521c7bafe7SRobert P. J. Day# See the file "Documentation/sparse.txt" for more details, including
531c7bafe7SRobert P. J. Day# where to get the "sparse" utility.
541da177e4SLinus Torvalds
55b8b0618cSCheng Renquanifeq ("$(origin C)", "command line")
56b8b0618cSCheng Renquan  KBUILD_CHECKSRC = $(C)
571da177e4SLinus Torvaldsendif
581da177e4SLinus Torvaldsifndef KBUILD_CHECKSRC
591da177e4SLinus Torvalds  KBUILD_CHECKSRC = 0
601da177e4SLinus Torvaldsendif
611da177e4SLinus Torvalds
621da177e4SLinus Torvalds# Use make M=dir to specify directory of external module to build
631da177e4SLinus Torvalds# Old syntax make ... SUBDIRS=$PWD is still supported
641da177e4SLinus Torvalds# Setting the environment variable KBUILD_EXTMOD take precedence
651da177e4SLinus Torvaldsifdef SUBDIRS
661da177e4SLinus Torvalds  KBUILD_EXTMOD ?= $(SUBDIRS)
671da177e4SLinus Torvaldsendif
681da177e4SLinus Torvalds
69b8b0618cSCheng Renquanifeq ("$(origin M)", "command line")
70b8b0618cSCheng Renquan  KBUILD_EXTMOD := $(M)
71b8b0618cSCheng Renquanendif
721da177e4SLinus Torvalds
731da177e4SLinus Torvalds# kbuild supports saving output files in a separate directory.
741da177e4SLinus Torvalds# To locate output files in a separate directory two syntaxes are supported.
751da177e4SLinus Torvalds# In both cases the working directory must be the root of the kernel src.
761da177e4SLinus Torvalds# 1) O=
771da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/"
78070b98bfSSam Ravnborg#
791da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT
801da177e4SLinus Torvalds# Set the environment variable KBUILD_OUTPUT to point to the directory
811da177e4SLinus Torvalds# where the output files shall be placed.
821da177e4SLinus Torvalds# export KBUILD_OUTPUT=dir/to/store/output/files/
831da177e4SLinus Torvalds# make
841da177e4SLinus Torvalds#
851da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment
861da177e4SLinus Torvalds# variable.
871da177e4SLinus Torvalds
881da177e4SLinus Torvalds
891da177e4SLinus Torvalds# KBUILD_SRC is set on invocation of make in OBJ directory
901da177e4SLinus Torvalds# KBUILD_SRC is not intended to be used by the regular user (for now)
911da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),)
921da177e4SLinus Torvalds
931da177e4SLinus Torvalds# OK, Make called in directory where kernel src resides
941da177e4SLinus Torvalds# Do we want to locate output files in a separate directory?
95b8b0618cSCheng Renquanifeq ("$(origin O)", "command line")
96b8b0618cSCheng Renquan  KBUILD_OUTPUT := $(O)
971da177e4SLinus Torvaldsendif
981da177e4SLinus Torvalds
991da177e4SLinus Torvalds# That's our default target when none is given on the command line
1004f193362SPaul SmithPHONY := _all
1011da177e4SLinus Torvalds_all:
1021da177e4SLinus Torvalds
1031cacc9abSSam Ravnborg# Cancel implicit rules on top Makefile
1041cacc9abSSam Ravnborg$(CURDIR)/Makefile Makefile: ;
1051cacc9abSSam Ravnborg
1061da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
1071da177e4SLinus Torvalds# Invoke a second make in the output directory, passing relevant variables
1081da177e4SLinus Torvalds# check that the output directory actually exists
1091da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
1101da177e4SLinus TorvaldsKBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
1111da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1121da177e4SLinus Torvalds     $(error output directory "$(saved-output)" does not exist))
1131da177e4SLinus Torvalds
1140b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1150b35786dSMilton Miller
1161cacc9abSSam Ravnborg$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
1170b35786dSMilton Miller	$(Q)@:
1180b35786dSMilton Miller
1190b35786dSMilton Millersub-make: FORCE
12023a45e2cSSam Ravnborg	$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
12123a45e2cSSam Ravnborg	KBUILD_SRC=$(CURDIR) \
1220b35786dSMilton Miller	KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile \
1230b35786dSMilton Miller	$(filter-out _all sub-make,$(MAKECMDGOALS))
1241da177e4SLinus Torvalds
1251da177e4SLinus Torvalds# Leave processing to above invocation of make
1261da177e4SLinus Torvaldsskip-makefile := 1
1271da177e4SLinus Torvaldsendif # ifneq ($(KBUILD_OUTPUT),)
1281da177e4SLinus Torvaldsendif # ifeq ($(KBUILD_SRC),)
1291da177e4SLinus Torvalds
1301da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
1311da177e4SLinus Torvaldsifeq ($(skip-makefile),)
1321da177e4SLinus Torvalds
1331da177e4SLinus Torvalds# If building an external module we do not care about the all: rule
1341da177e4SLinus Torvalds# but instead _all depend on modules
1354f193362SPaul SmithPHONY += all
1361da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
1371da177e4SLinus Torvalds_all: all
1381da177e4SLinus Torvaldselse
1391da177e4SLinus Torvalds_all: modules
1401da177e4SLinus Torvaldsendif
1411da177e4SLinus Torvalds
1421da177e4SLinus Torvaldssrctree		:= $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
1431da177e4SLinus Torvaldsobjtree		:= $(CURDIR)
1441da177e4SLinus Torvaldssrc		:= $(srctree)
1451da177e4SLinus Torvaldsobj		:= $(objtree)
1461da177e4SLinus Torvalds
1470f558c33SMattia DongiliVPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
1481da177e4SLinus Torvalds
14911294235SAmerigo Wangexport srctree objtree VPATH
1501da177e4SLinus Torvalds
1511da177e4SLinus Torvalds
1521da177e4SLinus Torvalds# SUBARCH tells the usermode build what the underlying arch is.  That is set
1531da177e4SLinus Torvalds# first, and if a usermode build is happening, the "ARCH=um" on the command
1541da177e4SLinus Torvalds# line overrides the setting of ARCH below.  If a native build is happening,
1551da177e4SLinus Torvalds# then ARCH is assigned, getting whatever value it gets normally, and 
1561da177e4SLinus Torvalds# SUBARCH is subsequently ignored.
1571da177e4SLinus Torvalds
1581da177e4SLinus TorvaldsSUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
1591da177e4SLinus Torvalds				  -e s/arm.*/arm/ -e s/sa110/arm/ \
16039990b5eSLinus Torvalds				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
161236b1957SPaul Mundt				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
1623cc000b5SPaul Mundt				  -e s/sh[234].*/sh/ )
1631da177e4SLinus Torvalds
1641da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
1651da177e4SLinus Torvalds# ---------------------------------------------------------------------------
1661da177e4SLinus Torvalds#
1671da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
1681da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
1691da177e4SLinus Torvalds# ARCH can be set during invocation of make:
1701da177e4SLinus Torvalds# make ARCH=ia64
1711da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
1721da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
1731da177e4SLinus Torvalds
1741da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
1751da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
1761da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
1771da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
1781da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
1791da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
1801da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
1811da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
1824ce6efedSSam Ravnborgexport KBUILD_BUILDHOST := $(SUBARCH)
1832331d1a6SSam RavnborgARCH		?= $(SUBARCH)
1842331d1a6SSam RavnborgCROSS_COMPILE	?=
1851da177e4SLinus Torvalds
1861da177e4SLinus Torvalds# Architecture as present in compile.h
1876752ed90SThomas GleixnerUTS_MACHINE 	:= $(ARCH)
1886752ed90SThomas GleixnerSRCARCH 	:= $(ARCH)
1891da177e4SLinus Torvalds
190d746d647SSam Ravnborg# Additional ARCH settings for x86
191d746d647SSam Ravnborgifeq ($(ARCH),i386)
192d746d647SSam Ravnborg        SRCARCH := x86
193d746d647SSam Ravnborgendif
194d746d647SSam Ravnborgifeq ($(ARCH),x86_64)
195d746d647SSam Ravnborg        SRCARCH := x86
196d746d647SSam Ravnborgendif
19774b469f2SSam Ravnborg
1985e538790SSam Ravnborg# Additional ARCH settings for sparc
199a439fe51SSam Ravnborgifeq ($(ARCH),sparc64)
2005e538790SSam Ravnborg       SRCARCH := sparc
201a439fe51SSam Ravnborgendif
2022fb9b1bdSSam Ravnborg
2033cc000b5SPaul Mundt# Additional ARCH settings for sh
2043cc000b5SPaul Mundtifeq ($(ARCH),sh64)
2053cc000b5SPaul Mundt       SRCARCH := sh
2063cc000b5SPaul Mundtendif
2073cc000b5SPaul Mundt
2085e538790SSam Ravnborg# Where to locate arch specific headers
2095e538790SSam Ravnborghdr-arch  := $(SRCARCH)
2105e538790SSam Ravnborg
21149148020SSam Ravnborgifeq ($(ARCH),m68knommu)
21249148020SSam Ravnborg       hdr-arch  := m68k
21349148020SSam Ravnborgendif
21449148020SSam Ravnborg
21514cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
21614cdd3c4SRoman Zippel
2171da177e4SLinus Torvalds# SHELL used by kbuild
2181da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
2191da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
2201da177e4SLinus Torvalds	  else echo sh; fi ; fi)
2211da177e4SLinus Torvalds
222070b98bfSSam RavnborgHOSTCC       = gcc
223070b98bfSSam RavnborgHOSTCXX      = g++
224070b98bfSSam RavnborgHOSTCFLAGS   = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
225070b98bfSSam RavnborgHOSTCXXFLAGS = -O2
2261da177e4SLinus Torvalds
227070b98bfSSam Ravnborg# Decide whether to build built-in, modular, or both.
228070b98bfSSam Ravnborg# Normally, just do built-in.
2291da177e4SLinus Torvalds
2301da177e4SLinus TorvaldsKBUILD_MODULES :=
2311da177e4SLinus TorvaldsKBUILD_BUILTIN := 1
2321da177e4SLinus Torvalds
2331da177e4SLinus Torvalds#	If we have only "make modules", don't compile built-in objects.
2341da177e4SLinus Torvalds#	When we're building modules with modversions, we need to consider
2351da177e4SLinus Torvalds#	the built-in objects during the descend as well, in order to
236070b98bfSSam Ravnborg#	make sure the checksums are up to date before we record them.
2371da177e4SLinus Torvalds
2381da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),modules)
2391da177e4SLinus Torvalds  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
2401da177e4SLinus Torvaldsendif
2411da177e4SLinus Torvalds
2421da177e4SLinus Torvalds#	If we have "make <whatever> modules", compile modules
2431da177e4SLinus Torvalds#	in addition to whatever we do anyway.
2441da177e4SLinus Torvalds#	Just "make" or "make all" shall build modules as well
2451da177e4SLinus Torvalds
2461da177e4SLinus Torvaldsifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
2471da177e4SLinus Torvalds  KBUILD_MODULES := 1
2481da177e4SLinus Torvaldsendif
2491da177e4SLinus Torvalds
2501da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),)
2511da177e4SLinus Torvalds  KBUILD_MODULES := 1
2521da177e4SLinus Torvaldsendif
2531da177e4SLinus Torvalds
254e579d351SSam Ravnborgexport KBUILD_MODULES KBUILD_BUILTIN
2561da177e4SLinus Torvalds
2571da177e4SLinus Torvalds# Beautify output
2581da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2591da177e4SLinus Torvalds#
2601da177e4SLinus Torvalds# Normally, we echo the whole command before executing it. By making
2611da177e4SLinus Torvalds# that echo $($(quiet)$(cmd)), we now have the possibility to set
2621da177e4SLinus Torvalds# $(quiet) to choose other forms of output instead, e.g.
2631da177e4SLinus Torvalds#
2641da177e4SLinus Torvalds#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
2651da177e4SLinus Torvalds#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
2661da177e4SLinus Torvalds#
2671da177e4SLinus Torvalds# If $(quiet) is empty, the whole command will be printed.
2681da177e4SLinus Torvalds# If it is set to "quiet_", only the short version will be printed. 
269070b98bfSSam Ravnborg# If it is set to "silent_", nothing will be printed at all, since
2701da177e4SLinus Torvalds# the variable $(silent_cmd_cc_o_c) doesn't exist.
2711da177e4SLinus Torvalds#
272a58a414fSAdrian Bunk# A simple variant is to prefix commands with $(Q) - that's useful
2731da177e4SLinus Torvalds# for commands that shall be hidden in non-verbose mode.
2741da177e4SLinus Torvalds#
2751da177e4SLinus Torvalds#	$(Q)ln $@ :<
2761da177e4SLinus Torvalds#
2771da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
2781da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 1 then the above command is displayed.
2791da177e4SLinus Torvalds
2801da177e4SLinus Torvaldsifeq ($(KBUILD_VERBOSE),1)
2811da177e4SLinus Torvalds  quiet =
2821da177e4SLinus Torvalds  Q =
2831da177e4SLinus Torvaldselse
2841da177e4SLinus Torvalds  quiet=quiet_
2851da177e4SLinus Torvalds  Q = @
2861da177e4SLinus Torvaldsendif
2871da177e4SLinus Torvalds
2881da177e4SLinus Torvalds# If the user is running make -s (silent mode), suppress echoing of
2891da177e4SLinus Torvalds# commands
2901da177e4SLinus Torvalds
2911da177e4SLinus Torvaldsifneq ($(findstring s,$(MAKEFLAGS)),)
2921da177e4SLinus Torvalds  quiet=silent_
2931da177e4SLinus Torvaldsendif
2941da177e4SLinus Torvalds
2951da177e4SLinus Torvaldsexport quiet Q KBUILD_VERBOSE
2961da177e4SLinus Torvalds
2971da177e4SLinus Torvalds
2981da177e4SLinus Torvalds# Look for make include files relative to root of kernel src
2991da177e4SLinus TorvaldsMAKEFLAGS += --include-dir=$(srctree)
3001da177e4SLinus Torvalds
3011cacc9abSSam Ravnborg# We need some generic definitions (do not try to remake the file).
3021cacc9abSSam Ravnborg$(srctree)/scripts/Kbuild.include: ;
30315964864SOleg Verychinclude $(srctree)/scripts/Kbuild.include
3041da177e4SLinus Torvalds
3051da177e4SLinus Torvalds# Make variables (CC, etc...)
3061da177e4SLinus Torvalds
3071da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
3081da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
3091da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
3101da177e4SLinus TorvaldsCPP		= $(CC) -E
3111da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
3121da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
3131da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
3141da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
3151da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
3161da177e4SLinus TorvaldsAWK		= awk
3171da177e4SLinus TorvaldsGENKSYMS	= scripts/genksyms/genksyms
318caa27b66SSam RavnborgINSTALLKERNEL  := installkernel
3191da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
3201da177e4SLinus TorvaldsKALLSYMS	= scripts/kallsyms
3211da177e4SLinus TorvaldsPERL		= perl
3221da177e4SLinus TorvaldsCHECK		= sparse
3231da177e4SLinus Torvalds
32480a7d1d9SHannes EderCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
32580a7d1d9SHannes Eder		  -Wbitwise -Wno-return-void $(CF)
3261da177e4SLinus TorvaldsMODFLAGS	= -DMODULE
3271da177e4SLinus TorvaldsCFLAGS_MODULE   = $(MODFLAGS)
3281da177e4SLinus TorvaldsAFLAGS_MODULE   = $(MODFLAGS)
329405d967dSTejun HeoLDFLAGS_MODULE  = -T $(srctree)/scripts/
3301da177e4SLinus TorvaldsCFLAGS_KERNEL	=
3311da177e4SLinus TorvaldsAFLAGS_KERNEL	=
3322521f2c2SPeter OberparleiterCFLAGS_GCOV	= -fprofile-arcs -ftest-coverage
3331da177e4SLinus Torvalds
3341da177e4SLinus Torvalds
3351da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
3361da177e4SLinus Torvalds# Needed to be compatible with the O= option
3371da177e4SLinus TorvaldsLINUXINCLUDE    := -Iinclude \
3382dd34b48SRussell King                   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \
3395e4786f7SSam Ravnborg                   -I$(srctree)/arch/$(hdr-arch)/include               \
3405e4786f7SSam Ravnborg                   -include include/linux/autoconf.h
3411da177e4SLinus Torvalds
342d8672b40SSam RavnborgKBUILD_CPPFLAGS := -D__KERNEL__
3431da177e4SLinus Torvalds
344a0f97e06SSam RavnborgKBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
34594bed2a9SDave Jones		   -fno-strict-aliasing -fno-common \
346a8735821SFloris Kraak		   -Werror-implicit-function-declaration \
347a3ca86aeSEugene Teo		   -Wno-format-security \
348a3ca86aeSEugene Teo		   -fno-delete-null-pointer-checks
349222d394dSSam RavnborgKBUILD_AFLAGS   := -D__ASSEMBLY__
3501da177e4SLinus Torvalds
351f1d28fb0SRoman Zippel# Read KERNELRELEASE from include/config/kernel.release (if it exists)
352f1d28fb0SRoman ZippelKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
354cb58455cSSam Ravnborg
357caa27b66SSam Ravnborgexport CPP AR NM STRIP OBJCOPY OBJDUMP
3601da177e4SLinus Torvalds
3641da177e4SLinus Torvalds
3651da177e4SLinus Torvalds# When compiling out-of-tree modules, put MODVERDIR in the module
3661da177e4SLinus Torvalds# tree rather than in the kernel tree. The kernel tree might
3671da177e4SLinus Torvalds# even be read-only.
3681da177e4SLinus Torvaldsexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
3691da177e4SLinus Torvalds
3701da177e4SLinus Torvalds# Files to ignore in find ... statements
3711da177e4SLinus Torvalds
372406119f4STrond 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
373406119f4STrond Myklebustexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc --exclude .hg --exclude .git
3741da177e4SLinus Torvalds
3751da177e4SLinus Torvalds# ===========================================================================
3761da177e4SLinus Torvalds# Rules shared between *config targets and build targets
3771da177e4SLinus Torvalds
3781da177e4SLinus Torvalds# Basic helpers built in scripts/
3794f193362SPaul SmithPHONY += scripts_basic
3801da177e4SLinus Torvaldsscripts_basic:
3811da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/basic
3821da177e4SLinus Torvalds
383cd05e6bdSJan Beulich# To avoid any implicit rule to kick in, define an empty command.
384cd05e6bdSJan Beulichscripts/basic/%: scripts_basic ;
385cd05e6bdSJan Beulich
3864f193362SPaul SmithPHONY += outputmakefile
387fd5f0cd6SJan Beulich# outputmakefile generates a Makefile in the output directory, if using a
388fd5f0cd6SJan Beulich# separate output directory. This allows convenient use of make in the
389fd5f0cd6SJan Beulich# output directory.
3901da177e4SLinus Torvaldsoutputmakefile:
391fd5f0cd6SJan Beulichifneq ($(KBUILD_SRC),)
39292979997SAndi Kleen	$(Q)ln -fsn $(srctree) source
393fd5f0cd6SJan Beulich	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
394fd5f0cd6SJan Beulich	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
395fd5f0cd6SJan Beulichendif
3961da177e4SLinus Torvalds
3971da177e4SLinus Torvalds# To make sure we do not include .config for any of the *config targets
3981da177e4SLinus Torvalds# catch them early, and hand them over to scripts/kconfig/Makefile
3991da177e4SLinus Torvalds# It is allowed to specify more targets when calling make, including
4001da177e4SLinus Torvalds# mixing *config targets and build targets.
401070b98bfSSam Ravnborg# For example 'make oldconfig all'.
4021da177e4SLinus Torvalds# Detect when mixed targets is specified, and make a second invocation
4031da177e4SLinus Torvalds# of make so .config is not included in this case either (for *config).
4041da177e4SLinus Torvalds
4053eb3c740SRoman Zippelno-dot-config-targets := clean mrproper distclean \
406c30a02e0SRoman Zippel			 cscope TAGS tags help %docs check% \
4073eb3c740SRoman Zippel			 include/linux/version.h headers_% \
4083eb3c740SRoman Zippel			 kernelrelease kernelversion
4091da177e4SLinus Torvalds
4101da177e4SLinus Torvaldsconfig-targets := 0
4111da177e4SLinus Torvaldsmixed-targets  := 0
4121da177e4SLinus Torvaldsdot-config     := 1
4131da177e4SLinus Torvalds
4141da177e4SLinus Torvaldsifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
4151da177e4SLinus Torvalds	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
4161da177e4SLinus Torvalds		dot-config := 0
4171da177e4SLinus Torvalds	endif
4181da177e4SLinus Torvaldsendif
4191da177e4SLinus Torvalds
4201da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
4211da177e4SLinus Torvalds        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
4221da177e4SLinus Torvalds                config-targets := 1
4231da177e4SLinus Torvalds                ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
4241da177e4SLinus Torvalds                        mixed-targets := 1
4251da177e4SLinus Torvalds                endif
4261da177e4SLinus Torvalds        endif
4271da177e4SLinus Torvaldsendif
4281da177e4SLinus Torvalds
4291da177e4SLinus Torvaldsifeq ($(mixed-targets),1)
4301da177e4SLinus Torvalds# ===========================================================================
4311da177e4SLinus Torvalds# We're called with mixed targets (*config and build targets).
4321da177e4SLinus Torvalds# Handle them one by one.
4331da177e4SLinus Torvalds
4341da177e4SLinus Torvalds%:: FORCE
4351da177e4SLinus Torvalds	$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
4361da177e4SLinus Torvalds
4371da177e4SLinus Torvaldselse
4381da177e4SLinus Torvaldsifeq ($(config-targets),1)
4391da177e4SLinus Torvalds# ===========================================================================
4401da177e4SLinus Torvalds# *config targets only - make sure prerequisites are updated, and descend
4411da177e4SLinus Torvalds# in scripts/kconfig to make the *config target
4421da177e4SLinus Torvalds
4431da177e4SLinus Torvalds# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
4441da177e4SLinus Torvalds# KBUILD_DEFCONFIG may point out an alternative default configuration
4451da177e4SLinus Torvalds# used for 'make defconfig'
44674b469f2SSam Ravnborginclude $(srctree)/arch/$(SRCARCH)/Makefile
4481da177e4SLinus Torvalds
44931110ebbSSam Ravnborgconfig: scripts_basic outputmakefile FORCE
45031110ebbSSam Ravnborg	$(Q)mkdir -p include/linux include/config
45131110ebbSSam Ravnborg	$(Q)$(MAKE) $(build)=scripts/kconfig $@
45231110ebbSSam Ravnborg
45331110ebbSSam Ravnborg%config: scripts_basic outputmakefile FORCE
454c955ccafSRoman Zippel	$(Q)mkdir -p include/linux include/config
4551da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/kconfig $@
4561da177e4SLinus Torvalds
4571da177e4SLinus Torvaldselse
4581da177e4SLinus Torvalds# ===========================================================================
4591da177e4SLinus Torvalds# Build targets only - this includes vmlinux, arch specific targets, clean
4601da177e4SLinus Torvalds# targets and others. In general all targets except *config targets.
4611da177e4SLinus Torvalds
4621da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
4631da177e4SLinus Torvalds# Additional helpers built in scripts/
4641da177e4SLinus Torvalds# Carefully list dependencies so we do not try to build scripts twice
465070b98bfSSam Ravnborg# in parallel
4664f193362SPaul SmithPHONY += scripts
4672e3646e5SRoman Zippelscripts: scripts_basic include/config/auto.conf
4681da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@)
4691da177e4SLinus Torvalds
4701da177e4SLinus Torvalds# Objects we will link into vmlinux / subdirs we need to visit
4711da177e4SLinus Torvaldsinit-y		:= init/
4724d2acfbfSDavid Woodhousedrivers-y	:= drivers/ sound/ firmware/
4731da177e4SLinus Torvaldsnet-y		:= net/
4741da177e4SLinus Torvaldslibs-y		:= lib/
4751da177e4SLinus Torvaldscore-y		:= usr/
4761da177e4SLinus Torvaldsendif # KBUILD_EXTMOD
4771da177e4SLinus Torvalds
4781da177e4SLinus Torvaldsifeq ($(dot-config),1)
4799ee4e336SSam Ravnborg# Read in config
4809ee4e336SSam Ravnborg-include include/config/auto.conf
4811da177e4SLinus Torvalds
4829ee4e336SSam Ravnborgifeq ($(KBUILD_EXTMOD),)
4831da177e4SLinus Torvalds# Read in dependencies to all Kconfig* files, make sure to run
4841da177e4SLinus Torvalds# oldconfig if changes are detected.
485c955ccafSRoman Zippel-include include/config/auto.conf.cmd
4861da177e4SLinus Torvalds
4871da177e4SLinus Torvalds# To avoid any implicit rule to kick in, define an empty command
48814cdd3c4SRoman Zippel$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
4891da177e4SLinus Torvalds
490c955ccafSRoman Zippel# If .config is newer than include/config/auto.conf, someone tinkered
491752625cfSSam Ravnborg# with it and forgot to run make oldconfig.
492070b98bfSSam Ravnborg# if auto.conf.cmd is missing then we are probably in a cleaned tree so
493752625cfSSam Ravnborg# we execute the config step to be sure to catch updated Kconfig files
49414cdd3c4SRoman Zippelinclude/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
4951da177e4SLinus Torvalds	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
4963041e47eSRoman Zippelelse
4979ee4e336SSam Ravnborg# external modules needs include/linux/autoconf.h and include/config/auto.conf
4989ee4e336SSam Ravnborg# but do not care if they are up-to-date. Use auto.conf to trigger the test
4999ee4e336SSam RavnborgPHONY += include/config/auto.conf
5009ee4e336SSam Ravnborg
5019ee4e336SSam Ravnborginclude/config/auto.conf:
5029ee4e336SSam Ravnborg	$(Q)test -e include/linux/autoconf.h -a -e $@ || (		\
5039ee4e336SSam Ravnborg	echo;								\
5049ee4e336SSam Ravnborg	echo "  ERROR: Kernel configuration is invalid.";		\
5059ee4e336SSam Ravnborg	echo "         include/linux/autoconf.h or $@ are missing.";	\
5069ee4e336SSam Ravnborg	echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";	\
5079ee4e336SSam Ravnborg	echo;								\
5089ee4e336SSam Ravnborg	/bin/false)
5099ee4e336SSam Ravnborg
5109ee4e336SSam Ravnborgendif # KBUILD_EXTMOD
511c955ccafSRoman Zippel
5121da177e4SLinus Torvaldselse
5131da177e4SLinus Torvalds# Dummy target needed, because used as prerequisite
514c955ccafSRoman Zippelinclude/config/auto.conf: ;
5159ee4e336SSam Ravnborgendif # $(dot-config)
5161da177e4SLinus Torvalds
5171da177e4SLinus Torvalds# The all: target is the default when no target is given on the
5181da177e4SLinus Torvalds# command line.
5191da177e4SLinus Torvalds# This allow a user to issue only 'make' to build a kernel including modules
520070b98bfSSam Ravnborg# Defaults vmlinux but it is usually overridden in the arch makefile
5211da177e4SLinus Torvaldsall: vmlinux
5221da177e4SLinus Torvalds
5231da177e4SLinus Torvaldsifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
524a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -Os
5251da177e4SLinus Torvaldselse
526a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -O2
5271da177e4SLinus Torvaldsendif
5281da177e4SLinus Torvalds
529bef5b54bSRalf Baechleinclude $(srctree)/arch/$(SRCARCH)/Makefile
530bef5b54bSRalf Baechle
53108f67461SMike Frysingerifneq ($(CONFIG_FRAME_WARN),0)
53235bb5b1eSAndi KleenKBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
53335bb5b1eSAndi Kleenendif
53435bb5b1eSAndi Kleen
535e06b8b98SSam Ravnborg# Force gcc to behave correct even for buggy distributions
5365d707e9cSTejun Heoifndef CONFIG_CC_STACKPROTECTOR
537e06b8b98SSam RavnborgKBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
5385d707e9cSTejun Heoendif
539e06b8b98SSam Ravnborg
5401da177e4SLinus Torvaldsifdef CONFIG_FRAME_POINTER
541a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls
5421da177e4SLinus Torvaldselse
543a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -fomit-frame-pointer
5441da177e4SLinus Torvaldsendif