You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 59KB

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