Makefile revision bfeffd15
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2bfeffd15SLinus TorvaldsVERSION = 5
3bfeffd15SLinus TorvaldsPATCHLEVEL = 0
455922c9dSLinus TorvaldsSUBLEVEL = 0
5bfeffd15SLinus TorvaldsEXTRAVERSION = -rc1
62e6e902dSLinus TorvaldsNAME = Shy Crocodile
71da177e4SLinus Torvalds
81da177e4SLinus Torvalds# *DOCUMENTATION*
91da177e4SLinus Torvalds# To see a list of typical targets execute "make help"
101da177e4SLinus Torvalds# More info can be located in ./README
111da177e4SLinus Torvalds# Comments in this file are targeted only to the developer, do not
121da177e4SLinus Torvalds# expect to learn how to build the kernel reading this file.
131da177e4SLinus Torvalds
14ba634eceSMasahiro Yamada# That's our default target when none is given on the command line
15ba634eceSMasahiro YamadaPHONY := _all
16ba634eceSMasahiro Yamada_all:
17ba634eceSMasahiro Yamada
1880463f1bSMasahiro Yamada# Do not use make's built-in rules and variables
1980463f1bSMasahiro Yamada# (this increases performance and avoids hard-to-debug behaviour)
2080463f1bSMasahiro YamadaMAKEFLAGS += -rR
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
37f49821eeSNicholas Piggin# unavoidable when linking the built-in.a 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)
133028568d8SMasahiro YamadaKBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
13416f8259cSBjørn Forsman								&& pwd)
1351da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1361c9e70a5SMasahiro Yamada     $(error failed to create output directory "$(saved-output)"))
1371da177e4SLinus Torvalds
13880463f1bSMasahiro Yamada# Look for make include files relative to root of kernel src
13980463f1bSMasahiro Yamada#
14080463f1bSMasahiro Yamada# This does not become effective immediately because MAKEFLAGS is re-parsed
14180463f1bSMasahiro Yamada# once after the Makefile is read.  It is OK since we are going to invoke
14280463f1bSMasahiro Yamada# 'sub-make' below.
14380463f1bSMasahiro YamadaMAKEFLAGS += --include-dir=$(CURDIR)
14480463f1bSMasahiro Yamada
1450b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1460b35786dSMilton Miller
1471cacc9abSSam Ravnborg$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
14816f89098SCharles Keepax	@:
1490b35786dSMilton Miller
150c4e6fff1SCao jin# Invoke a second make in the output directory, passing relevant variables
1512e8d696bSMasahiro Yamadasub-make:
152745a2543SMasahiro Yamada	$(Q)$(MAKE) -C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR) \
153aa55c8e2SMasahiro Yamada	-f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
1541da177e4SLinus Torvalds
1551da177e4SLinus Torvalds# Leave processing to above invocation of make
1561da177e4SLinus Torvaldsskip-makefile := 1
1571da177e4SLinus Torvaldsendif # ifneq ($(KBUILD_OUTPUT),)
1581da177e4SLinus Torvaldsendif # ifeq ($(KBUILD_SRC),)
1591da177e4SLinus Torvalds
1601da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
1611da177e4SLinus Torvaldsifeq ($(skip-makefile),)
1621da177e4SLinus Torvalds
1637ff52571SMasahiro Yamada# Do not print "Entering directory ...",
1647ff52571SMasahiro Yamada# but we want to display it when entering to the output directory
1657ff52571SMasahiro Yamada# so that IDEs/editors are able to understand relative filenames.
1667ff52571SMasahiro YamadaMAKEFLAGS += --no-print-directory
1677ff52571SMasahiro Yamada
168aa55c8e2SMasahiro Yamada# Call a source code checker (by default, "sparse") as part of the
169aa55c8e2SMasahiro Yamada# C compilation.
170aa55c8e2SMasahiro Yamada#
171aa55c8e2SMasahiro Yamada# Use 'make C=1' to enable checking of only re-compiled files.
172aa55c8e2SMasahiro Yamada# Use 'make C=2' to enable checking of *all* source files, regardless
173aa55c8e2SMasahiro Yamada# of whether they are re-compiled or not.
174aa55c8e2SMasahiro Yamada#
175036db11cSCao jin# See the file "Documentation/dev-tools/sparse.rst" for more details,
176036db11cSCao jin# including where to get the "sparse" utility.
177aa55c8e2SMasahiro Yamada
178aa55c8e2SMasahiro Yamadaifeq ("$(origin C)", "command line")
179aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = $(C)
180aa55c8e2SMasahiro Yamadaendif
181aa55c8e2SMasahiro Yamadaifndef KBUILD_CHECKSRC
182aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = 0
183aa55c8e2SMasahiro Yamadaendif
184aa55c8e2SMasahiro Yamada
185aa55c8e2SMasahiro Yamada# Use make M=dir to specify directory of external module to build
186aa55c8e2SMasahiro Yamada# Old syntax make ... SUBDIRS=$PWD is still supported
187aa55c8e2SMasahiro Yamada# Setting the environment variable KBUILD_EXTMOD take precedence
188aa55c8e2SMasahiro Yamadaifdef SUBDIRS
1890126be38SMasahiro Yamada  $(warning ================= WARNING ================)
1900126be38SMasahiro Yamada  $(warning 'SUBDIRS' will be removed after Linux 5.3)
1910126be38SMasahiro Yamada  $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead)
1920126be38SMasahiro Yamada  $(warning ==========================================)
193aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD ?= $(SUBDIRS)
194aa55c8e2SMasahiro Yamadaendif
195aa55c8e2SMasahiro Yamada
196aa55c8e2SMasahiro Yamadaifeq ("$(origin M)", "command line")
197aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD := $(M)
198aa55c8e2SMasahiro Yamadaendif
199aa55c8e2SMasahiro Yamada
2009da0763bSMichal Marekifeq ($(KBUILD_SRC),)
2019da0763bSMichal Marek        # building in the source tree
2029da0763bSMichal Marek        srctree := .
2039da0763bSMichal Marekelse
2049da0763bSMichal Marek        ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
2059da0763bSMichal Marek                # building in a subdirectory of the source tree
2069da0763bSMichal Marek                srctree := ..
2079da0763bSMichal Marek        else
2089da0763bSMichal Marek                srctree := $(KBUILD_SRC)
2099da0763bSMichal Marek        endif
2109da0763bSMichal Marekendif
2112c1f4f12SMasahiro Yamada
2132c1f4f12SMasahiro Yamada
2147e1c0477SMichal Marekobjtree		:= .
2151da177e4SLinus Torvaldssrc		:= $(srctree)
2161da177e4SLinus Torvaldsobj		:= $(objtree)
2171da177e4SLinus Torvalds
2180f558c33SMattia DongiliVPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
2191da177e4SLinus Torvalds
22011294235SAmerigo Wangexport srctree objtree VPATH
2211da177e4SLinus Torvalds
2222c1f4f12SMasahiro Yamada# To make sure we do not include .config for any of the *config targets
2232c1f4f12SMasahiro Yamada# catch them early, and hand them over to scripts/kconfig/Makefile
2242c1f4f12SMasahiro Yamada# It is allowed to specify more targets when calling make, including
2252c1f4f12SMasahiro Yamada# mixing *config targets and build targets.
2262c1f4f12SMasahiro Yamada# For example 'make oldconfig all'.
2272c1f4f12SMasahiro Yamada# Detect when mixed targets is specified, and make a second invocation
2282c1f4f12SMasahiro Yamada# of make so .config is not included in this case either (for *config).
2292c1f4f12SMasahiro Yamada
2302c1f4f12SMasahiro Yamadaversion_h := include/generated/uapi/linux/version.h
2312c1f4f12SMasahiro Yamadaold_version_h := include/linux/version.h
2322c1f4f12SMasahiro Yamada
23322340a06SMasahiro Yamadaclean-targets := %clean mrproper cleandocs
23422340a06SMasahiro Yamadano-dot-config-targets := $(clean-targets) \
2352c1f4f12SMasahiro Yamada			 cscope gtags TAGS tags help% %docs check% coccicheck \
2362c1f4f12SMasahiro Yamada			 $(version_h) headers_% archheaders archscripts \
23763e31a67SMasahiro Yamada			 %asm-generic kernelversion %src-pkg
238a29d4d8cSMasahiro Yamadano-sync-config-targets := $(no-dot-config-targets) install %install \
239a29d4d8cSMasahiro Yamada			   kernelrelease
2402c1f4f12SMasahiro Yamada
241d7942413SMasahiro Yamadaconfig-targets  := 0
242d7942413SMasahiro Yamadamixed-targets   := 0
243d7942413SMasahiro Yamadadot-config      := 1
244d7942413SMasahiro Yamadamay-sync-config := 1
2452c1f4f12SMasahiro Yamada
2462c1f4f12SMasahiro Yamadaifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
2472c1f4f12SMasahiro Yamada	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
2482c1f4f12SMasahiro Yamada		dot-config := 0
2492c1f4f12SMasahiro Yamada	endif
2502c1f4f12SMasahiro Yamadaendif
2512c1f4f12SMasahiro Yamada
252d7942413SMasahiro Yamadaifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
253d7942413SMasahiro Yamada	ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
254d7942413SMasahiro Yamada		may-sync-config := 0
255d7942413SMasahiro Yamada	endif
256d7942413SMasahiro Yamadaendif
257d7942413SMasahiro Yamada
258d7942413SMasahiro Yamadaifneq ($(KBUILD_EXTMOD),)
259d7942413SMasahiro Yamada	may-sync-config := 0
260d7942413SMasahiro Yamadaendif
261d7942413SMasahiro Yamada
2622c1f4f12SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
2632c1f4f12SMasahiro Yamada        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
2642c1f4f12SMasahiro Yamada                config-targets := 1
2652c1f4f12SMasahiro Yamada                ifneq ($(words $(MAKECMDGOALS)),1)
2662c1f4f12SMasahiro Yamada                        mixed-targets := 1
2672c1f4f12SMasahiro Yamada                endif
2682c1f4f12SMasahiro Yamada        endif
2692c1f4f12SMasahiro Yamadaendif
27022340a06SMasahiro Yamada
27122340a06SMasahiro Yamada# For "make -j clean all", "make -j mrproper defconfig all", etc.
27222340a06SMasahiro Yamadaifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
27322340a06SMasahiro Yamada        ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
27422340a06SMasahiro Yamada                mixed-targets := 1
27522340a06SMasahiro Yamada        endif
27622340a06SMasahiro Yamadaendif
27722340a06SMasahiro Yamada
2782c1f4f12SMasahiro Yamada# install and modules_install need also be processed one by one
2792c1f4f12SMasahiro Yamadaifneq ($(filter install,$(MAKECMDGOALS)),)
2802c1f4f12SMasahiro Yamada        ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
2812c1f4f12SMasahiro Yamada	        mixed-targets := 1
2822c1f4f12SMasahiro Yamada        endif
2832c1f4f12SMasahiro Yamadaendif
2842c1f4f12SMasahiro Yamada
2852c1f4f12SMasahiro Yamadaifeq ($(mixed-targets),1)
2862c1f4f12SMasahiro Yamada# ===========================================================================
2872c1f4f12SMasahiro Yamada# We're called with mixed targets (*config and build targets).
2882c1f4f12SMasahiro Yamada# Handle them one by one.
2892c1f4f12SMasahiro Yamada
2902c1f4f12SMasahiro YamadaPHONY += $(MAKECMDGOALS) __build_one_by_one
2912c1f4f12SMasahiro Yamada
2922c1f4f12SMasahiro Yamada$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
2932c1f4f12SMasahiro Yamada	@:
2942c1f4f12SMasahiro Yamada
2952c1f4f12SMasahiro Yamada__build_one_by_one:
2962c1f4f12SMasahiro Yamada	$(Q)set -e; \
2972c1f4f12SMasahiro Yamada	for i in $(MAKECMDGOALS); do \
2982c1f4f12SMasahiro Yamada		$(MAKE) -f $(srctree)/Makefile $$i; \
2992c1f4f12SMasahiro Yamada	done
3002c1f4f12SMasahiro Yamada
3012c1f4f12SMasahiro Yamadaelse
3022c1f4f12SMasahiro Yamada
3032c1f4f12SMasahiro Yamada# We need some generic definitions (do not try to remake the file).
3042c1f4f12SMasahiro Yamadascripts/Kbuild.include: ;
3052c1f4f12SMasahiro Yamadainclude scripts/Kbuild.include
3062c1f4f12SMasahiro Yamada
3072c1f4f12SMasahiro Yamada# Read KERNELRELEASE from include/config/kernel.release (if it exists)
3082c1f4f12SMasahiro YamadaKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
3112c1f4f12SMasahiro Yamada
312b2d35fa5SAnders Roxellinclude scripts/subarch.include
3131da177e4SLinus Torvalds
3141da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
3151da177e4SLinus Torvalds# ---------------------------------------------------------------------------
3161da177e4SLinus Torvalds#
3171da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
3181da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
3191da177e4SLinus Torvalds# ARCH can be set during invocation of make:
3201da177e4SLinus Torvalds# make ARCH=ia64
3211da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
3221da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
3231da177e4SLinus Torvalds
3241da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
3251da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
3261da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
3271da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
3281da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
3291da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
3301da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
3311da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
3322331d1a6SSam RavnborgARCH		?= $(SUBARCH)
3331da177e4SLinus Torvalds
3341da177e4SLinus Torvalds# Architecture as present in compile.h
3356752ed90SThomas GleixnerUTS_MACHINE 	:= $(ARCH)
3366752ed90SThomas GleixnerSRCARCH 	:= $(ARCH)
3371da177e4SLinus Torvalds
338d746d647SSam Ravnborg# Additional ARCH settings for x86
339d746d647SSam Ravnborgifeq ($(ARCH),i386)
340d746d647SSam Ravnborg        SRCARCH := x86
341d746d647SSam Ravnborgendif
342d746d647SSam Ravnborgifeq ($(ARCH),x86_64)
343d746d647SSam Ravnborg        SRCARCH := x86
344d746d647SSam Ravnborgendif
34574b469f2SSam Ravnborg
3465e538790SSam Ravnborg# Additional ARCH settings for sparc
347e69f58c0SNamhyung Kimifeq ($(ARCH),sparc32)
348e69f58c0SNamhyung Kim       SRCARCH := sparc
349e69f58c0SNamhyung Kimendif
350a439fe51SSam Ravnborgifeq ($(ARCH),sparc64)
3515e538790SSam Ravnborg       SRCARCH := sparc
352a439fe51SSam Ravnborgendif
3532fb9b1bdSSam Ravnborg
3543cc000b5SPaul Mundt# Additional ARCH settings for sh
3553cc000b5SPaul Mundtifeq ($(ARCH),sh64)
3563cc000b5SPaul Mundt       SRCARCH := sh
3573cc000b5SPaul Mundtendif
3583cc000b5SPaul Mundt
35914cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
36041263fc6SBen Gardinerexport KCONFIG_CONFIG
36114cdd3c4SRoman Zippel
3621da177e4SLinus Torvalds# SHELL used by kbuild
3631da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
3641da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
3651da177e4SLinus Torvalds	  else echo sh; fi ; fi)
3661da177e4SLinus Torvalds
3676d79a7b4SMasahiro YamadaHOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
3686d79a7b4SMasahiro YamadaHOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
3696d79a7b4SMasahiro YamadaHOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
370d7f14c66SUwe Kleine-König
371070b98bfSSam RavnborgHOSTCC       = gcc
372070b98bfSSam RavnborgHOSTCXX      = g++
37396f14fe7SLaura AbbottKBUILD_HOSTCFLAGS   := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
374f92d19e0SLaura Abbott		-fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \
375f92d19e0SLaura Abbott		$(HOSTCFLAGS)
3791da177e4SLinus Torvalds
3801da177e4SLinus Torvalds# Make variables (CC, etc...)
3811da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
3821da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
3831da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
3841da177e4SLinus TorvaldsCPP		= $(CC) -E
3851da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
3861da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
3871da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
3881da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
3891da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
39073a4f6dbSMasahiro YamadaLEX		= flex
39173a4f6dbSMasahiro YamadaYACC		= bison
3921da177e4SLinus TorvaldsAWK		= awk
3931da177e4SLinus TorvaldsGENKSYMS	= scripts/genksyms/genksyms
394caa27b66SSam RavnborgINSTALLKERNEL  := installkernel
3951da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
3961da177e4SLinus TorvaldsPERL		= perl
397011bf125SMasahiro YamadaPYTHON		= python
398e9781b52SMasahiro YamadaPYTHON2		= python2
399e9781b52SMasahiro YamadaPYTHON3		= python3
4001da177e4SLinus TorvaldsCHECK		= sparse
4011da177e4SLinus Torvalds
40280a7d1d9SHannes EderCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
4036c49f359SLuc Van Oostenryck		  -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
404b36fad65SMichal MarekNOSTDINC_FLAGS  =
4056588169dSSam RavnborgCFLAGS_MODULE   =
4066588169dSSam RavnborgAFLAGS_MODULE   =
4076588169dSSam RavnborgLDFLAGS_MODULE  =
4081da177e4SLinus TorvaldsCFLAGS_KERNEL	=
4091da177e4SLinus TorvaldsAFLAGS_KERNEL	=
410b36fad65SMichal MarekLDFLAGS_vmlinux =
4111da177e4SLinus Torvalds
412abbf1590SDavid Howells# Use USERINCLUDE when you must reference the UAPI directories only.
413abbf1590SDavid HowellsUSERINCLUDE    := \
4149d022c54SMasahiro Yamada		-I$(srctree)/arch/$(SRCARCH)/include/uapi \
4159d022c54SMasahiro Yamada		-I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
416abbf1590SDavid Howells		-I$(srctree)/include/uapi \
4173308b285SArnd Bergmann		-I$(objtree)/include/generated/uapi \
418abbf1590SDavid Howells                -include $(srctree)/include/linux/kconfig.h
419abbf1590SDavid Howells
4201da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
4211da177e4SLinus Torvalds# Needed to be compatible with the O= option
422abbf1590SDavid HowellsLINUXINCLUDE    := \
4239d022c54SMasahiro Yamada		-I$(srctree)/arch/$(SRCARCH)/include \
4249d022c54SMasahiro Yamada		-I$(objtree)/arch/$(SRCARCH)/include/generated \
425abbf1590SDavid Howells		$(if $(KBUILD_SRC), -I$(srctree)/include) \
426f8224f7fSMasahiro Yamada		-I$(objtree)/include \
427f8224f7fSMasahiro Yamada		$(USERINCLUDE)
4281da177e4SLinus Torvalds
42942a92bccSMasahiro YamadaKBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-PIE
430eeb5687aSMasahiro YamadaKBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
43142a92bccSMasahiro Yamada		   -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
43261a0902aSMasahiro Yamada		   -Werror-implicit-function-declaration -Werror=implicit-int \
43351b97e35SKirill A. Shutemov		   -Wno-format-security \
434433dc2ebSMasahiro Yamada		   -std=gnu89
435433dc2ebSMasahiro YamadaKBUILD_CPPFLAGS := -D__KERNEL__
43680c00ba9SSam RavnborgKBUILD_AFLAGS_KERNEL :=
43780c00ba9SSam RavnborgKBUILD_CFLAGS_KERNEL :=
4386588169dSSam RavnborgKBUILD_AFLAGS_MODULE  := -DMODULE
4396588169dSSam RavnborgKBUILD_CFLAGS_MODULE  := -DMODULE
4406588169dSSam RavnborgKBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/
441d503ac53SMasahiro YamadaKBUILD_LDFLAGS :=
442433dc2ebSMasahiro YamadaGCC_PLUGINS_CFLAGS :=
4431da177e4SLinus Torvalds
4481da177e4SLinus Torvalds
45540df759eSMichal Marekexport KBUILD_ARFLAGS
4561da177e4SLinus Torvalds
4571da177e4SLinus Torvalds# When compiling out-of-tree modules, put MODVERDIR in the module
4581da177e4SLinus Torvalds# tree rather than in the kernel tree. The kernel tree might
4591da177e4SLinus Torvalds# even be read-only.
4601da177e4SLinus Torvaldsexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
4611da177e4SLinus Torvalds
4621da177e4SLinus Torvalds# Files to ignore in find ... statements
4631da177e4SLinus Torvalds
464ae63b2d7SPrarit Bhargavaexport RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o    \
465ae63b2d7SPrarit Bhargava			  -name CVS -o -name .pc -o -name .hg -o -name .git \) \
466ae63b2d7SPrarit Bhargava			  -prune -o
467450c6076SJesper Juhlexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
468450c6076SJesper Juhl			 --exclude CVS --exclude .pc --exclude .hg --exclude .git
4691da177e4SLinus Torvalds
4701da177e4SLinus Torvalds# ===========================================================================
4711da177e4SLinus Torvalds# Rules shared between *config targets and build targets
4721da177e4SLinus Torvalds
473312a3d09SCao jin# Basic helpers built in scripts/basic/
4744f193362SPaul SmithPHONY += scripts_basic
4751da177e4SLinus Torvaldsscripts_basic:
4761da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/basic
477638adb05SSteven Rostedt	$(Q)rm -f .tmp_quiet_recordmcount
4781da177e4SLinus Torvalds
479cd05e6bdSJan Beulich# To avoid any implicit rule to kick in, define an empty command.
480cd05e6bdSJan Beulichscripts/basic/%: scripts_basic ;
481cd05e6bdSJan Beulich
4824f193362SPaul SmithPHONY += outputmakefile
483fd5f0cd6SJan Beulich# outputmakefile generates a Makefile in the output directory, if using a
484fd5f0cd6SJan Beulich# separate output directory. This allows convenient use of make in the
485fd5f0cd6SJan Beulich# output directory.