History

kbuild: introduce hostprogs-always-y and userprogs-always-y

To build host programs, you need to add the program names to 'hostprogs' to use the necessary build rule, but it is not enough to build them because there is no dependency. There are two types of host programs: built as the prerequisite of another (e.g. gen_crc32table in lib/Makefile), or always built when Kbuild visits the Makefile (e.g. genksyms in scripts/genksyms/Makefile). The latter is typical in Makefiles under scripts/, which contains host programs globally used during the kernel build. To build them, you need to add them to both 'hostprogs' and 'always-y'. This commit adds hostprogs-always-y as a shorthand. The same applies to user programs. net/bpfilter/Makefile builds bpfilter_umh on demand, hence always-y is unneeded. In contrast, programs under samples/ are added to both 'userprogs' and 'always-y' so they are always built when Kbuild visits the Makefiles. userprogs-always-y works as a shorthand.

Masahiro Yamada committed 6 years ago

Commit faabed21 parent 85569d122 files · +78 −55Browse files

Unified · Split

22 files
  1. Documentation/kbuild/makefiles.rst +30 −1
  2. samples/auxdisplay/Makefile +1 −2
  3. samples/binderfs/Makefile +1 −2
  4. samples/connector/Makefile +1 −2
  5. samples/hidraw/Makefile +1 −2
  6. samples/mei/Makefile +1 −3
  7. samples/pidfd/Makefile +1 −3
  8. samples/seccomp/Makefile +1 −3
  9. samples/timers/Makefile +1 −2
  10. samples/uhid/Makefile +1 −2
  11. samples/vfs/Makefile +1 −2
  12. samples/watch_queue/Makefile +1 −2
  13. samples/watchdog/Makefile +1 −2
  14. scripts/Makefile +8 −10
  15. scripts/Makefile.clean +9 −3
  16. scripts/Makefile.lib +11 −0
  17. scripts/basic/Makefile +1 −2
  18. scripts/dtc/Makefile +2 −3
  19. scripts/genksyms/Makefile +1 −2
  20. scripts/mod/Makefile +2 −2
  21. scripts/selinux/genheaders/Makefile +1 −3
  22. scripts/selinux/mdp/Makefile +1 −2
