Makefile 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078
  1. # SPDX-License-Identifier: GPL-2.0
  2. VERSION = 6
  3. PATCHLEVEL = 12
  4. SUBLEVEL = 16
  5. EXTRAVERSION =
  6. NAME = Baby Opossum Posse
  7. # *DOCUMENTATION*
  8. # To see a list of typical targets execute "make help"
  9. # More info can be located in ./README
  10. # Comments in this file are targeted only to the developer, do not
  11. # expect to learn how to build the kernel reading this file.
  12. ifeq ($(filter output-sync,$(.FEATURES)),)
  13. $(error GNU Make >= 4.0 is required. Your Make version is $(MAKE_VERSION))
  14. endif
  15. $(if $(filter __%, $(MAKECMDGOALS)), \
  16. $(error targets prefixed with '__' are only for internal use))
  17. # That's our default target when none is given on the command line
  18. PHONY := __all
  19. __all:
  20. # We are using a recursive build, so we need to do a little thinking
  21. # to get the ordering right.
  22. #
  23. # Most importantly: sub-Makefiles should only ever modify files in
  24. # their own directory. If in some directory we have a dependency on
  25. # a file in another dir (which doesn't happen often, but it's often
  26. # unavoidable when linking the built-in.a targets which finally
  27. # turn into vmlinux), we will call a sub make in that other dir, and
  28. # after that we are sure that everything which is in that other dir
  29. # is now up to date.
  30. #
  31. # The only cases where we need to modify files which have global
  32. # effects are thus separated out and done before the recursive
  33. # descending is started. They are now explicitly listed as the
  34. # prepare rule.
  35. this-makefile := $(lastword $(MAKEFILE_LIST))
  36. abs_srctree := $(realpath $(dir $(this-makefile)))
  37. abs_objtree := $(CURDIR)
  38. ifneq ($(sub_make_done),1)
  39. # Do not use make's built-in rules and variables
  40. # (this increases performance and avoids hard-to-debug behaviour)
  41. MAKEFLAGS += -rR
  42. # Avoid funny character set dependencies
  43. unexport LC_ALL
  44. LC_COLLATE=C
  45. LC_NUMERIC=C
  46. export LC_COLLATE LC_NUMERIC
  47. # Avoid interference with shell env settings
  48. unexport GREP_OPTIONS
  49. # Beautify output
  50. # ---------------------------------------------------------------------------
  51. #
  52. # Most of build commands in Kbuild start with "cmd_". You can optionally define
  53. # "quiet_cmd_*". If defined, the short log is printed. Otherwise, no log from
  54. # that command is printed by default.
  55. #
  56. # e.g.)
  57. # quiet_cmd_depmod = DEPMOD $(MODLIB)
  58. # cmd_depmod = $(srctree)/scripts/depmod.sh $(DEPMOD) $(KERNELRELEASE)
  59. #
  60. # A simple variant is to prefix commands with $(Q) - that's useful
  61. # for commands that shall be hidden in non-verbose mode.
  62. #
  63. # $(Q)$(MAKE) $(build)=scripts/basic
  64. #
  65. # If KBUILD_VERBOSE contains 1, the whole command is echoed.
  66. # If KBUILD_VERBOSE contains 2, the reason for rebuilding is printed.
  67. #
  68. # To put more focus on warnings, be less verbose as default
  69. # Use 'make V=1' to see the full commands
  70. ifeq ("$(origin V)", "command line")
  71. KBUILD_VERBOSE = $(V)
  72. endif
  73. quiet = quiet_
  74. Q = @
  75. ifneq ($(findstring 1, $(KBUILD_VERBOSE)),)
  76. quiet =
  77. Q =
  78. endif
  79. # If the user is running make -s (silent mode), suppress echoing of
  80. # commands
  81. ifneq ($(findstring s,$(firstword -$(MAKEFLAGS))),)
  82. quiet=silent_
  83. override KBUILD_VERBOSE :=
  84. endif
  85. export quiet Q KBUILD_VERBOSE
  86. # Call a source code checker (by default, "sparse") as part of the
  87. # C compilation.
  88. #
  89. # Use 'make C=1' to enable checking of only re-compiled files.
  90. # Use 'make C=2' to enable checking of *all* source files, regardless
  91. # of whether they are re-compiled or not.
  92. #
  93. # See the file "Documentation/dev-tools/sparse.rst" for more details,
  94. # including where to get the "sparse" utility.
  95. ifeq ("$(origin C)", "command line")
  96. KBUILD_CHECKSRC = $(C)
  97. endif
  98. ifndef KBUILD_CHECKSRC
  99. KBUILD_CHECKSRC = 0
  100. endif
  101. export KBUILD_CHECKSRC
  102. # Enable "clippy" (a linter) as part of the Rust compilation.
  103. #
  104. # Use 'make CLIPPY=1' to enable it.
  105. ifeq ("$(origin CLIPPY)", "command line")
  106. KBUILD_CLIPPY := $(CLIPPY)
  107. endif
  108. export KBUILD_CLIPPY
  109. # Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the
  110. # directory of external module to build. Setting M= takes precedence.
  111. ifeq ("$(origin M)", "command line")
  112. KBUILD_EXTMOD := $(M)
  113. endif
  114. $(if $(word 2, $(KBUILD_EXTMOD)), \
  115. $(error building multiple external modules is not supported))
  116. $(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \
  117. $(error module directory path cannot contain '$x')))
  118. # Remove trailing slashes
  119. ifneq ($(filter %/, $(KBUILD_EXTMOD)),)
  120. KBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).)
  121. endif
  122. export KBUILD_EXTMOD
  123. # backward compatibility
  124. KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
  125. ifeq ("$(origin W)", "command line")
  126. KBUILD_EXTRA_WARN := $(W)
  127. endif
  128. export KBUILD_EXTRA_WARN
  129. # Kbuild will save output files in the current working directory.
  130. # This does not need to match to the root of the kernel source tree.
  131. #
  132. # For example, you can do this:
  133. #
  134. # cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
  135. #
  136. # If you want to save output files in a different location, there are
  137. # two syntaxes to specify it.
  138. #
  139. # 1) O=
  140. # Use "make O=dir/to/store/output/files/"
  141. #
  142. # 2) Set KBUILD_OUTPUT
  143. # Set the environment variable KBUILD_OUTPUT to point to the output directory.
  144. # export KBUILD_OUTPUT=dir/to/store/output/files/; make
  145. #
  146. # The O= assignment takes precedence over the KBUILD_OUTPUT environment
  147. # variable.
  148. # Do we want to change the working directory?
  149. ifeq ("$(origin O)", "command line")
  150. KBUILD_OUTPUT := $(O)
  151. endif
  152. ifneq ($(KBUILD_OUTPUT),)
  153. # $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first.
  154. $(shell mkdir -p "$(KBUILD_OUTPUT)")
  155. # $(realpath ...) resolves symlinks
  156. abs_objtree := $(realpath $(KBUILD_OUTPUT))
  157. $(if $(abs_objtree),,$(error failed to create output directory "$(KBUILD_OUTPUT)"))
  158. endif # ifneq ($(KBUILD_OUTPUT),)
  159. ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
  160. $(error source directory cannot contain spaces or colons)
  161. endif
  162. export sub_make_done := 1
  163. endif # sub_make_done
  164. ifeq ($(abs_objtree),$(CURDIR))
  165. # Suppress "Entering directory ..." if we are at the final work directory.
  166. no-print-directory := --no-print-directory
  167. else
  168. # Recursion to show "Entering directory ..."
  169. need-sub-make := 1
  170. endif
  171. ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),)
  172. # If --no-print-directory is unset, recurse once again to set it.
  173. # You may end up recursing into __sub-make twice. This is needed due to the
  174. # behavior change in GNU Make 4.4.1.
  175. need-sub-make := 1
  176. endif
  177. ifeq ($(need-sub-make),1)
  178. PHONY += $(MAKECMDGOALS) __sub-make
  179. $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
  180. @:
  181. # Invoke a second make in the output directory, passing relevant variables
  182. __sub-make:
  183. $(Q)$(MAKE) $(no-print-directory) -C $(abs_objtree) \
  184. -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
  185. else # need-sub-make
  186. # We process the rest of the Makefile if this is the final invocation of make
  187. ifeq ($(abs_srctree),$(abs_objtree))
  188. # building in the source tree
  189. srctree := .
  190. building_out_of_srctree :=
  191. else
  192. ifeq ($(abs_srctree)/,$(dir $(abs_objtree)))
  193. # building in a subdirectory of the source tree
  194. srctree := ..
  195. else
  196. srctree := $(abs_srctree)
  197. endif
  198. building_out_of_srctree := 1
  199. endif
  200. ifneq ($(KBUILD_ABS_SRCTREE),)
  201. srctree := $(abs_srctree)
  202. endif
  203. objtree := .
  204. VPATH :=
  205. ifeq ($(KBUILD_EXTMOD),)
  206. ifdef building_out_of_srctree
  207. VPATH := $(srctree)
  208. endif
  209. endif
  210. export building_out_of_srctree srctree objtree VPATH
  211. # To make sure we do not include .config for any of the *config targets
  212. # catch them early, and hand them over to scripts/kconfig/Makefile
  213. # It is allowed to specify more targets when calling make, including
  214. # mixing *config targets and build targets.
  215. # For example 'make oldconfig all'.
  216. # Detect when mixed targets is specified, and make a second invocation
  217. # of make so .config is not included in this case either (for *config).
  218. version_h := include/generated/uapi/linux/version.h
  219. clean-targets := %clean mrproper cleandocs
  220. no-dot-config-targets := $(clean-targets) \
  221. cscope gtags TAGS tags help% %docs check% coccicheck \
  222. $(version_h) headers headers_% archheaders archscripts \
  223. %asm-generic kernelversion %src-pkg dt_binding_check \
  224. outputmakefile rustavailable rustfmt rustfmtcheck
  225. no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \
  226. image_name
  227. single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %.symtypes %/
  228. config-build :=
  229. mixed-build :=
  230. need-config := 1
  231. may-sync-config := 1
  232. single-build :=
  233. ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
  234. ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
  235. need-config :=
  236. endif
  237. endif
  238. ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
  239. ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
  240. may-sync-config :=
  241. endif
  242. endif
  243. need-compiler := $(may-sync-config)
  244. ifneq ($(KBUILD_EXTMOD),)
  245. may-sync-config :=
  246. endif
  247. ifeq ($(KBUILD_EXTMOD),)
  248. ifneq ($(filter %config,$(MAKECMDGOALS)),)
  249. config-build := 1
  250. ifneq ($(words $(MAKECMDGOALS)),1)
  251. mixed-build := 1
  252. endif
  253. endif
  254. endif
  255. # We cannot build single targets and the others at the same time
  256. ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),)
  257. single-build := 1
  258. ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),)
  259. mixed-build := 1
  260. endif
  261. endif
  262. # For "make -j clean all", "make -j mrproper defconfig all", etc.
  263. ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
  264. ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
  265. mixed-build := 1
  266. endif
  267. endif
  268. # install and modules_install need also be processed one by one
  269. ifneq ($(filter install,$(MAKECMDGOALS)),)
  270. ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
  271. mixed-build := 1
  272. endif
  273. endif
  274. ifdef mixed-build
  275. # ===========================================================================
  276. # We're called with mixed targets (*config and build targets).
  277. # Handle them one by one.
  278. PHONY += $(MAKECMDGOALS) __build_one_by_one
  279. $(MAKECMDGOALS): __build_one_by_one
  280. @:
  281. __build_one_by_one:
  282. $(Q)set -e; \
  283. for i in $(MAKECMDGOALS); do \
  284. $(MAKE) -f $(srctree)/Makefile $$i; \
  285. done
  286. else # !mixed-build
  287. include $(srctree)/scripts/Kbuild.include
  288. # Read KERNELRELEASE from include/config/kernel.release (if it exists)
  289. KERNELRELEASE = $(call read-file, include/config/kernel.release)
  290. KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
  291. export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
  292. include $(srctree)/scripts/subarch.include
  293. # Cross compiling and selecting different set of gcc/bin-utils
  294. # ---------------------------------------------------------------------------
  295. #
  296. # When performing cross compilation for other architectures ARCH shall be set
  297. # to the target architecture. (See arch/* for the possibilities).
  298. # ARCH can be set during invocation of make:
  299. # make ARCH=arm64
  300. # Another way is to have ARCH set in the environment.
  301. # The default ARCH is the host where make is executed.
  302. # CROSS_COMPILE specify the prefix used for all executables used
  303. # during compilation. Only gcc and related bin-utils executables
  304. # are prefixed with $(CROSS_COMPILE).
  305. # CROSS_COMPILE can be set on the command line
  306. # make CROSS_COMPILE=aarch64-linux-gnu-
  307. # Alternatively CROSS_COMPILE can be set in the environment.
  308. # Default value for CROSS_COMPILE is not to prefix executables
  309. # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
  310. ARCH ?= $(SUBARCH)
  311. # Architecture as present in compile.h
  312. UTS_MACHINE := $(ARCH)
  313. SRCARCH := $(ARCH)
  314. # Additional ARCH settings for x86
  315. ifeq ($(ARCH),i386)
  316. SRCARCH := x86
  317. endif
  318. ifeq ($(ARCH),x86_64)
  319. SRCARCH := x86
  320. endif
  321. # Additional ARCH settings for sparc
  322. ifeq ($(ARCH),sparc32)
  323. SRCARCH := sparc
  324. endif
  325. ifeq ($(ARCH),sparc64)
  326. SRCARCH := sparc
  327. endif
  328. # Additional ARCH settings for parisc
  329. ifeq ($(ARCH),parisc64)
  330. SRCARCH := parisc
  331. endif
  332. export cross_compiling :=
  333. ifneq ($(SRCARCH),$(SUBARCH))
  334. cross_compiling := 1
  335. endif
  336. KCONFIG_CONFIG ?= .config
  337. export KCONFIG_CONFIG
  338. # SHELL used by kbuild
  339. CONFIG_SHELL := sh
  340. HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
  341. HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
  342. HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
  343. ifneq ($(LLVM),)
  344. ifneq ($(filter %/,$(LLVM)),)
  345. LLVM_PREFIX := $(LLVM)
  346. else ifneq ($(filter -%,$(LLVM)),)
  347. LLVM_SUFFIX := $(LLVM)
  348. endif
  349. HOSTCC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
  350. HOSTCXX = $(LLVM_PREFIX)clang++$(LLVM_SUFFIX)
  351. else
  352. HOSTCC = gcc
  353. HOSTCXX = g++
  354. endif
  355. HOSTRUSTC = rustc
  356. HOSTPKG_CONFIG = pkg-config
  357. KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
  358. -O2 -fomit-frame-pointer -std=gnu11
  359. KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
  360. KBUILD_USERLDFLAGS := $(USERLDFLAGS)
  361. # These flags apply to all Rust code in the tree, including the kernel and
  362. # host programs.
  363. export rust_common_flags := --edition=2021 \
  364. -Zbinary_dep_depinfo=y \
  365. -Astable_features \
  366. -Dunsafe_op_in_unsafe_fn \
  367. -Dnon_ascii_idents \
  368. -Wrust_2018_idioms \
  369. -Wunreachable_pub \
  370. -Wmissing_docs \
  371. -Wrustdoc::missing_crate_level_docs \
  372. -Wclippy::all \
  373. -Wclippy::mut_mut \
  374. -Wclippy::needless_bitwise_bool \
  375. -Wclippy::needless_continue \
  376. -Aclippy::needless_lifetimes \
  377. -Wclippy::no_mangle_with_rust_abi \
  378. -Wclippy::dbg_macro
  379. KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \
  380. $(HOSTCFLAGS) -I $(srctree)/scripts/include
  381. KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \
  382. -I $(srctree)/scripts/include
  383. KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
  384. -Zallow-features= $(HOSTRUSTFLAGS)
  385. KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
  386. KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
  387. # Make variables (CC, etc...)
  388. CPP = $(CC) -E
  389. ifneq ($(LLVM),)
  390. CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
  391. LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
  392. AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
  393. NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX)
  394. OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
  395. OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
  396. READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
  397. STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
  398. else
  399. CC = $(CROSS_COMPILE)gcc
  400. LD = $(CROSS_COMPILE)ld
  401. AR = $(CROSS_COMPILE)ar
  402. NM = $(CROSS_COMPILE)nm
  403. OBJCOPY = $(CROSS_COMPILE)objcopy
  404. OBJDUMP = $(CROSS_COMPILE)objdump
  405. READELF = $(CROSS_COMPILE)readelf
  406. STRIP = $(CROSS_COMPILE)strip
  407. endif
  408. RUSTC = rustc
  409. RUSTDOC = rustdoc
  410. RUSTFMT = rustfmt
  411. CLIPPY_DRIVER = clippy-driver
  412. BINDGEN = bindgen
  413. PAHOLE = pahole
  414. RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
  415. LEX = flex
  416. YACC = bison
  417. AWK = awk
  418. INSTALLKERNEL := installkernel
  419. PERL = perl
  420. PYTHON3 = python3
  421. CHECK = sparse
  422. BASH = bash
  423. KGZIP = gzip
  424. KBZIP2 = bzip2
  425. KLZOP = lzop
  426. LZMA = lzma
  427. LZ4 = lz4
  428. XZ = xz
  429. ZSTD = zstd
  430. CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
  431. -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
  432. NOSTDINC_FLAGS :=
  433. CFLAGS_MODULE =
  434. RUSTFLAGS_MODULE =
  435. AFLAGS_MODULE =
  436. LDFLAGS_MODULE =
  437. CFLAGS_KERNEL =
  438. RUSTFLAGS_KERNEL =
  439. AFLAGS_KERNEL =
  440. LDFLAGS_vmlinux =
  441. # Use USERINCLUDE when you must reference the UAPI directories only.
  442. USERINCLUDE := \
  443. -I$(srctree)/arch/$(SRCARCH)/include/uapi \
  444. -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
  445. -I$(srctree)/include/uapi \
  446. -I$(objtree)/include/generated/uapi \
  447. -include $(srctree)/include/linux/compiler-version.h \
  448. -include $(srctree)/include/linux/kconfig.h
  449. # Use LINUXINCLUDE when you must reference the include/ directory.
  450. # Needed to be compatible with the O= option
  451. LINUXINCLUDE := \
  452. -I$(srctree)/arch/$(SRCARCH)/include \
  453. -I$(objtree)/arch/$(SRCARCH)/include/generated \
  454. $(if $(building_out_of_srctree),-I$(srctree)/include) \
  455. -I$(objtree)/include \
  456. $(USERINCLUDE)
  457. KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
  458. KBUILD_CFLAGS :=
  459. KBUILD_CFLAGS += -std=gnu11
  460. KBUILD_CFLAGS += -fshort-wchar
  461. KBUILD_CFLAGS += -funsigned-char
  462. KBUILD_CFLAGS += -fno-common
  463. KBUILD_CFLAGS += -fno-PIE
  464. KBUILD_CFLAGS += -fno-strict-aliasing
  465. KBUILD_CPPFLAGS := -D__KERNEL__
  466. KBUILD_RUSTFLAGS := $(rust_common_flags) \
  467. -Cpanic=abort -Cembed-bitcode=n -Clto=n \
  468. -Cforce-unwind-tables=n -Ccodegen-units=1 \
  469. -Csymbol-mangling-version=v0 \
  470. -Crelocation-model=static \
  471. -Zfunction-sections=n \
  472. -Wclippy::float_arithmetic
  473. KBUILD_AFLAGS_KERNEL :=
  474. KBUILD_CFLAGS_KERNEL :=
  475. KBUILD_RUSTFLAGS_KERNEL :=
  476. KBUILD_AFLAGS_MODULE := -DMODULE
  477. KBUILD_CFLAGS_MODULE := -DMODULE
  478. KBUILD_RUSTFLAGS_MODULE := --cfg MODULE
  479. KBUILD_LDFLAGS_MODULE :=
  480. KBUILD_LDFLAGS :=
  481. CLANG_FLAGS :=
  482. ifeq ($(KBUILD_CLIPPY),1)
  483. RUSTC_OR_CLIPPY_QUIET := CLIPPY
  484. RUSTC_OR_CLIPPY = $(CLIPPY_DRIVER)
  485. else
  486. RUSTC_OR_CLIPPY_QUIET := RUSTC
  487. RUSTC_OR_CLIPPY = $(RUSTC)
  488. endif
  489. # Allows the usage of unstable features in stable compilers.
  490. export RUSTC_BOOTSTRAP := 1
  491. export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG
  492. export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN
  493. export HOSTRUSTC KBUILD_HOSTRUSTFLAGS
  494. export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
  495. export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
  496. export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
  497. export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
  498. export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS
  499. export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
  500. export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
  501. export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE
  502. export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
  503. export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE
  504. export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL
  505. # Files to ignore in find ... statements
  506. export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
  507. -name CVS -o -name .pc -o -name .hg -o -name .git \) \
  508. -prune -o
  509. # ===========================================================================
  510. # Rules shared between *config targets and build targets
  511. # Basic helpers built in scripts/basic/
  512. PHONY += scripts_basic
  513. scripts_basic:
  514. $(Q)$(MAKE) $(build)=scripts/basic
  515. PHONY += outputmakefile
  516. ifdef building_out_of_srctree
  517. # Before starting out-of-tree build, make sure the source tree is clean.
  518. # outputmakefile generates a Makefile in the output directory, if using a
  519. # separate output directory. This allows convenient use of make in the
  520. # output directory.
  521. # At the same time when output Makefile generated, generate .gitignore to
  522. # ignore whole output directory
  523. quiet_cmd_makefile = GEN Makefile
  524. cmd_makefile = { \
  525. echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \
  526. echo "include $(srctree)/Makefile"; \
  527. } > Makefile
  528. outputmakefile:
  529. @if [ -f $(srctree)/.config -o \
  530. -d $(srctree)/include/config -o \
  531. -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
  532. echo >&2 "***"; \
  533. echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
  534. echo >&2 "*** in $(abs_srctree)";\
  535. echo >&2 "***"; \
  536. false; \
  537. fi
  538. $(Q)ln -fsn $(srctree) source
  539. $(call cmd,makefile)
  540. $(Q)test -e .gitignore || \
  541. { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
  542. endif
  543. # The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
  544. # Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
  545. # CC_VERSION_TEXT and RUSTC_VERSION_TEXT are referenced from Kconfig (so they
  546. # need export), and from include/config/auto.conf.cmd to detect the compiler
  547. # upgrade.
  548. CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
  549. RUSTC_VERSION_TEXT = $(subst $(pound),,$(shell $(RUSTC) --version 2>/dev/null))
  550. ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
  551. include $(srctree)/scripts/Makefile.clang
  552. endif
  553. # Include this also for config targets because some architectures need
  554. # cc-cross-prefix to determine CROSS_COMPILE.
  555. ifdef need-compiler
  556. include $(srctree)/scripts/Makefile.compiler
  557. endif
  558. ifdef config-build
  559. # ===========================================================================
  560. # *config targets only - make sure prerequisites are updated, and descend
  561. # in scripts/kconfig to make the *config target
  562. # Read arch-specific Makefile to set KBUILD_DEFCONFIG as needed.
  563. # KBUILD_DEFCONFIG may point out an alternative default configuration
  564. # used for 'make defconfig'
  565. include $(srctree)/arch/$(SRCARCH)/Makefile
  566. export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT RUSTC_VERSION_TEXT
  567. config: outputmakefile scripts_basic FORCE
  568. $(Q)$(MAKE) $(build)=scripts/kconfig $@
  569. %config: outputmakefile scripts_basic FORCE
  570. $(Q)$(MAKE) $(build)=scripts/kconfig $@
  571. else #!config-build
  572. # ===========================================================================
  573. # Build targets only - this includes vmlinux, arch-specific targets, clean
  574. # targets and others. In general all targets except *config targets.
  575. # If building an external module we do not care about the all: rule
  576. # but instead __all depend on modules
  577. PHONY += all
  578. ifeq ($(KBUILD_EXTMOD),)
  579. __all: all
  580. else
  581. __all: modules
  582. endif
  583. targets :=
  584. # Decide whether to build built-in, modular, or both.
  585. # Normally, just do built-in.
  586. KBUILD_MODULES :=
  587. KBUILD_BUILTIN := 1
  588. # If we have only "make modules", don't compile built-in objects.
  589. ifeq ($(MAKECMDGOALS),modules)
  590. KBUILD_BUILTIN :=
  591. endif
  592. # If we have "make <whatever> modules", compile modules
  593. # in addition to whatever we do anyway.
  594. # Just "make" or "make all" shall build modules as well
  595. ifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),)
  596. KBUILD_MODULES := 1
  597. endif
  598. ifeq ($(MAKECMDGOALS),)
  599. KBUILD_MODULES := 1
  600. endif
  601. export KBUILD_MODULES KBUILD_BUILTIN
  602. ifdef need-config
  603. include include/config/auto.conf
  604. endif
  605. ifeq ($(KBUILD_EXTMOD),)
  606. # Objects we will link into vmlinux / subdirs we need to visit
  607. core-y :=
  608. drivers-y :=
  609. libs-y := lib/
  610. endif # KBUILD_EXTMOD
  611. # The all: target is the default when no target is given on the
  612. # command line.
  613. # This allow a user to issue only 'make' to build a kernel including modules
  614. # Defaults to vmlinux, but the arch makefile usually adds further targets
  615. all: vmlinux
  616. CFLAGS_GCOV := -fprofile-arcs -ftest-coverage
  617. ifdef CONFIG_CC_IS_GCC
  618. CFLAGS_GCOV += -fno-tree-loop-im
  619. endif
  620. export CFLAGS_GCOV
  621. # The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
  622. ifdef CONFIG_FUNCTION_TRACER
  623. CC_FLAGS_FTRACE := -pg
  624. endif
  625. include $(srctree)/arch/$(SRCARCH)/Makefile
  626. ifdef need-config
  627. ifdef may-sync-config
  628. # Read in dependencies to all Kconfig* files, make sure to run syncconfig if
  629. # changes are detected. This should be included after arch/$(SRCARCH)/Makefile
  630. # because some architectures define CROSS_COMPILE there.
  631. include include/config/auto.conf.cmd
  632. $(KCONFIG_CONFIG):
  633. @echo >&2 '***'
  634. @echo >&2 '*** Configuration file "$@" not found!'
  635. @echo >&2 '***'
  636. @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or'
  637. @echo >&2 '*** "make menuconfig" or "make xconfig").'
  638. @echo >&2 '***'
  639. @/bin/false
  640. # The actual configuration files used during the build are stored in
  641. # include/generated/ and include/config/. Update them if .config is newer than
  642. # include/config/auto.conf (which mirrors .config).
  643. #
  644. # This exploits the 'multi-target pattern rule' trick.
  645. # The syncconfig should be executed only once to make all the targets.
  646. # (Note: use the grouped target '&:' when we bump to GNU Make 4.3)
  647. #
  648. # Do not use $(call cmd,...) here. That would suppress prompts from syncconfig,
  649. # so you cannot notice that Kconfig is waiting for the user input.
  650. %/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h %/generated/rustc_cfg: $(KCONFIG_CONFIG)
  651. $(Q)$(kecho) " SYNC $@"
  652. $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
  653. else # !may-sync-config
  654. # External modules and some install targets need include/generated/autoconf.h
  655. # and include/config/auto.conf but do not care if they are up-to-date.
  656. # Use auto.conf to trigger the test
  657. PHONY += include/config/auto.conf
  658. include/config/auto.conf:
  659. @test -e include/generated/autoconf.h -a -e $@ || ( \
  660. echo >&2; \
  661. echo >&2 " ERROR: Kernel configuration is invalid."; \
  662. echo >&2 " include/generated/autoconf.h or $@ are missing.";\
  663. echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
  664. echo >&2 ; \
  665. /bin/false)
  666. endif # may-sync-config
  667. endif # need-config
  668. KBUILD_CFLAGS += -fno-delete-null-pointer-checks
  669. ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
  670. KBUILD_CFLAGS += -O2
  671. KBUILD_RUSTFLAGS += -Copt-level=2
  672. else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
  673. KBUILD_CFLAGS += -Os
  674. KBUILD_RUSTFLAGS += -Copt-level=s
  675. endif
  676. # Always set `debug-assertions` and `overflow-checks` because their default
  677. # depends on `opt-level` and `debug-assertions`, respectively.
  678. KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n)
  679. KBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n)
  680. # Tell gcc to never replace conditional load with a non-conditional one
  681. ifdef CONFIG_CC_IS_GCC
  682. # gcc-10 renamed --param=allow-store-data-races=0 to
  683. # -fno-allow-store-data-races.
  684. KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
  685. KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races)
  686. endif
  687. ifdef CONFIG_READABLE_ASM
  688. # Disable optimizations that make assembler listings hard to read.
  689. # reorder blocks reorders the control in the function
  690. # ipa clone creates specialized cloned functions
  691. # partial inlining inlines only parts of functions
  692. KBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining
  693. endif
  694. stackp-flags-y := -fno-stack-protector
  695. stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
  696. stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
  697. KBUILD_CFLAGS += $(stackp-flags-y)
  698. KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
  699. KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y)
  700. ifdef CONFIG_FRAME_POINTER
  701. KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
  702. KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
  703. else
  704. # Some targets (ARM with Thumb2, for example), can't be built with frame
  705. # pointers. For those, we don't have FUNCTION_TRACER automatically
  706. # select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is
  707. # incompatible with -fomit-frame-pointer with current GCC, so we don't use
  708. # -fomit-frame-pointer with FUNCTION_TRACER.
  709. # In the Rust target specification, "frame-pointer" is set explicitly
  710. # to "may-omit".
  711. ifndef CONFIG_FUNCTION_TRACER
  712. KBUILD_CFLAGS += -fomit-frame-pointer
  713. endif
  714. endif
  715. # Initialize all stack variables with a 0xAA pattern.
  716. ifdef CONFIG_INIT_STACK_ALL_PATTERN
  717. KBUILD_CFLAGS += -ftrivial-auto-var-init=pattern
  718. endif
  719. # Initialize all stack variables with a zero value.
  720. ifdef CONFIG_INIT_STACK_ALL_ZERO
  721. KBUILD_CFLAGS += -ftrivial-auto-var-init=zero
  722. ifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER
  723. # https://github.com/llvm/llvm-project/issues/44842
  724. CC_AUTO_VAR_INIT_ZERO_ENABLER := -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
  725. export CC_AUTO_VAR_INIT_ZERO_ENABLER
  726. KBUILD_CFLAGS += $(CC_AUTO_VAR_INIT_ZERO_ENABLER)
  727. endif
  728. endif
  729. # While VLAs have been removed, GCC produces unreachable stack probes
  730. # for the randomize_kstack_offset feature. Disable it for all compilers.
  731. KBUILD_CFLAGS += $(call cc-option, -fno-stack-clash-protection)
  732. # Clear used registers at func exit (to reduce data lifetime and ROP gadgets).
  733. ifdef CONFIG_ZERO_CALL_USED_REGS
  734. KBUILD_CFLAGS += -fzero-call-used-regs=used-gpr
  735. endif
  736. ifdef CONFIG_FUNCTION_TRACER
  737. ifdef CONFIG_FTRACE_MCOUNT_USE_CC
  738. CC_FLAGS_FTRACE += -mrecord-mcount
  739. ifdef CONFIG_HAVE_NOP_MCOUNT
  740. ifeq ($(call cc-option-yn, -mnop-mcount),y)
  741. CC_FLAGS_FTRACE += -mnop-mcount
  742. CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
  743. endif
  744. endif
  745. endif
  746. ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
  747. ifdef CONFIG_HAVE_OBJTOOL_NOP_MCOUNT
  748. CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
  749. endif
  750. endif
  751. ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
  752. ifdef CONFIG_HAVE_C_RECORDMCOUNT
  753. BUILD_C_RECORDMCOUNT := y
  754. export BUILD_C_RECORDMCOUNT
  755. endif
  756. endif
  757. ifdef CONFIG_HAVE_FENTRY
  758. # s390-linux-gnu-gcc did not support -mfentry until gcc-9.
  759. ifeq ($(call cc-option-yn, -mfentry),y)
  760. CC_FLAGS_FTRACE += -mfentry
  761. CC_FLAGS_USING += -DCC_USING_FENTRY
  762. endif
  763. endif
  764. export CC_FLAGS_FTRACE
  765. KBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING)
  766. KBUILD_AFLAGS += $(CC_FLAGS_USING)
  767. endif
  768. # We trigger additional mismatches with less inlining
  769. ifdef CONFIG_DEBUG_SECTION_MISMATCH
  770. KBUILD_CFLAGS += -fno-inline-functions-called-once
  771. endif
  772. # `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0).
  773. ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
  774. KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
  775. KBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y
  776. LDFLAGS_vmlinux += --gc-sections
  777. endif
  778. ifdef CONFIG_SHADOW_CALL_STACK
  779. ifndef CONFIG_DYNAMIC_SCS
  780. CC_FLAGS_SCS := -fsanitize=shadow-call-stack
  781. KBUILD_CFLAGS += $(CC_FLAGS_SCS)
  782. KBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stack
  783. endif
  784. export CC_FLAGS_SCS
  785. endif
  786. ifdef CONFIG_LTO_CLANG
  787. ifdef CONFIG_LTO_CLANG_THIN
  788. CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit
  789. else
  790. CC_FLAGS_LTO := -flto
  791. endif
  792. CC_FLAGS_LTO += -fvisibility=hidden
  793. # Limit inlining across translation units to reduce binary size
  794. KBUILD_LDFLAGS += -mllvm -import-instr-limit=5
  795. endif
  796. ifdef CONFIG_LTO
  797. KBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO)
  798. KBUILD_AFLAGS += -fno-lto
  799. export CC_FLAGS_LTO
  800. endif
  801. ifdef CONFIG_CFI_CLANG
  802. CC_FLAGS_CFI := -fsanitize=kcfi
  803. ifdef CONFIG_CFI_ICALL_NORMALIZE_INTEGERS
  804. CC_FLAGS_CFI += -fsanitize-cfi-icall-experimental-normalize-integers
  805. endif
  806. ifdef CONFIG_RUST
  807. # Always pass -Zsanitizer-cfi-normalize-integers as CONFIG_RUST selects
  808. # CONFIG_CFI_ICALL_NORMALIZE_INTEGERS.
  809. RUSTC_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers
  810. KBUILD_RUSTFLAGS += $(RUSTC_FLAGS_CFI)
  811. export RUSTC_FLAGS_CFI
  812. endif
  813. KBUILD_CFLAGS += $(CC_FLAGS_CFI)
  814. export CC_FLAGS_CFI
  815. endif
  816. # Architectures can define flags to add/remove for floating-point support
  817. CC_FLAGS_FPU += -D_LINUX_FPU_COMPILATION_UNIT
  818. export CC_FLAGS_FPU
  819. export CC_FLAGS_NO_FPU
  820. ifneq ($(CONFIG_FUNCTION_ALIGNMENT),0)
  821. # Set the minimal function alignment. Use the newer GCC option
  822. # -fmin-function-alignment if it is available, or fall back to -falign-funtions.
  823. # See also CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT.
  824. ifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT
  825. KBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT)
  826. else
  827. KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)
  828. endif
  829. endif
  830. # arch Makefile may override CC so keep this after arch Makefile is included
  831. NOSTDINC_FLAGS += -nostdinc
  832. # To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE,
  833. # the kernel uses only C99 flexible arrays for dynamically sized trailing
  834. # arrays. Enforce this for everything that may examine structure sizes and
  835. # perform bounds checking.
  836. KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
  837. #Currently, disable -Wstringop-overflow for GCC 11, globally.
  838. KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow)
  839. KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
  840. # disable invalid "can't wrap" optimizations for signed / pointers
  841. KBUILD_CFLAGS += -fno-strict-overflow
  842. # Make sure -fstack-check isn't enabled (like gentoo apparently did)
  843. KBUILD_CFLAGS += -fno-stack-check
  844. # conserve stack if available
  845. ifdef CONFIG_CC_IS_GCC
  846. KBUILD_CFLAGS += -fconserve-stack
  847. endif
  848. # change __FILE__ to the relative path from the srctree
  849. KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
  850. # include additional Makefiles when needed
  851. include-y := scripts/Makefile.extrawarn
  852. include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug
  853. include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf
  854. include-$(CONFIG_KASAN) += scripts/Makefile.kasan
  855. include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan
  856. include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan
  857. include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan
  858. include-$(CONFIG_KCOV) += scripts/Makefile.kcov
  859. include-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstruct
  860. include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins
  861. include $(addprefix $(srctree)/, $(include-y))
  862. # scripts/Makefile.gcc-plugins is intentionally included last.
  863. # Do not add $(call cc-option,...) below this line. When you build the kernel
  864. # from the clean source tree, the GCC plugins do not exist at this point.
  865. # Add user supplied CPPFLAGS, AFLAGS, CFLAGS and RUSTFLAGS as the last assignments
  866. KBUILD_CPPFLAGS += $(KCPPFLAGS)
  867. KBUILD_AFLAGS += $(KAFLAGS)
  868. KBUILD_CFLAGS += $(KCFLAGS)
  869. KBUILD_RUSTFLAGS += $(KRUSTFLAGS)
  870. KBUILD_LDFLAGS_MODULE += --build-id=sha1
  871. LDFLAGS_vmlinux += --build-id=sha1
  872. KBUILD_LDFLAGS += -z noexecstack
  873. ifeq ($(CONFIG_LD_IS_BFD),y)
  874. KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments)
  875. endif
  876. ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
  877. LDFLAGS_vmlinux += -X
  878. endif
  879. ifeq ($(CONFIG_RELR),y)
  880. # ld.lld before 15 did not support -z pack-relative-relocs.
  881. LDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs)
  882. endif
  883. # We never want expected sections to be placed heuristically by the
  884. # linker. All sections should be explicitly named in the linker script.
  885. ifdef CONFIG_LD_ORPHAN_WARN
  886. LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
  887. endif
  888. # Align the bit size of userspace programs with the kernel
  889. KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
  890. KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
  891. # make the checker run with the right architecture
  892. CHECKFLAGS += --arch=$(ARCH)
  893. # insure the checker run with the right endianness
  894. CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
  895. # the checker needs the correct machine size
  896. CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
  897. # Default kernel image to build when no specific target is given.
  898. # KBUILD_IMAGE may be overruled on the command line or
  899. # set in the environment
  900. # Also any assignments in arch/$(ARCH)/Makefile take precedence over
  901. # this default value
  902. export KBUILD_IMAGE ?= vmlinux
  903. #
  904. # INSTALL_PATH specifies where to place the updated kernel and system map
  905. # images. Default is /boot, but you can set it to other values
  906. export INSTALL_PATH ?= /boot
  907. #
  908. # INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots.
  909. # Like INSTALL_MOD_PATH, it isn't defined in the Makefile, but can be passed as
  910. # an argument if needed. Otherwise it defaults to the kernel install path
  911. #
  912. export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
  913. #
  914. # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
  915. # relocations required by build roots. This is not defined in the
  916. # makefile but the argument can be passed to make if needed.
  917. #
  918. MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
  919. export MODLIB
  920. PHONY += prepare0
  921. export extmod_prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)
  922. export MODORDER := $(extmod_prefix)modules.order
  923. export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps
  924. ifeq ($(KBUILD_EXTMOD),)
  925. build-dir := .
  926. clean-dirs := $(sort . Documentation \
  927. $(patsubst %/,%,$(filter %/, $(core-) \
  928. $(drivers-) $(libs-))))
  929. export ARCH_CORE := $(core-y)
  930. export ARCH_LIB := $(filter %/, $(libs-y))
  931. export ARCH_DRIVERS := $(drivers-y) $(drivers-m)
  932. # Externally visible symbols (used by link-vmlinux.sh)
  933. KBUILD_VMLINUX_OBJS := ./built-in.a
  934. ifdef CONFIG_MODULES
  935. KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
  936. KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
  937. else
  938. KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
  939. endif
  940. export KBUILD_VMLINUX_LIBS
  941. export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
  942. ifdef CONFIG_TRIM_UNUSED_KSYMS
  943. # For the kernel to actually contain only the needed exported symbols,
  944. # we have to build modules as well to determine what those symbols are.
  945. KBUILD_MODULES := 1
  946. endif
  947. # '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
  948. quiet_cmd_ar_vmlinux.a = AR $@
  949. cmd_ar_vmlinux.a = \
  950. rm -f $@; \
  951. $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \
  952. $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
  953. targets += vmlinux.a
  954. vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
  955. $(call if_changed,ar_vmlinux.a)
  956. PHONY += vmlinux_o
  957. vmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS)
  958. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o
  959. vmlinux.o modules.builtin.modinfo modules.builtin: vmlinux_o
  960. @:
  961. PHONY += vmlinux
  962. # LDFLAGS_vmlinux in the top Makefile defines linker flags for the top vmlinux,
  963. # not for decompressors. LDFLAGS_vmlinux in arch/*/boot/compressed/Makefile is
  964. # unrelated; the decompressors just happen to have the same base name,
  965. # arch/*/boot/compressed/vmlinux.
  966. # Export LDFLAGS_vmlinux only to scripts/Makefile.vmlinux.
  967. #
  968. # _LDFLAGS_vmlinux is a workaround for the 'private export' bug:
  969. # https://savannah.gnu.org/bugs/?61463
  970. # For Make > 4.4, the following simple code will work:
  971. # vmlinux: private export LDFLAGS_vmlinux := $(LDFLAGS_vmlinux)
  972. vmlinux: private _LDFLAGS_vmlinux := $(LDFLAGS_vmlinux)
  973. vmlinux: export LDFLAGS_vmlinux = $(_LDFLAGS_vmlinux)
  974. vmlinux: vmlinux.o $(KBUILD_LDS) modpost
  975. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux
  976. # The actual objects are generated when descending,
  977. # make sure no implicit rule kicks in
  978. $(sort $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)): . ;
  979. ifeq ($(origin KERNELRELEASE),file)
  980. filechk_kernel.release = $(srctree)/scripts/setlocalversion $(srctree)
  981. else
  982. filechk_kernel.release = echo $(KERNELRELEASE)
  983. endif
  984. # Store (new) KERNELRELEASE string in include/config/kernel.release
  985. include/config/kernel.release: FORCE
  986. $(call filechk,kernel.release)
  987. # Additional helpers built in scripts/
  988. # Carefully list dependencies so we do not try to build scripts twice
  989. # in parallel
  990. PHONY += scripts
  991. scripts: scripts_basic scripts_dtc
  992. $(Q)$(MAKE) $(build)=$(@)
  993. # Things we need to do before we recursively start building the kernel
  994. # or the modules are listed in "prepare".
  995. # A multi level approach is used. prepareN is processed before prepareN-1.
  996. # archprepare is used in arch Makefiles and when processed asm symlink,
  997. # version.h and scripts_basic is processed / created.
  998. PHONY += prepare archprepare
  999. archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \
  1000. asm-generic $(version_h) include/generated/utsrelease.h \
  1001. include/generated/compile.h include/generated/autoconf.h remove-stale-files
  1002. prepare0: archprepare
  1003. $(Q)$(MAKE) $(build)=scripts/mod
  1004. $(Q)$(MAKE) $(build)=. prepare
  1005. # All the preparing..
  1006. prepare: prepare0
  1007. ifdef CONFIG_RUST
  1008. +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh
  1009. $(Q)$(MAKE) $(build)=rust
  1010. endif
  1011. PHONY += remove-stale-files
  1012. remove-stale-files:
  1013. $(Q)$(srctree)/scripts/remove-stale-files
  1014. # Support for using generic headers in asm-generic
  1015. asm-generic := -f $(srctree)/scripts/Makefile.asm-headers obj
  1016. PHONY += asm-generic uapi-asm-generic
  1017. asm-generic: uapi-asm-generic
  1018. $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \
  1019. generic=include/asm-generic
  1020. uapi-asm-generic:
  1021. $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
  1022. generic=include/uapi/asm-generic
  1023. # Generate some files
  1024. # ---------------------------------------------------------------------------
  1025. # KERNELRELEASE can change from a few different places, meaning version.h
  1026. # needs to be updated, so this check is forced on all builds
  1027. uts_len := 64
  1028. define filechk_utsrelease.h
  1029. if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
  1030. echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
  1031. exit 1; \
  1032. fi; \
  1033. echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"
  1034. endef
  1035. define filechk_version.h
  1036. if [ $(SUBLEVEL) -gt 255 ]; then \
  1037. echo \#define LINUX_VERSION_CODE $(shell \
  1038. expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \
  1039. else \
  1040. echo \#define LINUX_VERSION_CODE $(shell \
  1041. expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \
  1042. fi; \
  1043. echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \
  1044. ((c) > 255 ? 255 : (c)))'; \
  1045. echo \#define LINUX_VERSION_MAJOR $(VERSION); \
  1046. echo \#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL); \
  1047. echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)
  1048. endef
  1049. $(version_h): private PATCHLEVEL := $(or $(PATCHLEVEL), 0)
  1050. $(version_h): private SUBLEVEL := $(or $(SUBLEVEL), 0)
  1051. $(version_h): FORCE
  1052. $(call filechk,version.h)
  1053. include/generated/utsrelease.h: include/config/kernel.release FORCE
  1054. $(call filechk,utsrelease.h)
  1055. filechk_compile.h = $(srctree)/scripts/mkcompile_h \
  1056. "$(UTS_MACHINE)" "$(CONFIG_CC_VERSION_TEXT)" "$(LD)"
  1057. include/generated/compile.h: FORCE
  1058. $(call filechk,compile.h)
  1059. PHONY += headerdep
  1060. headerdep:
  1061. $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
  1062. $(srctree)/scripts/headerdep.pl -I$(srctree)/include
  1063. # ---------------------------------------------------------------------------
  1064. # Kernel headers
  1065. #Default location for installed headers
  1066. export INSTALL_HDR_PATH = $(objtree)/usr
  1067. quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include
  1068. cmd_headers_install = \
  1069. mkdir -p $(INSTALL_HDR_PATH); \
  1070. rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
  1071. usr/include $(INSTALL_HDR_PATH)
  1072. PHONY += headers_install
  1073. headers_install: headers
  1074. $(call cmd,headers_install)
  1075. PHONY += archheaders archscripts
  1076. hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
  1077. PHONY += headers
  1078. headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
  1079. $(if $(filter um, $(SRCARCH)), $(error Headers not exportable for UML))
  1080. $(Q)$(MAKE) $(hdr-inst)=include/uapi
  1081. $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi
  1082. ifdef CONFIG_HEADERS_INSTALL
  1083. prepare: headers
  1084. endif
  1085. PHONY += scripts_unifdef
  1086. scripts_unifdef: scripts_basic
  1087. $(Q)$(MAKE) $(build)=scripts scripts/unifdef
  1088. # ---------------------------------------------------------------------------
  1089. # Install
  1090. # Many distributions have the custom install script, /sbin/installkernel.
  1091. # If DKMS is installed, 'make install' will eventually recurse back
  1092. # to this Makefile to build and install external modules.
  1093. # Cancel sub_make_done so that options such as M=, V=, etc. are parsed.
  1094. quiet_cmd_install = INSTALL $(INSTALL_PATH)
  1095. cmd_install = unset sub_make_done; $(srctree)/scripts/install.sh
  1096. # ---------------------------------------------------------------------------
  1097. # vDSO install
  1098. PHONY += vdso_install
  1099. vdso_install: export INSTALL_FILES = $(vdso-install-y)
  1100. vdso_install:
  1101. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vdsoinst
  1102. # ---------------------------------------------------------------------------
  1103. # Tools
  1104. ifdef CONFIG_OBJTOOL
  1105. prepare: tools/objtool
  1106. endif
  1107. ifdef CONFIG_BPF
  1108. ifdef CONFIG_DEBUG_INFO_BTF
  1109. prepare: tools/bpf/resolve_btfids
  1110. endif
  1111. endif
  1112. # The tools build system is not a part of Kbuild and tends to introduce
  1113. # its own unique issues. If you need to integrate a new tool into Kbuild,
  1114. # please consider locating that tool outside the tools/ tree and using the
  1115. # standard Kbuild "hostprogs" syntax instead of adding a new tools/* entry
  1116. # here. See Documentation/kbuild/makefiles.rst for details.
  1117. PHONY += resolve_btfids_clean
  1118. resolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids
  1119. # tools/bpf/resolve_btfids directory might not exist
  1120. # in output directory, skip its clean in that case
  1121. resolve_btfids_clean:
  1122. ifneq ($(wildcard $(resolve_btfids_O)),)
  1123. $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
  1124. endif
  1125. tools/: FORCE
  1126. $(Q)mkdir -p $(objtree)/tools
  1127. $(Q)$(MAKE) LDFLAGS= O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
  1128. tools/%: FORCE
  1129. $(Q)mkdir -p $(objtree)/tools
  1130. $(Q)$(MAKE) LDFLAGS= O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
  1131. # ---------------------------------------------------------------------------
  1132. # Kernel selftest
  1133. PHONY += kselftest
  1134. kselftest: headers
  1135. $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
  1136. kselftest-%: headers FORCE
  1137. $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
  1138. PHONY += kselftest-merge
  1139. kselftest-merge:
  1140. $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!))
  1141. $(Q)find $(srctree)/tools/testing/selftests -name config -o -name config.$(UTS_MACHINE) | \
  1142. xargs $(srctree)/scripts/kconfig/merge_config.sh -y -m $(objtree)/.config
  1143. $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
  1144. # ---------------------------------------------------------------------------
  1145. # Devicetree files
  1146. ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
  1147. dtstree := arch/$(SRCARCH)/boot/dts
  1148. endif
  1149. ifneq ($(dtstree),)
  1150. %.dtb: dtbs_prepare
  1151. $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
  1152. %.dtbo: dtbs_prepare
  1153. $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
  1154. PHONY += dtbs dtbs_prepare dtbs_install dtbs_check
  1155. dtbs: dtbs_prepare
  1156. $(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1
  1157. # include/config/kernel.release is actually needed when installing DTBs because
  1158. # INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make
  1159. # dtbs_install depend on it as dtbs_install may run as root.
  1160. dtbs_prepare: include/config/kernel.release scripts_dtc
  1161. ifneq ($(filter dtbs_check, $(MAKECMDGOALS)),)
  1162. export CHECK_DTBS=y
  1163. endif
  1164. ifneq ($(CHECK_DTBS),)
  1165. dtbs_prepare: dt_binding_schemas
  1166. endif
  1167. dtbs_check: dtbs
  1168. dtbs_install:
  1169. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree)
  1170. ifdef CONFIG_OF_EARLY_FLATTREE
  1171. all: dtbs
  1172. endif
  1173. endif
  1174. PHONY += scripts_dtc
  1175. scripts_dtc: scripts_basic
  1176. $(Q)$(MAKE) $(build)=scripts/dtc
  1177. ifneq ($(filter dt_binding_check, $(MAKECMDGOALS)),)
  1178. export CHECK_DTBS=y
  1179. endif
  1180. PHONY += dt_binding_check dt_binding_schemas
  1181. dt_binding_check: dt_binding_schemas scripts_dtc
  1182. $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings $@
  1183. dt_binding_schemas:
  1184. $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings
  1185. PHONY += dt_compatible_check
  1186. dt_compatible_check: dt_binding_schemas
  1187. $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings $@
  1188. # ---------------------------------------------------------------------------
  1189. # Modules
  1190. ifdef CONFIG_MODULES
  1191. # By default, build modules as well
  1192. all: modules
  1193. # When we're building modules with modversions, we need to consider
  1194. # the built-in objects during the descend as well, in order to
  1195. # make sure the checksums are up to date before we record them.
  1196. ifdef CONFIG_MODVERSIONS
  1197. KBUILD_BUILTIN := 1
  1198. endif
  1199. # Build modules
  1200. #
  1201. # *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFO_BTF_MODULES
  1202. # is an exception.
  1203. ifdef CONFIG_DEBUG_INFO_BTF_MODULES
  1204. KBUILD_BUILTIN := 1
  1205. modules: vmlinux
  1206. endif
  1207. modules: modules_prepare
  1208. # Target to prepare building external modules
  1209. modules_prepare: prepare
  1210. $(Q)$(MAKE) $(build)=scripts scripts/module.lds
  1211. endif # CONFIG_MODULES
  1212. ###
  1213. # Cleaning is done on three levels.
  1214. # make clean Delete most generated files
  1215. # Leave enough to build external modules
  1216. # make mrproper Delete the current configuration, and all generated files
  1217. # make distclean Remove editor backup files, patch leftover files and the like
  1218. # Directories & files removed with 'make clean'
  1219. CLEAN_FILES += vmlinux.symvers modules-only.symvers \
  1220. modules.builtin modules.builtin.modinfo modules.nsdeps \
  1221. modules.builtin.ranges vmlinux.o.map \
  1222. compile_commands.json rust/test \
  1223. rust-project.json .vmlinux.objs .vmlinux.export.c
  1224. # Directories & files removed with 'make mrproper'
  1225. MRPROPER_FILES += include/config include/generated \
  1226. arch/$(SRCARCH)/include/generated .objdiff \
  1227. debian snap tar-install PKGBUILD pacman \
  1228. .config .config.old .version \
  1229. Module.symvers \
  1230. certs/signing_key.pem \
  1231. certs/x509.genkey \
  1232. vmlinux-gdb.py \
  1233. rpmbuild \
  1234. rust/libmacros.so
  1235. # clean - Delete most, but leave enough to build external modules
  1236. #
  1237. clean: private rm-files := $(CLEAN_FILES)
  1238. PHONY += archclean vmlinuxclean
  1239. vmlinuxclean:
  1240. $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
  1241. $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
  1242. clean: archclean vmlinuxclean resolve_btfids_clean
  1243. # mrproper - Delete all generated files, including .config
  1244. #
  1245. mrproper: private rm-files := $(MRPROPER_FILES)
  1246. mrproper-dirs := $(addprefix _mrproper_,scripts)
  1247. PHONY += $(mrproper-dirs) mrproper
  1248. $(mrproper-dirs):
  1249. $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
  1250. mrproper: clean $(mrproper-dirs)
  1251. $(call cmd,rmfiles)
  1252. @find . $(RCS_FIND_IGNORE) \
  1253. \( -name '*.rmeta' \) \
  1254. -type f -print | xargs rm -f
  1255. # distclean
  1256. #
  1257. PHONY += distclean
  1258. distclean: mrproper
  1259. @find . $(RCS_FIND_IGNORE) \
  1260. \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
  1261. -o -name '*.bak' -o -name '#*#' -o -name '*%' \
  1262. -o -name 'core' -o -name tags -o -name TAGS -o -name 'cscope*' \
  1263. -o -name GPATH -o -name GRTAGS -o -name GSYMS -o -name GTAGS \) \
  1264. -type f -print | xargs rm -f
  1265. # Packaging of the kernel to various formats
  1266. # ---------------------------------------------------------------------------
  1267. %src-pkg: FORCE
  1268. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
  1269. %pkg: include/config/kernel.release FORCE
  1270. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
  1271. # Brief documentation of the typical targets used
  1272. # ---------------------------------------------------------------------------
  1273. boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)
  1274. boards := $(sort $(notdir $(boards)))
  1275. board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
  1276. board-dirs := $(sort $(notdir $(board-dirs:/=)))
  1277. PHONY += help
  1278. help:
  1279. @echo 'Cleaning targets:'
  1280. @echo ' clean - Remove most generated files but keep the config and'
  1281. @echo ' enough build support to build external modules'
  1282. @echo ' mrproper - Remove all generated files + config + various backup files'
  1283. @echo ' distclean - mrproper + remove editor backup and patch files'
  1284. @echo ''
  1285. @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
  1286. @echo ''
  1287. @echo 'Other generic targets:'
  1288. @echo ' all - Build all targets marked with [*]'
  1289. @echo '* vmlinux - Build the bare kernel'
  1290. @echo '* modules - Build all modules'
  1291. @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
  1292. @echo ' vdso_install - Install unstripped vdso to INSTALL_MOD_PATH (default: /)'
  1293. @echo ' dir/ - Build all files in dir and below'
  1294. @echo ' dir/file.[ois] - Build specified target only'
  1295. @echo ' dir/file.ll - Build the LLVM assembly file'
  1296. @echo ' (requires compiler support for LLVM assembly generation)'
  1297. @echo ' dir/file.lst - Build specified mixed source/assembly target only'
  1298. @echo ' (requires a recent binutils and recent build (System.map))'
  1299. @echo ' dir/file.ko - Build module including final link'
  1300. @echo ' modules_prepare - Set up for building external modules'
  1301. @echo ' tags/TAGS - Generate tags file for editors'
  1302. @echo ' cscope - Generate cscope index'
  1303. @echo ' gtags - Generate GNU GLOBAL index'
  1304. @echo ' kernelrelease - Output the release version string (use with make -s)'
  1305. @echo ' kernelversion - Output the version stored in Makefile (use with make -s)'
  1306. @echo ' image_name - Output the image name (use with make -s)'
  1307. @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
  1308. echo ' (default: $(INSTALL_HDR_PATH))'; \
  1309. echo ''
  1310. @echo 'Static analysers:'
  1311. @echo ' checkstack - Generate a list of stack hogs and consider all functions'
  1312. @echo ' with a stack size larger than MINSTACKSIZE (default: 100)'
  1313. @echo ' versioncheck - Sanity check on version.h usage'
  1314. @echo ' includecheck - Check for duplicate included header files'
  1315. @echo ' export_report - List the usages of all exported symbols'
  1316. @echo ' headerdep - Detect inclusion cycles in headers'
  1317. @echo ' coccicheck - Check with Coccinelle'
  1318. @echo ' clang-analyzer - Check with clang static analyzer'
  1319. @echo ' clang-tidy - Check with clang-tidy'
  1320. @echo ''
  1321. @echo 'Tools:'
  1322. @echo ' nsdeps - Generate missing symbol namespace dependencies'
  1323. @echo ''
  1324. @echo 'Kernel selftest:'
  1325. @echo ' kselftest - Build and run kernel selftest'
  1326. @echo ' Build, install, and boot kernel before'
  1327. @echo ' running kselftest on it'
  1328. @echo ' Run as root for full coverage'
  1329. @echo ' kselftest-all - Build kernel selftest'
  1330. @echo ' kselftest-install - Build and install kernel selftest'
  1331. @echo ' kselftest-clean - Remove all generated kselftest files'
  1332. @echo ' kselftest-merge - Merge all the config dependencies of'
  1333. @echo ' kselftest to existing .config.'
  1334. @echo ''
  1335. @echo 'Rust targets:'
  1336. @echo ' rustavailable - Checks whether the Rust toolchain is'
  1337. @echo ' available and, if not, explains why.'
  1338. @echo ' rustfmt - Reformat all the Rust code in the kernel'
  1339. @echo ' rustfmtcheck - Checks if all the Rust code in the kernel'
  1340. @echo ' is formatted, printing a diff otherwise.'
  1341. @echo ' rustdoc - Generate Rust documentation'
  1342. @echo ' (requires kernel .config)'
  1343. @echo ' rusttest - Runs the Rust tests'
  1344. @echo ' (requires kernel .config; downloads external repos)'
  1345. @echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file'
  1346. @echo ' (requires kernel .config)'
  1347. @echo ' dir/file.[os] - Build specified target only'
  1348. @echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing.'
  1349. @echo ' Run with RUSTFMT=n to skip reformatting if needed.'
  1350. @echo ' The output is not intended to be compilable.'
  1351. @echo ' dir/file.ll - Build the LLVM assembly file'
  1352. @echo ''
  1353. @$(if $(dtstree), \
  1354. echo 'Devicetree:'; \
  1355. echo '* dtbs - Build device tree blobs for enabled boards'; \
  1356. echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \
  1357. echo ' dt_binding_check - Validate device tree binding documents and examples'; \
  1358. echo ' dt_binding_schemas - Build processed device tree binding schemas'; \
  1359. echo ' dtbs_check - Validate device tree source files';\
  1360. echo '')
  1361. @echo 'Userspace tools targets:'
  1362. @echo ' use "make tools/help"'
  1363. @echo ' or "cd tools; make help"'
  1364. @echo ''
  1365. @echo 'Kernel packaging:'
  1366. @$(MAKE) -f $(srctree)/scripts/Makefile.package help
  1367. @echo ''
  1368. @echo 'Documentation targets:'
  1369. @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
  1370. @echo ''
  1371. @echo 'Architecture-specific targets ($(SRCARCH)):'
  1372. @$(or $(archhelp),\
  1373. echo ' No architecture-specific help defined for $(SRCARCH)')
  1374. @echo ''
  1375. @$(if $(boards), \
  1376. $(foreach b, $(boards), \
  1377. printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
  1378. echo '')
  1379. @$(if $(board-dirs), \
  1380. $(foreach b, $(board-dirs), \
  1381. printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
  1382. printf " %-16s - Show all of the above\\n" help-boards; \
  1383. echo '')
  1384. @echo ' make V=n [targets] 1: verbose build'
  1385. @echo ' 2: give reason for rebuild of target'
  1386. @echo ' V=1 and V=2 can be combined with V=12'
  1387. @echo ' make O=dir [targets] Locate all output files in "dir", including .config'
  1388. @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK'
  1389. @echo ' (sparse by default)'
  1390. @echo ' make C=2 [targets] Force check of all c source with $$CHECK'
  1391. @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections'
  1392. @echo ' make W=n [targets] Enable extra build checks, n=1,2,3,c,e where'
  1393. @echo ' 1: warnings which may be relevant and do not occur too often'
  1394. @echo ' 2: warnings which occur quite often but may still be relevant'
  1395. @echo ' 3: more obscure warnings, can most likely be ignored'
  1396. @echo ' c: extra checks in the configuration stage (Kconfig)'
  1397. @echo ' e: warnings are being treated as errors'
  1398. @echo ' Multiple levels can be combined with W=12 or W=123'
  1399. @$(if $(dtstree), \
  1400. echo ' make CHECK_DTBS=1 [targets] Check all generated dtb files against schema'; \
  1401. echo ' This can be applied both to "dtbs" and to individual "foo.dtb" targets' ; \
  1402. )
  1403. @echo ''
  1404. @echo 'Execute "make" or "make all" to build all targets marked with [*] '
  1405. @echo 'For further info see the ./README file'
  1406. help-board-dirs := $(addprefix help-,$(board-dirs))
  1407. help-boards: $(help-board-dirs)
  1408. boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
  1409. $(help-board-dirs): help-%:
  1410. @echo 'Architecture-specific targets ($(SRCARCH) $*):'
  1411. @$(if $(boards-per-dir), \
  1412. $(foreach b, $(boards-per-dir), \
  1413. printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
  1414. echo '')
  1415. # Documentation targets
  1416. # ---------------------------------------------------------------------------
  1417. DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \
  1418. linkcheckdocs dochelp refcheckdocs texinfodocs infodocs
  1419. PHONY += $(DOC_TARGETS)
  1420. $(DOC_TARGETS):
  1421. $(Q)$(MAKE) $(build)=Documentation $@
  1422. # Rust targets
  1423. # ---------------------------------------------------------------------------
  1424. # "Is Rust available?" target
  1425. PHONY += rustavailable
  1426. rustavailable:
  1427. +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh && echo "Rust is available!"
  1428. # Documentation target
  1429. #
  1430. # Using the singular to avoid running afoul of `no-dot-config-targets`.
  1431. PHONY += rustdoc
  1432. rustdoc: prepare
  1433. $(Q)$(MAKE) $(build)=rust $@
  1434. # Testing target
  1435. PHONY += rusttest
  1436. rusttest: prepare
  1437. $(Q)$(MAKE) $(build)=rust $@
  1438. # Formatting targets
  1439. PHONY += rustfmt rustfmtcheck
  1440. # We skip `rust/alloc` since we want to minimize the diff w.r.t. upstream.
  1441. #
  1442. # We match using absolute paths since `find` does not resolve them
  1443. # when matching, which is a problem when e.g. `srctree` is `..`.
  1444. # We `grep` afterwards in order to remove the directory entry itself.
  1445. rustfmt:
  1446. $(Q)find $(abs_srctree) -type f -name '*.rs' \
  1447. -o -path $(abs_srctree)/rust/alloc -prune \
  1448. -o -path $(abs_objtree)/rust/test -prune \
  1449. | grep -Fv $(abs_srctree)/rust/alloc \
  1450. | grep -Fv $(abs_objtree)/rust/test \
  1451. | grep -Fv generated \
  1452. | xargs $(RUSTFMT) $(rustfmt_flags)
  1453. rustfmtcheck: rustfmt_flags = --check
  1454. rustfmtcheck: rustfmt
  1455. # Misc
  1456. # ---------------------------------------------------------------------------
  1457. PHONY += misc-check
  1458. misc-check:
  1459. $(Q)$(srctree)/scripts/misc-check
  1460. all: misc-check
  1461. PHONY += scripts_gdb
  1462. scripts_gdb: prepare0
  1463. $(Q)$(MAKE) $(build)=scripts/gdb
  1464. $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
  1465. ifdef CONFIG_GDB_SCRIPTS
  1466. all: scripts_gdb
  1467. endif
  1468. else # KBUILD_EXTMOD
  1469. filechk_kernel.release = echo $(KERNELRELEASE)
  1470. ###
  1471. # External module support.
  1472. # When building external modules the kernel used as basis is considered
  1473. # read-only, and no consistency checks are made and the make
  1474. # system is not used on the basis kernel. If updates are required
  1475. # in the basis kernel ordinary make commands (without M=...) must be used.
  1476. # We are always building only modules.
  1477. KBUILD_BUILTIN :=
  1478. KBUILD_MODULES := 1
  1479. build-dir := $(KBUILD_EXTMOD)
  1480. compile_commands.json: $(extmod_prefix)compile_commands.json
  1481. PHONY += compile_commands.json
  1482. clean-dirs := $(KBUILD_EXTMOD)
  1483. clean: private rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \
  1484. $(KBUILD_EXTMOD)/compile_commands.json
  1485. PHONY += prepare
  1486. # now expand this into a simple variable to reduce the cost of shell evaluations
  1487. prepare: CC_VERSION_TEXT := $(CC_VERSION_TEXT)
  1488. prepare:
  1489. @if [ "$(CC_VERSION_TEXT)" != "$(CONFIG_CC_VERSION_TEXT)" ]; then \
  1490. echo >&2 "warning: the compiler differs from the one used to build the kernel"; \
  1491. echo >&2 " The kernel was built by: $(CONFIG_CC_VERSION_TEXT)"; \
  1492. echo >&2 " You are using: $(CC_VERSION_TEXT)"; \
  1493. fi
  1494. PHONY += help
  1495. help:
  1496. @echo ' Building external modules.'
  1497. @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
  1498. @echo ''
  1499. @echo ' modules - default target, build the module(s)'
  1500. @echo ' modules_install - install the module'
  1501. @echo ' clean - remove generated files in module directory only'
  1502. @echo ' rust-analyzer - generate rust-project.json rust-analyzer support file'
  1503. @echo ''
  1504. ifndef CONFIG_MODULES
  1505. modules modules_install: __external_modules_error
  1506. __external_modules_error:
  1507. @echo >&2 '***'
  1508. @echo >&2 '*** The present kernel disabled CONFIG_MODULES.'
  1509. @echo >&2 '*** You cannot build or install external modules.'
  1510. @echo >&2 '***'
  1511. @false
  1512. endif
  1513. endif # KBUILD_EXTMOD
  1514. # ---------------------------------------------------------------------------
  1515. # Modules
  1516. PHONY += modules modules_install modules_sign modules_prepare
  1517. modules_install:
  1518. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst \
  1519. sign-only=$(if $(filter modules_install,$(MAKECMDGOALS)),,y)
  1520. ifeq ($(CONFIG_MODULE_SIG),y)
  1521. # modules_sign is a subset of modules_install.
  1522. # 'make modules_install modules_sign' is equivalent to 'make modules_install'.
  1523. modules_sign: modules_install
  1524. @:
  1525. else
  1526. modules_sign:
  1527. @echo >&2 '***'
  1528. @echo >&2 '*** CONFIG_MODULE_SIG is disabled. You cannot sign modules.'
  1529. @echo >&2 '***'
  1530. @false
  1531. endif
  1532. ifdef CONFIG_MODULES
  1533. $(MODORDER): $(build-dir)
  1534. @:
  1535. # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
  1536. # This is solely useful to speed up test compiles.
  1537. modules: modpost
  1538. ifneq ($(KBUILD_MODPOST_NOFINAL),1)
  1539. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
  1540. endif
  1541. PHONY += modules_check
  1542. modules_check: $(MODORDER)
  1543. $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
  1544. else # CONFIG_MODULES
  1545. modules:
  1546. @:
  1547. KBUILD_MODULES :=
  1548. endif # CONFIG_MODULES
  1549. PHONY += modpost
  1550. modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
  1551. $(if $(KBUILD_MODULES), modules_check)
  1552. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
  1553. # Single targets
  1554. # ---------------------------------------------------------------------------
  1555. # To build individual files in subdirectories, you can do like this:
  1556. #
  1557. # make foo/bar/baz.s
  1558. #
  1559. # The supported suffixes for single-target are listed in 'single-targets'
  1560. #
  1561. # To build only under specific subdirectories, you can do like this:
  1562. #
  1563. # make foo/bar/baz/
  1564. ifdef single-build
  1565. # .ko is special because modpost is needed
  1566. single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
  1567. single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
  1568. $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
  1569. $(single-ko): single_modules
  1570. @:
  1571. $(single-no-ko): $(build-dir)
  1572. @:
  1573. # Remove MODORDER when done because it is not the real one.
  1574. PHONY += single_modules
  1575. single_modules: $(single-no-ko) modules_prepare
  1576. $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$(m:%.ko=%.o);) } > $(MODORDER)
  1577. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
  1578. ifneq ($(KBUILD_MODPOST_NOFINAL),1)
  1579. $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
  1580. endif
  1581. $(Q)rm -f $(MODORDER)
  1582. single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
  1583. KBUILD_MODULES := 1
  1584. endif
  1585. # Preset locale variables to speed up the build process. Limit locale
  1586. # tweaks to this spot to avoid wrong language settings when running
  1587. # make menuconfig etc.
  1588. # Error messages still appears in the original language
  1589. PHONY += $(build-dir)
  1590. $(build-dir): prepare
  1591. $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
  1592. clean-dirs := $(addprefix _clean_, $(clean-dirs))
  1593. PHONY += $(clean-dirs) clean
  1594. $(clean-dirs):
  1595. $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
  1596. clean: $(clean-dirs)
  1597. $(call cmd,rmfiles)
  1598. @find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
  1599. \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
  1600. -o -name '*.ko.*' \
  1601. -o -name '*.dtb' -o -name '*.dtbo' \
  1602. -o -name '*.dtb.S' -o -name '*.dtbo.S' \
  1603. -o -name '*.dt.yaml' -o -name 'dtbs-list' \
  1604. -o -name '*.dwo' -o -name '*.lst' \
  1605. -o -name '*.su' -o -name '*.mod' \
  1606. -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
  1607. -o -name '*.lex.c' -o -name '*.tab.[ch]' \
  1608. -o -name '*.asn1.[ch]' \
  1609. -o -name '*.symtypes' -o -name 'modules.order' \
  1610. -o -name '*.c.[012]*.*' \
  1611. -o -name '*.ll' \
  1612. -o -name '*.gcno' \
  1613. \) -type f -print \
  1614. -o -name '.tmp_*' -print \
  1615. | xargs rm -rf
  1616. # Generate tags for editors
  1617. # ---------------------------------------------------------------------------
  1618. quiet_cmd_tags = GEN $@
  1619. cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@
  1620. tags TAGS cscope gtags: FORCE
  1621. $(call cmd,tags)
  1622. # Generate rust-project.json (a file that describes the structure of non-Cargo
  1623. # Rust projects) for rust-analyzer (an implementation of the Language Server
  1624. # Protocol).
  1625. PHONY += rust-analyzer
  1626. rust-analyzer:
  1627. +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh
  1628. $(Q)$(MAKE) $(build)=rust $@
  1629. # Script to generate missing namespace dependencies
  1630. # ---------------------------------------------------------------------------
  1631. PHONY += nsdeps
  1632. nsdeps: export KBUILD_NSDEPS=1
  1633. nsdeps: modules
  1634. $(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps
  1635. # Clang Tooling
  1636. # ---------------------------------------------------------------------------
  1637. quiet_cmd_gen_compile_commands = GEN $@
  1638. cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
  1639. $(extmod_prefix)compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \
  1640. $(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \
  1641. $(if $(CONFIG_MODULES), $(MODORDER)) FORCE
  1642. $(call if_changed,gen_compile_commands)
  1643. targets += $(extmod_prefix)compile_commands.json
  1644. PHONY += clang-tidy clang-analyzer
  1645. ifdef CONFIG_CC_IS_CLANG
  1646. quiet_cmd_clang_tools = CHECK $<
  1647. cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<
  1648. clang-tidy clang-analyzer: $(extmod_prefix)compile_commands.json
  1649. $(call cmd,clang_tools)
  1650. else
  1651. clang-tidy clang-analyzer:
  1652. @echo "$@ requires CC=clang" >&2
  1653. @false
  1654. endif
  1655. # Scripts to check various things for consistency
  1656. # ---------------------------------------------------------------------------
  1657. PHONY += includecheck versioncheck coccicheck export_report
  1658. includecheck:
  1659. find $(srctree)/* $(RCS_FIND_IGNORE) \
  1660. -name '*.[hcS]' -type f -print | sort \
  1661. | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
  1662. versioncheck:
  1663. find $(srctree)/* $(RCS_FIND_IGNORE) \
  1664. -name '*.[hcS]' -type f -print | sort \
  1665. | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
  1666. coccicheck:
  1667. $(Q)$(BASH) $(srctree)/scripts/$@
  1668. export_report:
  1669. $(PERL) $(srctree)/scripts/export_report.pl
  1670. PHONY += checkstack kernelrelease kernelversion image_name
  1671. # UML needs a little special treatment here. It wants to use the host
  1672. # toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone
  1673. # else wants $(ARCH), including people doing cross-builds, which means
  1674. # that $(SUBARCH) doesn't work here.
  1675. ifeq ($(ARCH), um)
  1676. CHECKSTACK_ARCH := $(SUBARCH)
  1677. else
  1678. CHECKSTACK_ARCH := $(ARCH)
  1679. endif
  1680. MINSTACKSIZE ?= 100
  1681. checkstack:
  1682. $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
  1683. $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) $(MINSTACKSIZE)
  1684. kernelrelease:
  1685. @$(filechk_kernel.release)
  1686. kernelversion:
  1687. @echo $(KERNELVERSION)
  1688. image_name:
  1689. @echo $(KBUILD_IMAGE)
  1690. PHONY += run-command
  1691. run-command:
  1692. $(Q)$(KBUILD_RUN_COMMAND)
  1693. quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
  1694. cmd_rmfiles = rm -rf $(rm-files)
  1695. # read saved command lines for existing targets
  1696. existing-targets := $(wildcard $(sort $(targets)))
  1697. -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
  1698. endif # config-build
  1699. endif # mixed-build
  1700. endif # need-sub-make
  1701. PHONY += FORCE
  1702. FORCE:
  1703. # Declare the contents of the PHONY variable as phony. We keep that
  1704. # information in a variable so we can use it in if_changed and friends.
  1705. .PHONY: $(PHONY)