Skip to content

Commit faabed2

Browse files
committed
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 <[email protected]> Acked-by: Miguel Ojeda <[email protected]>
1 parent 85569d1 commit faabed2

File tree

22 files changed

+78
-55
lines changed

22 files changed

+78
-55
lines changed

Documentation/kbuild/makefiles.rst

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,10 @@ Both possibilities are described in the following.
749749
hostprogs := lxdialog
750750
always-y := $(hostprogs)
751751

752+
Kbuild provides the following shorthand for this:
753+
754+
hostprogs-always-y := lxdialog
755+
752756
This will tell kbuild to build lxdialog even if not referenced in
753757
any rule.
754758

@@ -831,7 +835,32 @@ The syntax is quite similar. The difference is to use "userprogs" instead of
831835
5.4 When userspace programs are actually built
832836
----------------------------------------------
833837

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.
835864

836865
6 Kbuild clean infrastructure
837866
=============================

samples/auxdisplay/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
userprogs := cfag12864b-example
3-
always-y := $(userprogs)
2+
userprogs-always-y += cfag12864b-example

samples/binderfs/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
userprogs := binderfs_example
3-
always-y := $(userprogs)
2+
userprogs-always-y += binderfs_example
43

54
userccflags += -I usr/include

samples/connector/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
obj-$(CONFIG_SAMPLE_CONNECTOR) += cn_test.o
33

4-
userprogs := ucon
5-
always-$(CONFIG_CC_CAN_LINK) := $(userprogs)
4+
userprogs-always-$(CONFIG_CC_CAN_LINK) += ucon
65

76
userccflags += -I usr/include

samples/hidraw/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
userprogs := hid-example
3-
always-y := $(userprogs)
2+
userprogs-always-y += hid-example
43

54
userccflags += -I usr/include

samples/mei/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
22
# 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
64

75
userccflags += -I usr/include

samples/pidfd/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
3-
usertprogs := pidfd-metadata
4-
always-y := $(userprogs)
2+
usertprogs-always-y += pidfd-metadata
53

64
userccflags += -I usr/include

samples/seccomp/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# 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
33

44
bpf-fancy-objs := bpf-fancy.o bpf-helper.o
55

66
userccflags += -I usr/include
7-
8-
always-y := $(userprogs)

samples/timers/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
userprogs := hpet_example
3-
always-y := $(userprogs)
2+
userprogs-always-y += hpet_example
43

54
userccflags += -I usr/include

samples/uhid/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
userprogs := uhid-example
3-
always-y := $(userprogs)
2+
userprogs-always-y += uhid-example
43

54
userccflags += -I usr/include

0 commit comments

Comments
 (0)