Makefile 74 KB

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