Makefile 63 KB

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