Makefile revision 55922c9d
155922c9dSLinus TorvaldsVERSION = 3
255922c9dSLinus TorvaldsPATCHLEVEL = 0
355922c9dSLinus TorvaldsSUBLEVEL = 0
455922c9dSLinus TorvaldsEXTRAVERSION = -rc1
555922c9dSLinus TorvaldsNAME = Sneaky 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
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
19c051346bSH. Peter Anvin# Avoid funny character set dependencies
2006b5dc64SH. Peter Anvinunexport LC_ALL
21c051346bSH. Peter AnvinLC_COLLATE=C
22c051346bSH. Peter AnvinLC_NUMERIC=C
2307105202SMichal Marekexport LC_COLLATE LC_NUMERIC
24c051346bSH. Peter Anvin
251da177e4SLinus Torvalds# We are using a recursive build, so we need to do a little thinking
261da177e4SLinus Torvalds# to get the ordering right.
271da177e4SLinus Torvalds#
281da177e4SLinus Torvalds# Most importantly: sub-Makefiles should only ever modify files in
291da177e4SLinus Torvalds# their own directory. If in some directory we have a dependency on
301da177e4SLinus Torvalds# a file in another dir (which doesn't happen often, but it's often
311da177e4SLinus Torvalds# unavoidable when linking the built-in.o targets which finally
321da177e4SLinus Torvalds# turn into vmlinux), we will call a sub make in that other dir, and
331da177e4SLinus Torvalds# after that we are sure that everything which is in that other dir
341da177e4SLinus Torvalds# is now up to date.
351da177e4SLinus Torvalds#
361da177e4SLinus Torvalds# The only cases where we need to modify files which have global
371da177e4SLinus Torvalds# effects are thus separated out and done before the recursive
381da177e4SLinus Torvalds# descending is started. They are now explicitly listed as the
391da177e4SLinus Torvalds# prepare rule.
401da177e4SLinus Torvalds
411da177e4SLinus Torvalds# To put more focus on warnings, be less verbose as default
421da177e4SLinus Torvalds# Use 'make V=1' to see the full commands
431da177e4SLinus Torvalds
44b8b0618cSCheng Renquanifeq ("$(origin V)", "command line")
45b8b0618cSCheng Renquan  KBUILD_VERBOSE = $(V)
461da177e4SLinus Torvaldsendif
471da177e4SLinus Torvaldsifndef KBUILD_VERBOSE
481da177e4SLinus Torvalds  KBUILD_VERBOSE = 0
491da177e4SLinus Torvaldsendif
501da177e4SLinus Torvalds
511c7bafe7SRobert P. J. Day# Call a source code checker (by default, "sparse") as part of the
521c7bafe7SRobert P. J. Day# C compilation.
531c7bafe7SRobert P. J. Day#
541c7bafe7SRobert P. J. Day# Use 'make C=1' to enable checking of only re-compiled files.
551c7bafe7SRobert P. J. Day# Use 'make C=2' to enable checking of *all* source files, regardless
561c7bafe7SRobert P. J. Day# of whether they are re-compiled or not.
571c7bafe7SRobert P. J. Day#
581c7bafe7SRobert P. J. Day# See the file "Documentation/sparse.txt" for more details, including
591c7bafe7SRobert P. J. Day# where to get the "sparse" utility.
601da177e4SLinus Torvalds
61b8b0618cSCheng Renquanifeq ("$(origin C)", "command line")
62b8b0618cSCheng Renquan  KBUILD_CHECKSRC = $(C)
631da177e4SLinus Torvaldsendif
641da177e4SLinus Torvaldsifndef KBUILD_CHECKSRC
651da177e4SLinus Torvalds  KBUILD_CHECKSRC = 0
661da177e4SLinus Torvaldsendif
671da177e4SLinus Torvalds
681da177e4SLinus Torvalds# Use make M=dir to specify directory of external module to build
691da177e4SLinus Torvalds# Old syntax make ... SUBDIRS=$PWD is still supported
701da177e4SLinus Torvalds# Setting the environment variable KBUILD_EXTMOD take precedence
711da177e4SLinus Torvaldsifdef SUBDIRS
721da177e4SLinus Torvalds  KBUILD_EXTMOD ?= $(SUBDIRS)
731da177e4SLinus Torvaldsendif
741da177e4SLinus Torvalds
75b8b0618cSCheng Renquanifeq ("$(origin M)", "command line")
76b8b0618cSCheng Renquan  KBUILD_EXTMOD := $(M)
77b8b0618cSCheng Renquanendif
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?
101b8b0618cSCheng Renquanifeq ("$(origin O)", "command line")
102b8b0618cSCheng Renquan  KBUILD_OUTPUT := $(O)
1031da177e4SLinus Torvaldsendif
1041da177e4SLinus Torvalds
1054a5838adSBorislav Petkovifeq ("$(origin W)", "command line")
10628bc20dcSSam Ravnborg  export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
1074a5838adSBorislav Petkovendif
1084a5838adSBorislav Petkov
1091da177e4SLinus Torvalds# That's our default target when none is given on the command line
1104f193362SPaul SmithPHONY := _all
1111da177e4SLinus Torvalds_all:
1121da177e4SLinus Torvalds
1131cacc9abSSam Ravnborg# Cancel implicit rules on top Makefile
1141cacc9abSSam Ravnborg$(CURDIR)/Makefile Makefile: ;
1151cacc9abSSam Ravnborg
1161da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
1171da177e4SLinus Torvalds# Invoke a second make in the output directory, passing relevant variables
1181da177e4SLinus Torvalds# check that the output directory actually exists
1191da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
1201da177e4SLinus TorvaldsKBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
1211da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1221da177e4SLinus Torvalds     $(error output directory "$(saved-output)" does not exist))
1231da177e4SLinus Torvalds
1240b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1250b35786dSMilton Miller
1261cacc9abSSam Ravnborg$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
1270b35786dSMilton Miller	$(Q)@:
1280b35786dSMilton Miller
1290b35786dSMilton Millersub-make: FORCE
13023a45e2cSSam Ravnborg	$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
13123a45e2cSSam Ravnborg	KBUILD_SRC=$(CURDIR) \
1320b35786dSMilton Miller	KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile \
1330b35786dSMilton Miller	$(filter-out _all sub-make,$(MAKECMDGOALS))
1341da177e4SLinus Torvalds
1351da177e4SLinus Torvalds# Leave processing to above invocation of make
1361da177e4SLinus Torvaldsskip-makefile := 1
1371da177e4SLinus Torvaldsendif # ifneq ($(KBUILD_OUTPUT),)
1381da177e4SLinus Torvaldsendif # ifeq ($(KBUILD_SRC),)
1391da177e4SLinus Torvalds
1401da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
1411da177e4SLinus Torvaldsifeq ($(skip-makefile),)
1421da177e4SLinus Torvalds
1431da177e4SLinus Torvalds# If building an external module we do not care about the all: rule
1441da177e4SLinus Torvalds# but instead _all depend on modules
1454f193362SPaul SmithPHONY += all
1461da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
1471da177e4SLinus Torvalds_all: all
1481da177e4SLinus Torvaldselse
1491da177e4SLinus Torvalds_all: modules
1501da177e4SLinus Torvaldsendif
1511da177e4SLinus Torvalds
1521da177e4SLinus Torvaldssrctree		:= $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
1531da177e4SLinus Torvaldsobjtree		:= $(CURDIR)
1541da177e4SLinus Torvaldssrc		:= $(srctree)
1551da177e4SLinus Torvaldsobj		:= $(objtree)
1561da177e4SLinus Torvalds
1570f558c33SMattia DongiliVPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
1581da177e4SLinus Torvalds
15911294235SAmerigo Wangexport srctree objtree VPATH
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/ \
1723cc000b5SPaul Mundt				  -e s/sh[234].*/sh/ )
1731da177e4SLinus Torvalds
1741da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
1751da177e4SLinus Torvalds# ---------------------------------------------------------------------------
1761da177e4SLinus Torvalds#
1771da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
1781da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
1791da177e4SLinus Torvalds# ARCH can be set during invocation of make:
1801da177e4SLinus Torvalds# make ARCH=ia64
1811da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
1821da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
1831da177e4SLinus Torvalds
1841da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
1851da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
1861da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
1871da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
1881da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
1891da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
19084336466SRoland McGrath# A third alternative is to store a setting in .config so that plain
19184336466SRoland McGrath# "make" in the configured kernel build directory always uses that.
1921da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
1931da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
1944ce6efedSSam Ravnborgexport KBUILD_BUILDHOST := $(SUBARCH)
1952331d1a6SSam RavnborgARCH		?= $(SUBARCH)
19684336466SRoland McGrathCROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)
1971da177e4SLinus Torvalds
1981da177e4SLinus Torvalds# Architecture as present in compile.h
1996752ed90SThomas GleixnerUTS_MACHINE 	:= $(ARCH)
2006752ed90SThomas GleixnerSRCARCH 	:= $(ARCH)
2011da177e4SLinus Torvalds
202d746d647SSam Ravnborg# Additional ARCH settings for x86
203d746d647SSam Ravnborgifeq ($(ARCH),i386)
204d746d647SSam Ravnborg        SRCARCH := x86
205d746d647SSam Ravnborgendif
206d746d647SSam Ravnborgifeq ($(ARCH),x86_64)
207d746d647SSam Ravnborg        SRCARCH := x86
208d746d647SSam Ravnborgendif
20974b469f2SSam Ravnborg
2105e538790SSam Ravnborg# Additional ARCH settings for sparc
211e69f58c0SNamhyung Kimifeq ($(ARCH),sparc32)
212e69f58c0SNamhyung Kim       SRCARCH := sparc
213e69f58c0SNamhyung Kimendif
214a439fe51SSam Ravnborgifeq ($(ARCH),sparc64)
2155e538790SSam Ravnborg       SRCARCH := sparc
216a439fe51SSam Ravnborgendif
2172fb9b1bdSSam Ravnborg
2183cc000b5SPaul Mundt# Additional ARCH settings for sh
2193cc000b5SPaul Mundtifeq ($(ARCH),sh64)
2203cc000b5SPaul Mundt       SRCARCH := sh
2213cc000b5SPaul Mundtendif
2223cc000b5SPaul Mundt
22318aecc2bSChris Metcalf# Additional ARCH settings for tile
2246738d321SChris Metcalfifeq ($(ARCH),tilepro)
2256738d321SChris Metcalf       SRCARCH := tile
2266738d321SChris Metcalfendif
22718aecc2bSChris Metcalfifeq ($(ARCH),tilegx)
22818aecc2bSChris Metcalf       SRCARCH := tile
22918aecc2bSChris Metcalfendif
23018aecc2bSChris Metcalf
2315e538790SSam Ravnborg# Where to locate arch specific headers
2325e538790SSam Ravnborghdr-arch  := $(SRCARCH)
2335e538790SSam Ravnborg
23449148020SSam Ravnborgifeq ($(ARCH),m68knommu)
23549148020SSam Ravnborg       hdr-arch  := m68k
23649148020SSam Ravnborgendif
23749148020SSam Ravnborg
23814cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
23941263fc6SBen Gardinerexport KCONFIG_CONFIG
24014cdd3c4SRoman Zippel
2411da177e4SLinus Torvalds# SHELL used by kbuild
2421da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
2431da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
2441da177e4SLinus Torvalds	  else echo sh; fi ; fi)
2451da177e4SLinus Torvalds
246070b98bfSSam RavnborgHOSTCC       = gcc
247070b98bfSSam RavnborgHOSTCXX      = g++
24825583d4bSJosh TriplettHOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
249070b98bfSSam RavnborgHOSTCXXFLAGS = -O2
2501da177e4SLinus Torvalds
251070b98bfSSam Ravnborg# Decide whether to build built-in, modular, or both.
252070b98bfSSam Ravnborg# Normally, just do built-in.
2531da177e4SLinus Torvalds
2541da177e4SLinus TorvaldsKBUILD_MODULES :=
2551da177e4SLinus TorvaldsKBUILD_BUILTIN := 1
2561da177e4SLinus Torvalds
2571da177e4SLinus Torvalds#	If we have only "make modules", don't compile built-in objects.
2581da177e4SLinus Torvalds#	When we're building modules with modversions, we need to consider
2591da177e4SLinus Torvalds#	the built-in objects during the descend as well, in order to
260070b98bfSSam Ravnborg#	make sure the checksums are up to date before we record them.
2611da177e4SLinus Torvalds
2621da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),modules)
2631da177e4SLinus Torvalds  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
2641da177e4SLinus Torvaldsendif
2651da177e4SLinus Torvalds
2661da177e4SLinus Torvalds#	If we have "make <whatever> modules", compile modules
2671da177e4SLinus Torvalds#	in addition to whatever we do anyway.
2681da177e4SLinus Torvalds#	Just "make" or "make all" shall build modules as well
2691da177e4SLinus Torvalds
2701da177e4SLinus Torvaldsifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
2711da177e4SLinus Torvalds  KBUILD_MODULES := 1
2721da177e4SLinus Torvaldsendif
2731da177e4SLinus Torvalds
2741da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),)
2751da177e4SLinus Torvalds  KBUILD_MODULES := 1
2761da177e4SLinus Torvaldsendif
2771da177e4SLinus Torvalds
278e579d351SSam Ravnborgexport KBUILD_MODULES KBUILD_BUILTIN
2791da177e4SLinus Torvaldsexport KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
2801da177e4SLinus Torvalds
2811da177e4SLinus Torvalds# Beautify output
2821da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2831da177e4SLinus Torvalds#
2841da177e4SLinus Torvalds# Normally, we echo the whole command before executing it. By making
2851da177e4SLinus Torvalds# that echo $($(quiet)$(cmd)), we now have the possibility to set
2861da177e4SLinus Torvalds# $(quiet) to choose other forms of output instead, e.g.
2871da177e4SLinus Torvalds#
2881da177e4SLinus Torvalds#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
2891da177e4SLinus Torvalds#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
2901da177e4SLinus Torvalds#
2911da177e4SLinus Torvalds# If $(quiet) is empty, the whole command will be printed.
2921da177e4SLinus Torvalds# If it is set to "quiet_", only the short version will be printed. 
293070b98bfSSam Ravnborg# If it is set to "silent_", nothing will be printed at all, since
2941da177e4SLinus Torvalds# the variable $(silent_cmd_cc_o_c) doesn't exist.
2951da177e4SLinus Torvalds#
296a58a414fSAdrian Bunk# A simple variant is to prefix commands with $(Q) - that's useful
2971da177e4SLinus Torvalds# for commands that shall be hidden in non-verbose mode.
2981da177e4SLinus Torvalds#
2991da177e4SLinus Torvalds#	$(Q)ln $@ :<
3001da177e4SLinus Torvalds#
3011da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
3021da177e4SLinus Torvalds# If KBUILD_VERBOSE equals 1 then the above command is displayed.
3031da177e4SLinus Torvalds
3041da177e4SLinus Torvaldsifeq ($(KBUILD_VERBOSE),1)
3051da177e4SLinus Torvalds  quiet =
3061da177e4SLinus Torvalds  Q =
3071da177e4SLinus Torvaldselse
3081da177e4SLinus Torvalds  quiet=quiet_
3091da177e4SLinus Torvalds  Q = @
3101da177e4SLinus Torvaldsendif
3111da177e4SLinus Torvalds
3121da177e4SLinus Torvalds# If the user is running make -s (silent mode), suppress echoing of
3131da177e4SLinus Torvalds# commands
3141da177e4SLinus Torvalds
3151da177e4SLinus Torvaldsifneq ($(findstring s,$(MAKEFLAGS)),)
3161da177e4SLinus Torvalds  quiet=silent_
3171da177e4SLinus Torvaldsendif
3181da177e4SLinus Torvalds
3191da177e4SLinus Torvaldsexport quiet Q KBUILD_VERBOSE
3201da177e4SLinus Torvalds
3211da177e4SLinus Torvalds
3221da177e4SLinus Torvalds# Look for make include files relative to root of kernel src
3231da177e4SLinus TorvaldsMAKEFLAGS += --include-dir=$(srctree)
3241da177e4SLinus Torvalds
3251cacc9abSSam Ravnborg# We need some generic definitions (do not try to remake the file).
3261cacc9abSSam Ravnborg$(srctree)/scripts/Kbuild.include: ;
32715964864SOleg Verychinclude $(srctree)/scripts/Kbuild.include
3281da177e4SLinus Torvalds
3291da177e4SLinus Torvalds# Make variables (CC, etc...)
3301da177e4SLinus Torvalds
3311da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
3321da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
3331da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
3341da177e4SLinus TorvaldsCPP		= $(CC) -E
3351da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
3361da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
3371da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
3381da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
3391da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
3401da177e4SLinus TorvaldsAWK		= awk
3411da177e4SLinus TorvaldsGENKSYMS	= scripts/genksyms/genksyms
342caa27b66SSam RavnborgINSTALLKERNEL  := installkernel
3431da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
3441da177e4SLinus TorvaldsKALLSYMS	= scripts/kallsyms
3451da177e4SLinus TorvaldsPERL		= perl
3461da177e4SLinus TorvaldsCHECK		= sparse
3471da177e4SLinus Torvalds
34880a7d1d9SHannes EderCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
34980a7d1d9SHannes Eder		  -Wbitwise -Wno-return-void $(CF)
3506588169dSSam RavnborgCFLAGS_MODULE   =
3516588169dSSam RavnborgAFLAGS_MODULE   =
3526588169dSSam RavnborgLDFLAGS_MODULE  =
3531da177e4SLinus TorvaldsCFLAGS_KERNEL	=
3541da177e4SLinus TorvaldsAFLAGS_KERNEL	=
3552521f2c2SPeter OberparleiterCFLAGS_GCOV	= -fprofile-arcs -ftest-coverage
3561da177e4SLinus Torvalds
3571da177e4SLinus Torvalds
3581da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
3591da177e4SLinus Torvalds# Needed to be compatible with the O= option
360d8ecc5cdSSam RavnborgLINUXINCLUDE    := -I$(srctree)/arch/$(hdr-arch)/include \
361d8ecc5cdSSam Ravnborg                   -Iarch/$(hdr-arch)/include/generated -Iinclude \
36296f13045SSam Ravnborg                   $(if $(KBUILD_SRC), -I$(srctree)/include) \
363264a2683SSam Ravnborg                   -include include/generated/autoconf.h
3641da177e4SLinus Torvalds
365d8672b40SSam RavnborgKBUILD_CPPFLAGS := -D__KERNEL__
3661da177e4SLinus Torvalds
367a0f97e06SSam RavnborgKBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
36894bed2a9SDave Jones		   -fno-strict-aliasing -fno-common \
369a8735821SFloris Kraak		   -Werror-implicit-function-declaration \
370a3ca86aeSEugene Teo		   -Wno-format-security \
371a3ca86aeSEugene Teo		   -fno-delete-null-pointer-checks
37280c00ba9SSam RavnborgKBUILD_AFLAGS_KERNEL :=
37380c00ba9SSam RavnborgKBUILD_CFLAGS_KERNEL :=
374222d394dSSam RavnborgKBUILD_AFLAGS   := -D__ASSEMBLY__
3756588169dSSam RavnborgKBUILD_AFLAGS_MODULE  := -DMODULE
3766588169dSSam RavnborgKBUILD_CFLAGS_MODULE  := -DMODULE
3776588169dSSam RavnborgKBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
3781da177e4SLinus Torvalds
379f1d28fb0SRoman Zippel# Read KERNELRELEASE from include/config/kernel.release (if it exists)
380f1d28fb0SRoman ZippelKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
3812244cbd8SSam RavnborgKERNELVERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
382cb58455cSSam Ravnborg
383070b98bfSSam Ravnborgexport VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
38480ef88d6SSam Ravnborgexport ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
385caa27b66SSam Ravnborgexport CPP AR NM STRIP OBJCOPY OBJDUMP
386caa27b66SSam Ravnborgexport MAKE AWK GENKSYMS INSTALLKERNEL PERL UTS_MACHINE
387070b98bfSSam Ravnborgexport HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
3881da177e4SLinus Torvalds
38906c5040cSSam Ravnborgexport KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
3902521f2c2SPeter Oberparleiterexport KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV
391222d394dSSam Ravnborgexport KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
3926588169dSSam Ravnborgexport KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
39380c00ba9SSam Ravnborgexport KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
39440df759eSMichal Marekexport KBUILD_ARFLAGS
3951da177e4SLinus Torvalds
3961da177e4SLinus Torvalds# When compiling out-of-tree modules, put MODVERDIR in the module
3971da177e4SLinus Torvalds# tree rather than in the kernel tree. The kernel tree might
3981da177e4SLinus Torvalds# even be read-only.
3991da177e4SLinus Torvaldsexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
4001da177e4SLinus Torvalds
4011da177e4SLinus Torvalds# Files to ignore in find ... statements
4021da177e4SLinus Torvalds
403406119f4STrond 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
404406119f4STrond Myklebustexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc --exclude .hg --exclude .git
4051da177e4SLinus Torvalds
4061da177e4SLinus Torvalds# ===========================================================================
4071da177e4SLinus Torvalds# Rules shared between *config targets and build targets
4081da177e4SLinus Torvalds
4091da177e4SLinus Torvalds# Basic helpers built in scripts/
4104f193362SPaul SmithPHONY += scripts_basic
4111da177e4SLinus Torvaldsscripts_basic:
4121da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/basic
413638adb05SSteven Rostedt	$(Q)rm -f .tmp_quiet_recordmcount
4141da177e4SLinus Torvalds
415cd05e6bdSJan Beulich# To avoid any implicit rule to kick in, define an empty command.
416cd05e6bdSJan Beulichscripts/basic/%: scripts_basic ;
417cd05e6bdSJan Beulich
4184f193362SPaul SmithPHONY += outputmakefile
419fd5f0cd6SJan Beulich# outputmakefile generates a Makefile in the output directory, if using a
420fd5f0cd6SJan Beulich# separate output directory. This allows convenient use of make in the
421fd5f0cd6SJan Beulich# output directory.
4221da177e4SLinus Torvaldsoutputmakefile:
423fd5f0cd6SJan Beulichifneq ($(KBUILD_SRC),)
42492979997SAndi Kleen	$(Q)ln -fsn $(srctree) source
425fd5f0cd6SJan Beulich	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
426fd5f0cd6SJan Beulich	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
427fd5f0cd6SJan Beulichendif
4281da177e4SLinus Torvalds
429d8ecc5cdSSam Ravnborg# Support for using generic headers in asm-generic
430d8ecc5cdSSam RavnborgPHONY += asm-generic
431d8ecc5cdSSam Ravnborgasm-generic:
432d8ecc5cdSSam Ravnborg	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
433d8ecc5cdSSam Ravnborg	            obj=arch/$(SRCARCH)/include/generated/asm
434d8ecc5cdSSam Ravnborg
4351da177e4SLinus Torvalds# To make sure we do not include .config for any of the *config targets
4361da177e4SLinus Torvalds# catch them early, and hand them over to scripts/kconfig/Makefile
4371da177e4SLinus Torvalds# It is allowed to specify more targets when calling make, including
4381da177e4SLinus Torvalds# mixing *config targets and build targets.
439070b98bfSSam Ravnborg# For example 'make oldconfig all'.
4401da177e4SLinus Torvalds# Detect when mixed targets is specified, and make a second invocation
4411da177e4SLinus Torvalds# of make so .config is not included in this case either (for *config).
4421da177e4SLinus Torvalds
4433eb3c740SRoman Zippelno-dot-config-targets := clean mrproper distclean \
444f4ed1009SJianbin Kang			 cscope gtags TAGS tags help %docs check% coccicheck \
4453eb3c740SRoman Zippel			 include/linux/version.h headers_% \
4464aed2fd8SLinus Torvalds			 kernelversion %src-pkg
4471da177e4SLinus Torvalds
4481da177e4SLinus Torvaldsconfig-targets := 0
4491da177e4SLinus Torvaldsmixed-targets  := 0
4501da177e4SLinus Torvaldsdot-config     := 1
4511da177e4SLinus Torvalds
4521da177e4SLinus Torvaldsifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
4531da177e4SLinus Torvalds	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
4541da177e4SLinus Torvalds		dot-config := 0
4551da177e4SLinus Torvalds	endif
4561da177e4SLinus Torvaldsendif
4571da177e4SLinus Torvalds
4581da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
4591da177e4SLinus Torvalds        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
4601da177e4SLinus Torvalds                config-targets := 1
4611da177e4SLinus Torvalds                ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
4621da177e4SLinus Torvalds                        mixed-targets := 1
4631da177e4SLinus Torvalds                endif
4641da177e4SLinus Torvalds        endif
4651da177e4SLinus Torvaldsendif
4661da177e4SLinus Torvalds
4671da177e4SLinus Torvaldsifeq ($(mixed-targets),1)
4681da177e4SLinus Torvalds# ===========================================================================
4691da177e4SLinus Torvalds# We're called with mixed targets (*config and build targets).
4701da177e4SLinus Torvalds# Handle them one by one.
4711da177e4SLinus Torvalds
4721da177e4SLinus Torvalds%:: FORCE
4731da177e4SLinus Torvalds	$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
4741da177e4SLinus Torvalds
4751da177e4SLinus Torvaldselse
4761da177e4SLinus Torvaldsifeq ($(config-targets),1)
4771da177e4SLinus Torvalds# ===========================================================================
4781da177e4SLinus Torvalds# *config targets only - make sure prerequisites are updated, and descend
4791da177e4SLinus Torvalds# in scripts/kconfig to make the *config target
4801da177e4SLinus Torvalds
4811da177e4SLinus Torvalds# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
4821da177e4SLinus Torvalds# KBUILD_DEFCONFIG may point out an alternative default configuration
4831da177e4SLinus Torvalds# used for 'make defconfig'
48474b469f2SSam Ravnborginclude $(srctree)/arch/$(SRCARCH)/Makefile
48561bee204SAl Viroexport KBUILD_DEFCONFIG KBUILD_KCONFIG
4861da177e4SLinus Torvalds
48731110ebbSSam Ravnborgconfig: scripts_basic outputmakefile FORCE
48831110ebbSSam Ravnborg	$(Q)mkdir -p include/linux include/config
48931110ebbSSam Ravnborg	$(Q)$(MAKE) $(build)=scripts/kconfig $@
49031110ebbSSam Ravnborg
49131110ebbSSam Ravnborg%config: scripts_basic outputmakefile FORCE
492c955ccafSRoman Zippel	$(Q)mkdir -p include/linux include/config
4931da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/kconfig $@
4941da177e4SLinus Torvalds
4951da177e4SLinus Torvaldselse
4961da177e4SLinus Torvalds# ===========================================================================
4971da177e4SLinus Torvalds# Build targets only - this includes vmlinux, arch specific targets, clean
4981da177e4SLinus Torvalds# targets and others. In general all targets except *config targets.
4991da177e4SLinus Torvalds
5001da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
5011da177e4SLinus Torvalds# Additional helpers built in scripts/
5021da177e4SLinus Torvalds# Carefully list dependencies so we do not try to build scripts twice
503070b98bfSSam Ravnborg# in parallel
5044f193362SPaul SmithPHONY += scripts
505bc081dd6SMichal Marekscripts: scripts_basic include/config/auto.conf include/config/tristate.conf
5061da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=$(@)
5071da177e4SLinus Torvalds
5081da177e4SLinus Torvalds# Objects we will link into vmlinux / subdirs we need to visit
5091da177e4SLinus Torvaldsinit-y		:= init/
5104d2acfbfSDavid Woodhousedrivers-y	:= drivers/ sound/ firmware/
5111da177e4SLinus Torvaldsnet-y		:= net/
5121da177e4SLinus Torvaldslibs-y		:= lib/
5131da177e4SLinus Torvaldscore-y		:= usr/
5141da177e4SLinus Torvaldsendif # KBUILD_EXTMOD
5151da177e4SLinus Torvalds
5161da177e4SLinus Torvaldsifeq ($(dot-config),1)
5179ee4e336SSam Ravnborg# Read in config
5189ee4e336SSam Ravnborg-include include/config/auto.conf
5191da177e4SLinus Torvalds
520