Makefile 61 KB

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