Makefile 73 KB

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