Makefile revision 6b12de69
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2bfeffd15SLinus TorvaldsVERSION = 5
3bfeffd15SLinus TorvaldsPATCHLEVEL = 0
455922c9dSLinus TorvaldsSUBLEVEL = 0
5f17b5f06SLinus TorvaldsEXTRAVERSION = -rc4
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
181da177e4SLinus Torvalds# We are using a recursive build, so we need to do a little thinking
191da177e4SLinus Torvalds# to get the ordering right.
201da177e4SLinus Torvalds#
211da177e4SLinus Torvalds# Most importantly: sub-Makefiles should only ever modify files in
221da177e4SLinus Torvalds# their own directory. If in some directory we have a dependency on
231da177e4SLinus Torvalds# a file in another dir (which doesn't happen often, but it's often
24f49821eeSNicholas Piggin# unavoidable when linking the built-in.a targets which finally
251da177e4SLinus Torvalds# turn into vmlinux), we will call a sub make in that other dir, and
261da177e4SLinus Torvalds# after that we are sure that everything which is in that other dir
271da177e4SLinus Torvalds# is now up to date.
281da177e4SLinus Torvalds#
291da177e4SLinus Torvalds# The only cases where we need to modify files which have global
301da177e4SLinus Torvalds# effects are thus separated out and done before the recursive
311da177e4SLinus Torvalds# descending is started. They are now explicitly listed as the
321da177e4SLinus Torvalds# prepare rule.
331da177e4SLinus Torvalds
343812b8c5SMasahiro Yamadaifneq ($(sub-make-done),1)
353812b8c5SMasahiro Yamada
363812b8c5SMasahiro Yamada# Do not use make's built-in rules and variables
373812b8c5SMasahiro Yamada# (this increases performance and avoids hard-to-debug behaviour)
383812b8c5SMasahiro YamadaMAKEFLAGS += -rR
393812b8c5SMasahiro Yamada
40b999923cSMasahiro Yamada# 'MAKEFLAGS += -rR' does not become immediately effective for old
41b999923cSMasahiro Yamada# GNU Make versions. Cancel implicit rules for this Makefile.
42b999923cSMasahiro Yamada$(lastword $(MAKEFILE_LIST)): ;
43b999923cSMasahiro Yamada
443812b8c5SMasahiro Yamada# Avoid funny character set dependencies
453812b8c5SMasahiro Yamadaunexport LC_ALL
463812b8c5SMasahiro YamadaLC_COLLATE=C
473812b8c5SMasahiro YamadaLC_NUMERIC=C
483812b8c5SMasahiro Yamadaexport LC_COLLATE LC_NUMERIC
493812b8c5SMasahiro Yamada
503812b8c5SMasahiro Yamada# Avoid interference with shell env settings
513812b8c5SMasahiro Yamadaunexport GREP_OPTIONS
523812b8c5SMasahiro Yamada
53066b7ed9SMichal Marek# Beautify output
54066b7ed9SMichal Marek# ---------------------------------------------------------------------------
55066b7ed9SMichal Marek#
56066b7ed9SMichal Marek# Normally, we echo the whole command before executing it. By making
57066b7ed9SMichal Marek# that echo $($(quiet)$(cmd)), we now have the possibility to set
58066b7ed9SMichal Marek# $(quiet) to choose other forms of output instead, e.g.
59066b7ed9SMichal Marek#
60066b7ed9SMichal Marek#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
61066b7ed9SMichal Marek#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
62066b7ed9SMichal Marek#
63066b7ed9SMichal Marek# If $(quiet) is empty, the whole command will be printed.
64066b7ed9SMichal Marek# If it is set to "quiet_", only the short version will be printed.
65066b7ed9SMichal Marek# If it is set to "silent_", nothing will be printed at all, since
66066b7ed9SMichal Marek# the variable $(silent_cmd_cc_o_c) doesn't exist.
67066b7ed9SMichal Marek#
68066b7ed9SMichal Marek# A simple variant is to prefix commands with $(Q) - that's useful
69066b7ed9SMichal Marek# for commands that shall be hidden in non-verbose mode.
70066b7ed9SMichal Marek#
71066b7ed9SMichal Marek#	$(Q)ln $@ :<
72066b7ed9SMichal Marek#
73066b7ed9SMichal Marek# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
74066b7ed9SMichal Marek# If KBUILD_VERBOSE equals 1 then the above command is displayed.
75066b7ed9SMichal Marek#
761da177e4SLinus Torvalds# To put more focus on warnings, be less verbose as default
771da177e4SLinus Torvalds# Use 'make V=1' to see the full commands
781da177e4SLinus Torvalds
79b8b0618cSCheng Renquanifeq ("$(origin V)", "command line")
80b8b0618cSCheng Renquan  KBUILD_VERBOSE = $(V)
811da177e4SLinus Torvaldsendif
821da177e4SLinus Torvaldsifndef KBUILD_VERBOSE
831da177e4SLinus Torvalds  KBUILD_VERBOSE = 0
841da177e4SLinus Torvaldsendif
851da177e4SLinus Torvalds
86066b7ed9SMichal Marekifeq ($(KBUILD_VERBOSE),1)
87066b7ed9SMichal Marek  quiet =
88066b7ed9SMichal Marek  Q =
89066b7ed9SMichal Marekelse
90066b7ed9SMichal Marek  quiet=quiet_
91066b7ed9SMichal Marek  Q = @
92066b7ed9SMichal Marekendif
93066b7ed9SMichal Marek
94066b7ed9SMichal Marek# If the user is running make -s (silent mode), suppress echoing of
95066b7ed9SMichal Marek# commands
96066b7ed9SMichal Marek
976f0fa58eSMasahiro Yamadaifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
98066b7ed9SMichal Marek  quiet=silent_
99066b7ed9SMichal Marekendif
100066b7ed9SMichal Marek
101066b7ed9SMichal Marekexport quiet Q KBUILD_VERBOSE
102066b7ed9SMichal Marek
1031da177e4SLinus Torvalds# kbuild supports saving output files in a separate directory.
1041da177e4SLinus Torvalds# To locate output files in a separate directory two syntaxes are supported.
1051da177e4SLinus Torvalds# In both cases the working directory must be the root of the kernel src.
1061da177e4SLinus Torvalds# 1) O=
1071da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/"
108070b98bfSSam Ravnborg#
1091da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT
1101da177e4SLinus Torvalds# Set the environment variable KBUILD_OUTPUT to point to the directory
1111da177e4SLinus Torvalds# where the output files shall be placed.
1121da177e4SLinus Torvalds# export KBUILD_OUTPUT=dir/to/store/output/files/
1131da177e4SLinus Torvalds# make
1141da177e4SLinus Torvalds#
1151da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment
1161da177e4SLinus Torvalds# variable.
1171da177e4SLinus Torvalds
118c4e6fff1SCao jin# KBUILD_SRC is not intended to be used by the regular user (for now),
119c4e6fff1SCao jin# it is set on invocation of make with KBUILD_OUTPUT or O= specified.
1201da177e4SLinus Torvalds
1211da177e4SLinus Torvalds# OK, Make called in directory where kernel src resides
1221da177e4SLinus Torvalds# Do we want to locate output files in a separate directory?
123b8b0618cSCheng Renquanifeq ("$(origin O)", "command line")
124b8b0618cSCheng Renquan  KBUILD_OUTPUT := $(O)
1251da177e4SLinus Torvaldsendif
1261da177e4SLinus Torvalds
12751193b76SRobert Jarzmikifneq ($(words $(subst :, ,$(CURDIR))), 1)
12851193b76SRobert Jarzmik  $(error main directory cannot contain spaces nor colons)
12951193b76SRobert Jarzmikendif
13051193b76SRobert Jarzmik
1311da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
1321da177e4SLinus Torvalds# check that the output directory actually exists
1331da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
134028568d8SMasahiro YamadaKBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
13516f8259cSBjørn Forsman								&& pwd)
1361da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1371c9e70a5SMasahiro Yamada     $(error failed to create output directory "$(saved-output)"))
1381da177e4SLinus Torvalds
13980463f1bSMasahiro Yamada# Look for make include files relative to root of kernel src
14080463f1bSMasahiro Yamada#
14180463f1bSMasahiro Yamada# This does not become effective immediately because MAKEFLAGS is re-parsed
14280463f1bSMasahiro Yamada# once after the Makefile is read.  It is OK since we are going to invoke
14380463f1bSMasahiro Yamada# 'sub-make' below.
14480463f1bSMasahiro YamadaMAKEFLAGS += --include-dir=$(CURDIR)
14580463f1bSMasahiro Yamada
1463812b8c5SMasahiro Yamadaelse
1473812b8c5SMasahiro Yamada
1483812b8c5SMasahiro Yamada# Do not print "Entering directory ..." at all for in-tree build.
1493812b8c5SMasahiro YamadaMAKEFLAGS += --no-print-directory
1503812b8c5SMasahiro Yamada
1513812b8c5SMasahiro Yamadaendif # ifneq ($(KBUILD_OUTPUT),)
1523812b8c5SMasahiro Yamada
1530b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1540b35786dSMilton Miller
1551cacc9abSSam Ravnborg$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
15616f89098SCharles Keepax	@:
1570b35786dSMilton Miller
158c4e6fff1SCao jin# Invoke a second make in the output directory, passing relevant variables
1592e8d696bSMasahiro Yamadasub-make:
1603812b8c5SMasahiro Yamada	$(Q)$(MAKE) sub-make-done=1 \
1613812b8c5SMasahiro Yamada	$(if $(KBUILD_OUTPUT),-C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR)) \
162aa55c8e2SMasahiro Yamada	-f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
1631da177e4SLinus Torvalds
1643812b8c5SMasahiro Yamadaelse # sub-make-done
1651da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
1661da177e4SLinus Torvalds
1677ff52571SMasahiro Yamada# Do not print "Entering directory ...",
1687ff52571SMasahiro Yamada# but we want to display it when entering to the output directory
1697ff52571SMasahiro Yamada# so that IDEs/editors are able to understand relative filenames.
1707ff52571SMasahiro YamadaMAKEFLAGS += --no-print-directory
1717ff52571SMasahiro Yamada
172aa55c8e2SMasahiro Yamada# Call a source code checker (by default, "sparse") as part of the
173aa55c8e2SMasahiro Yamada# C compilation.
174aa55c8e2SMasahiro Yamada#
175aa55c8e2SMasahiro Yamada# Use 'make C=1' to enable checking of only re-compiled files.
176aa55c8e2SMasahiro Yamada# Use 'make C=2' to enable checking of *all* source files, regardless
177aa55c8e2SMasahiro Yamada# of whether they are re-compiled or not.
178aa55c8e2SMasahiro Yamada#
179036db11cSCao jin# See the file "Documentation/dev-tools/sparse.rst" for more details,
180036db11cSCao jin# including where to get the "sparse" utility.
181aa55c8e2SMasahiro Yamada
182aa55c8e2SMasahiro Yamadaifeq ("$(origin C)", "command line")
183aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = $(C)
184aa55c8e2SMasahiro Yamadaendif
185aa55c8e2SMasahiro Yamadaifndef KBUILD_CHECKSRC
186aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = 0
187aa55c8e2SMasahiro Yamadaendif
188aa55c8e2SMasahiro Yamada
189aa55c8e2SMasahiro Yamada# Use make M=dir to specify directory of external module to build
190aa55c8e2SMasahiro Yamada# Old syntax make ... SUBDIRS=$PWD is still supported
191aa55c8e2SMasahiro Yamada# Setting the environment variable KBUILD_EXTMOD take precedence
192aa55c8e2SMasahiro Yamadaifdef SUBDIRS
1930126be38SMasahiro Yamada  $(warning ================= WARNING ================)
1940126be38SMasahiro Yamada  $(warning 'SUBDIRS' will be removed after Linux 5.3)
1950126be38SMasahiro Yamada  $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead)
1960126be38SMasahiro Yamada  $(warning ==========================================)
197aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD ?= $(SUBDIRS)
198aa55c8e2SMasahiro Yamadaendif
199aa55c8e2SMasahiro Yamada
200aa55c8e2SMasahiro Yamadaifeq ("$(origin M)", "command line")
201aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD := $(M)
202aa55c8e2SMasahiro Yamadaendif
203aa55c8e2SMasahiro Yamada
2049da0763bSMichal Marekifeq ($(KBUILD_SRC),)
2059da0763bSMichal Marek        # building in the source tree
2069da0763bSMichal Marek        srctree := .
2079da0763bSMichal Marekelse
2089da0763bSMichal Marek        ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
2099da0763bSMichal Marek                # building in a subdirectory of the source tree
2109da0763bSMichal Marek                srctree := ..
2119da0763bSMichal Marek        else
2129da0763bSMichal Marek                srctree := $(KBUILD_SRC)
2139da0763bSMichal Marek        endif
2149da0763bSMichal Marekendif
2152c1f4f12SMasahiro Yamada
2162c1f4f12SMasahiro Yamadaexport KBUILD_CHECKSRC KBUILD_EXTMOD KBUILD_SRC
2172c1f4f12SMasahiro Yamada
2187e1c0477SMichal Marekobjtree		:= .
2191da177e4SLinus Torvaldssrc		:= $(srctree)
2201da177e4SLinus Torvaldsobj		:= $(objtree)
2211da177e4SLinus Torvalds
2226b12de69SMasahiro YamadaVPATH		:= $(srctree)
2231da177e4SLinus Torvalds
22411294235SAmerigo Wangexport srctree objtree VPATH
2251da177e4SLinus Torvalds
2262c1f4f12SMasahiro Yamada# To make sure we do not include .config for any of the *config targets
2272c1f4f12SMasahiro Yamada# catch them early, and hand them over to scripts/kconfig/Makefile
2282c1f4f12SMasahiro Yamada# It is allowed to specify more targets when calling make, including
2292c1f4f12SMasahiro Yamada# mixing *config targets and build targets.
2302c1f4f12SMasahiro Yamada# For example 'make oldconfig all'.
2312c1f4f12SMasahiro Yamada# Detect when mixed targets is specified, and make a second invocation
2322c1f4f12SMasahiro Yamada# of make so .config is not included in this case either (for *config).
2332c1f4f12SMasahiro Yamada
2342c1f4f12SMasahiro Yamadaversion_h := include/generated/uapi/linux/version.h
2352c1f4f12SMasahiro Yamadaold_version_h := include/linux/version.h
2362c1f4f12SMasahiro Yamada
23722340a06SMasahiro Yamadaclean-targets := %clean mrproper cleandocs
23822340a06SMasahiro Yamadano-dot-config-targets := $(clean-targets) \
2392c1f4f12SMasahiro Yamada			 cscope gtags TAGS tags help% %docs check% coccicheck \
2402c1f4f12SMasahiro Yamada			 $(version_h) headers_% archheaders archscripts \
24163e31a67SMasahiro Yamada			 %asm-generic kernelversion %src-pkg
242a29d4d8cSMasahiro Yamadano-sync-config-targets := $(no-dot-config-targets) install %install \
243a29d4d8cSMasahiro Yamada			   kernelrelease
2442c1f4f12SMasahiro Yamada
245d7942413SMasahiro Yamadaconfig-targets  := 0
246d7942413SMasahiro Yamadamixed-targets   := 0
247d7942413SMasahiro Yamadadot-config      := 1
248d7942413SMasahiro Yamadamay-sync-config := 1
2492c1f4f12SMasahiro Yamada
2502c1f4f12SMasahiro Yamadaifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
2512c1f4f12SMasahiro Yamada	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
2522c1f4f12SMasahiro Yamada		dot-config := 0
2532c1f4f12SMasahiro Yamada	endif
2542c1f4f12SMasahiro Yamadaendif
2552c1f4f12SMasahiro Yamada
256d7942413SMasahiro Yamadaifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
257d7942413SMasahiro Yamada	ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
258d7942413SMasahiro Yamada		may-sync-config := 0
259d7942413SMasahiro Yamada	endif
260d7942413SMasahiro Yamadaendif
261d7942413SMasahiro Yamada
262d7942413SMasahiro Yamadaifneq ($(KBUILD_EXTMOD),)
263d7942413SMasahiro Yamada	may-sync-config := 0
264d7942413SMasahiro Yamadaendif
265d7942413SMasahiro Yamada
2662c1f4f12SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
2672c1f4f12SMasahiro Yamada        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
2682c1f4f12SMasahiro Yamada                config-targets := 1
2692c1f4f12SMasahiro Yamada                ifneq ($(words $(MAKECMDGOALS)),1)
2702c1f4f12SMasahiro Yamada                        mixed-targets := 1
2712c1f4f12SMasahiro Yamada                endif
2722c1f4f12SMasahiro Yamada        endif
2732c1f4f12SMasahiro Yamadaendif
27422340a06SMasahiro Yamada
27522340a06SMasahiro Yamada# For "make -j clean all", "make -j mrproper defconfig all", etc.
27622340a06SMasahiro Yamadaifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
27722340a06SMasahiro Yamada        ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
27822340a06SMasahiro Yamada                mixed-targets := 1
27922340a06SMasahiro Yamada        endif
28022340a06SMasahiro Yamadaendif
28122340a06SMasahiro Yamada
2822c1f4f12SMasahiro Yamada# install and modules_install need also be processed one by one
2832c1f4f12SMasahiro Yamadaifneq ($(filter install,$(MAKECMDGOALS)),)
2842c1f4f12SMasahiro Yamada        ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
2852c1f4f12SMasahiro Yamada	        mixed-targets := 1
2862c1f4f12SMasahiro Yamada        endif
2872c1f4f12SMasahiro Yamadaendif
2882c1f4f12SMasahiro Yamada
2892c1f4f12SMasahiro Yamadaifeq ($(mixed-targets),1)
2902c1f4f12SMasahiro Yamada# ===========================================================================
2912c1f4f12SMasahiro Yamada# We're called with mixed targets (*config and build targets).
2922c1f4f12SMasahiro Yamada# Handle them one by one.
2932c1f4f12SMasahiro Yamada
2942c1f4f12SMasahiro YamadaPHONY += $(MAKECMDGOALS) __build_one_by_one
2952c1f4f12SMasahiro Yamada
2962c1f4f12SMasahiro Yamada$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
2972c1f4f12SMasahiro Yamada	@:
2982c1f4f12SMasahiro Yamada
2992c1f4f12SMasahiro Yamada__build_one_by_one:
3002c1f4f12SMasahiro Yamada	$(Q)set -e; \
3012c1f4f12SMasahiro Yamada	for i in $(MAKECMDGOALS); do \
3022c1f4f12SMasahiro Yamada		$(MAKE) -f $(srctree)/Makefile $$i; \
3032c1f4f12SMasahiro Yamada	done
3042c1f4f12SMasahiro Yamada
3052c1f4f12SMasahiro Yamadaelse
3062c1f4f12SMasahiro Yamada
3072c1f4f12SMasahiro Yamadainclude scripts/Kbuild.include
3082c1f4f12SMasahiro Yamada
3092c1f4f12SMasahiro Yamada# Read KERNELRELEASE from include/config/kernel.release (if it exists)
3102c1f4f12SMasahiro YamadaKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
3112c1f4f12SMasahiro YamadaKERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
3122c1f4f12SMasahiro Yamadaexport VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
3132c1f4f12SMasahiro Yamada
314b2d35fa5SAnders Roxellinclude scripts/subarch.include
3151da177e4SLinus Torvalds
3161da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
3171da177e4SLinus Torvalds# ---------------------------------------------------------------------------
3181da177e4SLinus Torvalds#
3191da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
3201da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
3211da177e4SLinus Torvalds# ARCH can be set during invocation of make:
3221da177e4SLinus Torvalds# make ARCH=ia64
3231da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
3241da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
3251da177e4SLinus Torvalds
3261da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
3271da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
3281da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
3291da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
3301da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
3311da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
3321da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
3331da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
3342331d1a6SSam RavnborgARCH		?= $(SUBARCH)
3351da177e4SLinus Torvalds
3361da177e4SLinus Torvalds# Architecture as present in compile.h
3376752ed90SThomas GleixnerUTS_MACHINE 	:= $(ARCH)
3386752ed90SThomas GleixnerSRCARCH 	:= $(ARCH)
3391da177e4SLinus Torvalds
340d746d647SSam Ravnborg# Additional ARCH settings for x86
341d746d647SSam Ravnborgifeq ($(ARCH),i386)
342d746d647SSam Ravnborg        SRCARCH := x86
343d746d647SSam Ravnborgendif
344d746d647SSam Ravnborgifeq ($(ARCH),x86_64)
345d746d647SSam Ravnborg        SRCARCH := x86
346d746d647SSam Ravnborgendif
34774b469f2SSam Ravnborg
3485e538790SSam Ravnborg# Additional ARCH settings for sparc
349e69f58c0SNamhyung Kimifeq ($(ARCH),sparc32)
350e69f58c0SNamhyung Kim       SRCARCH := sparc
351e69f58c0SNamhyung Kimendif
352a439fe51SSam Ravnborgifeq ($(ARCH),sparc64)
3535e538790SSam Ravnborg       SRCARCH := sparc
354a439fe51SSam Ravnborgendif
3552fb9b1bdSSam Ravnborg
3563cc000b5SPaul Mundt# Additional ARCH settings for sh
3573cc000b5SPaul Mundtifeq ($(ARCH),sh64)
3583cc000b5SPaul Mundt       SRCARCH := sh
3593cc000b5SPaul Mundtendif
3603cc000b5SPaul Mundt
36114cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
36241263fc6SBen Gardinerexport KCONFIG_CONFIG
36314cdd3c4SRoman Zippel
3641da177e4SLinus Torvalds# SHELL used by kbuild
3651da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
3661da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
3671da177e4SLinus Torvalds	  else echo sh; fi ; fi)
3681da177e4SLinus Torvalds
3696d79a7b4SMasahiro YamadaHOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
3706d79a7b4SMasahiro YamadaHOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
3716d79a7b4SMasahiro YamadaHOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
372d7f14c66SUwe Kleine-König
373070b98bfSSam RavnborgHOSTCC       = gcc
374070b98bfSSam RavnborgHOSTCXX      = g++
37596f14fe7SLaura AbbottKBUILD_HOSTCFLAGS   := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
376f92d19e0SLaura Abbott		-fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \
377f92d19e0SLaura Abbott		$(HOSTCFLAGS)
378f92d19e0SLaura AbbottKBUILD_HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
379f92d19e0SLaura AbbottKBUILD_HOSTLDFLAGS  := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
380f92d19e0SLaura AbbottKBUILD_HOSTLDLIBS   := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
3811da177e4SLinus Torvalds
3821da177e4SLinus Torvalds# Make variables (CC, etc...)
3831da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
3841da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
3851da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
3861da177e4SLinus TorvaldsCPP		= $(CC) -E
3871da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
3881da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
3891da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
3901da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
3911da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
39273a4f6dbSMasahiro YamadaLEX		= flex
39373a4f6dbSMasahiro YamadaYACC		= bison
3941da177e4SLinus TorvaldsAWK		= awk
395caa27b66SSam RavnborgINSTALLKERNEL  := installkernel
3961da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
3971da177e4SLinus TorvaldsPERL		= perl
398011bf125SMasahiro YamadaPYTHON		= python
399e9781b52SMasahiro YamadaPYTHON2		= python2
400e9781b52SMasahiro YamadaPYTHON3		= python3
4011da177e4SLinus TorvaldsCHECK		= sparse
4021da177e4SLinus Torvalds
40380a7d1d9SHannes EderCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
4046c49f359SLuc Van Oostenryck		  -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
405b36fad65SMichal MarekNOSTDINC_FLAGS  =
4066588169dSSam RavnborgCFLAGS_MODULE   =
4076588169dSSam RavnborgAFLAGS_MODULE   =
4086588169dSSam RavnborgLDFLAGS_MODULE  =
4091da177e4SLinus TorvaldsCFLAGS_KERNEL	=
4101da177e4SLinus TorvaldsAFLAGS_KERNEL	=
411b36fad65SMichal MarekLDFLAGS_vmlinux =
4121da177e4SLinus Torvalds
413abbf1590SDavid Howells# Use USERINCLUDE when you must reference the UAPI directories only.
414abbf1590SDavid HowellsUSERINCLUDE    := \
4159d022c54SMasahiro Yamada		-I$(srctree)/arch/$(SRCARCH)/include/uapi \
4169d022c54SMasahiro Yamada		-I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
417abbf1590SDavid Howells		-I$(srctree)/include/uapi \
4183308b285SArnd Bergmann		-I$(objtree)/include/generated/uapi \
419abbf1590SDavid Howells                -include $(srctree)/include/linux/kconfig.h
420abbf1590SDavid Howells
4211da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
4221da177e4SLinus Torvalds# Needed to be compatible with the O= option
423abbf1590SDavid HowellsLINUXINCLUDE    := \
4249d022c54SMasahiro Yamada		-I$(srctree)/arch/$(SRCARCH)/include \
4259d022c54SMasahiro Yamada		-I$(objtree)/arch/$(SRCARCH)/include/generated \
426abbf1590SDavid Howells		$(if $(KBUILD_SRC), -I$(srctree)/include) \
427f8224f7fSMasahiro Yamada		-I$(objtree)/include \
428f8224f7fSMasahiro Yamada		$(USERINCLUDE)
4291da177e4SLinus Torvalds
43042a92bccSMasahiro YamadaKBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-PIE
431eeb5687aSMasahiro YamadaKBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
43242a92bccSMasahiro Yamada		   -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
43361a0902aSMasahiro Yamada		   -Werror-implicit-function-declaration -Werror=implicit-int \
43451b97e35SKirill A. Shutemov		   -Wno-format-security \
435433dc2ebSMasahiro Yamada		   -std=gnu89
436433dc2ebSMasahiro YamadaKBUILD_CPPFLAGS := -D__KERNEL__
43780c00ba9SSam RavnborgKBUILD_AFLAGS_KERNEL :=
43880c00ba9SSam RavnborgKBUILD_CFLAGS_KERNEL :=
4396588169dSSam RavnborgKBUILD_AFLAGS_MODULE  := -DMODULE
4406588169dSSam RavnborgKBUILD_CFLAGS_MODULE  := -DMODULE
4416588169dSSam RavnborgKBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
442d503ac53SMasahiro YamadaKBUILD_LDFLAGS :=
443433dc2ebSMasahiro YamadaGCC_PLUGINS_CFLAGS :=
4441da177e4SLinus Torvalds
44596f14fe7SLaura Abbottexport ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
4468377bd2bSLaura Abbottexport CPP AR NM STRIP OBJCOPY OBJDUMP KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
44788110713SMasahiro Yamadaexport MAKE LEX YACC AWK INSTALLKERNEL PERL PYTHON PYTHON2 PYTHON3 UTS_MACHINE
44810844aebSLaura Abbottexport HOSTCXX KBUILD_HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
4491da177e4SLinus Torvalds
450d503ac53SMasahiro Yamadaexport KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
4510e410e15SAndrey Konovalovexport KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
4520e410e15SAndrey Konovalovexport CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN
453222d394dSSam Ravnborgexport KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
454