aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2017-10-03 23:56:06 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2017-10-09 21:01:29 -0400
commit2c1f4f125159f10521944cea23e33a00fcf85ede (patch)
tree7c44205044aadfadfce3150feac9b048e8a45703 /Makefile
parentba634eceb535d95e87ef09caae7814b3687c6036 (diff)
kbuild: re-order the code to not parse unnecessary variables
The top Makefile is divided into some sections such as mixed targets, config targets, build targets, etc. When we build mixed targets, Kbuild just invokes submake to process them one by one. In this case, compiler-related variables like CC, KBUILD_CFLAGS, etc. are unneeded. Check what kind of targets we are building first, and parse variables for building only when necessary. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile233
1 files changed, 118 insertions, 115 deletions
diff --git a/Makefile b/Makefile
index a793ed153f7a..1ec97b902e52 100644
--- a/Makefile
+++ b/Makefile
@@ -186,15 +186,6 @@ ifeq ("$(origin M)", "command line")
186 KBUILD_EXTMOD := $(M) 186 KBUILD_EXTMOD := $(M)
187endif 187endif
188 188
189# If building an external module we do not care about the all: rule
190# but instead _all depend on modules
191PHONY += all
192ifeq ($(KBUILD_EXTMOD),)
193_all: all
194else
195_all: modules
196endif
197
198ifeq ($(KBUILD_SRC),) 189ifeq ($(KBUILD_SRC),)
199 # building in the source tree 190 # building in the source tree
200 srctree := . 191 srctree := .
@@ -206,6 +197,9 @@ else
206 srctree := $(KBUILD_SRC) 197 srctree := $(KBUILD_SRC)
207 endif 198 endif
208endif 199endif
200
201export KBUILD_CHECKSRC KBUILD_EXTMOD KBUILD_SRC
202
209objtree := . 203objtree := .
210src := $(srctree) 204src := $(srctree)
211obj := $(objtree) 205obj := $(objtree)
@@ -214,6 +208,74 @@ VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
214 208
215export srctree objtree VPATH 209export srctree objtree VPATH
216 210
211# To make sure we do not include .config for any of the *config targets
212# catch them early, and hand them over to scripts/kconfig/Makefile
213# It is allowed to specify more targets when calling make, including
214# mixing *config targets and build targets.
215# For example 'make oldconfig all'.
216# Detect when mixed targets is specified, and make a second invocation
217# of make so .config is not included in this case either (for *config).
218
219version_h := include/generated/uapi/linux/version.h
220old_version_h := include/linux/version.h
221
222no-dot-config-targets := clean mrproper distclean \
223 cscope gtags TAGS tags help% %docs check% coccicheck \
224 $(version_h) headers_% archheaders archscripts \
225 kernelversion %src-pkg
226
227config-targets := 0
228mixed-targets := 0
229dot-config := 1
230
231ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
232 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
233 dot-config := 0
234 endif
235endif
236
237ifeq ($(KBUILD_EXTMOD),)
238 ifneq ($(filter config %config,$(MAKECMDGOALS)),)
239 config-targets := 1
240 ifneq ($(words $(MAKECMDGOALS)),1)
241 mixed-targets := 1
242 endif
243 endif
244endif
245# install and modules_install need also be processed one by one
246ifneq ($(filter install,$(MAKECMDGOALS)),)
247 ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
248 mixed-targets := 1
249 endif
250endif
251
252ifeq ($(mixed-targets),1)
253# ===========================================================================
254# We're called with mixed targets (*config and build targets).
255# Handle them one by one.
256
257PHONY += $(MAKECMDGOALS) __build_one_by_one
258
259$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
260 @:
261
262__build_one_by_one:
263 $(Q)set -e; \
264 for i in $(MAKECMDGOALS); do \
265 $(MAKE) -f $(srctree)/Makefile $$i; \
266 done
267
268else
269
270# We need some generic definitions (do not try to remake the file).
271scripts/Kbuild.include: ;
272include scripts/Kbuild.include
273
274# Read KERNELRELEASE from include/config/kernel.release (if it exists)
275KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
276KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
277export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
278
217# SUBARCH tells the usermode build what the underlying arch is. That is set 279# SUBARCH tells the usermode build what the underlying arch is. That is set
218# first, and if a usermode build is happening, the "ARCH=um" on the command 280# first, and if a usermode build is happening, the "ARCH=um" on the command
219# line overrides the setting of ARCH below. If a native build is happening, 281# line overrides the setting of ARCH below. If a native build is happening,
@@ -308,40 +370,6 @@ HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
308 -Wno-missing-field-initializers -fno-delete-null-pointer-checks 370 -Wno-missing-field-initializers -fno-delete-null-pointer-checks
309endif 371endif
310 372
311# Decide whether to build built-in, modular, or both.
312# Normally, just do built-in.
313
314KBUILD_MODULES :=
315KBUILD_BUILTIN := 1
316
317# If we have only "make modules", don't compile built-in objects.
318# When we're building modules with modversions, we need to consider
319# the built-in objects during the descend as well, in order to
320# make sure the checksums are up to date before we record them.
321
322ifeq ($(MAKECMDGOALS),modules)
323 KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
324endif
325
326# If we have "make <whatever> modules", compile modules
327# in addition to whatever we do anyway.
328# Just "make" or "make all" shall build modules as well
329
330ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
331 KBUILD_MODULES := 1
332endif
333
334ifeq ($(MAKECMDGOALS),)
335 KBUILD_MODULES := 1
336endif
337
338export KBUILD_MODULES KBUILD_BUILTIN
339export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
340
341# We need some generic definitions (do not try to remake the file).
342scripts/Kbuild.include: ;
343include scripts/Kbuild.include
344
345# Make variables (CC, etc...) 373# Make variables (CC, etc...)
346AS = $(CROSS_COMPILE)as 374AS = $(CROSS_COMPILE)as
347LD = $(CROSS_COMPILE)ld 375LD = $(CROSS_COMPILE)ld
@@ -406,11 +434,6 @@ KBUILD_AFLAGS_MODULE := -DMODULE
406KBUILD_CFLAGS_MODULE := -DMODULE 434KBUILD_CFLAGS_MODULE := -DMODULE
407KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds 435KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
408 436
409# Read KERNELRELEASE from include/config/kernel.release (if it exists)
410KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
411KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
412
413export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
414export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC 437export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
415export CPP AR NM STRIP OBJCOPY OBJDUMP HOSTLDFLAGS HOST_LOADLIBES 438export CPP AR NM STRIP OBJCOPY OBJDUMP HOSTLDFLAGS HOST_LOADLIBES
416export MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE 439export MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE
@@ -459,73 +482,6 @@ ifneq ($(KBUILD_SRC),)
459 $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) 482 $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
460endif 483endif
461 484
462# Support for using generic headers in asm-generic
463PHONY += asm-generic uapi-asm-generic
464asm-generic: uapi-asm-generic
465 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
466 src=asm obj=arch/$(SRCARCH)/include/generated/asm
467uapi-asm-generic:
468 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
469 src=uapi/asm obj=arch/$(SRCARCH)/include/generated/uapi/asm
470
471# To make sure we do not include .config for any of the *config targets
472# catch them early, and hand them over to scripts/kconfig/Makefile
473# It is allowed to specify more targets when calling make, including
474# mixing *config targets and build targets.
475# For example 'make oldconfig all'.
476# Detect when mixed targets is specified, and make a second invocation
477# of make so .config is not included in this case either (for *config).
478
479version_h := include/generated/uapi/linux/version.h
480old_version_h := include/linux/version.h
481
482no-dot-config-targets := clean mrproper distclean \
483 cscope gtags TAGS tags help% %docs check% coccicheck \
484 $(version_h) headers_% archheaders archscripts \
485 kernelversion %src-pkg
486
487config-targets := 0
488mixed-targets := 0
489dot-config := 1
490
491ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
492 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
493 dot-config := 0
494 endif
495endif
496
497ifeq ($(KBUILD_EXTMOD),)
498 ifneq ($(filter config %config,$(MAKECMDGOALS)),)
499 config-targets := 1
500 ifneq ($(words $(MAKECMDGOALS)),1)
501 mixed-targets := 1
502 endif
503 endif
504endif
505# install and modules_install need also be processed one by one
506ifneq ($(filter install,$(MAKECMDGOALS)),)
507 ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
508 mixed-targets := 1
509 endif
510endif
511
512ifeq ($(mixed-targets),1)
513# ===========================================================================
514# We're called with mixed targets (*config and build targets).
515# Handle them one by one.
516
517PHONY += $(MAKECMDGOALS) __build_one_by_one
518
519$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
520 @:
521
522__build_one_by_one:
523 $(Q)set -e; \
524 for i in $(MAKECMDGOALS); do \
525 $(MAKE) -f $(srctree)/Makefile $$i; \
526 done
527
528else
529ifeq ($(config-targets),1) 485ifeq ($(config-targets),1)
530# =========================================================================== 486# ===========================================================================
531# *config targets only - make sure prerequisites are updated, and descend 487# *config targets only - make sure prerequisites are updated, and descend
@@ -548,6 +504,44 @@ else
548# Build targets only - this includes vmlinux, arch specific targets, clean 504# Build targets only - this includes vmlinux, arch specific targets, clean
549# targets and others. In general all targets except *config targets. 505# targets and others. In general all targets except *config targets.
550 506
507# If building an external module we do not care about the all: rule
508# but instead _all depend on modules
509PHONY += all
510ifeq ($(KBUILD_EXTMOD),)
511_all: all
512else
513_all: modules
514endif
515
516# Decide whether to build built-in, modular, or both.
517# Normally, just do built-in.
518
519KBUILD_MODULES :=
520KBUILD_BUILTIN := 1
521
522# If we have only "make modules", don't compile built-in objects.
523# When we're building modules with modversions, we need to consider
524# the built-in objects during the descend as well, in order to
525# make sure the checksums are up to date before we record them.
526
527ifeq ($(MAKECMDGOALS),modules)
528 KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
529endif
530
531# If we have "make <whatever> modules", compile modules
532# in addition to whatever we do anyway.
533# Just "make" or "make all" shall build modules as well
534
535ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
536 KBUILD_MODULES := 1
537endif
538
539ifeq ($(MAKECMDGOALS),)
540 KBUILD_MODULES := 1
541endif
542
543export KBUILD_MODULES KBUILD_BUILTIN
544
551ifeq ($(KBUILD_EXTMOD),) 545ifeq ($(KBUILD_EXTMOD),)
552# Additional helpers built in scripts/ 546# Additional helpers built in scripts/
553# Carefully list dependencies so we do not try to build scripts twice 547# Carefully list dependencies so we do not try to build scripts twice
@@ -1063,6 +1057,15 @@ prepare0: archprepare gcc-plugins
1063# All the preparing.. 1057# All the preparing..
1064prepare: prepare0 prepare-objtool 1058prepare: prepare0 prepare-objtool
1065 1059
1060# Support for using generic headers in asm-generic
1061PHONY += asm-generic uapi-asm-generic
1062asm-generic: uapi-asm-generic
1063 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
1064 src=asm obj=arch/$(SRCARCH)/include/generated/asm
1065uapi-asm-generic:
1066 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
1067 src=uapi/asm obj=arch/$(SRCARCH)/include/generated/uapi/asm
1068
1066PHONY += prepare-objtool 1069PHONY += prepare-objtool
1067prepare-objtool: $(objtool_target) 1070prepare-objtool: $(objtool_target)
1068 1071