Makefile revision 14cdd3c4
11da177e4SLinus TorvaldsVERSION = 2
21da177e4SLinus TorvaldsPATCHLEVEL = 6
36246b612SLinus TorvaldsSUBLEVEL = 17
41def630aSLinus TorvaldsEXTRAVERSION =-rc6
51def630aSLinus TorvaldsNAME=Crazed Snow-Weasel
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
131da177e4SLinus Torvalds# Do not print "Entering directory ..."
141da177e4SLinus TorvaldsMAKEFLAGS += --no-print-directory
151da177e4SLinus Torvalds
161da177e4SLinus Torvalds# We are using a recursive build, so we need to do a little thinking
171da177e4SLinus Torvalds# to get the ordering right.
181da177e4SLinus Torvalds#
191da177e4SLinus Torvalds# Most importantly: sub-Makefiles should only ever modify files in
201da177e4SLinus Torvalds# their own directory. If in some directory we have a dependency on
211da177e4SLinus Torvalds# a file in another dir (which doesn't happen often, but it's often
221da177e4SLinus Torvalds# unavoidable when linking the built-in.o targets which finally
231da177e4SLinus Torvalds# turn into vmlinux), we will call a sub make in that other dir, and
241da177e4SLinus Torvalds# after that we are sure that everything which is in that other dir
251da177e4SLinus Torvalds# is now up to date.
261da177e4SLinus Torvalds#
271da177e4SLinus Torvalds# The only cases where we need to modify files which have global
281da177e4SLinus Torvalds# effects are thus separated out and done before the recursive
291da177e4SLinus Torvalds# descending is started. They are now explicitly listed as the
301da177e4SLinus Torvalds# prepare rule.
311da177e4SLinus Torvalds
321da177e4SLinus Torvalds# To put more focus on warnings, be less verbose as default
331da177e4SLinus Torvalds# Use 'make V=1' to see the full commands
341da177e4SLinus Torvalds
351da177e4SLinus Torvaldsifdef V
361da177e4SLinus Torvalds  ifeq ("$(origin V)", "command line")
371da177e4SLinus Torvalds    KBUILD_VERBOSE = $(V)
381da177e4SLinus Torvalds  endif
391da177e4SLinus Torvaldsendif
401da177e4SLinus Torvaldsifndef KBUILD_VERBOSE
411da177e4SLinus Torvalds  KBUILD_VERBOSE = 0
421da177e4SLinus Torvaldsendif
431da177e4SLinus Torvalds
441da177e4SLinus Torvalds# Call sparse as part of compilation of C files
451da177e4SLinus Torvalds# Use 'make C=1' to enable sparse checking
461da177e4SLinus Torvalds
471da177e4SLinus Torvaldsifdef C
481da177e4SLinus Torvalds  ifeq ("$(origin C)", "command line")
491da177e4SLinus Torvalds    KBUILD_CHECKSRC = $(C)
501da177e4SLinus Torvalds  endif
511da177e4SLinus Torvaldsendif
521da177e4SLinus Torvaldsifndef KBUILD_CHECKSRC
531da177e4SLinus Torvalds  KBUILD_CHECKSRC = 0
541da177e4SLinus Torvaldsendif
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds# Use make M=dir to specify directory of external module to build
571da177e4SLinus Torvalds# Old syntax make ... SUBDIRS=$PWD is still supported
581da177e4SLinus Torvalds# Setting the environment variable KBUILD_EXTMOD take precedence
591da177e4SLinus Torvaldsifdef SUBDIRS
601da177e4SLinus Torvalds  KBUILD_EXTMOD ?= $(SUBDIRS)
611da177e4SLinus Torvaldsendif
621da177e4SLinus Torvaldsifdef M
631da177e4SLinus Torvalds  ifeq ("$(origin M)", "command line")
641da177e4SLinus Torvalds    KBUILD_EXTMOD := $(M)
651da177e4SLinus Torvalds  endif
661da177e4SLinus Torvaldsendif
671da177e4SLinus Torvalds
681da177e4SLinus Torvalds
691da177e4SLinus Torvalds# kbuild supports saving output files in a separate directory.
701da177e4SLinus Torvalds# To locate output files in a separate directory two syntaxes are supported.
711da177e4SLinus Torvalds# In both cases the working directory must be the root of the kernel src.
721da177e4SLinus Torvalds# 1) O=
731da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/"
741da177e4SLinus Torvalds# 
751da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT
761da177e4SLinus Torvalds# Set the environment variable KBUILD_OUTPUT to point to the directory
771da177e4SLinus Torvalds# where the output files shall be placed.
781da177e4SLinus Torvalds# export KBUILD_OUTPUT=dir/to/store/output/files/
791da177e4SLinus Torvalds# make
801da177e4SLinus Torvalds#
811da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment
821da177e4SLinus Torvalds# variable.
831da177e4SLinus Torvalds
841da177e4SLinus Torvalds
851da177e4SLinus Torvalds# KBUILD_SRC is set on invocation of make in OBJ directory
861da177e4SLinus Torvalds# KBUILD_SRC is not intended to be used by the regular user (for now)
871da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),)
881da177e4SLinus Torvalds
891da177e4SLinus Torvalds# OK, Make called in directory where kernel src resides
901da177e4SLinus Torvalds# Do we want to locate output files in a separate directory?
911da177e4SLinus Torvaldsifdef O
921da177e4SLinus Torvalds  ifeq ("$(origin O)", "command line")
931da177e4SLinus Torvalds    KBUILD_OUTPUT := $(O)
941da177e4SLinus Torvalds  endif
951da177e4SLinus Torvaldsendif
961da177e4SLinus Torvalds
971da177e4SLinus Torvalds# That's our default target when none is given on the command line
984f193362SPaul SmithPHONY := _all
991da177e4SLinus Torvalds_all:
1001da177e4SLinus Torvalds
1011da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
1021da177e4SLinus Torvalds# Invoke a second make in the output directory, passing relevant variables
1031da177e4SLinus Torvalds# check that the output directory actually exists
1041da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
1051da177e4SLinus TorvaldsKBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
1061da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1071da177e4SLinus Torvalds     $(error output directory "$(saved-output)" does not exist))
1081da177e4SLinus Torvalds
1094f193362SPaul SmithPHONY += $(MAKECMDGOALS)
1101da177e4SLinus Torvalds
11136cbbe5eSBenjamin LaHaise$(filter-out _all,$(MAKECMDGOALS)) _all:
11223a45e2cSSam Ravnborg	$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
11323a45e2cSSam Ravnborg	KBUILD_SRC=$(CURDIR) \
11436cbbe5eSBenjamin LaHaise	KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile $@
1151da177e4SLinus Torvalds
1161da177e4SLinus Torvalds# Leave processing to above invocation of make
1171da177e4SLinus Torvaldsskip-makefile := 1
1181da177e4SLinus Torvaldsendif # ifneq ($(KBUILD_OUTPUT),)
1191da177e4SLinus Torvaldsendif # ifeq ($(KBUILD_SRC),)
1201da177e4SLinus Torvalds
1211da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
1221da177e4SLinus Torvaldsifeq ($(skip-makefile),)
1231da177e4SLinus Torvalds
1241da177e4SLinus Torvalds# If building an external module we do not care about the all: rule
1251da177e4SLinus Torvalds# but instead _all depend on modules
1264f193362SPaul SmithPHONY += all
1271da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
1281da177e4SLinus Torvalds_all: all
1291da177e4SLinus Torvaldselse
1301da177e4SLinus Torvalds_all: modules
1311da177e4SLinus Torvaldsendif
1321da177e4SLinus Torvalds
1331da177e4SLinus Torvaldssrctree		:= $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
1341da177e4SLinus TorvaldsTOPDIR		:= $(srctree)
1351da177e4SLinus Torvalds# FIXME - TOPDIR is obsolete, use srctree/objtree
1361da177e4SLinus Torvaldsobjtree		:= $(CURDIR)
1371da177e4SLinus Torvaldssrc		:= $(srctree)
1381da177e4SLinus Torvaldsobj		:= $(objtree)
1391da177e4SLinus Torvalds
1400f558c33SMattia DongiliVPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
1411da177e4SLinus Torvalds
1421da177e4SLinus Torvaldsexport srctree objtree VPATH TOPDIR
1431da177e4SLinus Torvalds
1441da177e4SLinus Torvalds
1451da177e4SLinus Torvalds# SUBARCH tells the usermode build what the underlying arch is.  That is set
1461da177e4SLinus Torvalds# first, and if a usermode build is happening, the "ARCH=um" on the command
1471da177e4SLinus Torvalds# line overrides the setting of ARCH below.  If a native build is happening,
1481da177e4SLinus Torvalds# then ARCH is assigned, getting whatever value it gets normally, and 
1491da177e4SLinus Torvalds# SUBARCH is subsequently ignored.
1501da177e4SLinus Torvalds
1511da177e4SLinus TorvaldsSUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
1521da177e4SLinus Torvalds				  -e s/arm.*/arm/ -e s/sa110/arm/ \
15339990b5eSLinus Torvalds				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
1548999257cSMartin Michlmayr				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
1551da177e4SLinus Torvalds
1561da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
1571da177e4SLinus Torvalds# ---------------------------------------------------------------------------
1581da177e4SLinus Torvalds#
1591da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
1601da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
1611da177e4SLinus Torvalds# ARCH can be set during invocation of make:
1621da177e4SLinus Torvalds# make ARCH=ia64
1631da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
1641da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
1651da177e4SLinus Torvalds
1661da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
1671da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
1681da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
1691da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
1701da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
1711da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
1721da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
1731da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
1741da177e4SLinus Torvalds
1751da177e4SLinus TorvaldsARCH		?= $(SUBARCH)
1761da177e4SLinus TorvaldsCROSS_COMPILE	?=
1771da177e4SLinus Torvalds
1781da177e4SLinus Torvalds# Architecture as present in compile.h
1791da177e4SLinus TorvaldsUTS_MACHINE := $(ARCH)
1801da177e4SLinus Torvalds
18114cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
18214cdd3c4SRoman Zippel
1831da177e4SLinus Torvalds# SHELL used by kbuild
1841da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
1851da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
1861da177e4SLinus Torvalds	  else echo sh; fi ; fi)
1871da177e4SLinus Torvalds
1881da177e4SLinus TorvaldsHOSTCC  	= gcc
1891da177e4SLinus TorvaldsHOSTCXX  	= g++
1901da177e4SLinus TorvaldsHOSTCFLAGS	= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
1911da177e4SLinus TorvaldsHOSTCXXFLAGS	= -O2
1921da177e4SLinus Torvalds
1931da177e4SLinus Torvalds# 	Decide whether to build built-in, modular, or both.
1941da177e4SLinus Torvalds#	Normally, just do built-in.
1951da177e4SLinus Torvalds
1961da177e4SLinus TorvaldsKBUILD_MODULES :=
1971da177e4SLinus TorvaldsKBUILD_BUILTIN := 1
1981da177e4SLinus Torvalds
1991da177e4SLinus Torvalds#	If we have only "make modules", don't compile built-in objects.
2001da177e4SLinus Torvalds#	When we're building modules with modversions, we need to consider
2011da177e4SLinus Torvalds#	the built-in objects during the descend as well, in order to
2021da177e4SLinus Torvalds#	make sure the checksums are uptodate before we record them.
2031da177e4SLinus Torvalds
2041da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),modules)
2051da177e4SLinus Torvalds  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
2061da177e4SLinus Torvaldsendif
2071da177e4SLinus Torvalds
2081da177e4SLinus Torvalds#	If we have "make <whatever> modules", compile modules
2091da177e4SLinus Torvalds#	in addition to whatever we do anyway.
2101da177e4SLinus Torvalds#	Just "make" or "make all" shall build modules as well
2111da177e4SLinus Torvalds
2121da177e4SLinus Torvaldsifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
2131da177e4SLinus Torvalds  KBUILD_MODULES := 1
2141da177e4SLinus Torvaldsendif
2151da177e4SLinus Torvalds
2161da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),)
2171da177e4SLinus Torvalds  KBUILD_MODULES := 1
2181da177e4SLinus Torvaldsendif
2191da177e4SLinus Torvalds
220e579d351SSam Ravnborgexport KBUILD_MODULES KBUILD_BUILTIN
2211da177e4SLinus Torvaldsexport KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
2221da177e4SLinus Torvalds
2231da177e4SLinus Torvalds# Beautify output
2241da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2251da177e4SLinus Torvalds#
2261da177e4SLinus Torvalds# Normally, we echo the whole command before executing it. By making
2271da177e4SLinus Torvalds# that echo $($(quiet)$(cmd)), we now have the possibility to set
2281da177e4SLinus Torvalds# $(quiet) to choose other forms of output instead, e.g.
2291da177e4SLinus Torvalds#
2301da177e4SLinus Torvalds#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
2311da177e4SLinus Torvalds#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
2321da177e4SLinus Torvalds#
2331da177e4SLinus Torvalds# If $(quiet) is empty, the whole command will be printed.
2341da177e4SLinus Torvalds# If it is set to "quiet_", only the short version will be printed. 
2351da177e4SLinus Torvalds# If it is set to "silent_", nothing wil be printed at all, since
2361da177e4SLinus Torvalds# the variable $(silent_cmd_cc_o_c) doesn't exist.
2371da177e4SLinus Torvalds#
238a58a414fSAdrian Bunk# A simple variant is to prefix commands with $(Q) - that's useful
2391da177e4SLinus Torvalds# for commands that shall be hidden in non-verbose mode.
2401da177e4SLinus Torvalds#
2411da177e4SLinus Torvalds#	$(Q)ln $@ :<
2421da177e4SLinus Torvalds#
2431da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
2441da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 1 then the above command is displayed.
2451da177e4SLinus Torvalds
2461da177e4SLinus Torvaldsifeq ($(KBUILD_VERBOSE),1)
2471da177e4SLinus Torvalds  quiet =
2481da177e4SLinus Torvalds  Q =
2491da177e4SLinus Torvaldselse
2501da177e4SLinus Torvalds  quiet=quiet_
2511da177e4SLinus Torvalds  Q = @
2521da177e4SLinus Torvaldsendif
2531da177e4SLinus Torvalds
2541da177e4SLinus Torvalds# If the user is running make -s (silent mode), suppress echoing of
2551da177e4SLinus Torvalds# commands
2561da177e4SLinus Torvalds
2571da177e4SLinus Torvaldsifneq ($(findstring s,$(MAKEFLAGS)),)
2581da177e4SLinus Torvalds  quiet=silent_
2591da177e4SLinus Torvaldsendif
2601da177e4SLinus Torvalds
2611da177e4SLinus Torvaldsexport quiet Q KBUILD_VERBOSE
2621da177e4SLinus Torvalds
2631da177e4SLinus Torvalds
2641da177e4SLinus Torvalds# Look for make include files relative to root of kernel src
2651da177e4SLinus TorvaldsMAKEFLAGS += --include-dir=$(srctree)
2661da177e4SLinus Torvalds
2678ec4b4ffSSam Ravnborg# We need some generic definitions
2682a691470SSam Ravnborginclude  $(srctree)/scripts/Kbuild.include
2698ec4b4ffSSam Ravnborg
2701da177e4SLinus Torvalds# For maximum performance (+ possibly random breakage, uncomment
2711da177e4SLinus Torvalds# the following)
2721da177e4SLinus Torvalds
2731da177e4SLinus Torvalds#MAKEFLAGS += -rR
2741da177e4SLinus Torvalds
2751da177e4SLinus Torvalds# Make variables (CC, etc...)
2761da177e4SLinus Torvalds
2771da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
2781da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
2791da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
2801da177e4SLinus TorvaldsCPP		= $(CC) -E
2811da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
2821da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
2831da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
2841da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
2851da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
2861da177e4SLinus TorvaldsAWK		= awk
2871da177e4SLinus TorvaldsGENKSYMS	= scripts/genksyms/genksyms
2881da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
2891da177e4SLinus TorvaldsKALLSYMS	= scripts/kallsyms
2901da177e4SLinus TorvaldsPERL		= perl
2911da177e4SLinus TorvaldsCHECK		= sparse
2921da177e4SLinus Torvalds
293af4ca457SAl ViroCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF)
2941da177e4SLinus TorvaldsMODFLAGS	= -DMODULE
2951da177e4SLinus TorvaldsCFLAGS_MODULE   = $(MODFLAGS)
2961da177e4SLinus TorvaldsAFLAGS_MODULE   = $(MODFLAGS)
2971da177e4SLinus TorvaldsLDFLAGS_MODULE  = -r
2981da177e4SLinus TorvaldsCFLAGS_KERNEL	=
2991da177e4SLinus TorvaldsAFLAGS_KERNEL	=
3001da177e4SLinus Torvalds
3011da177e4SLinus Torvalds
3021da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
3031da177e4SLinus Torvalds# Needed to be compatible with the O= option
3041da177e4SLinus TorvaldsLINUXINCLUDE    := -Iinclude \
3052dd34b48SRussell King                   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \
306e623a3b8SZachary Amsden		   -include include/linux/autoconf.h
3071da177e4SLinus Torvalds
3081da177e4SLinus TorvaldsCPPFLAGS        := -D__KERNEL__ $(LINUXINCLUDE)
3091da177e4SLinus Torvalds
3103c521e06SOlaf HeringCFLAGS 		:= -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
3116edfba1bSAndi Kleen	  	   -fno-strict-aliasing -fno-common
3121da177e4SLinus TorvaldsAFLAGS		:= -D__ASSEMBLY__
3131da177e4SLinus Torvalds
314f1d28fb0SRoman Zippel# Read KERNELRELEASE from include/config/kernel.release (if it exists)
315f1d28fb0SRoman ZippelKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
3162244cbd8SSam RavnborgKERNELVERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
317cb58455cSSam Ravnborg
3182244cbd8SSam Ravnborgexport	VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION \
3191da177e4SLinus Torvalds	ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
3201da177e4SLinus Torvalds	CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
3211da177e4SLinus Torvalds	HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
3221da177e4SLinus Torvalds
3231da177e4SLinus Torvaldsexport CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
3241da177e4SLinus Torvaldsexport CFLAGS CFLAGS_KERNEL CFLAGS_MODULE 
3251da177e4SLinus Torvaldsexport AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
3261da177e4SLinus Torvalds
3271da177e4SLinus Torvalds# When compiling out-of-tree modules, put MODVERDIR in the module
3281da177e4SLinus Torvalds# tree rather than in the kernel tree. The kernel tree might
3291da177e4SLinus Torvalds# even be read-only.
3301da177e4SLinus Torvaldsexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
3311da177e4SLinus Torvalds
3321da177e4SLinus Torvalds# Files to ignore in find ... statements
3331da177e4SLinus Torvalds
334406119f4STrond 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
335406119f4STrond Myklebustexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc --exclude .hg --exclude .git
3361da177e4SLinus Torvalds
3371da177e4SLinus Torvalds# ===========================================================================
3381da177e4SLinus Torvalds# Rules shared between *config targets and build targets
3391da177e4SLinus Torvalds
3401da177e4SLinus Torvalds# Basic helpers built in scripts/
3414f193362SPaul SmithPHONY += scripts_basic
3421da177e4SLinus Torvaldsscripts_basic:
3431da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/basic
3441da177e4SLinus Torvalds
345cd05e6bdSJan Beulich# To avoid any implicit rule to kick in, define an empty command.
346cd05e6bdSJan Beulichscripts/basic/%: scripts_basic ;
347cd05e6bdSJan Beulich
3484f193362SPaul SmithPHONY += outputmakefile
349fd5f0cd6SJan Beulich# outputmakefile generates a Makefile in the output directory, if using a
350fd5f0cd6SJan Beulich# separate output directory. This allows convenient use of make in the
351fd5f0cd6SJan Beulich# output directory.
3521da177e4SLinus Torvaldsoutputmakefile:
353fd5f0cd6SJan Beulichifneq ($(KBUILD_SRC),)
354fd5f0cd6SJan Beulich	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
355fd5f0cd6SJan Beulich	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
356fd5f0cd6SJan Beulichendif
3571da177e4SLinus Torvalds
3581da177e4SLinus Torvalds# To make sure we do not include .config for any of the *config targets
3591da177e4SLinus Torvalds# catch them early, and hand them over to scripts/kconfig/Makefile
3601da177e4SLinus Torvalds# It is allowed to specify more targets when calling make, including
3611da177e4SLinus Torvalds# mixing *config targets and build targets.
3621da177e4SLinus Torvalds# For example 'make oldconfig all'. 
3631da177e4SLinus Torvalds# Detect when mixed targets is specified, and make a second invocation
3641da177e4SLinus Torvalds# of make so .config is not included in this case either (for *config).
3651da177e4SLinus Torvalds
3661da177e4SLinus Torvaldsno-dot-config-targets := clean mrproper distclean \
3676b6a462cSAndreas Schwab			 cscope TAGS tags help %docs check%
3681da177e4SLinus Torvalds
3691da177e4SLinus Torvaldsconfig-targets := 0
3701da177e4SLinus Torvaldsmixed-targets  := 0
3711da177e4SLinus Torvaldsdot-config     := 1
3721da177e4SLinus Torvalds
3731da177e4SLinus Torvaldsifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
3741da177e4SLinus Torvalds	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
3751da177e4SLinus Torvalds		dot-config := 0
3761da177e4SLinus Torvalds	endif
3771da177e4SLinus Torvaldsendif
3781da177e4SLinus Torvalds
3791da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
3801da177e4SLinus Torvalds        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
3811da177e4SLinus Torvalds                config-targets := 1
3821da177e4SLinus Torvalds                ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
3831da177e4SLinus Torvalds                        mixed-targets := 1
3841da177e4SLinus Torvalds                endif
3851da177e4SLinus Torvalds        endif
3861da177e4SLinus Torvaldsendif
3871da177e4SLinus Torvalds
3881da177e4SLinus Torvaldsifeq ($(mixed-targets),1)
3891da177e4SLinus Torvalds# ===========================================================================
3901da177e4SLinus Torvalds# We're called with mixed targets (*config and build targets).
3911da177e4SLinus Torvalds# Handle them one by one.
3921da177e4SLinus Torvalds
3931da177e4SLinus Torvalds%:: FORCE
3941da177e4SLinus Torvalds	$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
3951da177e4SLinus Torvalds
3961da177e4SLinus Torvaldselse
3971da177e4SLinus Torvaldsifeq ($(config-targets),1)
3981da177e4SLinus Torvalds# ===========================================================================
3991da177e4SLinus Torvalds# *config targets only - make sure prerequisites are updated, and descend
4001da177e4SLinus Torvalds# in scripts/kconfig to make the *config target
4011da177e4SLinus Torvalds
4021da177e4SLinus Torvalds# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
4031da177e4SLinus Torvalds# KBUILD_DEFCONFIG may point out an alternative default configuration
4041da177e4SLinus Torvalds# used for 'make defconfig'
4051da177e4SLinus Torvaldsinclude $(srctree)/arch/$(ARCH)/Makefile
4061da177e4SLinus Torvaldsexport KBUILD_DEFCONFIG
4071da177e4SLinus Torvalds
408cd05e6bdSJan Beulichconfig %config: scripts_basic outputmakefile FORCE
409c955ccafSRoman Zippel	$(Q)mkdir -p include/linux include/config
4101da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/kconfig $@
4111da177e4SLinus Torvalds
4121da177e4SLinus Torvaldselse
4131da177e4SLinus Torvalds# ===========================================================================
4141da177e4SLinus Torvalds# Build targets only - this includes vmlinux, arch specific targets, clean
4151da177e4SLinus Torvalds# targets and others. In general all targets except *config targets.
4161da177e4SLinus Torvalds
4171da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
4181da177e4SLinus Torvalds# Additional helpers built in scripts/
4191da177e4SLinus Torvalds# Carefully list dependencies so we do not try to build scripts twice
4201da177e4SLinus Torvalds# in parrallel
4214f193362SPaul SmithPHONY += scripts
4222e3646e5SRoman Zippelscripts: scripts_basic include/config/auto.conf
4231da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@)
4241da177e4SLinus Torvalds
4251da177e4SLinus Torvalds# Objects we will link into vmlinux / subdirs we need to visit
4261da177e4SLinus Torvaldsinit-y		:= init/
4271da177e4SLinus Torvaldsdrivers-y	:= drivers/ sound/
4281da177e4SLinus Torvaldsnet-y		:= net/
4291da177e4SLinus Torvaldslibs-y		:= lib/
4301da177e4SLinus Torvaldscore-y		:= usr/
4311da177e4SLinus Torvaldsendif # KBUILD_EXTMOD
4321da177e4SLinus Torvalds
4331da177e4SLinus Torvaldsifeq ($(dot-config),1)
4341da177e4SLinus Torvalds# In this section, we need .config
4351da177e4SLinus Torvalds
4361da177e4SLinus Torvalds# Read in dependencies to all Kconfig* files, make sure to run
4371da177e4SLinus Torvalds# oldconfig if changes are detected.
438c955ccafSRoman Zippel-include include/config/auto.conf.cmd
439c955ccafSRoman Zippel-include include/config/auto.conf
4401da177e4SLinus Torvalds
4411da177e4SLinus Torvalds# To avoid any implicit rule to kick in, define an empty command
44214cdd3c4SRoman Zippel$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
4431da177e4SLinus Torvalds
444c955ccafSRoman Zippel# If .config is newer than include/config/auto.conf, someone tinkered
445752625cfSSam Ravnborg# with it and forgot to run make oldconfig.
446c955ccafSRoman Zippel# if auto.conf.cmd is missing then we are probarly in a cleaned tree so
447752625cfSSam Ravnborg# we execute the config step to be sure to catch updated Kconfig files
44814cdd3c4SRoman Zippelinclude/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
4491da177e4SLinus Torvalds	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
450c955ccafSRoman Zippel
4511da177e4SLinus Torvaldselse
4521da177e4SLinus Torvalds# Dummy target needed, because used as prerequisite
453c955ccafSRoman Zippelinclude/config/auto.conf: ;
4541da177e4SLinus Torvaldsendif
4551da177e4SLinus Torvalds
4561da177e4SLinus Torvalds# The all: target is the default when no target is given on the
4571da177e4SLinus Torvalds# command line.
4581da177e4SLinus Torvalds# This allow a user to issue only 'make' to build a kernel including modules
4591da177e4SLinus Torvalds# Defaults vmlinux but it is usually overriden in the arch makefile
4601da177e4SLinus Torvaldsall: vmlinux
4611da177e4SLinus Torvalds
4621da177e4SLinus Torvaldsifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
4631da177e4SLinus TorvaldsCFLAGS		+= -Os
4641da177e4SLinus Torvaldselse
4651da177e4SLinus TorvaldsCFLAGS		+= -O2
4661da177e4SLinus Torvaldsendif
4671da177e4SLinus Torvalds
4681da177e4SLinus Torvaldsifdef CONFIG_FRAME_POINTER
4690030cbf0SMatthias UrlichsCFLAGS		+= -fno-omit-frame-pointer $(call cc-option,-fno-optimize-sibling-calls,)
4701da177e4SLinus Torvaldselse
4711da177e4SLinus TorvaldsCFLAGS		+= -fomit-frame-pointer
4721da177e4SLinus Torvaldsendif
4731da177e4SLinus Torvalds
474604bf5a2SJan Beulichifdef CONFIG_UNWIND_INFO
475604bf5a2SJan BeulichCFLAGS		+= -fasynchronous-unwind-tables
476604bf5a2SJan Beulichendif
477604bf5a2SJan Beulich
4781da177e4SLinus Torvaldsifdef CONFIG_DEBUG_INFO
4791da177e4SLinus TorvaldsCFLAGS		+= -g
4801da177e4SLinus Torvaldsendif
4811da177e4SLinus Torvalds
4821da177e4SLinus Torvaldsinclude $(srctree)/arch/$(ARCH)/Makefile
4831da177e4SLinus Torvalds
484e8e69931SSam Ravnborg# arch Makefile may override CC so keep this after arch Makefile is included
485e8f5bdb0SRik van RielNOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
486e8e69931SSam RavnborgCHECKFLAGS     += $(NOSTDINC_FLAGS)
487e8e69931SSam Ravnborg
4881da177e4SLinus Torvalds# warn about C99 declaration after statement
4891da177e4SLinus TorvaldsCFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
4901da177e4SLinus Torvalds
4911da177e4SLinus Torvalds# disable pointer signedness warnings in gcc 4.0
4921da177e4SLinus TorvaldsCFLAGS += $(call cc-option,-Wno-pointer-sign,)
4931da177e4SLinus Torvalds
4941da177e4SLinus Torvalds# Default kernel image to build when no specific target is given.
4951da177e4SLinus Torvalds# KBUILD_IMAGE may be overruled on the commandline or
4961da177e4SLinus Torvalds# set in the environment
4971da177e4SLinus Torvalds# Also any assignments in arch/$(ARCH)/Makefile take precedence over
4981da177e4SLinus Torvalds# this default value
4991da177e4SLinus Torvaldsexport KBUILD_IMAGE ?= vmlinux
5001da177e4SLinus Torvalds
5011da177e4SLinus Torvalds#
5021da177e4SLinus Torvalds# INSTALL_PATH specifies where to place the updated kernel and system map
5031da177e4SLinus Torvalds# images. Default is /boot, but you can set it to other values
5041da177e4SLinus Torvaldsexport	INSTALL_PATH ?= /boot
5051da177e4SLinus Torvalds
5061da177e4SLinus Torvalds#
5071da177e4SLinus Torvalds# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
5081da177e4SLinus Torvalds# relocations required by build roots.  This is not defined in the
5091da177e4SLinus Torvalds# makefile but the arguement can be passed to make if needed.
5101da177e4SLinus Torvalds#
5111da177e4SLinus Torvalds
512df9df036SSam RavnborgMODLIB	= $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
5131da177e4SLinus Torvaldsexport MODLIB
5141da177e4SLinus Torvalds
5151da177e4SLinus Torvalds
5161da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
5173a65dfe8SJens Axboecore-y		+= kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5181da177e4SLinus Torvalds
5191da177e4SLinus Torvaldsvmlinux-dirs	:= $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
5201da177e4SLinus Torvalds		     $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
5211da177e4SLinus Torvalds		     $(net-y) $(net-m) $(libs-y) $(libs-m)))
5221da177e4SLinus Torvalds
5231da177e4SLinus Torvaldsvmlinux-alldirs	:= $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \
5241da177e4SLinus Torvalds		     $(init-n) $(init-) \
5251da177e4SLinus Torvalds		     $(core-n) $(core-) $(drivers-n) $(drivers-) \
5261da177e4SLinus Torvalds		     $(net-n)  $(net-)  $(libs-n)    $(libs-))))
5271da177e4SLinus Torvalds
5281da177e4SLinus Torvaldsinit-y		:= $(patsubst %/, %/built-in.o, $(init-y))
5291da177e4SLinus Torvaldscore-y		:= $(patsubst %/, %/built-in.o, $(core-y))
5301da177e4SLinus Torvaldsdrivers-y	:= $(patsubst %/, %/built-in.o, $(drivers-y))
5311da177e4SLinus Torvaldsnet-y		:= $(patsubst %/, %/built-in.o, $(net-y))
5321da177e4SLinus Torvaldslibs-y1		:= $(patsubst %/, %/lib.a, $(libs-y))
5331da177e4SLinus Torvaldslibs-y2		:= $(patsubst %/, %/built-in.o, $(libs-y))
5341da177e4SLinus Torvaldslibs-y		:= $(libs-y1) $(libs-y2)
5351da177e4SLinus Torvalds
5361da177e4SLinus Torvalds# Build vmlinux
5371da177e4SLinus Torvalds# ---------------------------------------------------------------------------
5381da177e4SLinus Torvalds# vmlinux is build from the objects selected by $(vmlinux-init) and
5391da177e4SLinus Torvalds# $(vmlinux-main). Most are built-in.o files from top-level directories
5401da177e4SLinus Torvalds# in the kernel tree, others are specified in arch/$(ARCH)Makefile.
5411da177e4SLinus Torvalds# Ordering when linking is important, and $(vmlinux-init) must be first.
5421da177e4SLinus Torvalds#
5431da177e4SLinus Torvalds# vmlinux
5441da177e4SLinus Torvalds#   ^
5451da177e4SLinus Torvalds#   |
5461da177e4SLinus Torvalds#   +-< $(vmlinux-init)
5471da177e4SLinus Torvalds#   |   +--< init/version.o + more
5481da177e4SLinus Torvalds#   |
5491da177e4SLinus Torvalds#   +--< $(vmlinux-main)
5501da177e4SLinus Torvalds#   |    +--< driver/built-in.o mm/built-in.o + more
5511da177e4SLinus Torvalds#   |
5521da177e4SLinus Torvalds#   +-< kallsyms.o (see description in CONFIG_KALLSYMS section)
5531da177e4SLinus Torvalds#
5541da177e4SLinus Torvalds# vmlinux version (uname -v) cannot be updated during normal
5551da177e4SLinus Torvalds# descending-into-subdirs phase since we do not yet know if we need to
5561da177e4SLinus Torvalds# update vmlinux.
5571da177e4SLinus Torvalds# Therefore this step is delayed until just before final link of vmlinux -
5581da177e4SLinus Torvalds# except in the kallsyms case where it is done just before adding the
5591da177e4SLinus Torvalds# symbols to the kernel.
5601da177e4SLinus Torvalds#
5611da177e4SLinus Torvalds# System.map is generated to document addresses of all kernel symbols
5621da177e4SLinus Torvalds
5631da177e4SLinus Torvaldsvmlinux-init := $(head-y) $(init-y)
5641da177e4SLinus Torvaldsvmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)
5651da177e4SLinus Torvaldsvmlinux-all  := $(vmlinux-init) $(vmlinux-main)
5661da177e4SLinus Torvaldsvmlinux-lds  := arch/$(ARCH)/kernel/vmlinux.lds
5671da177e4SLinus Torvalds
5681da177e4SLinus Torvalds# Rule to link vmlinux - also used during CONFIG_KALLSYMS
5691da177e4SLinus Torvalds# May be overridden by arch/$(ARCH)/Makefile
5701da177e4SLinus Torvaldsquiet_cmd_vmlinux__ ?= LD      $@
5711da177e4SLinus Torvalds      cmd_vmlinux__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) -o $@ \
5721da177e4SLinus Torvalds      -T $(vmlinux-lds) $(vmlinux-init)                          \
5731da177e4SLinus Torvalds      --start-group $(vmlinux-main) --end-group                  \
5741da177e4SLinus Torvalds      $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) FORCE ,$^)
5751da177e4SLinus Torvalds
5761da177e4SLinus Torvalds# Generate new vmlinux version
5771da177e4SLinus Torvaldsquiet_cmd_vmlinux_version = GEN     .version
5781da177e4SLinus Torvalds      cmd_vmlinux_version = set -e;                     \
5794e25d8bbSJan Beulich	if [ ! -r .version ]; then			\
5804e25d8bbSJan Beulich	  rm -f .version;				\
5814e25d8bbSJan Beulich	  echo 1 >.version;				\
5824e25d8bbSJan Beulich	else						\
5834e25d8bbSJan Beulich	  mv .version .old_version;			\
5844e25d8bbSJan Beulich	  expr 0$$(cat .old_version) + 1 >.version;	\
5854e25d8bbSJan Beulich	fi;						\
5861da177e4SLinus Torvalds	$(MAKE) $(build)=init
5871da177e4SLinus Torvalds
5881da177e4SLinus Torvalds# Generate System.map
5891da177e4SLinus Torvaldsquiet_cmd_sysmap = SYSMAP 
5901da177e4SLinus Torvalds      cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
5911da177e4SLinus Torvalds
5921da177e4SLinus Torvalds# Link of vmlinux
5931da177e4SLinus Torvalds# If CONFIG_KALLSYMS is set .version is already updated
594