Makefile 67 KB

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