Makefile revision 5e538790
11da177e4SLinus TorvaldsVERSION = 2
21da177e4SLinus TorvaldsPATCHLEVEL = 6
357f8f7b6SLinus TorvaldsSUBLEVEL = 28
4061e41fdSLinus TorvaldsEXTRAVERSION = -rc7
5061e41fdSLinus TorvaldsNAME = Erotic Pickled Herring
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
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
1111cacc9abSSam Ravnborg# Cancel implicit rules on top Makefile
1121cacc9abSSam Ravnborg$(CURDIR)/Makefile Makefile: ;
1131cacc9abSSam Ravnborg
1141da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
1151da177e4SLinus Torvalds# Invoke a second make in the output directory, passing relevant variables
1161da177e4SLinus Torvalds# check that the output directory actually exists
1171da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
1181da177e4SLinus TorvaldsKBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
1191da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1201da177e4SLinus Torvalds     $(error output directory "$(saved-output)" does not exist))
1211da177e4SLinus Torvalds
1220b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1230b35786dSMilton Miller
1241cacc9abSSam Ravnborg$(filter-out _all sub-make $(CURDIR)/Makefile, $(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/ \
17212760cb4SPaul Mundt				  -e s/sh.*/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
1924ce6efedSSam Ravnborgexport KBUILD_BUILDHOST := $(SUBARCH)
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
2085e538790SSam Ravnborg# Additional ARCH settings for sparc
209a439fe51SSam Ravnborgifeq ($(ARCH),sparc64)
2105e538790SSam Ravnborg       SRCARCH := sparc
211a439fe51SSam Ravnborgendif
2122fb9b1bdSSam Ravnborg
2135e538790SSam Ravnborg# Where to locate arch specific headers
2145e538790SSam Ravnborghdr-arch  := $(SRCARCH)
2155e538790SSam Ravnborg
21614cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
21714cdd3c4SRoman Zippel
2181da177e4SLinus Torvalds# SHELL used by kbuild
2191da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
2201da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
2211da177e4SLinus Torvalds	  else echo sh; fi ; fi)
2221da177e4SLinus Torvalds
223070b98bfSSam RavnborgHOSTCC       = gcc
224070b98bfSSam RavnborgHOSTCXX      = g++
225070b98bfSSam RavnborgHOSTCFLAGS   = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
226070b98bfSSam RavnborgHOSTCXXFLAGS = -O2
2271da177e4SLinus Torvalds
228070b98bfSSam Ravnborg# Decide whether to build built-in, modular, or both.
229070b98bfSSam Ravnborg# Normally, just do built-in.
2301da177e4SLinus Torvalds
2311da177e4SLinus TorvaldsKBUILD_MODULES :=
2321da177e4SLinus TorvaldsKBUILD_BUILTIN := 1
2331da177e4SLinus Torvalds
2341da177e4SLinus Torvalds#	If we have only "make modules", don't compile built-in objects.
2351da177e4SLinus Torvalds#	When we're building modules with modversions, we need to consider
2361da177e4SLinus Torvalds#	the built-in objects during the descend as well, in order to
237070b98bfSSam Ravnborg#	make sure the checksums are up to date before we record them.
2381da177e4SLinus Torvalds
2391da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),modules)
2401da177e4SLinus Torvalds  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
2411da177e4SLinus Torvaldsendif
2421da177e4SLinus Torvalds
2431da177e4SLinus Torvalds#	If we have "make <whatever> modules", compile modules
2441da177e4SLinus Torvalds#	in addition to whatever we do anyway.
2451da177e4SLinus Torvalds#	Just "make" or "make all" shall build modules as well
2461da177e4SLinus Torvalds
2471da177e4SLinus Torvaldsifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
2481da177e4SLinus Torvalds  KBUILD_MODULES := 1
2491da177e4SLinus Torvaldsendif
2501da177e4SLinus Torvalds
2511da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),)
2521da177e4SLinus Torvalds  KBUILD_MODULES := 1
2531da177e4SLinus Torvaldsendif
2541da177e4SLinus Torvalds
255e579d351SSam Ravnborgexport KBUILD_MODULES KBUILD_BUILTIN
2571da177e4SLinus Torvalds
2581da177e4SLinus Torvalds# Beautify output
2591da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2601da177e4SLinus Torvalds#
2611da177e4SLinus Torvalds# Normally, we echo the whole command before executing it. By making
2621da177e4SLinus Torvalds# that echo $($(quiet)$(cmd)), we now have the possibility to set
2631da177e4SLinus Torvalds# $(quiet) to choose other forms of output instead, e.g.
2641da177e4SLinus Torvalds#
2651da177e4SLinus Torvalds#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
2661da177e4SLinus Torvalds#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
2671da177e4SLinus Torvalds#
2681da177e4SLinus Torvalds# If $(quiet) is empty, the whole command will be printed.
2691da177e4SLinus Torvalds# If it is set to "quiet_", only the short version will be printed. 
270070b98bfSSam Ravnborg# If it is set to "silent_", nothing will be printed at all, since
2711da177e4SLinus Torvalds# the variable $(silent_cmd_cc_o_c) doesn't exist.
2721da177e4SLinus Torvalds#
273a58a414fSAdrian Bunk# A simple variant is to prefix commands with $(Q) - that's useful
2741da177e4SLinus Torvalds# for commands that shall be hidden in non-verbose mode.
2751da177e4SLinus Torvalds#
2761da177e4SLinus Torvalds#	$(Q)ln $@ :<
2771da177e4SLinus Torvalds#
2781da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
2791da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 1 then the above command is displayed.
2801da177e4SLinus Torvalds
2811da177e4SLinus Torvaldsifeq ($(KBUILD_VERBOSE),1)
2821da177e4SLinus Torvalds  quiet =
2831da177e4SLinus Torvalds  Q =
2841da177e4SLinus Torvaldselse
2851da177e4SLinus Torvalds  quiet=quiet_
2861da177e4SLinus Torvalds  Q = @
2871da177e4SLinus Torvaldsendif
2881da177e4SLinus Torvalds
2891da177e4SLinus Torvalds# If the user is running make -s (silent mode), suppress echoing of
2901da177e4SLinus Torvalds# commands
2911da177e4SLinus Torvalds
2921da177e4SLinus Torvaldsifneq ($(findstring s,$(MAKEFLAGS)),)
2931da177e4SLinus Torvalds  quiet=silent_
2941da177e4SLinus Torvaldsendif
2951da177e4SLinus Torvalds
2961da177e4SLinus Torvaldsexport quiet Q KBUILD_VERBOSE
2971da177e4SLinus Torvalds
2981da177e4SLinus Torvalds
2991da177e4SLinus Torvalds# Look for make include files relative to root of kernel src
3001da177e4SLinus TorvaldsMAKEFLAGS += --include-dir=$(srctree)
3011da177e4SLinus Torvalds
3021cacc9abSSam Ravnborg# We need some generic definitions (do not try to remake the file).
3031cacc9abSSam Ravnborg$(srctree)/scripts/Kbuild.include: ;
30415964864SOleg Verychinclude $(srctree)/scripts/Kbuild.include
3051da177e4SLinus Torvalds
3061da177e4SLinus Torvalds# Make variables (CC, etc...)
3071da177e4SLinus Torvalds
3081da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
3091da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
3101da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
3111da177e4SLinus TorvaldsCPP		= $(CC) -E
3121da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
3131da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
3141da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
3151da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
3161da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
3171da177e4SLinus TorvaldsAWK		= awk
3181da177e4SLinus TorvaldsGENKSYMS	= scripts/genksyms/genksyms
3191da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
3201da177e4SLinus TorvaldsKALLSYMS	= scripts/kallsyms
3211da177e4SLinus TorvaldsPERL		= perl
3221da177e4SLinus TorvaldsCHECK		= sparse
3231da177e4SLinus Torvalds
324af4ca457SAl ViroCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF)
3251da177e4SLinus TorvaldsMODFLAGS	= -DMODULE
3261da177e4SLinus TorvaldsCFLAGS_MODULE   = $(MODFLAGS)
3271da177e4SLinus TorvaldsAFLAGS_MODULE   = $(MODFLAGS)
328114f5157SRoland McGrathLDFLAGS_MODULE  =
3291da177e4SLinus TorvaldsCFLAGS_KERNEL	=
3301da177e4SLinus TorvaldsAFLAGS_KERNEL	=
3311da177e4SLinus Torvalds
3321da177e4SLinus Torvalds
3331da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
3341da177e4SLinus Torvalds# Needed to be compatible with the O= option
3351da177e4SLinus TorvaldsLINUXINCLUDE    := -Iinclude \
3362dd34b48SRussell King                   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \
3375e4786f7SSam Ravnborg                   -I$(srctree)/arch/$(hdr-arch)/include               \
3385e4786f7SSam Ravnborg                   -include include/linux/autoconf.h
3391da177e4SLinus Torvalds
3411da177e4SLinus Torvalds
342a0f97e06SSam RavnborgKBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
34394bed2a9SDave Jones		   -fno-strict-aliasing -fno-common \
34494bed2a9SDave Jones		   -Werror-implicit-function-declaration
345222d394dSSam RavnborgKBUILD_AFLAGS   := -D__ASSEMBLY__
3461da177e4SLinus Torvalds
347f1d28fb0SRoman Zippel# Read KERNELRELEASE from include/config/kernel.release (if it exists)
348f1d28fb0SRoman ZippelKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
350cb58455cSSam Ravnborg
3551da177e4SLinus Torvalds
3591da177e4SLinus Torvalds
3601da177e4SLinus Torvalds# When compiling out-of-tree modules, put MODVERDIR in the module
3611da177e4SLinus Torvalds# tree rather than in the kernel tree. The kernel tree might
3621da177e4SLinus Torvalds# even be read-only.
3631da177e4SLinus Torvaldsexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
3641da177e4SLinus Torvalds
3651da177e4SLinus Torvalds# Files to ignore in find ... statements
3661da177e4SLinus Torvalds
367406119f4STrond 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
368406119f4STrond Myklebustexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc --exclude .hg --exclude .git
3691da177e4SLinus Torvalds
3701da177e4SLinus Torvalds# ===========================================================================
3711da177e4SLinus Torvalds# Rules shared between *config targets and build targets
3721da177e4SLinus Torvalds
3731da177e4SLinus Torvalds# Basic helpers built in scripts/
3744f193362SPaul SmithPHONY += scripts_basic
3751da177e4SLinus Torvaldsscripts_basic:
3761da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/basic
3771da177e4SLinus Torvalds
378cd05e6bdSJan Beulich# To avoid any implicit rule to kick in, define an empty command.
379cd05e6bdSJan Beulichscripts/basic/%: scripts_basic ;
380cd05e6bdSJan Beulich
3814f193362SPaul SmithPHONY += outputmakefile
382fd5f0cd6SJan Beulich# outputmakefile generates a Makefile in the output directory, if using a
383fd5f0cd6SJan Beulich# separate output directory. This allows convenient use of make in the
384fd5f0cd6SJan Beulich# output directory.
3851da177e4SLinus Torvaldsoutputmakefile:
386fd5f0cd6SJan Beulichifneq ($(KBUILD_SRC),)
387fd5f0cd6SJan Beulich	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
388fd5f0cd6SJan Beulich	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
389fd5f0cd6SJan Beulichendif
3901da177e4SLinus Torvalds
3911da177e4SLinus Torvalds# To make sure we do not include .config for any of the *config targets
3921da177e4SLinus Torvalds# catch them early, and hand them over to scripts/kconfig/Makefile
3931da177e4SLinus Torvalds# It is allowed to specify more targets when calling make, including
3941da177e4SLinus Torvalds# mixing *config targets and build targets.
395070b98bfSSam Ravnborg# For example 'make oldconfig all'.
3961da177e4SLinus Torvalds# Detect when mixed targets is specified, and make a second invocation
3971da177e4SLinus Torvalds# of make so .config is not included in this case either (for *config).
3981da177e4SLinus Torvalds
3993eb3c740SRoman Zippelno-dot-config-targets := clean mrproper distclean \
400c30a02e0SRoman Zippel			 cscope TAGS tags help %docs check% \
4013eb3c740SRoman Zippel			 include/linux/version.h headers_% \
4023eb3c740SRoman Zippel			 kernelrelease kernelversion
4031da177e4SLinus Torvalds
4041da177e4SLinus Torvaldsconfig-targets := 0
4051da177e4SLinus Torvaldsmixed-targets  := 0
4061da177e4SLinus Torvaldsdot-config     := 1
4071da177e4SLinus Torvalds
4081da177e4SLinus Torvaldsifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
4091da177e4SLinus Torvalds	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
4101da177e4SLinus Torvalds		dot-config := 0
4111da177e4SLinus Torvalds	endif
4121da177e4SLinus Torvaldsendif
4131da177e4SLinus Torvalds
4141da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
4151da177e4SLinus Torvalds        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
4161da177e4SLinus Torvalds                config-targets := 1
4171da177e4SLinus Torvalds                ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
4181da177e4SLinus Torvalds                        mixed-targets := 1
4191da177e4SLinus Torvalds                endif
4201da177e4SLinus Torvalds        endif
4211da177e4SLinus Torvaldsendif
4221da177e4SLinus Torvalds
4231da177e4SLinus Torvaldsifeq ($(mixed-targets),1)
4241da177e4SLinus Torvalds# ===========================================================================
4251da177e4SLinus Torvalds# We're called with mixed targets (*config and build targets).
4261da177e4SLinus Torvalds# Handle them one by one.
4271da177e4SLinus Torvalds
4281da177e4SLinus Torvalds%:: FORCE
4291da177e4SLinus Torvalds	$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
4301da177e4SLinus Torvalds
4311da177e4SLinus Torvaldselse
4321da177e4SLinus Torvaldsifeq ($(config-targets),1)
4331da177e4SLinus Torvalds# ===========================================================================
4341da177e4SLinus Torvalds# *config targets only - make sure prerequisites are updated, and descend
4351da177e4SLinus Torvalds# in scripts/kconfig to make the *config target
4361da177e4SLinus Torvalds
4371da177e4SLinus Torvalds# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
4381da177e4SLinus Torvalds# KBUILD_DEFCONFIG may point out an alternative default configuration
4391da177e4SLinus Torvalds# used for 'make defconfig'
44074b469f2SSam Ravnborginclude $(srctree)/arch/$(SRCARCH)/Makefile
4421da177e4SLinus Torvalds
443cd05e6bdSJan Beulichconfig %config: scripts_basic outputmakefile FORCE
444c955ccafSRoman Zippel	$(Q)mkdir -p include/linux include/config
4451da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/kconfig $@
4461da177e4SLinus Torvalds
4471da177e4SLinus Torvaldselse
4481da177e4SLinus Torvalds# ===========================================================================
4491da177e4SLinus Torvalds# Build targets only - this includes vmlinux, arch specific targets, clean
4501da177e4SLinus Torvalds# targets and others. In general all targets except *config targets.
4511da177e4SLinus Torvalds
4521da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
4531da177e4SLinus Torvalds# Additional helpers built in scripts/
4541da177e4SLinus Torvalds# Carefully list dependencies so we do not try to build scripts twice
455070b98bfSSam Ravnborg# in parallel
4564f193362SPaul SmithPHONY += scripts
4572e3646e5SRoman Zippelscripts: scripts_basic include/config/auto.conf
4581da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@)
4591da177e4SLinus Torvalds
4601da177e4SLinus Torvalds# Objects we will link into vmlinux / subdirs we need to visit
4611da177e4SLinus Torvaldsinit-y		:= init/
4624d2acfbfSDavid Woodhousedrivers-y	:= drivers/ sound/ firmware/
4631da177e4SLinus Torvaldsnet-y		:= net/
4641da177e4SLinus Torvaldslibs-y		:= lib/
4651da177e4SLinus Torvaldscore-y		:= usr/
4661da177e4SLinus Torvaldsendif # KBUILD_EXTMOD
4671da177e4SLinus Torvalds
4681da177e4SLinus Torvaldsifeq ($(dot-config),1)
4699ee4e336SSam Ravnborg# Read in config
4709ee4e336SSam Ravnborg-include include/config/auto.conf
4711da177e4SLinus Torvalds
4729ee4e336SSam Ravnborgifeq ($(KBUILD_EXTMOD),)
4731da177e4SLinus Torvalds# Read in dependencies to all Kconfig* files, make sure to run
4741da177e4SLinus Torvalds# oldconfig if changes are detected.
475c955ccafSRoman Zippel-include include/config/auto.conf.cmd
4761da177e4SLinus Torvalds
4771da177e4SLinus Torvalds# To avoid any implicit rule to kick in, define an empty command
47814cdd3c4SRoman Zippel$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
4791da177e4SLinus Torvalds
480c955ccafSRoman Zippel# If .config is newer than include/config/auto.conf, someone tinkered
481752625cfSSam Ravnborg# with it and forgot to run make oldconfig.
482070b98bfSSam Ravnborg# if auto.conf.cmd is missing then we are probably in a cleaned tree so
483752625cfSSam Ravnborg# we execute the config step to be sure to catch updated Kconfig files
48414cdd3c4SRoman Zippelinclude/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
4851da177e4SLinus Torvalds	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
4863041e47eSRoman Zippelelse
4879ee4e336SSam Ravnborg# external modules needs include/linux/autoconf.h and include/config/auto.conf
4889ee4e336SSam Ravnborg# but do not care if they are up-to-date. Use auto.conf to trigger the test
4899ee4e336SSam RavnborgPHONY += include/config/auto.conf
4909ee4e336SSam Ravnborg
4919ee4e336SSam Ravnborginclude/config/auto.conf:
4929ee4e336SSam Ravnborg	$(Q)test -e include/linux/autoconf.h -a -e $@ || (		\
4939ee4e336SSam Ravnborg	echo;								\
4949ee4e336SSam Ravnborg	echo "  ERROR: Kernel configuration is invalid.";		\
4959ee4e336SSam Ravnborg	echo "         include/linux/autoconf.h or $@ are missing.";	\
4969ee4e336SSam Ravnborg	echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";	\
4979ee4e336SSam Ravnborg	echo;								\
4989ee4e336SSam Ravnborg	/bin/false)
4999ee4e336SSam Ravnborg
5009ee4e336SSam Ravnborgendif # KBUILD_EXTMOD
501c955ccafSRoman Zippel
5021da177e4SLinus Torvaldselse
5031da177e4SLinus Torvalds# Dummy target needed, because used as prerequisite
504c955ccafSRoman Zippelinclude/config/auto.conf: ;
5059ee4e336SSam Ravnborgendif # $(dot-config)
5061da177e4SLinus Torvalds
5071da177e4SLinus Torvalds# The all: target is the default when no target is given on the
5081da177e4SLinus Torvalds# command line.
5091da177e4SLinus Torvalds# This allow a user to issue only 'make' to build a kernel including modules
510070b98bfSSam Ravnborg# Defaults vmlinux but it is usually overridden in the arch makefile
5111da177e4SLinus Torvaldsall: vmlinux
5121da177e4SLinus Torvalds
5131da177e4SLinus Torvaldsifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
514a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -Os
5151da177e4SLinus Torvaldselse
516a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -O2
5171da177e4SLinus Torvaldsendif
5181da177e4SLinus Torvalds
519bef5b54bSRalf Baechleinclude $(srctree)/arch/$(SRCARCH)/Makefile
520bef5b54bSRalf Baechle
52135bb5b1eSAndi Kleenifneq (CONFIG_FRAME_WARN,0)
52235bb5b1eSAndi KleenKBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
52335bb5b1eSAndi Kleenendif
52435bb5b1eSAndi Kleen
525e06b8b98SSam Ravnborg# Force gcc to behave correct even for buggy distributions
526e06b8b98SSam Ravnborg# Arch Makefiles may override this setting
527e06b8b98SSam RavnborgKBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
528e06b8b98SSam Ravnborg
5291da177e4SLinus Torvaldsifdef CONFIG_FRAME_POINTER
530a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls
5311da177e4SLinus Torvaldselse
532a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -fomit-frame-pointer
5331da177e4SLinus Torvaldsendif
5341da177e4SLinus Torvalds
5351da177e4SLinus Torvaldsifdef CONFIG_DEBUG_INFO
536a0f97e06SSam RavnborgKBUILD_CFLAGS	+= -g
537222d394dSSam RavnborgKBUILD_AFLAGS	+= -gdwarf-2
5381da177e4SLinus Torvaldsendif
5391da177e4SLinus Torvalds
540606576ceSSteven Rostedtifdef CONFIG_FUNCTION_TRACER
54116444a8aSArnaldo Carvalho de MeloKBUILD_CFLAGS	+= -pg
54216444a8aSArnaldo Carvalho de Meloendif
54316444a8aSArnaldo Carvalho de Melo
54491341d4bSSam Ravnborg# We trigger additional mismatches with less inlining
54591341d4bSSam Ravnborgifdef CONFIG_DEBUG_SECTION_MISMATCH
54691341d4bSSam RavnborgKBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
54791341d4bSSam Ravnborgendif
54891341d4bSSam Ravnborg
549e8e69931SSam Ravnborg# arch Makefile may override CC so keep this after arch Makefile is included
550e8f5bdb0SRik van RielNOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
551e8e69931SSam RavnborgCHECKFLAGS     += $(NOSTDINC_FLAGS)
552e8e69931SSam Ravnborg
5531da177e4SLinus Torvalds# warn about C99 declaration after statement
554a0f97e06SSam RavnborgKBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
5551da177e4SLinus Torvalds
556070b98bfSSam Ravnborg# disable pointer signed / unsigned warnings in gcc 4.0
557a0f97e06SSam RavnborgKBUILD_CFLAGS += $(call cc-option,-Wno-pointer-sign,)
5581da177e4SLinus Torvalds
55906c5040cSSam Ravnborg# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
56069ee0b35SSam Ravnborg# But warn user when we do so
56169ee0b35SSam Ravnborgwarn-assign = \
56269ee0b35SSam Ravnborg$(warning "WARNING: Appending $$K$(1) ($(K$(1))) from $(origin K$(1)) to kernel $$$(1)")
56369ee0b35SSam Ravnborg
56469ee0b35SSam Ravnborgifneq ($(KCPPFLAGS),)
56569ee0b35SSam Ravnborg        $(call warn-assign,CPPFLAGS)
56669ee0b35SSam Ravnborg        KBUILD_CPPFLAGS += $(KCPPFLAGS)
56769ee0b35SSam Ravnborgendif
56869ee0b35SSam Ravnborgifneq ($(KAFLAGS),)
56969ee0b35SSam Ravnborg        $(call warn-assign,AFLAGS)
57069ee0b35SSam Ravnborg        KBUILD_AFLAGS += $(KAFLAGS)
57169ee0b35SSam Ravnborgendif
57269ee0b35SSam Ravnborgifneq ($(KCFLAGS),)
57369ee0b35SSam Ravnborg        $(call warn-assign,CFLAGS)
57469ee0b35SSam Ravnborg        KBUILD_CFLAGS += $(KCFLAGS)