Makefile revision 688931a5
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2bfeffd15SLinus TorvaldsVERSION = 5
39e98c678SLinus TorvaldsPATCHLEVEL = 1
455922c9dSLinus TorvaldsSUBLEVEL = 0
59e98c678SLinus 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
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
403812b8c5SMasahiro Yamada# Avoid funny character set dependencies
413812b8c5SMasahiro Yamadaunexport LC_ALL
423812b8c5SMasahiro YamadaLC_COLLATE=C
433812b8c5SMasahiro YamadaLC_NUMERIC=C
443812b8c5SMasahiro Yamadaexport LC_COLLATE LC_NUMERIC
453812b8c5SMasahiro Yamada
463812b8c5SMasahiro Yamada# Avoid interference with shell env settings
473812b8c5SMasahiro Yamadaunexport GREP_OPTIONS
483812b8c5SMasahiro Yamada
49066b7ed9SMichal Marek# Beautify output
50066b7ed9SMichal Marek# ---------------------------------------------------------------------------
51066b7ed9SMichal Marek#
52066b7ed9SMichal Marek# Normally, we echo the whole command before executing it. By making
53066b7ed9SMichal Marek# that echo $($(quiet)$(cmd)), we now have the possibility to set
54066b7ed9SMichal Marek# $(quiet) to choose other forms of output instead, e.g.
55066b7ed9SMichal Marek#
56066b7ed9SMichal Marek#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
57066b7ed9SMichal Marek#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
58066b7ed9SMichal Marek#
59066b7ed9SMichal Marek# If $(quiet) is empty, the whole command will be printed.
60066b7ed9SMichal Marek# If it is set to "quiet_", only the short version will be printed.
61066b7ed9SMichal Marek# If it is set to "silent_", nothing will be printed at all, since
62066b7ed9SMichal Marek# the variable $(silent_cmd_cc_o_c) doesn't exist.
63066b7ed9SMichal Marek#
64066b7ed9SMichal Marek# A simple variant is to prefix commands with $(Q) - that's useful
65066b7ed9SMichal Marek# for commands that shall be hidden in non-verbose mode.
66066b7ed9SMichal Marek#
67066b7ed9SMichal Marek#	$(Q)ln $@ :<
68066b7ed9SMichal Marek#
69066b7ed9SMichal Marek# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
70066b7ed9SMichal Marek# If KBUILD_VERBOSE equals 1 then the above command is displayed.
71066b7ed9SMichal Marek#
721da177e4SLinus Torvalds# To put more focus on warnings, be less verbose as default
731da177e4SLinus Torvalds# Use 'make V=1' to see the full commands
741da177e4SLinus Torvalds
75b8b0618cSCheng Renquanifeq ("$(origin V)", "command line")
76b8b0618cSCheng Renquan  KBUILD_VERBOSE = $(V)
771da177e4SLinus Torvaldsendif
781da177e4SLinus Torvaldsifndef KBUILD_VERBOSE
791da177e4SLinus Torvalds  KBUILD_VERBOSE = 0
801da177e4SLinus Torvaldsendif
811da177e4SLinus Torvalds
82066b7ed9SMichal Marekifeq ($(KBUILD_VERBOSE),1)
83066b7ed9SMichal Marek  quiet =
84066b7ed9SMichal Marek  Q =
85066b7ed9SMichal Marekelse
86066b7ed9SMichal Marek  quiet=quiet_
87066b7ed9SMichal Marek  Q = @
88066b7ed9SMichal Marekendif
89066b7ed9SMichal Marek
90066b7ed9SMichal Marek# If the user is running make -s (silent mode), suppress echoing of
91066b7ed9SMichal Marek# commands
92066b7ed9SMichal Marek
936f0fa58eSMasahiro Yamadaifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
94066b7ed9SMichal Marek  quiet=silent_
95066b7ed9SMichal Marekendif
96066b7ed9SMichal Marek
97066b7ed9SMichal Marekexport quiet Q KBUILD_VERBOSE
98066b7ed9SMichal Marek
991da177e4SLinus Torvalds# kbuild supports saving output files in a separate directory.
1001da177e4SLinus Torvalds# To locate output files in a separate directory two syntaxes are supported.
1011da177e4SLinus Torvalds# In both cases the working directory must be the root of the kernel src.
1021da177e4SLinus Torvalds# 1) O=
1031da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/"
104070b98bfSSam Ravnborg#
1051da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT
1061da177e4SLinus Torvalds# Set the environment variable KBUILD_OUTPUT to point to the directory
1071da177e4SLinus Torvalds# where the output files shall be placed.
1081da177e4SLinus Torvalds# export KBUILD_OUTPUT=dir/to/store/output/files/
1091da177e4SLinus Torvalds# make
1101da177e4SLinus Torvalds#
1111da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment
1121da177e4SLinus Torvalds# variable.
1131da177e4SLinus Torvalds
114c4e6fff1SCao jin# KBUILD_SRC is not intended to be used by the regular user (for now),
115c4e6fff1SCao jin# it is set on invocation of make with KBUILD_OUTPUT or O= specified.
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
12351193b76SRobert Jarzmikifneq ($(words $(subst :, ,$(CURDIR))), 1)
12451193b76SRobert Jarzmik  $(error main directory cannot contain spaces nor colons)
12551193b76SRobert Jarzmikendif
12651193b76SRobert Jarzmik
1271da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
1281da177e4SLinus Torvalds# check that the output directory actually exists
1291da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
130028568d8SMasahiro YamadaKBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
13116f8259cSBjørn Forsman								&& pwd)
1321da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1331c9e70a5SMasahiro Yamada     $(error failed to create output directory "$(saved-output)"))
1341da177e4SLinus Torvalds
13580463f1bSMasahiro Yamada# Look for make include files relative to root of kernel src
13680463f1bSMasahiro Yamada#
13780463f1bSMasahiro Yamada# This does not become effective immediately because MAKEFLAGS is re-parsed
13880463f1bSMasahiro Yamada# once after the Makefile is read.  It is OK since we are going to invoke
13980463f1bSMasahiro Yamada# 'sub-make' below.
14080463f1bSMasahiro YamadaMAKEFLAGS += --include-dir=$(CURDIR)
14180463f1bSMasahiro Yamada
142688931a5SMasahiro Yamadaneed-sub-make := 1
1433812b8c5SMasahiro Yamadaelse
1443812b8c5SMasahiro Yamada
1453812b8c5SMasahiro Yamada# Do not print "Entering directory ..." at all for in-tree build.
1463812b8c5SMasahiro YamadaMAKEFLAGS += --no-print-directory
1473812b8c5SMasahiro Yamada
1483812b8c5SMasahiro Yamadaendif # ifneq ($(KBUILD_OUTPUT),)
1493812b8c5SMasahiro Yamada
150688931a5SMasahiro Yamadaifneq ($(filter 3.%,$(MAKE_VERSION)),)
151688931a5SMasahiro Yamada# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x
152688931a5SMasahiro Yamada# We need to invoke sub-make to avoid implicit rules in the top Makefile.
153688931a5SMasahiro Yamadaneed-sub-make := 1
154688931a5SMasahiro Yamada# Cancel implicit rules for this Makefile.
155688931a5SMasahiro Yamada$(lastword $(MAKEFILE_LIST)): ;
156688931a5SMasahiro Yamadaendif
157688931a5SMasahiro Yamada
158688931a5SMasahiro Yamadaifeq ($(need-sub-make),1)
159688931a5SMasahiro Yamada
1600b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1610b35786dSMilton Miller
1621cacc9abSSam Ravnborg$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
16316f89098SCharles Keepax	@:
1640b35786dSMilton Miller
165c4e6fff1SCao jin# Invoke a second make in the output directory, passing relevant variables
1662e8d696bSMasahiro Yamadasub-make:
1673812b8c5SMasahiro Yamada	$(Q)$(MAKE) sub-make-done=1 \
1683812b8c5SMasahiro Yamada	$(if $(KBUILD_OUTPUT),-C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR)) \
169aa55c8e2SMasahiro Yamada	-f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
1701da177e4SLinus Torvalds
171688931a5SMasahiro Yamadaendif # need-sub-make
172688931a5SMasahiro Yamadaendif # sub-make-done
173688931a5SMasahiro Yamada
1741da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
175688931a5SMasahiro Yamadaifeq ($(need-sub-make),)
1761da177e4SLinus Torvalds
1777ff52571SMasahiro Yamada# Do not print "Entering directory ...",
1787ff52571SMasahiro Yamada# but we want to display it when entering to the output directory
1797ff52571SMasahiro Yamada# so that IDEs/editors are able to understand relative filenames.
1807ff52571SMasahiro YamadaMAKEFLAGS += --no-print-directory
1817ff52571SMasahiro Yamada
182aa55c8e2SMasahiro Yamada# Call a source code checker (by default, "sparse") as part of the
183aa55c8e2SMasahiro Yamada# C compilation.
184aa55c8e2SMasahiro Yamada#
185aa55c8e2SMasahiro Yamada# Use 'make C=1' to enable checking of only re-compiled files.
186aa55c8e2SMasahiro Yamada# Use 'make C=2' to enable checking of *all* source files, regardless
187aa55c8e2SMasahiro Yamada# of whether they are re-compiled or not.
188aa55c8e2SMasahiro Yamada#
189036db11cSCao jin# See the file "Documentation/dev-tools/sparse.rst" for more details,
190036db11cSCao jin# including where to get the "sparse" utility.
191aa55c8e2SMasahiro Yamada
192aa55c8e2SMasahiro Yamadaifeq ("$(origin C)", "command line")
193aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = $(C)
194aa55c8e2SMasahiro Yamadaendif
195aa55c8e2SMasahiro Yamadaifndef KBUILD_CHECKSRC
196aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = 0
197aa55c8e2SMasahiro Yamadaendif
198aa55c8e2SMasahiro Yamada
199aa55c8e2SMasahiro Yamada# Use make M=dir to specify directory of external module to build
200aa55c8e2SMasahiro Yamada# Old syntax make ... SUBDIRS=$PWD is still supported
201aa55c8e2SMasahiro Yamada# Setting the environment variable KBUILD_EXTMOD take precedence
202aa55c8e2SMasahiro Yamadaifdef SUBDIRS
2030126be38SMasahiro Yamada  $(warning ================= WARNING ================)
2040126be38SMasahiro Yamada  $(warning 'SUBDIRS' will be removed after Linux 5.3)
2050126be38SMasahiro Yamada  $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead)
2060126be38SMasahiro Yamada  $(warning ==========================================)
207aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD ?= $(SUBDIRS)
208aa55c8e2SMasahiro Yamadaendif
209aa55c8e2SMasahiro Yamada
210aa55c8e2SMasahiro Yamadaifeq ("$(origin M)", "command line")
211aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD := $(M)
212aa55c8e2SMasahiro Yamadaendif
213aa55c8e2SMasahiro Yamada
2149da0763bSMichal Marekifeq ($(KBUILD_SRC),)
2159da0763bSMichal Marek        # building in the source tree
2169da0763bSMichal Marek        srctree := .
2179da0763bSMichal Marekelse
2189da0763bSMichal Marek        ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
2199da0763bSMichal Marek                # building in a subdirectory of the source tree
2209da0763bSMichal Marek                srctree := ..
2219da0763bSMichal Marek        else
2229da0763bSMichal Marek                srctree := $(KBUILD_SRC)
2239da0763bSMichal Marek        endif
2249da0763bSMichal Marekendif
2252c1f4f12SMasahiro Yamada
2272c1f4f12SMasahiro Yamada
2287e1c0477SMichal Marekobjtree		:= .
2291da177e4SLinus Torvaldssrc		:= $(srctree)
2301da177e4SLinus Torvaldsobj		:= $(objtree)
2311da177e4SLinus Torvalds
2326b12de69SMasahiro YamadaVPATH		:= $(srctree)
2331da177e4SLinus Torvalds
23411294235SAmerigo Wangexport srctree objtree VPATH
2351da177e4SLinus Torvalds
2362c1f4f12SMasahiro Yamada# To make sure we do not include .config for any of the *config targets
2372c1f4f12SMasahiro Yamada# catch them early, and hand them over to scripts/kconfig/Makefile
2382c1f4f12SMasahiro Yamada# It is allowed to specify more targets when calling make, including
2392c1f4f12SMasahiro Yamada# mixing *config targets and build targets.
2402c1f4f12SMasahiro Yamada# For example 'make oldconfig all'.
2412c1f4f12SMasahiro Yamada# Detect when mixed targets is specified, and make a second invocation
2422c1f4f12SMasahiro Yamada# of make so .config is not included in this case either (for *config).
2432c1f4f12SMasahiro Yamada
2442c1f4f12SMasahiro Yamadaversion_h := include/generated/uapi/linux/version.h
2452c1f4f12SMasahiro Yamadaold_version_h := include/linux/version.h
2462c1f4f12SMasahiro Yamada
24722340a06SMasahiro Yamadaclean-targets := %clean mrproper cleandocs
24822340a06SMasahiro Yamadano-dot-config-targets := $(clean-targets) \
2492c1f4f12SMasahiro Yamada			 cscope gtags TAGS tags help% %docs check% coccicheck \
2502c1f4f12SMasahiro Yamada			 $(version_h) headers_% archheaders archscripts \
25163e31a67SMasahiro Yamada			 %asm-generic kernelversion %src-pkg
252a29d4d8cSMasahiro Yamadano-sync-config-targets := $(no-dot-config-targets) install %install \
253a29d4d8cSMasahiro Yamada			   kernelrelease
2542c1f4f12SMasahiro Yamada
255d7942413SMasahiro Yamadaconfig-targets  := 0
256d7942413SMasahiro Yamadamixed-targets   := 0
257d7942413SMasahiro Yamadadot-config      := 1
258d7942413SMasahiro Yamadamay-sync-config := 1
2592c1f4f12SMasahiro Yamada
2602c1f4f12SMasahiro Yamadaifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
2612c1f4f12SMasahiro Yamada	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
2622c1f4f12SMasahiro Yamada		dot-config := 0
2632c1f4f12SMasahiro Yamada	endif
2642c1f4f12SMasahiro Yamadaendif
2652c1f4f12SMasahiro Yamada
266d7942413SMasahiro Yamadaifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
267d7942413SMasahiro Yamada	ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
268d7942413SMasahiro Yamada		may-sync-config := 0
269d7942413SMasahiro Yamada	endif
270d7942413SMasahiro Yamadaendif
271d7942413SMasahiro Yamada
272d7942413SMasahiro Yamadaifneq ($(KBUILD_EXTMOD),)
273d7942413SMasahiro Yamada	may-sync-config := 0
274d7942413SMasahiro Yamadaendif
275d7942413SMasahiro Yamada
2762c1f4f12SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
2772c1f4f12SMasahiro Yamada        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
2782c1f4f12SMasahiro Yamada                config-targets := 1
2792c1f4f12SMasahiro Yamada                ifneq ($(words $(MAKECMDGOALS)),1)
2802c1f4f12SMasahiro Yamada                        mixed-targets := 1
2812c1f4f12SMasahiro Yamada                endif
2822c1f4f12SMasahiro Yamada        endif
2832c1f4f12SMasahiro Yamadaendif
28422340a06SMasahiro Yamada
28522340a06SMasahiro Yamada# For "make -j clean all", "make -j mrproper defconfig all", etc.
28622340a06SMasahiro Yamadaifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
28722340a06SMasahiro Yamada        ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
28822340a06SMasahiro Yamada                mixed-targets := 1
28922340a06SMasahiro Yamada        endif
29022340a06SMasahiro Yamadaendif
29122340a06SMasahiro Yamada
2922c1f4f12SMasahiro Yamada# install and modules_install need also be processed one by one
2932c1f4f12SMasahiro Yamadaifneq ($(filter install,$(MAKECMDGOALS)),)
2942c1f4f12SMasahiro Yamada        ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
2952c1f4f12SMasahiro Yamada	        mixed-targets := 1
2962c1f4f12SMasahiro Yamada        endif
2972c1f4f12SMasahiro Yamadaendif
2982c1f4f12SMasahiro Yamada
2992c1f4f12SMasahiro Yamadaifeq ($(mixed-targets),1)
3002c1f4f12SMasahiro Yamada# ===========================================================================
3012c1f4f12SMasahiro Yamada# We're called with mixed targets (*config and build targets).
3022c1f4f12SMasahiro Yamada# Handle them one by one.
3032c1f4f12SMasahiro Yamada
3042c1f4f12SMasahiro YamadaPHONY += $(MAKECMDGOALS) __build_one_by_one
3052c1f4f12SMasahiro Yamada
3062c1f4f12SMasahiro Yamada$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
3072c1f4f12SMasahiro Yamada	@:
3082c1f4f12SMasahiro Yamada
3092c1f4f12SMasahiro Yamada__build_one_by_one:
3102c1f4f12SMasahiro Yamada	$(Q)set -e; \
3112c1f4f12SMasahiro Yamada	for i in $(MAKECMDGOALS); do \
3122c1f4f12SMasahiro Yamada		$(MAKE) -f $(srctree)/Makefile $$i; \
3132c1f4f12SMasahiro Yamada	done
3142c1f4f12SMasahiro Yamada
3152c1f4f12SMasahiro Yamadaelse
3162c1f4f12SMasahiro Yamada
3172c1f4f12SMasahiro Yamadainclude scripts/Kbuild.include
3182c1f4f12SMasahiro Yamada
3192c1f4f12SMasahiro Yamada# Read KERNELRELEASE from include/config/kernel.release (if it exists)
3202c1f4f12SMasahiro YamadaKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
3232c1f4f12SMasahiro Yamada
324b2d35fa5SAnders Roxellinclude scripts/subarch.include
3251da177e4SLinus Torvalds
3261da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
3271da177e4SLinus Torvalds# ---------------------------------------------------------------------------
3281da177e4SLinus Torvalds#
3291da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
3301da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
3311da177e4SLinus Torvalds# ARCH can be set during invocation of make:
3321da177e4SLinus Torvalds# make ARCH=ia64
3331da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
3341da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
3351da177e4SLinus Torvalds
3361da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
3371da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
3381da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
3391da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
3401da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
3411da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
3421da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
3431da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
3442331d1a6SSam RavnborgARCH		?= $(SUBARCH)
3451da177e4SLinus Torvalds
3461da177e4SLinus Torvalds# Architecture as present in compile.h
3476752ed90SThomas GleixnerUTS_MACHINE 	:= $(ARCH)
3486752ed90SThomas GleixnerSRCARCH 	:= $(ARCH)
3491da177e4SLinus Torvalds
350d746d647SSam Ravnborg# Additional ARCH settings for x86
351d746d647SSam Ravnborgifeq ($(ARCH),i386)
352d746d647SSam Ravnborg        SRCARCH := x86
353d746d647SSam Ravnborgendif
354d746d647SSam Ravnborgifeq ($(ARCH),x86_64)
355d746d647SSam Ravnborg        SRCARCH := x86
356d746d647SSam Ravnborgendif
35774b469f2SSam Ravnborg
3585e538790SSam Ravnborg# Additional ARCH settings for sparc
359e69f58c0SNamhyung Kimifeq ($(ARCH),sparc32)
360e69f58c0SNamhyung Kim       SRCARCH := sparc
361e69f58c0SNamhyung Kimendif
362a439fe51SSam Ravnborgifeq ($(ARCH),sparc64)
3635e538790SSam Ravnborg       SRCARCH := sparc
364a439fe51SSam Ravnborgendif
3652fb9b1bdSSam Ravnborg
3663cc000b5SPaul Mundt# Additional ARCH settings for sh
3673cc000b5SPaul Mundtifeq ($(ARCH),sh64)
3683cc000b5SPaul Mundt       SRCARCH := sh
3693cc000b5SPaul Mundtendif
3703cc000b5SPaul Mundt
37114cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
37241263fc6SBen Gardinerexport KCONFIG_CONFIG
37314cdd3c4SRoman Zippel
3741da177e4SLinus Torvalds# SHELL used by kbuild
3751da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
3761da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
3771da177e4SLinus Torvalds	  else echo sh; fi ; fi)
3781da177e4SLinus Torvalds
3796d79a7b4SMasahiro YamadaHOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
3806d79a7b4SMasahiro YamadaHOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
3816d79a7b4SMasahiro YamadaHOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
382d7f14c66SUwe Kleine-König
383070b98bfSSam RavnborgHOSTCC       = gcc
384070b98bfSSam RavnborgHOSTCXX      = g++
38596f14fe7SLaura AbbottKBUILD_HOSTCFLAGS   := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
386f92d19e0SLaura Abbott		-fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \
387f92d19e0SLaura Abbott		$(HOSTCFLAGS)
3911da177e4SLinus Torvalds
3921da177e4SLinus Torvalds# Make variables (CC, etc...)
3931da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
3941da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
3951da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
3961da177e4SLinus TorvaldsCPP		= $(CC) -E
3971da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
3981da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
3991da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
4001da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
4011da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
40273a4f6dbSMasahiro YamadaLEX		= flex
40373a4f6dbSMasahiro YamadaYACC		= bison
4041da177e4SLinus TorvaldsAWK		= awk
405caa27b66SSam RavnborgINSTALLKERNEL  := installkernel
4061da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
4071da177e4SLinus TorvaldsPERL		= perl
408011bf125SMasahiro YamadaPYTHON		= python
409e9781b52SMasahiro YamadaPYTHON2		= python2
410e9781b52SMasahiro YamadaPYTHON3		= python3
4111da177e4SLinus TorvaldsCHECK		= sparse
4121da177e4SLinus Torvalds
41380a7d1d9SHannes EderCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
4146c49f359SLuc Van Oostenryck		  -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
4150c22be07SDouglas AndersonNOSTDINC_FLAGS :=
4166588169dSSam RavnborgCFLAGS_MODULE   =
4176588169dSSam RavnborgAFLAGS_MODULE   =
4186588169dSSam RavnborgLDFLAGS_MODULE  =
4191da177e4SLinus TorvaldsCFLAGS_KERNEL	=
4201da177e4SLinus TorvaldsAFLAGS_KERNEL	=
421b36fad65SMichal MarekLDFLAGS_vmlinux =
4221da177e4SLinus Torvalds
423abbf1590SDavid Howells# Use USERINCLUDE when you must reference the UAPI directories only.
424abbf1590SDavid HowellsUSERINCLUDE    := \
4259d022c54SMasahiro Yamada		-I$(srctree)/arch/$(SRCARCH)/include/uapi \
4269d022c54SMasahiro Yamada		-I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
427abbf1590SDavid Howells		-I$(srctree)/include/uapi \
4283308b285SArnd Bergmann		-I$(objtree)/include/generated/uapi \
429abbf1590SDavid Howells                -include $(srctree)/include/linux/kconfig.h
430abbf1590SDavid Howells
4311da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
4321da177e4SLinus Torvalds# Needed to be compatible with the O= option
433abbf1590SDavid HowellsLINUXINCLUDE    := \
4349d022c54SMasahiro Yamada		-I$(srctree)/arch/$(SRCARCH)/include \
4359d022c54SMasahiro Yamada		-I$(objtree)/arch/$(SRCARCH)/include/generated \
436abbf1590SDavid Howells		$(if $(KBUILD_SRC), -I$(srctree)/include) \
437f8224f7fSMasahiro Yamada		-I$(objtree)/include \
438f8224f7fSMasahiro Yamada		$(USERINCLUDE)
4391da177e4SLinus Torvalds
44042a92bccSMasahiro YamadaKBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-PIE
441eeb5687aSMasahiro YamadaKBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
44242a92bccSMasahiro Yamada		   -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
443b89f25eaSLuc Van Oostenryck		   -Werror=implicit-function-declaration -Werror=implicit-int \
44451b97e35SKirill A. Shutemov		   -Wno-format-security \
445433dc2ebSMasahiro Yamada		   -std=gnu89
446433dc2ebSMasahiro YamadaKBUILD_CPPFLAGS := -D__KERNEL__
44780c00ba9SSam RavnborgKBUILD_AFLAGS_KERNEL :=
44880c00ba9SSam RavnborgKBUILD_CFLAGS_KERNEL :=
4496588169dSSam RavnborgKBUILD_AFLAGS_MODULE  := -DMODULE
4506588169dSSam RavnborgKBUILD_CFLAGS_MODULE  := -DMODULE
4516588169dSSam RavnborgKBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/
452d503ac53SMasahiro YamadaKBUILD_LDFLAGS :=
453433dc2ebSMasahiro YamadaGCC_PLUGINS_CFLAGS :=