Makefile revision 2c1f4f12
1c517d838SLinus TorvaldsVERSION = 4
22bd6bf03SLinus TorvaldsPATCHLEVEL = 14
355922c9dSLinus TorvaldsSUBLEVEL = 0
49e66317dSLinus TorvaldsEXTRAVERSION = -rc3
5566cf877SLinus TorvaldsNAME = Fearless Coyote
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
13ba634eceSMasahiro Yamada# That's our default target when none is given on the command line
14ba634eceSMasahiro YamadaPHONY := _all
15ba634eceSMasahiro Yamada_all:
16ba634eceSMasahiro Yamada
17a436bb7bSMasahiro Yamada# o Do not use make's built-in rules and variables
18a436bb7bSMasahiro Yamada#   (this increases performance and avoids hard-to-debug behaviour);
19a436bb7bSMasahiro Yamada# o Look for make include files relative to root of kernel src
20a436bb7bSMasahiro YamadaMAKEFLAGS += -rR --include-dir=$(CURDIR)
211da177e4SLinus Torvalds
22c051346bSH. Peter Anvin# Avoid funny character set dependencies
2306b5dc64SH. Peter Anvinunexport LC_ALL
24c051346bSH. Peter AnvinLC_COLLATE=C
25c051346bSH. Peter AnvinLC_NUMERIC=C
2607105202SMichal Marekexport LC_COLLATE LC_NUMERIC
27c051346bSH. Peter Anvin
28ab7474eaSBorislav Petkov# Avoid interference with shell env settings
29ab7474eaSBorislav Petkovunexport GREP_OPTIONS
30ab7474eaSBorislav Petkov
311da177e4SLinus Torvalds# We are using a recursive build, so we need to do a little thinking
321da177e4SLinus Torvalds# to get the ordering right.
331da177e4SLinus Torvalds#
341da177e4SLinus Torvalds# Most importantly: sub-Makefiles should only ever modify files in
351da177e4SLinus Torvalds# their own directory. If in some directory we have a dependency on
361da177e4SLinus Torvalds# a file in another dir (which doesn't happen often, but it's often
371da177e4SLinus Torvalds# unavoidable when linking the built-in.o targets which finally
381da177e4SLinus Torvalds# turn into vmlinux), we will call a sub make in that other dir, and
391da177e4SLinus Torvalds# after that we are sure that everything which is in that other dir
401da177e4SLinus Torvalds# is now up to date.
411da177e4SLinus Torvalds#
421da177e4SLinus Torvalds# The only cases where we need to modify files which have global
431da177e4SLinus Torvalds# effects are thus separated out and done before the recursive
441da177e4SLinus Torvalds# descending is started. They are now explicitly listed as the
451da177e4SLinus Torvalds# prepare rule.
461da177e4SLinus Torvalds
47066b7ed9SMichal Marek# Beautify output
48066b7ed9SMichal Marek# ---------------------------------------------------------------------------
49066b7ed9SMichal Marek#
50066b7ed9SMichal Marek# Normally, we echo the whole command before executing it. By making
51066b7ed9SMichal Marek# that echo $($(quiet)$(cmd)), we now have the possibility to set
52066b7ed9SMichal Marek# $(quiet) to choose other forms of output instead, e.g.
53066b7ed9SMichal Marek#
54066b7ed9SMichal Marek#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
55066b7ed9SMichal Marek#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
56066b7ed9SMichal Marek#
57066b7ed9SMichal Marek# If $(quiet) is empty, the whole command will be printed.
58066b7ed9SMichal Marek# If it is set to "quiet_", only the short version will be printed.
59066b7ed9SMichal Marek# If it is set to "silent_", nothing will be printed at all, since
60066b7ed9SMichal Marek# the variable $(silent_cmd_cc_o_c) doesn't exist.
61066b7ed9SMichal Marek#
62066b7ed9SMichal Marek# A simple variant is to prefix commands with $(Q) - that's useful
63066b7ed9SMichal Marek# for commands that shall be hidden in non-verbose mode.
64066b7ed9SMichal Marek#
65066b7ed9SMichal Marek#	$(Q)ln $@ :<
66066b7ed9SMichal Marek#
67066b7ed9SMichal Marek# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
68066b7ed9SMichal Marek# If KBUILD_VERBOSE equals 1 then the above command is displayed.
69066b7ed9SMichal Marek#
701da177e4SLinus Torvalds# To put more focus on warnings, be less verbose as default
711da177e4SLinus Torvalds# Use 'make V=1' to see the full commands
721da177e4SLinus Torvalds
73b8b0618cSCheng Renquanifeq ("$(origin V)", "command line")
74b8b0618cSCheng Renquan  KBUILD_VERBOSE = $(V)
751da177e4SLinus Torvaldsendif
761da177e4SLinus Torvaldsifndef KBUILD_VERBOSE
771da177e4SLinus Torvalds  KBUILD_VERBOSE = 0
781da177e4SLinus Torvaldsendif
791da177e4SLinus Torvalds
80066b7ed9SMichal Marekifeq ($(KBUILD_VERBOSE),1)
81066b7ed9SMichal Marek  quiet =
82066b7ed9SMichal Marek  Q =
83066b7ed9SMichal Marekelse
84066b7ed9SMichal Marek  quiet=quiet_
85066b7ed9SMichal Marek  Q = @
86066b7ed9SMichal Marekendif
87066b7ed9SMichal Marek
88066b7ed9SMichal Marek# If the user is running make -s (silent mode), suppress echoing of
89066b7ed9SMichal Marek# commands
90066b7ed9SMichal Marek
916f0fa58eSMasahiro Yamadaifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
92066b7ed9SMichal Marek  quiet=silent_
93e572d088SJosh Poimboeuf  tools_silent=s
94066b7ed9SMichal Marekendif
95066b7ed9SMichal Marek
96066b7ed9SMichal Marekexport quiet Q KBUILD_VERBOSE
97066b7ed9SMichal Marek
981da177e4SLinus Torvalds# kbuild supports saving output files in a separate directory.
991da177e4SLinus Torvalds# To locate output files in a separate directory two syntaxes are supported.
1001da177e4SLinus Torvalds# In both cases the working directory must be the root of the kernel src.
1011da177e4SLinus Torvalds# 1) O=
1021da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/"
103070b98bfSSam Ravnborg#
1041da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT
1051da177e4SLinus Torvalds# Set the environment variable KBUILD_OUTPUT to point to the directory
1061da177e4SLinus Torvalds# where the output files shall be placed.
1071da177e4SLinus Torvalds# export KBUILD_OUTPUT=dir/to/store/output/files/
1081da177e4SLinus Torvalds# make
1091da177e4SLinus Torvalds#
1101da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment
1111da177e4SLinus Torvalds# variable.
1121da177e4SLinus Torvalds
113c4e6fff1SCao jin# KBUILD_SRC is not intended to be used by the regular user (for now),
114c4e6fff1SCao jin# it is set on invocation of make with KBUILD_OUTPUT or O= specified.
1151da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),)
1161da177e4SLinus Torvalds
1171da177e4SLinus Torvalds# OK, Make called in directory where kernel src resides
1181da177e4SLinus Torvalds# Do we want to locate output files in a separate directory?
119b8b0618cSCheng Renquanifeq ("$(origin O)", "command line")
120b8b0618cSCheng Renquan  KBUILD_OUTPUT := $(O)
1211da177e4SLinus Torvaldsendif
1221da177e4SLinus Torvalds
1231cacc9abSSam Ravnborg# Cancel implicit rules on top Makefile
1241cacc9abSSam Ravnborg$(CURDIR)/Makefile Makefile: ;
1251cacc9abSSam Ravnborg
12651193b76SRobert Jarzmikifneq ($(words $(subst :, ,$(CURDIR))), 1)
12751193b76SRobert Jarzmik  $(error main directory cannot contain spaces nor colons)
12851193b76SRobert Jarzmikendif
12951193b76SRobert Jarzmik
1301da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
1311da177e4SLinus Torvalds# check that the output directory actually exists
1321da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
1338e9b4667SMasahiro Yamada$(shell [ -d $(KBUILD_OUTPUT) ] || mkdir -p $(KBUILD_OUTPUT))
1348e9b4667SMasahiro YamadaKBUILD_OUTPUT := $(realpath $(KBUILD_OUTPUT))
1351da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1361c9e70a5SMasahiro Yamada     $(error failed to create output directory "$(saved-output)"))
1371da177e4SLinus Torvalds
1380b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1390b35786dSMilton Miller
1401cacc9abSSam Ravnborg$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
14116f89098SCharles Keepax	@:
1420b35786dSMilton Miller
143c4e6fff1SCao jin# Invoke a second make in the output directory, passing relevant variables
1442e8d696bSMasahiro Yamadasub-make:
145745a2543SMasahiro Yamada	$(Q)$(MAKE) -C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR) \
146aa55c8e2SMasahiro Yamada	-f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
1471da177e4SLinus Torvalds
1481da177e4SLinus Torvalds# Leave processing to above invocation of make
1491da177e4SLinus Torvaldsskip-makefile := 1
1501da177e4SLinus Torvaldsendif # ifneq ($(KBUILD_OUTPUT),)
1511da177e4SLinus Torvaldsendif # ifeq ($(KBUILD_SRC),)
1521da177e4SLinus Torvalds
1531da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
1541da177e4SLinus Torvaldsifeq ($(skip-makefile),)
1551da177e4SLinus Torvalds
1567ff52571SMasahiro Yamada# Do not print "Entering directory ...",
1577ff52571SMasahiro Yamada# but we want to display it when entering to the output directory
1587ff52571SMasahiro Yamada# so that IDEs/editors are able to understand relative filenames.
1597ff52571SMasahiro YamadaMAKEFLAGS += --no-print-directory
1607ff52571SMasahiro Yamada
161aa55c8e2SMasahiro Yamada# Call a source code checker (by default, "sparse") as part of the
162aa55c8e2SMasahiro Yamada# C compilation.
163aa55c8e2SMasahiro Yamada#
164aa55c8e2SMasahiro Yamada# Use 'make C=1' to enable checking of only re-compiled files.
165aa55c8e2SMasahiro Yamada# Use 'make C=2' to enable checking of *all* source files, regardless
166aa55c8e2SMasahiro Yamada# of whether they are re-compiled or not.
167aa55c8e2SMasahiro Yamada#
168036db11cSCao jin# See the file "Documentation/dev-tools/sparse.rst" for more details,
169036db11cSCao jin# including where to get the "sparse" utility.
170aa55c8e2SMasahiro Yamada
171aa55c8e2SMasahiro Yamadaifeq ("$(origin C)", "command line")
172aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = $(C)
173aa55c8e2SMasahiro Yamadaendif
174aa55c8e2SMasahiro Yamadaifndef KBUILD_CHECKSRC
175aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = 0
176aa55c8e2SMasahiro Yamadaendif
177aa55c8e2SMasahiro Yamada
178aa55c8e2SMasahiro Yamada# Use make M=dir to specify directory of external module to build
179aa55c8e2SMasahiro Yamada# Old syntax make ... SUBDIRS=$PWD is still supported
180aa55c8e2SMasahiro Yamada# Setting the environment variable KBUILD_EXTMOD take precedence
181aa55c8e2SMasahiro Yamadaifdef SUBDIRS
182aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD ?= $(SUBDIRS)
183aa55c8e2SMasahiro Yamadaendif
184aa55c8e2SMasahiro Yamada
185aa55c8e2SMasahiro Yamadaifeq ("$(origin M)", "command line")
186aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD := $(M)
187aa55c8e2SMasahiro Yamadaendif
188aa55c8e2SMasahiro Yamada
1899da0763bSMichal Marekifeq ($(KBUILD_SRC),)
1909da0763bSMichal Marek        # building in the source tree
1919da0763bSMichal Marek        srctree := .
1929da0763bSMichal Marekelse
1939da0763bSMichal Marek        ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
1949da0763bSMichal Marek                # building in a subdirectory of the source tree
1959da0763bSMichal Marek                srctree := ..
1969da0763bSMichal Marek        else
1979da0763bSMichal Marek                srctree := $(KBUILD_SRC)
1989da0763bSMichal Marek        endif
1999da0763bSMichal Marekendif
2002c1f4f12SMasahiro Yamada
2012c1f4f12SMasahiro Yamadaexport KBUILD_CHECKSRC KBUILD_EXTMOD KBUILD_SRC
2022c1f4f12SMasahiro Yamada
2037e1c0477SMichal Marekobjtree		:= .
2041da177e4SLinus Torvaldssrc		:= $(srctree)
2051da177e4SLinus Torvaldsobj		:= $(objtree)
2061da177e4SLinus Torvalds
2070f558c33SMattia DongiliVPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
2081da177e4SLinus Torvalds
20911294235SAmerigo Wangexport srctree objtree VPATH
2101da177e4SLinus Torvalds
2112c1f4f12SMasahiro Yamada# To make sure we do not include .config for any of the *config targets
2122c1f4f12SMasahiro Yamada# catch them early, and hand them over to scripts/kconfig/Makefile
2132c1f4f12SMasahiro Yamada# It is allowed to specify more targets when calling make, including
2142c1f4f12SMasahiro Yamada# mixing *config targets and build targets.
2152c1f4f12SMasahiro Yamada# For example 'make oldconfig all'.
2162c1f4f12SMasahiro Yamada# Detect when mixed targets is specified, and make a second invocation
2172c1f4f12SMasahiro Yamada# of make so .config is not included in this case either (for *config).
2182c1f4f12SMasahiro Yamada
2192c1f4f12SMasahiro Yamadaversion_h := include/generated/uapi/linux/version.h
2202c1f4f12SMasahiro Yamadaold_version_h := include/linux/version.h
2212c1f4f12SMasahiro Yamada
2222c1f4f12SMasahiro Yamadano-dot-config-targets := clean mrproper distclean \
2232c1f4f12SMasahiro Yamada			 cscope gtags TAGS tags help% %docs check% coccicheck \
2242c1f4f12SMasahiro Yamada			 $(version_h) headers_% archheaders archscripts \
2252c1f4f12SMasahiro Yamada			 kernelversion %src-pkg
2262c1f4f12SMasahiro Yamada
2272c1f4f12SMasahiro Yamadaconfig-targets := 0
2282c1f4f12SMasahiro Yamadamixed-targets  := 0
2292c1f4f12SMasahiro Yamadadot-config     := 1
2302c1f4f12SMasahiro Yamada
2312c1f4f12SMasahiro Yamadaifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
2322c1f4f12SMasahiro Yamada	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
2332c1f4f12SMasahiro Yamada		dot-config := 0
2342c1f4f12SMasahiro Yamada	endif
2352c1f4f12SMasahiro Yamadaendif
2362c1f4f12SMasahiro Yamada
2372c1f4f12SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
2382c1f4f12SMasahiro Yamada        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
2392c1f4f12SMasahiro Yamada                config-targets := 1
2402c1f4f12SMasahiro Yamada                ifneq ($(words $(MAKECMDGOALS)),1)
2412c1f4f12SMasahiro Yamada                        mixed-targets := 1
2422c1f4f12SMasahiro Yamada                endif
2432c1f4f12SMasahiro Yamada        endif
2442c1f4f12SMasahiro Yamadaendif
2452c1f4f12SMasahiro Yamada# install and modules_install need also be processed one by one
2462c1f4f12SMasahiro Yamadaifneq ($(filter install,$(MAKECMDGOALS)),)
2472c1f4f12SMasahiro Yamada        ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
2482c1f4f12SMasahiro Yamada	        mixed-targets := 1
2492c1f4f12SMasahiro Yamada        endif
2502c1f4f12SMasahiro Yamadaendif
2512c1f4f12SMasahiro Yamada
2522c1f4f12SMasahiro Yamadaifeq ($(mixed-targets),1)
2532c1f4f12SMasahiro Yamada# ===========================================================================
2542c1f4f12SMasahiro Yamada# We're called with mixed targets (*config and build targets).
2552c1f4f12SMasahiro Yamada# Handle them one by one.
2562c1f4f12SMasahiro Yamada
2572c1f4f12SMasahiro YamadaPHONY += $(MAKECMDGOALS) __build_one_by_one
2582c1f4f12SMasahiro Yamada
2592c1f4f12SMasahiro Yamada$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
2602c1f4f12SMasahiro Yamada	@:
2612c1f4f12SMasahiro Yamada
2622c1f4f12SMasahiro Yamada__build_one_by_one:
2632c1f4f12SMasahiro Yamada	$(Q)set -e; \
2642c1f4f12SMasahiro Yamada	for i in $(MAKECMDGOALS); do \
2652c1f4f12SMasahiro Yamada		$(MAKE) -f $(srctree)/Makefile $$i; \
2662c1f4f12SMasahiro Yamada	done
2672c1f4f12SMasahiro Yamada
2682c1f4f12SMasahiro Yamadaelse
2692c1f4f12SMasahiro Yamada
2702c1f4f12SMasahiro Yamada# We need some generic definitions (do not try to remake the file).
2712c1f4f12SMasahiro Yamadascripts/Kbuild.include: ;
2722c1f4f12SMasahiro Yamadainclude scripts/Kbuild.include
2732c1f4f12SMasahiro Yamada
2742c1f4f12SMasahiro Yamada# Read KERNELRELEASE from include/config/kernel.release (if it exists)
2752c1f4f12SMasahiro YamadaKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
2762c1f4f12SMasahiro YamadaKERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
2772c1f4f12SMasahiro Yamadaexport VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
2782c1f4f12SMasahiro Yamada
2791da177e4SLinus Torvalds# SUBARCH tells the usermode build what the underlying arch is.  That is set
2801da177e4SLinus Torvalds# first, and if a usermode build is happening, the "ARCH=um" on the command
2811da177e4SLinus Torvalds# line overrides the setting of ARCH below.  If a native build is happening,
28238385f8fSMasahiro Yamada# then ARCH is assigned, getting whatever value it gets normally, and
2831da177e4SLinus Torvalds# SUBARCH is subsequently ignored.
2841da177e4SLinus Torvalds
285ffee0de4SDavid WoodhouseSUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
286ffee0de4SDavid Woodhouse				  -e s/sun4u/sparc64/ \
2871da177e4SLinus Torvalds				  -e s/arm.*/arm/ -e s/sa110/arm/ \
28839990b5eSLinus Torvalds				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
289236b1957SPaul Mundt				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
290f1b99392SWill Deacon				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
2911da177e4SLinus Torvalds
2921da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
2931da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2941da177e4SLinus Torvalds#
2951da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
2961da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
2971da177e4SLinus Torvalds# ARCH can be set during invocation of make:
2981da177e4SLinus Torvalds# make ARCH=ia64
2991da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
3001da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
3011da177e4SLinus Torvalds
3021da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
3031da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
3041da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
3051da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
3061da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
3071da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
30884336466SRoland McGrath# A third alternative is to store a setting in .config so that plain
30984336466SRoland McGrath# "make" in the configured kernel build directory always uses that.
3101da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
3111da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
3122331d1a6SSam RavnborgARCH		?= $(SUBARCH)
31384336466SRoland McGrathCROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)
3141da177e4SLinus Torvalds
3151da177e4SLinus Torvalds# Architecture as present in compile.h
3166752ed90SThomas GleixnerUTS_MACHINE 	:= $(ARCH)
3176752ed90SThomas GleixnerSRCARCH 	:= $(ARCH)
3181da177e4SLinus Torvalds
319d746d647SSam Ravnborg# Additional ARCH settings for x86
320d746d647SSam Ravnborgifeq ($(ARCH),i386)
321d746d647SSam Ravnborg        SRCARCH := x86
322d746d647SSam Ravnborgendif
323d746d647SSam Ravnborgifeq ($(ARCH),x86_64)
324d746d647SSam Ravnborg        SRCARCH := x86
325d746d647SSam Ravnborgendif
32674b469f2SSam Ravnborg
3275e538790SSam Ravnborg# Additional ARCH settings for sparc
328e69f58c0SNamhyung Kimifeq ($(ARCH),sparc32)
329e69f58c0SNamhyung Kim       SRCARCH := sparc
330e69f58c0SNamhyung Kimendif
331a439fe51SSam Ravnborgifeq ($(ARCH),sparc64)
3325e538790SSam Ravnborg       SRCARCH := sparc
333a439fe51SSam Ravnborgendif
3342fb9b1bdSSam Ravnborg
3353cc000b5SPaul Mundt# Additional ARCH settings for sh
3363cc000b5SPaul Mundtifeq ($(ARCH),sh64)
3373cc000b5SPaul Mundt       SRCARCH := sh
3383cc000b5SPaul Mundtendif
3393cc000b5SPaul Mundt
34018aecc2bSChris Metcalf# Additional ARCH settings for tile
3416738d321SChris Metcalfifeq ($(ARCH),tilepro)
3426738d321SChris Metcalf       SRCARCH := tile
3436738d321SChris Metcalfendif
34418aecc2bSChris Metcalfifeq ($(ARCH),tilegx)
34518aecc2bSChris Metcalf       SRCARCH := tile
34618aecc2bSChris Metcalfendif
34718aecc2bSChris Metcalf
34814cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
34941263fc6SBen Gardinerexport KCONFIG_CONFIG
35014cdd3c4SRoman Zippel
3511da177e4SLinus Torvalds# SHELL used by kbuild
3521da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
3531da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
3541da177e4SLinus Torvalds	  else echo sh; fi ; fi)
3551da177e4SLinus Torvalds
356d7f14c66SUwe Kleine-KönigHOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS)
357d7f14c66SUwe Kleine-KönigHOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS)
358d7f14c66SUwe Kleine-KönigHOST_LFS_LIBS := $(shell getconf LFS_LIBS)
359d7f14c66SUwe Kleine-König
360070b98bfSSam RavnborgHOSTCC       = gcc
361070b98bfSSam RavnborgHOSTCXX      = g++
362d7f14c66SUwe Kleine-KönigHOSTCFLAGS   := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
363d7f14c66SUwe Kleine-König		-fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS)
364d7f14c66SUwe Kleine-KönigHOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS)
365d7f14c66SUwe Kleine-KönigHOSTLDFLAGS  := $(HOST_LFS_LDFLAGS)
366d7f14c66SUwe Kleine-KönigHOST_LOADLIBES := $(HOST_LFS_LIBS)
3671da177e4SLinus Torvalds
36861163efaSBehan Websterifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
36961163efaSBehan WebsterHOSTCFLAGS  += -Wno-unused-value -Wno-unused-parameter \
37061163efaSBehan Webster		-Wno-missing-field-initializers -fno-delete-null-pointer-checks
37161163efaSBehan Websterendif
37261163efaSBehan Webster
3731da177e4SLinus Torvalds# Make variables (CC, etc...)
3741da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
3751da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
3761da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
3771da177e4SLinus TorvaldsCPP		= $(CC) -E
3781da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
3791da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
3801da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
3811da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
3821da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
3831da177e4SLinus TorvaldsAWK		= awk
3841da177e4SLinus TorvaldsGENKSYMS	= scripts/genksyms/genksyms
385caa27b66SSam RavnborgINSTALLKERNEL  := installkernel
3861da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
3871da177e4SLinus TorvaldsPERL		= perl
388011bf125SMasahiro YamadaPYTHON		= python
3891da177e4SLinus TorvaldsCHECK		= sparse
3901da177e4SLinus Torvalds
39180a7d1d9SHannes EderCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
39280a7d1d9SHannes Eder		  -Wbitwise -Wno-return-void $(CF)
393b36fad65SMichal MarekNOSTDINC_FLAGS  =
3946588169dSSam RavnborgCFLAGS_MODULE   =
3956588169dSSam RavnborgAFLAGS_MODULE   =
3966588169dSSam RavnborgLDFLAGS_MODULE  =
3971da177e4SLinus TorvaldsCFLAGS_KERNEL	=
3981da177e4SLinus TorvaldsAFLAGS_KERNEL	=
399b36fad65SMichal MarekLDFLAGS_vmlinux =
400b334e19aSArnd BergmannCFLAGS_GCOV	:= -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disable-warning,maybe-uninitialized,)
401543c37cbSEmese RevfyCFLAGS_KCOV	:= $(call cc-option,-fsanitize-coverage=trace-pc,)
4021da177e4SLinus Torvalds
4031da177e4SLinus Torvalds
404abbf1590SDavid Howells# Use USERINCLUDE when you must reference the UAPI directories only.
405abbf1590SDavid HowellsUSERINCLUDE    := \
4069d022c54SMasahiro Yamada		-I$(srctree)/arch/$(SRCARCH)/include/uapi \
4079d022c54SMasahiro Yamada		-I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
408abbf1590SDavid Howells		-I$(srctree)/include/uapi \
4093308b285SArnd Bergmann		-I$(objtree)/include/generated/uapi \
410abbf1590SDavid Howells                -include $(srctree)/include/linux/kconfig.h
411abbf1590SDavid Howells
4121da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
4131da177e4SLinus Torvalds# Needed to be compatible with the O= option
414abbf1590SDavid HowellsLINUXINCLUDE    := \
4159d022c54SMasahiro Yamada		-I$(srctree)/arch/$(SRCARCH)/include \
4169d022c54SMasahiro Yamada		-I$(objtree)/arch/$(SRCARCH)/include/generated \
417abbf1590SDavid Howells		$(if $(KBUILD_SRC), -I$(srctree)/include) \
418f8224f7fSMasahiro Yamada		-I$(objtree)/include \
419f8224f7fSMasahiro Yamada		$(USERINCLUDE)
4201da177e4SLinus Torvalds
421d8672b40SSam RavnborgKBUILD_CPPFLAGS := -D__KERNEL__
4221da177e4SLinus Torvalds
423a0f97e06SSam RavnborgKBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
4248c97023cSArnd Bergmann		   -fno-strict-aliasing -fno-common -fshort-wchar \
425a8735821SFloris Kraak		   -Werror-implicit-function-declaration \
42651b97e35SKirill A. Shutemov		   -Wno-format-security \
427c6a38553SBorislav Petkov		   -std=gnu89 $(call cc-option,-fno-PIE)
428c6a38553SBorislav Petkov
429a1c48bb1SGeert Uytterhoeven
43080c00ba9SSam RavnborgKBUILD_AFLAGS_KERNEL :=
43180c00ba9SSam RavnborgKBUILD_CFLAGS_KERNEL :=
432c6a38553SBorislav PetkovKBUILD_AFLAGS   := -D__ASSEMBLY__ $(call cc-option,-fno-PIE)
4336588169dSSam RavnborgKBUILD_AFLAGS_MODULE  := -DMODULE
4346588169dSSam RavnborgKBUILD_CFLAGS_MODULE  := -DMODULE
4356588169dSSam RavnborgKBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
4361da177e4SLinus Torvalds
43780ef88d6SSam Ravnborgexport ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
438d7f14c66SUwe Kleine-Königexport CPP AR NM STRIP OBJCOPY OBJDUMP HOSTLDFLAGS HOST_LOADLIBES
439011bf125SMasahiro Yamadaexport MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE
440070b98bfSSam Ravnborgexport HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
4411da177e4SLinus Torvalds
44206c5040cSSam Ravnborgexport KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
4435c9a8750SDmitry Vyukovexport KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV CFLAGS_KCOV CFLAGS_KASAN CFLAGS_UBSAN
444222d394dSSam Ravnborgexport KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
4456588169dSSam Ravnborgexport KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
44680c00ba9SSam Ravnborgexport KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
44740df759eSMichal Marekexport KBUILD_ARFLAGS
4481da177e4SLinus Torvalds
4491da177e4SLinus Torvalds# When compiling out-of-tree modules, put MODVERDIR in the module
4501da177e4SLinus Torvalds# tree rather than in the kernel tree. The kernel tree might
4511da177e4SLinus Torvalds# even be read-only.
4521da177e4SLinus Torvaldsexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
4531da177e4SLinus Torvalds
4541da177e4SLinus Torvalds# Files to ignore in find ... statements
4551da177e4SLinus Torvalds
456ae63b2d7SPrarit Bhargavaexport RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o    \
457ae63b2d7SPrarit Bhargava			  -name CVS -o -name .pc -o -name .hg -o -name .git \) \
458ae63b2d7SPrarit Bhargava			  -prune -o
459450c6076SJesper Juhlexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
460450c6076SJesper Juhl			 --exclude CVS --exclude .pc --exclude .hg --exclude .git
4611da177e4SLinus Torvalds
4621da177e4SLinus Torvalds# ===========================================================================
4631da177e4SLinus Torvalds# Rules shared between *config targets and build targets
4641da177e4SLinus Torvalds
465312a3d09SCao jin# Basic helpers built in scripts/basic/
4664f193362SPaul SmithPHONY += scripts_basic
4671da177e4SLinus Torvaldsscripts_basic:
4681da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/basic
469638adb05SSteven Rostedt	$(Q)rm -f .tmp_quiet_recordmcount
4701da177e4SLinus Torvalds
471cd05e6bdSJan Beulich# To avoid any implicit rule to kick in, define an empty command.
472cd05e6bdSJan Beulichscripts/basic/%: scripts_basic ;
473cd05e6bdSJan Beulich
4744f193362SPaul SmithPHONY += outputmakefile
475fd5f0cd6SJan Beulich# outputmakefile generates a Makefile in the output directory, if using a
476fd5f0cd6SJan Beulich# separate output directory. This allows convenient use of make in the
477fd5f0cd6SJan Beulich# output directory.
4781da177e4SLinus Torvaldsoutputmakefile:
479fd5f0cd6SJan Beulichifneq ($(KBUILD_SRC),)
48092979997SAndi Kleen	$(Q)ln -fsn $(srctree) source
481fd5f0cd6SJan Beulich	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
482fd5f0cd6SJan Beulich	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
483fd5f0cd6SJan Beulichendif
4841da177e4SLinus Torvalds
4851da177e4SLinus Torvaldsifeq ($(config-targets),1)
4861da177e4SLinus Torvalds# ===========================================================================
4871da177e4SLinus Torvalds# *config targets only - make sure prerequisites are updated, and descend
4881da177e4SLinus Torvalds# in scripts/kconfig to make the *config target
4891da177e4SLinus Torvalds
4901da177e4SLinus Torvalds# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
4911da177e4SLinus Torvalds# KBUILD_DEFCONFIG may point out an alternative default configuration
4921da177e4SLinus Torvalds# used for 'make defconfig'
493a436bb7bSMasahiro Yamadainclude arch/$(SRCARCH)/Makefile
49461bee204SAl Viroexport KBUILD_DEFCONFIG KBUILD_KCONFIG
4951da177e4SLinus Torvalds
49631110ebbSSam Ravnborgconfig: scripts_basic outputmakefile FORCE
49731110ebbSSam Ravnborg	$(Q)$(MAKE) $(build)=scripts/kconfig $@
49831110ebbSSam Ravnborg
49931110ebbSSam Ravnborg%config: scripts_basic outputmakefile FORCE
5001da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/kconfig $@
5011da177e4SLinus Torvalds
5021da177e4SLinus Torvaldselse
5031da177e4SLinus Torvalds# ===========================================================================
5041da177e4SLinus Torvalds# Build targets only - this includes vmlinux, arch specific targets, clean
5051da177e4SLinus Torvalds# targets and others. In general all targets except *config targets.
5061da177e4SLinus Torvalds
5072c1f4f12SMasahiro Yamada# If building an external module we do not care about the all: rule
5082c1f4f12SMasahiro Yamada# but instead _all depend on modules
5092c1f4f12SMasahiro YamadaPHONY += all
5102c1f4f12SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
5112c1f4f12SMasahiro Yamada_all: all
5122c1f4f12SMasahiro Yamadaelse
513