Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>

+78 -55
+30 -1
Documentation/kbuild/makefiles.rst
··· 749 749 hostprogs := lxdialog 750 750 always-y := $(hostprogs) 751 751 752 + Kbuild provides the following shorthand for this: 753 + 754 + hostprogs-always-y := lxdialog 755 + 752 756 This will tell kbuild to build lxdialog even if not referenced in 753 757 any rule. 754 758 ··· 835 831 5.4 When userspace programs are actually built 836 832 ---------------------------------------------- 837 833 838 - Same as "When host programs are actually built". 834 + Kbuild builds userspace programs only when told to do so. 835 + There are two ways to do this. 836 + 837 + (1) Add it as the prerequisite of another file 838 + 839 + Example:: 840 + 841 + #net/bpfilter/Makefile 842 + userprogs := bpfilter_umh 843 + $(obj)/bpfilter_umh_blob.o: $(obj)/bpfilter_umh 844 + 845 + $(obj)/bpfilter_umh is built before $(obj)/bpfilter_umh_blob.o 846 + 847 + (2) Use always-y 848 + 849 + Example:: 850 + 851 + userprogs := binderfs_example 852 + always-y := $(userprogs) 853 + 854 + Kbuild provides the following shorthand for this: 855 + 856 + userprogs-always-y := binderfs_example 857 + 858 + This will tell Kbuild to build binderfs_example when it visits this 859 + Makefile. 839 860 840 861 6 Kbuild clean infrastructure 841 862 =============================
+1 -2
samples/auxdisplay/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - userprogs := cfag12864b-example 3 - always-y := $(userprogs) 2 + userprogs-always-y += cfag12864b-example
+1 -2
samples/binderfs/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 - userprogs := binderfs_example 3 - always-y := $(userprogs) 2 + userprogs-always-y += binderfs_example 4 3 5 4 userccflags += -I usr/include
+1 -2
samples/connector/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 obj-$(CONFIG_SAMPLE_CONNECTOR) += cn_test.o 3 3 4 - userprogs := ucon 5 - always-$(CONFIG_CC_CAN_LINK) := $(userprogs) 4 + userprogs-always-$(CONFIG_CC_CAN_LINK) += ucon 6 5 7 6 userccflags += -I usr/include
+1 -2
samples/hidraw/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - userprogs := hid-example 3 - always-y := $(userprogs) 2 + userprogs-always-y += hid-example 4 3 5 4 userccflags += -I usr/include
+1 -3
samples/mei/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 # Copyright (c) 2012-2019, Intel Corporation. All rights reserved. 3 - 4 - userprogs := mei-amt-version 5 - always-y := $(userprogs) 3 + userprogs-always-y += mei-amt-version 6 4 7 5 userccflags += -I usr/include
+1 -3
samples/pidfd/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - 3 - usertprogs := pidfd-metadata 4 - always-y := $(userprogs) 2 + usertprogs-always-y += pidfd-metadata 5 3 6 4 userccflags += -I usr/include
+1 -3
samples/seccomp/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - userprogs := bpf-fancy dropper bpf-direct user-trap 2 + userprogs-always-y += bpf-fancy dropper bpf-direct user-trap 3 3 4 4 bpf-fancy-objs := bpf-fancy.o bpf-helper.o 5 5 6 6 userccflags += -I usr/include 7 - 8 - always-y := $(userprogs)
+1 -2
samples/timers/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - userprogs := hpet_example 3 - always-y := $(userprogs) 2 + userprogs-always-y += hpet_example 4 3 5 4 userccflags += -I usr/include
+1 -2
samples/uhid/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 - userprogs := uhid-example 3 - always-y := $(userprogs) 2 + userprogs-always-y += uhid-example 4 3 5 4 userccflags += -I usr/include
+1 -2
samples/vfs/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 - userprogs := test-fsmount test-statx 3 - always-y := $(userprogs) 2 + userprogs-always-y += test-fsmount test-statx 4 3 5 4 userccflags += -I usr/include
+1 -2
samples/watch_queue/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 - userprogs := watch_test 3 - always-y := $(userprogs) 2 + userprogs-always-y += watch_test 4 3 5 4 userccflags += -I usr/include
+1 -2
samples/watchdog/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - userprogs := watchdog-simple 3 - always-y := $(userprogs) 2 + userprogs-always-y += watchdog-simple
+8 -10
scripts/Makefile
··· 3 3 # scripts contains sources for various helper programs used throughout 4 4 # the kernel for the build process. 5 5 6 - always-$(CONFIG_BUILD_BIN2C) += bin2c 7 - always-$(CONFIG_KALLSYMS) += kallsyms 8 - always-$(BUILD_C_RECORDMCOUNT) += recordmcount 9 - always-$(CONFIG_BUILDTIME_TABLE_SORT) += sorttable 10 - always-$(CONFIG_ASN1) += asn1_compiler 11 - always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file 12 - always-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += extract-cert 13 - always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert 6 + hostprogs-always-$(CONFIG_BUILD_BIN2C) += bin2c 7 + hostprogs-always-$(CONFIG_KALLSYMS) += kallsyms 8 + hostprogs-always-$(BUILD_C_RECORDMCOUNT) += recordmcount 9 + hostprogs-always-$(CONFIG_BUILDTIME_TABLE_SORT) += sorttable 10 + hostprogs-always-$(CONFIG_ASN1) += asn1_compiler 11 + hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file 12 + hostprogs-always-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += extract-cert 13 + hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert 14 14 15 15 HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include 16 16 HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include ··· 25 25 HOSTCFLAGS_sorttable.o += -DUNWINDER_ORC_ENABLED 26 26 HOSTLDLIBS_sorttable = -lpthread 27 27 endif 28 - 29 - hostprogs := $(always-y) $(always-m) 30 28 31 29 # The following programs are only built on demand 32 30 hostprogs += unifdef
+9 -3
scripts/Makefile.clean
··· 27 27 # build a list of files to remove, usually relative to the current 28 28 # directory 29 29 30 - __clean-files := $(extra-y) $(extra-m) $(extra-) \ 31 - $(always) $(always-y) $(always-m) $(always-) $(targets) $(clean-files) \ 32 - $(hostprogs) $(hostprogs-y) $(hostprogs-m) $(hostprogs-) $(userprogs) 30 + __clean-files := \ 31 + $(clean-files) $(targets) $(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 40 __clean-files := $(filter-out $(no-clean-files), $(__clean-files)) 35 41
+11
scripts/Makefile.lib
··· 68 68 69 69 always-y += $(always-m) 70 70 71 + # hostprogs-always-y += foo 72 + # ... is a shorthand for 73 + # hostprogs += foo 74 + # always-y += foo 75 + hostprogs += $(hostprogs-always-y) $(hostprogs-always-m) 76 + always-y += $(hostprogs-always-y) $(hostprogs-always-m) 77 + 78 + # userprogs-always-y is likewise. 79 + userprogs += $(userprogs-always-y) $(userprogs-always-m) 80 + always-y += $(userprogs-always-y) $(userprogs-always-m) 81 + 71 82 # DTB 72 83 # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built 73 84 extra-y += $(dtb-y)
+1 -2
scripts/basic/Makefile
··· 2 2 # 3 3 # fixdep: used to generate dependency information during build process 4 4 5 - hostprogs := fixdep 6 - always-y := $(hostprogs) 5 + hostprogs-always-y += fixdep
+2 -3
scripts/dtc/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 # scripts/dtc makefile 3 3 4 - hostprogs := dtc 5 - always-$(CONFIG_DTC) += $(hostprogs) 6 - always-$(CHECK_DT_BINDING) += $(hostprogs) 4 + hostprogs-always-$(CONFIG_DTC) += dtc 5 + hostprogs-always-$(CHECK_DT_BINDING) += dtc 7 6 8 7 dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \ 9 8 srcpos.o checks.o util.o
+1 -2
scripts/genksyms/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - hostprogs := genksyms 4 - always-y := $(hostprogs) 3 + hostprogs-always-y += genksyms 5 4 6 5 genksyms-objs := genksyms.o parse.tab.o lex.lex.o 7 6
+2 -2
scripts/mod/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 OBJECT_FILES_NON_STANDARD := y 3 3 4 - hostprogs := modpost mk_elfconfig 5 - always-y := $(hostprogs) empty.o 4 + hostprogs-always-y += modpost mk_elfconfig 5 + always-y += empty.o 6 6 7 7 modpost-objs := modpost.o file2alias.o sumversion.o 8 8
+1 -3
scripts/selinux/genheaders/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - hostprogs := genheaders 2 + hostprogs-always-y += genheaders 3 3 HOST_EXTRACFLAGS += \ 4 4 -I$(srctree)/include/uapi -I$(srctree)/include \ 5 5 -I$(srctree)/security/selinux/include 6 - 7 - always-y := $(hostprogs)
+1 -2
scripts/selinux/mdp/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - hostprogs := mdp 2 + hostprogs-always-y += mdp 3 3 HOST_EXTRACFLAGS += \ 4 4 -I$(srctree)/include/uapi -I$(srctree)/include \ 5 5 -I$(srctree)/security/selinux/include -I$(objtree)/include 6 6 7 - always-y := $(hostprogs) 8 7 clean-files := policy.* file_contexts