Commit 113b88ae authored by Sam Ravnborg's avatar Sam Ravnborg

kbuild: Introduce hostprogs-y, deprecate host-progs

Introducing hostprogs-y allows a user to use the typical Kbuild
pattern in a Kbuild file:
hostprogs-$(CONFIG_KALLSYMS) += ...

And then during cleaning the referenced file are still deleted.
Deprecate the old host-progs assignment but kept the functionlity.

External modules will continue to use host-progs for a while - drawback is
that they now see a warning.
Workaround - just assign both variables:
hostprogs-y := foo
host-progs  := $(hostprogs-y)

All in-kernel users will be converted in next patch.
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent 9c1bfb5f
...@@ -25,6 +25,7 @@ This document describes the Linux kernel Makefiles. ...@@ -25,6 +25,7 @@ This document describes the Linux kernel Makefiles.
--- 4.4 Using C++ for host programs --- 4.4 Using C++ for host programs
--- 4.5 Controlling compiler options for host programs --- 4.5 Controlling compiler options for host programs
--- 4.6 When host programs are actually built --- 4.6 When host programs are actually built
--- 4.7 Using hostprogs-$(CONFIG_FOO)
=== 5 Kbuild clean infrastructure === 5 Kbuild clean infrastructure
...@@ -387,7 +388,7 @@ compilation stage. ...@@ -387,7 +388,7 @@ compilation stage.
Two steps are required in order to use a host executable. Two steps are required in order to use a host executable.
The first step is to tell kbuild that a host program exists. This is The first step is to tell kbuild that a host program exists. This is
done utilising the variable host-prog. done utilising the variable hostprogs-y.
The second step is to add an explicit dependency to the executable. The second step is to add an explicit dependency to the executable.
This can be done in two ways. Either add the dependency in a rule, This can be done in two ways. Either add the dependency in a rule,
...@@ -402,7 +403,7 @@ Both possibilities are described in the following. ...@@ -402,7 +403,7 @@ Both possibilities are described in the following.
built on the build host. built on the build host.
Example: Example:
host-progs := bin2hex hostprogs-y := bin2hex
Kbuild assumes in the above example that bin2hex is made from a single Kbuild assumes in the above example that bin2hex is made from a single
c-source file named bin2hex.c located in the same directory as c-source file named bin2hex.c located in the same directory as
...@@ -418,7 +419,7 @@ Both possibilities are described in the following. ...@@ -418,7 +419,7 @@ Both possibilities are described in the following.
Example: Example:
#scripts/lxdialog/Makefile #scripts/lxdialog/Makefile
host-progs := lxdialog hostprogs-y := lxdialog
lxdialog-objs := checklist.o lxdialog.o lxdialog-objs := checklist.o lxdialog.o
Objects with extension .o are compiled from the corresponding .c Objects with extension .o are compiled from the corresponding .c
...@@ -438,7 +439,7 @@ Both possibilities are described in the following. ...@@ -438,7 +439,7 @@ Both possibilities are described in the following.
Example: Example:
#scripts/kconfig/Makefile #scripts/kconfig/Makefile
host-progs := conf hostprogs-y := conf
conf-objs := conf.o libkconfig.so conf-objs := conf.o libkconfig.so
libkconfig-objs := expr.o type.o libkconfig-objs := expr.o type.o
...@@ -457,7 +458,7 @@ Both possibilities are described in the following. ...@@ -457,7 +458,7 @@ Both possibilities are described in the following.
Example: Example:
#scripts/kconfig/Makefile #scripts/kconfig/Makefile
host-progs := qconf hostprogs-y := qconf
qconf-cxxobjs := qconf.o qconf-cxxobjs := qconf.o
In the example above the executable is composed of the C++ file In the example above the executable is composed of the C++ file
...@@ -468,7 +469,7 @@ Both possibilities are described in the following. ...@@ -468,7 +469,7 @@ Both possibilities are described in the following.
Example: Example:
#scripts/kconfig/Makefile #scripts/kconfig/Makefile
host-progs := qconf hostprogs-y := qconf
qconf-cxxobjs := qconf.o qconf-cxxobjs := qconf.o
qconf-objs := check.o qconf-objs := check.o
...@@ -509,7 +510,7 @@ Both possibilities are described in the following. ...@@ -509,7 +510,7 @@ Both possibilities are described in the following.
Example: Example:
#drivers/pci/Makefile #drivers/pci/Makefile
host-progs := gen-devlist hostprogs-y := gen-devlist
$(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist $(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist
( cd $(obj); ./gen-devlist ) < $< ( cd $(obj); ./gen-devlist ) < $<
...@@ -524,18 +525,32 @@ Both possibilities are described in the following. ...@@ -524,18 +525,32 @@ Both possibilities are described in the following.
Example: Example:
#scripts/lxdialog/Makefile #scripts/lxdialog/Makefile
host-progs := lxdialog hostprogs-y := lxdialog
always := $(host-progs) always := $(hostprogs-y)
This will tell kbuild to build lxdialog even if not referenced in This will tell kbuild to build lxdialog even if not referenced in
any rule. any rule.
--- 4.7 Using hostprogs-$(CONFIG_FOO)
A typcal pattern in a Kbuild file lok like this:
Example:
#scripts/Makefile
hostprogs-$(CONFIG_KALLSYMS) += kallsyms
Kbuild knows about both 'y' for built-in and 'm' for module.
So if a config symbol evaluate to 'm', kbuild will still build
the binary. In other words Kbuild handle hostprogs-m exactly
like hostprogs-y. But only hostprogs-y is recommend used
when no CONFIG symbol are involved.
=== 5 Kbuild clean infrastructure === 5 Kbuild clean infrastructure
"make clean" deletes most generated files in the src tree where the kernel "make clean" deletes most generated files in the src tree where the kernel
is compiled. This includes generated files such as host programs. is compiled. This includes generated files such as host programs.
Kbuild knows targets listed in $(host-progs), $(always), $(extra-y) and Kbuild knows targets listed in $(hostprogs-y), $(hostprogs-m), $(always),
$(targets). They are all deleted during "make clean". $(extra-y) and $(targets). They are all deleted during "make clean".
Files matching the patterns "*.[oas]", "*.ko", plus some additional files Files matching the patterns "*.[oas]", "*.ko", plus some additional files
generated by kbuild are deleted all over the kernel src tree when generated by kbuild are deleted all over the kernel src tree when
"make clean" is executed. "make clean" is executed.
......
...@@ -14,8 +14,13 @@ include $(obj)/Makefile ...@@ -14,8 +14,13 @@ include $(obj)/Makefile
include scripts/Makefile.lib include scripts/Makefile.lib
# Do not include host-progs rules unles needed
ifdef host-progs ifdef host-progs
$(warning kbuild: $(obj)/Makefile - Usage of host-progs is deprecated. Please replace with hostprogs-y!)
hostprogs-y += $(host-progs)
endif
# Do not include host rules unles needed
ifneq ($(hostprogs-y)$(hostprogs-m),)
include scripts/Makefile.host include scripts/Makefile.host
endif endif
......
...@@ -29,8 +29,10 @@ subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-)) ...@@ -29,8 +29,10 @@ subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
# Add subdir path # Add subdir path
subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn)) subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
__clean-files := $(extra-y) $(EXTRA_TARGETS) $(always) $(host-progs) \ __clean-files := $(extra-y) $(EXTRA_TARGETS) $(always) \
$(targets) $(clean-files) $(targets) $(clean-files) \
$(host-progs) \
$(hostprogs-y) $(hostprogs-m) $(hostprogs-)
__clean-files := $(wildcard \ __clean-files := $(wildcard \
$(addprefix $(obj)/, $(filter-out /%, $(__clean-files))) \ $(addprefix $(obj)/, $(filter-out /%, $(__clean-files))) \
$(filter /%, $(__clean-files))) $(filter /%, $(__clean-files)))
......
...@@ -6,21 +6,21 @@ ...@@ -6,21 +6,21 @@
# Both C and C++ is supported, but preferred language is C for such utilities. # Both C and C++ is supported, but preferred language is C for such utilities.
# #
# Samle syntax (see Documentation/kbuild/makefile.txt for reference) # Samle syntax (see Documentation/kbuild/makefile.txt for reference)
# host-progs := bin2hex # hostprogs-y := bin2hex
# Will compile bin2hex.c and create an executable named bin2hex # Will compile bin2hex.c and create an executable named bin2hex
# #
# host-progs := lxdialog # hostprogs-y := lxdialog
# lxdialog-objs := checklist.o lxdialog.o # lxdialog-objs := checklist.o lxdialog.o
# Will compile lxdialog.c and checklist.c, and then link the executable # Will compile lxdialog.c and checklist.c, and then link the executable
# lxdialog, based on checklist.o and lxdialog.o # lxdialog, based on checklist.o and lxdialog.o
# #
# host-progs := qconf # hostprogs-y := qconf
# qconf-cxxobjs := qconf.o # qconf-cxxobjs := qconf.o
# qconf-objs := menu.o # qconf-objs := menu.o
# Will compile qconf as a C++ program, and menu as a C program. # Will compile qconf as a C++ program, and menu as a C program.
# They are linked as C++ code to the executable qconf # They are linked as C++ code to the executable qconf
# host-progs := conf # hostprogs-y := conf
# conf-objs := conf.o libkconfig.so # conf-objs := conf.o libkconfig.so
# libkconfig-objs := expr.o type.o # libkconfig-objs := expr.o type.o
# Will create a shared library named libkconfig.so that consist of # Will create a shared library named libkconfig.so that consist of
...@@ -30,26 +30,28 @@ ...@@ -30,26 +30,28 @@
# libkconfig.so as the executable conf. # libkconfig.so as the executable conf.
# Note: Shared libraries consisting of C++ files are not supported # Note: Shared libraries consisting of C++ files are not supported
# host-progs := tools/build may have been specified. Retreive directory __hostprogs := $(hostprogs-y)$(hostprogs-m)
obj-dirs += $(foreach f,$(host-progs), $(if $(dir $(f)),$(dir $(f))))
# hostprogs-y := tools/build may have been specified. Retreive directory
obj-dirs += $(foreach f,$(__hostprogs), $(if $(dir $(f)),$(dir $(f))))
obj-dirs := $(strip $(sort $(filter-out ./,$(obj-dirs)))) obj-dirs := $(strip $(sort $(filter-out ./,$(obj-dirs))))
# C code # C code
# Executables compiled from a single .c file # Executables compiled from a single .c file
host-csingle := $(foreach m,$(host-progs),$(if $($(m)-objs),,$(m))) host-csingle := $(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m)))
# C executables linked based on several .o files # C executables linked based on several .o files
host-cmulti := $(foreach m,$(host-progs),\ host-cmulti := $(foreach m,$(__hostprogs),\
$(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m)))) $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
# Object (.o) files compiled from .c files # Object (.o) files compiled from .c files
host-cobjs := $(sort $(foreach m,$(host-progs),$($(m)-objs))) host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
# C++ code # C++ code
# C++ executables compiled from at least on .cc file # C++ executables compiled from at least on .cc file
# and zero or more .c files # and zero or more .c files
host-cxxmulti := $(foreach m,$(host-progs),$(if $($(m)-cxxobjs),$(m))) host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
# C++ Object (.o) files compiled from .cc files # C++ Object (.o) files compiled from .cc files
host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs))) host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
...@@ -63,7 +65,7 @@ host-cobjs := $(filter-out %.so,$(host-cobjs)) ...@@ -63,7 +65,7 @@ host-cobjs := $(filter-out %.so,$(host-cobjs))
#Object (.o) files used by the shared libaries #Object (.o) files used by the shared libaries
host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs)))) host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
host-progs := $(addprefix $(obj)/,$(host-progs)) __hostprogs := $(addprefix $(obj)/,$(__hostprogs))
host-csingle := $(addprefix $(obj)/,$(host-csingle)) host-csingle := $(addprefix $(obj)/,$(host-csingle))
host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment