Makefile revision 25b146c5
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2bfeffd15SLinus TorvaldsVERSION = 5
39e98c678SLinus TorvaldsPATCHLEVEL = 1
455922c9dSLinus TorvaldsSUBLEVEL = 0
579a3aaa7SLinus TorvaldsEXTRAVERSION = -rc3
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
34221cc2d2SMasahiro 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
9925b146c5SMasahiro Yamada# Kbuild will save output files in the current working directory.
10025b146c5SMasahiro Yamada# This does not need to match to the root of the kernel source tree.
10125b146c5SMasahiro Yamada#
10225b146c5SMasahiro Yamada# For example, you can do this:
10325b146c5SMasahiro Yamada#
10425b146c5SMasahiro Yamada#  cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
10525b146c5SMasahiro Yamada#
10625b146c5SMasahiro Yamada# If you want to save output files in a different location, there are
10725b146c5SMasahiro Yamada# two syntaxes to specify it.
10825b146c5SMasahiro Yamada#
1091da177e4SLinus Torvalds# 1) O=
1101da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/"
111070b98bfSSam Ravnborg#
1121da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT
11325b146c5SMasahiro Yamada# Set the environment variable KBUILD_OUTPUT to point to the output directory.
11425b146c5SMasahiro Yamada# export KBUILD_OUTPUT=dir/to/store/output/files/; make
1151da177e4SLinus Torvalds#
1161da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment
1171da177e4SLinus Torvalds# variable.
1181da177e4SLinus Torvalds
11925b146c5SMasahiro Yamada# Do we want to change the working directory?
120b8b0618cSCheng Renquanifeq ("$(origin O)", "command line")
121b8b0618cSCheng Renquan  KBUILD_OUTPUT := $(O)
1221da177e4SLinus Torvaldsendif
1231da177e4SLinus Torvalds
12425b146c5SMasahiro Yamadaifneq ($(KBUILD_OUTPUT),)
12525b146c5SMasahiro Yamada# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
12625b146c5SMasahiro Yamada# expand a shell special character '~'. We use a somewhat tedious way here.
12725b146c5SMasahiro Yamadaabs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
12825b146c5SMasahiro Yamada$(if $(abs_objtree),, \
12925b146c5SMasahiro Yamada     $(error failed to create output directory "$(KBUILD_OUTPUT)"))
13025b146c5SMasahiro Yamada
13125b146c5SMasahiro Yamada# $(realpath ...) resolves symlinks
13225b146c5SMasahiro Yamadaabs_objtree := $(realpath $(abs_objtree))
13325b146c5SMasahiro Yamadaelse
13425b146c5SMasahiro Yamadaabs_objtree := $(CURDIR)
13525b146c5SMasahiro Yamadaendif # ifneq ($(KBUILD_OUTPUT),)
13625b146c5SMasahiro Yamada
13725b146c5SMasahiro Yamadaifeq ($(abs_objtree),$(CURDIR))
13825b146c5SMasahiro Yamada# Suppress "Entering directory ..." unless we are changing the work directory.
13925b146c5SMasahiro YamadaMAKEFLAGS += --no-print-directory
14025b146c5SMasahiro Yamadaelse
14125b146c5SMasahiro Yamadaneed-sub-make := 1
14251193b76SRobert Jarzmikendif
14351193b76SRobert Jarzmik
14425b146c5SMasahiro Yamadaabs_srctree := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
14525b146c5SMasahiro Yamada
14625b146c5SMasahiro Yamadaifneq ($(words $(subst :, ,$(abs_srctree))), 1)
14725b146c5SMasahiro Yamada$(error source directory cannot contain spaces or colons)
14825b146c5SMasahiro Yamadaendif
1491da177e4SLinus Torvalds
15025b146c5SMasahiro Yamadaifneq ($(abs_srctree),$(abs_objtree))
15180463f1bSMasahiro Yamada# Look for make include files relative to root of kernel src
15280463f1bSMasahiro Yamada#
15380463f1bSMasahiro Yamada# This does not become effective immediately because MAKEFLAGS is re-parsed
15425b146c5SMasahiro Yamada# once after the Makefile is read. We need to invoke sub-make.
15525b146c5SMasahiro YamadaMAKEFLAGS += --include-dir=$(abs_srctree)
156688931a5SMasahiro Yamadaneed-sub-make := 1
15725b146c5SMasahiro Yamadaendif
1583812b8c5SMasahiro Yamada
159688931a5SMasahiro Yamadaifneq ($(filter 3.%,$(MAKE_VERSION)),)
160688931a5SMasahiro Yamada# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x
161688931a5SMasahiro Yamada# We need to invoke sub-make to avoid implicit rules in the top Makefile.
162688931a5SMasahiro Yamadaneed-sub-make := 1
163688931a5SMasahiro Yamada# Cancel implicit rules for this Makefile.
164688931a5SMasahiro Yamada$(lastword $(MAKEFILE_LIST)): ;
165688931a5SMasahiro Yamadaendif
166688931a5SMasahiro Yamada
16725b146c5SMasahiro Yamadaexport abs_srctree abs_objtree
168221cc2d2SMasahiro Yamadaexport sub_make_done := 1
169221cc2d2SMasahiro Yamada
170688931a5SMasahiro Yamadaifeq ($(need-sub-make),1)
171688931a5SMasahiro Yamada
1720b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1730b35786dSMilton Miller
1740209987fSMasahiro Yamada$(filter-out _all sub-make $(lastword $(MAKEFILE_LIST)), $(MAKECMDGOALS)) _all: sub-make
17516f89098SCharles Keepax	@:
1760b35786dSMilton Miller
177c4e6fff1SCao jin# Invoke a second make in the output directory, passing relevant variables
1782e8d696bSMasahiro Yamadasub-make:
17925b146c5SMasahiro Yamada	$(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
1801da177e4SLinus Torvalds
181688931a5SMasahiro Yamadaendif # need-sub-make
182221cc2d2SMasahiro Yamadaendif # sub_make_done
183688931a5SMasahiro Yamada
1841da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
185688931a5SMasahiro Yamadaifeq ($(need-sub-make),)
1861da177e4SLinus Torvalds
1877ff52571SMasahiro Yamada# Do not print "Entering directory ...",
1887ff52571SMasahiro Yamada# but we want to display it when entering to the output directory
1897ff52571SMasahiro Yamada# so that IDEs/editors are able to understand relative filenames.
1907ff52571SMasahiro YamadaMAKEFLAGS += --no-print-directory
1917ff52571SMasahiro Yamada
192aa55c8e2SMasahiro Yamada# Call a source code checker (by default, "sparse") as part of the
193aa55c8e2SMasahiro Yamada# C compilation.
194aa55c8e2SMasahiro Yamada#
195aa55c8e2SMasahiro Yamada# Use 'make C=1' to enable checking of only re-compiled files.
196aa55c8e2SMasahiro Yamada# Use 'make C=2' to enable checking of *all* source files, regardless
197aa55c8e2SMasahiro Yamada# of whether they are re-compiled or not.
198aa55c8e2SMasahiro Yamada#
199036db11cSCao jin# See the file "Documentation/dev-tools/sparse.rst" for more details,
200036db11cSCao jin# including where to get the "sparse" utility.
201aa55c8e2SMasahiro Yamada
202aa55c8e2SMasahiro Yamadaifeq ("$(origin C)", "command line")
203aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = $(C)
204aa55c8e2SMasahiro Yamadaendif
205aa55c8e2SMasahiro Yamadaifndef KBUILD_CHECKSRC
206aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = 0
207aa55c8e2SMasahiro Yamadaendif
208aa55c8e2SMasahiro Yamada
209aa55c8e2SMasahiro Yamada# Use make M=dir to specify directory of external module to build
210aa55c8e2SMasahiro Yamada# Old syntax make ... SUBDIRS=$PWD is still supported
211aa55c8e2SMasahiro Yamada# Setting the environment variable KBUILD_EXTMOD take precedence
212aa55c8e2SMasahiro Yamadaifdef SUBDIRS
2130126be38SMasahiro Yamada  $(warning ================= WARNING ================)
2140126be38SMasahiro Yamada  $(warning 'SUBDIRS' will be removed after Linux 5.3)
2150126be38SMasahiro Yamada  $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead)
2160126be38SMasahiro Yamada  $(warning ==========================================)
217aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD ?= $(SUBDIRS)
218aa55c8e2SMasahiro Yamadaendif
219aa55c8e2SMasahiro Yamada
220aa55c8e2SMasahiro Yamadaifeq ("$(origin M)", "command line")
221aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD := $(M)
222aa55c8e2SMasahiro Yamadaendif
223aa55c8e2SMasahiro Yamada
22425b146c5SMasahiro Yamadaifeq ($(abs_srctree),$(abs_objtree))
2259da0763bSMichal Marek        # building in the source tree
2269da0763bSMichal Marek        srctree := .
2279da0763bSMichal Marekelse
22825b146c5SMasahiro Yamada        ifeq ($(abs_srctree)/,$(dir $(abs_objtree)))
2299da0763bSMichal Marek                # building in a subdirectory of the source tree
2309da0763bSMichal Marek                srctree := ..
2319da0763bSMichal Marek        else
23225b146c5SMasahiro Yamada                srctree := $(abs_srctree)
2339da0763bSMichal Marek        endif
23425b146c5SMasahiro Yamada
23525b146c5SMasahiro Yamada	# TODO:
23625b146c5SMasahiro Yamada	# KBUILD_SRC is only used to distinguish in-tree/out-of-tree build.
23725b146c5SMasahiro Yamada	# Replace it with $(srctree) or something.
23825b146c5SMasahiro Yamada	KBUILD_SRC := $(abs_srctree)
2399da0763bSMichal Marekendif
2402c1f4f12SMasahiro Yamada
2422c1f4f12SMasahiro Yamada
2437e1c0477SMichal Marekobjtree		:= .
2441da177e4SLinus Torvaldssrc		:= $(srctree)
2451da177e4SLinus Torvaldsobj		:= $(objtree)
2461da177e4SLinus Torvalds
2476b12de69SMasahiro YamadaVPATH		:= $(srctree)
2481da177e4SLinus Torvalds
24911294235SAmerigo Wangexport srctree objtree VPATH
2501da177e4SLinus Torvalds
2512c1f4f12SMasahiro Yamada# To make sure we do not include .config for any of the *config targets
2522c1f4f12SMasahiro Yamada# catch them early, and hand them over to scripts/kconfig/Makefile
2532c1f4f12SMasahiro Yamada# It is allowed to specify more targets when calling make, including
2542c1f4f12SMasahiro Yamada# mixing *config targets and build targets.
2552c1f4f12SMasahiro Yamada# For example 'make oldconfig all'.
2562c1f4f12SMasahiro Yamada# Detect when mixed targets is specified, and make a second invocation
2572c1f4f12SMasahiro Yamada# of make so .config is not included in this case either (for *config).
2582c1f4f12SMasahiro Yamada
2592c1f4f12SMasahiro Yamadaversion_h := include/generated/uapi/linux/version.h
2602c1f4f12SMasahiro Yamadaold_version_h := include/linux/version.h
2612c1f4f12SMasahiro Yamada
26222340a06SMasahiro Yamadaclean-targets := %clean mrproper cleandocs
26322340a06SMasahiro Yamadano-dot-config-targets := $(clean-targets) \
2642c1f4f12SMasahiro Yamada			 cscope gtags TAGS tags help% %docs check% coccicheck \
2652c1f4f12SMasahiro Yamada			 $(version_h) headers_% archheaders archscripts \
26663e31a67SMasahiro Yamada			 %asm-generic kernelversion %src-pkg
267a29d4d8cSMasahiro Yamadano-sync-config-targets := $(no-dot-config-targets) install %install \
268a29d4d8cSMasahiro Yamada			   kernelrelease
2692c1f4f12SMasahiro Yamada
270d7942413SMasahiro Yamadaconfig-targets  := 0
271d7942413SMasahiro Yamadamixed-targets   := 0
272d7942413SMasahiro Yamadadot-config      := 1
273d7942413SMasahiro Yamadamay-sync-config := 1
2742c1f4f12SMasahiro Yamada
2752c1f4f12SMasahiro Yamadaifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
2762c1f4f12SMasahiro Yamada	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
2772c1f4f12SMasahiro Yamada		dot-config := 0
2782c1f4f12SMasahiro Yamada	endif
2792c1f4f12SMasahiro Yamadaendif
2802c1f4f12SMasahiro Yamada
281d7942413SMasahiro Yamadaifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
282d7942413SMasahiro Yamada	ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
283d7942413SMasahiro Yamada		may-sync-config := 0
284d7942413SMasahiro Yamada	endif
285d7942413SMasahiro Yamadaendif
286d7942413SMasahiro Yamada
287d7942413SMasahiro Yamadaifneq ($(KBUILD_EXTMOD),)
288d7942413SMasahiro Yamada	may-sync-config := 0
289d7942413SMasahiro Yamadaendif
290d7942413SMasahiro Yamada
2912c1f4f12SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
2922c1f4f12SMasahiro Yamada        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
2932c1f4f12SMasahiro Yamada                config-targets := 1
2942c1f4f12SMasahiro Yamada                ifneq ($(words $(MAKECMDGOALS)),1)
2952c1f4f12SMasahiro Yamada                        mixed-targets := 1
2962c1f4f12SMasahiro Yamada                endif
2972c1f4f12SMasahiro Yamada        endif
2982c1f4f12SMasahiro Yamadaendif
29922340a06SMasahiro Yamada
30022340a06SMasahiro Yamada# For "make -j clean all", "make -j mrproper defconfig all", etc.
30122340a06SMasahiro Yamadaifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
30222340a06SMasahiro Yamada        ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
30322340a06SMasahiro Yamada                mixed-targets := 1
30422340a06SMasahiro Yamada        endif
30522340a06SMasahiro Yamadaendif
30622340a06SMasahiro Yamada
3072c1f4f12SMasahiro Yamada# install and modules_install need also be processed one by one
3082c1f4f12SMasahiro Yamadaifneq ($(filter install,$(MAKECMDGOALS)),)
3092c1f4f12SMasahiro Yamada        ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
3102c1f4f12SMasahiro Yamada	        mixed-targets := 1
3112c1f4f12SMasahiro Yamada        endif
3122c1f4f12SMasahiro Yamadaendif
3132c1f4f12SMasahiro Yamada
3142c1f4f12SMasahiro Yamadaifeq ($(mixed-targets),1)
3152c1f4f12SMasahiro Yamada# ===========================================================================
3162c1f4f12SMasahiro Yamada# We're called with mixed targets (*config and build targets).
3172c1f4f12SMasahiro Yamada# Handle them one by one.
3182c1f4f12SMasahiro Yamada
3192c1f4f12SMasahiro YamadaPHONY += $(MAKECMDGOALS) __build_one_by_one
3202c1f4f12SMasahiro Yamada
3212c1f4f12SMasahiro Yamada$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
3222c1f4f12SMasahiro Yamada	@:
3232c1f4f12SMasahiro Yamada
3242c1f4f12SMasahiro Yamada__build_one_by_one:
3252c1f4f12SMasahiro Yamada	$(Q)set -e; \
3262c1f4f12SMasahiro Yamada	for i in $(MAKECMDGOALS); do \
3272c1f4f12SMasahiro Yamada		$(MAKE) -f $(srctree)/Makefile $$i; \
3282c1f4f12SMasahiro Yamada	done
3292c1f4f12SMasahiro Yamada
3302c1f4f12SMasahiro Yamadaelse
3312c1f4f12SMasahiro Yamada
3322c1f4f12SMasahiro Yamadainclude scripts/Kbuild.include
3332c1f4f12SMasahiro Yamada
3342c1f4f12SMasahiro Yamada# Read KERNELRELEASE from include/config/kernel.release (if it exists)
3352c1f4f12SMasahiro YamadaKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
3382c1f4f12SMasahiro Yamada
339b2d35fa5SAnders Roxellinclude scripts/subarch.include
3401da177e4SLinus Torvalds
3411da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
3421da177e4SLinus Torvalds# ---------------------------------------------------------------------------
3431da177e4SLinus Torvalds#
3441da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
3451da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
3461da177e4SLinus Torvalds# ARCH can be set during invocation of make:
3471da177e4SLinus Torvalds# make ARCH=ia64
3481da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
3491da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
3501da177e4SLinus Torvalds
3511da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
3521da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
3531da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
3541da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
3551da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
3561da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
3571da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
3581da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
3592331d1a6SSam RavnborgARCH		?= $(SUBARCH)
3601da177e4SLinus Torvalds
3611da177e4SLinus Torvalds# Architecture as present in compile.h
3626752ed90SThomas GleixnerUTS_MACHINE 	:= $(ARCH)
3636752ed90SThomas GleixnerSRCARCH 	:= $(ARCH)
3641da177e4SLinus Torvalds
365d746d647SSam Ravnborg# Additional ARCH settings for x86
366d746d647SSam Ravnborgifeq ($(ARCH),i386)
367d746d647SSam Ravnborg        SRCARCH := x86
368d746d647SSam Ravnborgendif
369d746d647SSam Ravnborgifeq ($(ARCH),x86_64)
370d746d647SSam Ravnborg        SRCARCH := x86
371d746d647SSam Ravnborgendif
37274b469f2SSam Ravnborg
3735e538790SSam Ravnborg# Additional ARCH settings for sparc
374e69f58c0SNamhyung Kimifeq ($(ARCH),sparc32)
375e69f58c0SNamhyung Kim       SRCARCH := sparc
376e69f58c0SNamhyung Kimendif
377a439fe51SSam Ravnborgifeq ($(ARCH),sparc64)
3785e538790SSam Ravnborg       SRCARCH := sparc
379a439fe51SSam Ravnborgendif
3802fb9b1bdSSam Ravnborg
3813cc000b5SPaul Mundt# Additional ARCH settings for sh
3823cc000b5SPaul Mundtifeq ($(ARCH),sh64)
3833cc000b5SPaul Mundt       SRCARCH := sh
3843cc000b5SPaul Mundtendif
3853cc000b5SPaul Mundt
38614cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
38741263fc6SBen Gardinerexport KCONFIG_CONFIG
38814cdd3c4SRoman Zippel
3891da177e4SLinus Torvalds# SHELL used by kbuild
3901da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
3911da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
3921da177e4SLinus Torvalds	  else echo sh; fi ; fi)
3931da177e4SLinus Torvalds
3946d79a7b4SMasahiro YamadaHOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
3956d79a7b4SMasahiro YamadaHOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
3966d79a7b4SMasahiro YamadaHOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
397d7f14c66SUwe Kleine-König
398070b98bfSSam RavnborgHOSTCC       = gcc
399070b98bfSSam RavnborgHOSTCXX      = g++
40096f14fe7SLaura AbbottKBUILD_HOSTCFLAGS   := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
401f92d19e0SLaura Abbott		-fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \
402f92d19e0SLaura Abbott		$(HOSTCFLAGS)
4061da177e4SLinus Torvalds
4071da177e4SLinus Torvalds# Make variables (CC, etc...)
4081da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
4091da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
4101da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
4111da177e4SLinus TorvaldsCPP		= $(CC) -E
4121da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
4131da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
4141da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
4151da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
4161da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
41773a4f6dbSMasahiro YamadaLEX		= flex
41873a4f6dbSMasahiro YamadaYACC		= bison
4191da177e4SLinus TorvaldsAWK		= awk
420caa27b66SSam RavnborgINSTALLKERNEL  := installkernel
4211da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
4221da177e4SLinus TorvaldsPERL		= perl
423011bf125SMasahiro YamadaPYTHON		= python
424e9781b52SMasahiro YamadaPYTHON2		= python2
425e9781b52SMasahiro YamadaPYTHON3		= python3
4261da177e4SLinus TorvaldsCHECK		= sparse
4271da177e4SLinus Torvalds
42880a7d1d9SHannes EderCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
4296c49f359SLuc Van Oostenryck		  -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
4300c22be07SDouglas AndersonNOSTDINC_FLAGS :=
4316588169dSSam RavnborgCFLAGS_MODULE   =
4326588169dSSam RavnborgAFLAGS_MODULE   =
4336588169dSSam RavnborgLDFLAGS_MODULE  =
4341da177e4SLinus TorvaldsCFLAGS_KERNEL	=
4351da177e4SLinus TorvaldsAFLAGS_KERNEL	=
436b36fad65SMichal MarekLDFLAGS_vmlinux =
4371da177e4SLinus Torvalds
438abbf1590SDavid Howells# Use USERINCLUDE when you must reference the UAPI directories only.
439abbf1590SDavid HowellsUSERINCLUDE    := \
4409d022c54SMasahiro Yamada		-I$(srctree)/arch/$(SRCARCH)/include/uapi \
4419d022c54SMasahiro Yamada		-I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
442abbf1590SDavid Howells		-I$(srctree)/include/uapi \
4433308b285SArnd Bergmann		-I$(objtree)/include/generated/uapi \
444abbf1590SDavid Howells                -include $(srctree)/include/linux/kconfig.h