Documentation/kbuild/makefiles.rst+30−1
@@ -749,6 +749,10 @@ Both possibilities are described in the following. · 748 unmodified lines
749 hostprogs := lxdialog749 hostprogs := lxdialog
750 always-y := $(hostprogs)750 always-y := $(hostprogs)
751 751
752 Kbuild provides the following shorthand for this:
753
754 hostprogs-always-y := lxdialog
755
752 This will tell kbuild to build lxdialog even if not referenced in756 This will tell kbuild to build lxdialog even if not referenced in
753 any rule.757 any rule.
754 758
@@ -831,7 +835,32 @@ The syntax is quite similar. The difference is to use "userprogs" instead of · 76 unmodified lines
8315.4 When userspace programs are actually built8355.4 When userspace programs are actually built
832----------------------------------------------836----------------------------------------------
833 837
834 Same as "When host programs are actually built".838 Kbuild builds userspace programs only when told to do so.
839 There are two ways to do this.
840
841 (1) Add it as the prerequisite of another file
842
843 Example::
844
845 #net/bpfilter/Makefile
846 userprogs := bpfilter_umh
847 $(obj)/bpfilter_umh_blob.o: $(obj)/bpfilter_umh
848
849 $(obj)/bpfilter_umh is built before $(obj)/bpfilter_umh_blob.o
850
851 (2) Use always-y
852
853 Example::
854
855 userprogs := binderfs_example
856 always-y := $(userprogs)
857
858 Kbuild provides the following shorthand for this:
859
860 userprogs-always-y := binderfs_example
861
862 This will tell Kbuild to build binderfs_example when it visits this
863 Makefile.
835 864
8366 Kbuild clean infrastructure8656 Kbuild clean infrastructure
837=============================866=============================
samples/auxdisplay/Makefile+1−2
@@ -1,3 +1,2 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2userprogs := cfag12864b-example2userprogs-always-y += cfag12864b-example
3always-y := $(userprogs)
samples/binderfs/Makefile+1−2
@@ -1,5 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0-only1# SPDX-License-Identifier: GPL-2.0-only
2userprogs := binderfs_example2userprogs-always-y += binderfs_example
3always-y := $(userprogs)
4 3
5userccflags += -I usr/include4userccflags += -I usr/include
samples/connector/Makefile+1−2
@@ -1,7 +1,6 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2obj-$(CONFIG_SAMPLE_CONNECTOR) += cn_test.o2obj-$(CONFIG_SAMPLE_CONNECTOR) += cn_test.o
3 3
4userprogs := ucon4userprogs-always-$(CONFIG_CC_CAN_LINK) += ucon
5always-$(CONFIG_CC_CAN_LINK) := $(userprogs)
6 5
7userccflags += -I usr/include6userccflags += -I usr/include
samples/hidraw/Makefile+1−2
@@ -1,5 +1,4 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2userprogs := hid-example2userprogs-always-y += hid-example
3always-y := $(userprogs)
4 3
5userccflags += -I usr/include4userccflags += -I usr/include
samples/mei/Makefile+1−3
@@ -1,7 +1,5 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2# Copyright (c) 2012-2019, Intel Corporation. All rights reserved.2# Copyright (c) 2012-2019, Intel Corporation. All rights reserved.
3 3userprogs-always-y += mei-amt-version
4userprogs := mei-amt-version
5always-y := $(userprogs)
6 4
7userccflags += -I usr/include5userccflags += -I usr/include
samples/pidfd/Makefile+1−3
@@ -1,6 +1,4 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2 2usertprogs-always-y += pidfd-metadata
3usertprogs := pidfd-metadata
4always-y := $(userprogs)
5 3
6userccflags += -I usr/include4userccflags += -I usr/include
samples/seccomp/Makefile+1−3
@@ -1,8 +1,6 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2userprogs := bpf-fancy dropper bpf-direct user-trap2userprogs-always-y += bpf-fancy dropper bpf-direct user-trap
3 3
4bpf-fancy-objs := bpf-fancy.o bpf-helper.o4bpf-fancy-objs := bpf-fancy.o bpf-helper.o
5 5
6userccflags += -I usr/include6userccflags += -I usr/include
7
8always-y := $(userprogs)
samples/timers/Makefile+1−2
@@ -1,5 +1,4 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2userprogs := hpet_example2userprogs-always-y += hpet_example
3always-y := $(userprogs)
4 3
5userccflags += -I usr/include4userccflags += -I usr/include
samples/uhid/Makefile+1−2
@@ -1,5 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0-only1# SPDX-License-Identifier: GPL-2.0-only
2userprogs := uhid-example2userprogs-always-y += uhid-example
3always-y := $(userprogs)
4 3
5userccflags += -I usr/include4userccflags += -I usr/include
samples/vfs/Makefile+1−2
@@ -1,5 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0-only1# SPDX-License-Identifier: GPL-2.0-only
2userprogs := test-fsmount test-statx2userprogs-always-y += test-fsmount test-statx
3always-y := $(userprogs)
4 3
5userccflags += -I usr/include4userccflags += -I usr/include
samples/watch_queue/Makefile+1−2
@@ -1,5 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0-only1# SPDX-License-Identifier: GPL-2.0-only
2userprogs := watch_test2userprogs-always-y += watch_test
3always-y := $(userprogs)
4 3
5userccflags += -I usr/include4userccflags += -I usr/include
samples/watchdog/Makefile+1−2
@@ -1,3 +1,2 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2userprogs := watchdog-simple2userprogs-always-y += watchdog-simple
3always-y := $(userprogs)
scripts/Makefile+8−10
@@ -3,14 +3,14 @@ · 2 unmodified lines
3# scripts contains sources for various helper programs used throughout3# scripts contains sources for various helper programs used throughout
4# the kernel for the build process.4# the kernel for the build process.
5 5
6always-$(CONFIG_BUILD_BIN2C) += bin2c6hostprogs-always-$(CONFIG_BUILD_BIN2C) += bin2c
7always-$(CONFIG_KALLSYMS) += kallsyms7hostprogs-always-$(CONFIG_KALLSYMS) += kallsyms
8always-$(BUILD_C_RECORDMCOUNT) += recordmcount8hostprogs-always-$(BUILD_C_RECORDMCOUNT) += recordmcount
9always-$(CONFIG_BUILDTIME_TABLE_SORT) += sorttable9hostprogs-always-$(CONFIG_BUILDTIME_TABLE_SORT) += sorttable
10always-$(CONFIG_ASN1) += asn1_compiler10hostprogs-always-$(CONFIG_ASN1) += asn1_compiler
11always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file11hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file
12always-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += extract-cert12hostprogs-always-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += extract-cert
13always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert13hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert
14 14
15HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include15HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include
16HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include16HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include
@@ -26,8 +26,6 @@ HOSTCFLAGS_sorttable.o += -DUNWINDER_ORC_ENABLED · 9 unmodified lines
26HOSTLDLIBS_sorttable = -lpthread26HOSTLDLIBS_sorttable = -lpthread
27endif27endif
28 28
29hostprogs := $(always-y) $(always-m)
30
31# The following programs are only built on demand29# The following programs are only built on demand
32hostprogs += unifdef30hostprogs += unifdef
33 31
scripts/Makefile.clean+9−3
@@ -27,9 +27,15 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn)) · 26 unmodified lines
27# build a list of files to remove, usually relative to the current27# build a list of files to remove, usually relative to the current
28# directory28# directory
29 29
30__clean-files := $(extra-y) $(extra-m) $(extra-) \30__clean-files := \
31 $(always) $(always-y) $(always-m) $(always-) $(targets) $(clean-files) \31 $(clean-files) $(targets) $(hostprogs) $(userprogs) \
32 $(hostprogs) $(hostprogs-y) $(hostprogs-m) $(hostprogs-) $(userprogs)32 $(extra-y) $(extra-m) $(extra-) \
33 $(always-y) $(always-m) $(always-) \
34 $(hostprogs-always-y) $(hostprogs-always-m) $(hostprogs-always-) \
35 $(userprogs-always-y) $(userprogs-always-m) $(userprogs-always-)
36
37# deprecated
38__clean-files += $(always) $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
33 39
34__clean-files := $(filter-out $(no-clean-files), $(__clean-files))40__clean-files := $(filter-out $(no-clean-files), $(__clean-files))
35 41
scripts/Makefile.lib+11−0
@@ -68,6 +68,17 @@ real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) · 67 unmodified lines
68 68
69always-y += $(always-m)69always-y += $(always-m)
70 70
71# hostprogs-always-y += foo
72# ... is a shorthand for
73# hostprogs += foo
74# always-y += foo
75hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
76always-y += $(hostprogs-always-y) $(hostprogs-always-m)
77
78# userprogs-always-y is likewise.
79userprogs += $(userprogs-always-y) $(userprogs-always-m)
80always-y += $(userprogs-always-y) $(userprogs-always-m)
81
71# DTB82# DTB
72# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built83# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
73extra-y += $(dtb-y)84extra-y += $(dtb-y)
scripts/basic/Makefile+1−2
@@ -2,5 +2,4 @@ · 1 unmodified line
2#2#
3# fixdep: used to generate dependency information during build process3# fixdep: used to generate dependency information during build process
4 4
5hostprogs := fixdep5hostprogs-always-y += fixdep
6always-y := $(hostprogs)
scripts/dtc/Makefile+2−3
@@ -1,9 +1,8 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2# scripts/dtc makefile2# scripts/dtc makefile
3 3
4hostprogs := dtc4hostprogs-always-$(CONFIG_DTC) += dtc
5always-$(CONFIG_DTC) += $(hostprogs)5hostprogs-always-$(CHECK_DT_BINDING) += dtc
6always-$(CHECK_DT_BINDING) += $(hostprogs)
7 6
8dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \7dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \
9 srcpos.o checks.o util.o8 srcpos.o checks.o util.o
scripts/genksyms/Makefile+1−2
@@ -1,7 +1,6 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2 2
3hostprogs := genksyms3hostprogs-always-y += genksyms
4always-y := $(hostprogs)
5 4
6genksyms-objs := genksyms.o parse.tab.o lex.lex.o5genksyms-objs := genksyms.o parse.tab.o lex.lex.o
7 6
scripts/mod/Makefile+2−2
@@ -1,8 +1,8 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2OBJECT_FILES_NON_STANDARD := y2OBJECT_FILES_NON_STANDARD := y
3 3
4hostprogs := modpost mk_elfconfig4hostprogs-always-y += modpost mk_elfconfig
5always-y := $(hostprogs) empty.o5always-y += empty.o
6 6
7modpost-objs := modpost.o file2alias.o sumversion.o7modpost-objs := modpost.o file2alias.o sumversion.o
8 8
scripts/selinux/genheaders/Makefile+1−3
@@ -1,7 +1,5 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2hostprogs := genheaders2hostprogs-always-y += genheaders
3HOST_EXTRACFLAGS += \3HOST_EXTRACFLAGS += \
4 -I$(srctree)/include/uapi -I$(srctree)/include \4 -I$(srctree)/include/uapi -I$(srctree)/include \
5 -I$(srctree)/security/selinux/include5 -I$(srctree)/security/selinux/include
6
7always-y := $(hostprogs)
scripts/selinux/mdp/Makefile+1−2
@@ -1,8 +1,7 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2hostprogs := mdp2hostprogs-always-y += mdp
3HOST_EXTRACFLAGS += \3HOST_EXTRACFLAGS += \
4 -I$(srctree)/include/uapi -I$(srctree)/include \4 -I$(srctree)/include/uapi -I$(srctree)/include \
5 -I$(srctree)/security/selinux/include -I$(objtree)/include5 -I$(srctree)/security/selinux/include -I$(objtree)/include
6 6
7always-y := $(hostprogs)
8clean-files := policy.* file_contexts7clean-files := policy.* file_contexts