Makefile 67 KB

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