Skip to content

Commit

Permalink
kbuild: rename hostprogs-y/always to hostprogs/always-y
Browse files Browse the repository at this point in the history
In old days, the "host-progs" syntax was used for specifying host
programs. It was renamed to the current "hostprogs-y" in 2004.

It is typically useful in scripts/Makefile because it allows Kbuild to
selectively compile host programs based on the kernel configuration.

This commit renames like follows:

  always       ->  always-y
  hostprogs-y  ->  hostprogs

So, scripts/Makefile will look like this:

  always-$(CONFIG_BUILD_BIN2C) += ...
  always-$(CONFIG_KALLSYMS)    += ...
      ...
  hostprogs := $(always-y) $(always-m)

I think this makes more sense because a host program is always a host
program, irrespective of the kernel configuration. We want to specify
which ones to compile by CONFIG options, so always-y will be handier.

The "always", "hostprogs-y", "hostprogs-m" will be kept for backward
compatibility for a while.

Signed-off-by: Masahiro Yamada <[email protected]>
  • Loading branch information
masahir0y committed Feb 3, 2020
1 parent faa7bdd commit 5f2fb52
Show file tree
Hide file tree
Showing 49 changed files with 172 additions and 190 deletions.
49 changes: 16 additions & 33 deletions Documentation/kbuild/makefiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ This document describes the Linux kernel Makefiles.
--- 4.3 Using C++ for host programs
--- 4.4 Controlling compiler options for host programs
--- 4.5 When host programs are actually built
--- 4.6 Using hostprogs-$(CONFIG_FOO)
=== 5 Kbuild clean infrastructure
Expand Down Expand Up @@ -595,11 +594,11 @@ compilation stage.
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
done utilising the variable hostprogs-y.
done utilising the variable "hostprogs".

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,
or utilise the variable $(always).
or utilise the variable "always-y".
Both possibilities are described in the following.

4.1 Simple Host Program
Expand All @@ -612,7 +611,7 @@ Both possibilities are described in the following.

Example::

hostprogs-y := bin2hex
hostprogs := bin2hex

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
Expand All @@ -630,7 +629,7 @@ Both possibilities are described in the following.
Example::

#scripts/lxdialog/Makefile
hostprogs-y := lxdialog
hostprogs := lxdialog
lxdialog-objs := checklist.o lxdialog.o

Objects with extension .o are compiled from the corresponding .c
Expand All @@ -650,7 +649,7 @@ Both possibilities are described in the following.
Example::

#scripts/kconfig/Makefile
hostprogs-y := qconf
hostprogs := qconf
qconf-cxxobjs := qconf.o

In the example above the executable is composed of the C++ file
Expand All @@ -662,7 +661,7 @@ Both possibilities are described in the following.
Example::

#scripts/kconfig/Makefile
hostprogs-y := qconf
hostprogs := qconf
qconf-cxxobjs := qconf.o
qconf-objs := check.o

Expand Down Expand Up @@ -710,55 +709,39 @@ Both possibilities are described in the following.
Example::

#drivers/pci/Makefile
hostprogs-y := gen-devlist
hostprogs := gen-devlist
$(obj)/devlist.h: $(src)/pci.ids $(obj)/gen-devlist
( cd $(obj); ./gen-devlist ) < $<

The target $(obj)/devlist.h will not be built before
$(obj)/gen-devlist is updated. Note that references to
the host programs in special rules must be prefixed with $(obj).

(2) Use $(always)
(2) Use always-y

When there is no suitable special rule, and the host program
shall be built when a makefile is entered, the $(always)
shall be built when a makefile is entered, the always-y
variable shall be used.

Example::

#scripts/lxdialog/Makefile
hostprogs-y := lxdialog
always := $(hostprogs-y)
hostprogs := lxdialog
always-y := $(hostprogs)

This will tell kbuild to build lxdialog even if not referenced in
any rule.

4.6 Using hostprogs-$(CONFIG_FOO)
---------------------------------

A typical pattern in a Kbuild file looks 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 evaluates to 'm', kbuild will still build
the binary. In other words, Kbuild handles hostprogs-m exactly
like hostprogs-y. But only hostprogs-y is recommended to be used
when no CONFIG symbols are involved.

5 Kbuild clean infrastructure
=============================

"make clean" deletes most generated files in the obj tree where the kernel
is compiled. This includes generated files such as host programs.
Kbuild knows targets listed in $(hostprogs-y), $(hostprogs-m), $(always),
$(extra-y) and $(targets). They are all deleted during "make clean".
Files matching the patterns "*.[oas]", "*.ko", plus some additional files
generated by kbuild are deleted all over the kernel src tree when
"make clean" is executed.
Kbuild knows targets listed in $(hostprogs), $(always-y), $(always-m),
$(always-), $(extra-y), $(extra-) and $(targets). They are all deleted
during "make clean". Files matching the patterns "*.[oas]", "*.ko", plus
some additional files generated by kbuild are deleted all over the kernel
source tree when "make clean" is executed.

Additional files or directories can be specified in kbuild makefiles by use of
$(clean-files).
Expand Down
8 changes: 4 additions & 4 deletions Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

bounds-file := include/generated/bounds.h

always := $(bounds-file)
always-y := $(bounds-file)
targets := kernel/bounds.s

$(bounds-file): kernel/bounds.s FORCE
Expand All @@ -28,7 +28,7 @@ $(timeconst-file): kernel/time/timeconst.bc FORCE

offsets-file := include/generated/asm-offsets.h

always += $(offsets-file)
always-y += $(offsets-file)
targets += arch/$(SRCARCH)/kernel/asm-offsets.s

arch/$(SRCARCH)/kernel/asm-offsets.s: $(timeconst-file) $(bounds-file)
Expand All @@ -39,7 +39,7 @@ $(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
#####
# Check for missing system calls

always += missing-syscalls
always-y += missing-syscalls

quiet_cmd_syscalls = CALL $<
cmd_syscalls = $(CONFIG_SHELL) $< $(CC) $(c_flags) $(missing_syscalls_flags)
Expand All @@ -50,7 +50,7 @@ missing-syscalls: scripts/checksyscalls.sh $(offsets-file) FORCE
#####
# Check atomic headers are up-to-date

always += old-atomics
always-y += old-atomics

quiet_cmd_atomics = CALL $<
cmd_atomics = $(CONFIG_SHELL) $<
Expand Down
2 changes: 1 addition & 1 deletion arch/alpha/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Copyright (C) 1994 by Linus Torvalds
#

hostprogs-y := tools/mkbb tools/objstrip
hostprogs := tools/mkbb tools/objstrip
targets := vmlinux.gz vmlinux \
vmlinux.nh tools/lxboot tools/bootlx tools/bootph \
tools/bootpzh bootloader bootpheader bootpzheader
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/vdso/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
include $(srctree)/lib/vdso/Makefile

hostprogs-y := vdsomunge
hostprogs := vdsomunge

obj-vdso := vgettimeofday.o datapage.o note.o

Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/kernel/vdso32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ VDSO_LDFLAGS += $(call cc32-ldoption,-fuse-ld=bfd)

# Borrow vdsomunge.c from the arm vDSO
# We have to use a relative path because scripts/Makefile.host prefixes
# $(hostprogs-y) with $(obj)
# $(hostprogs) with $(obj)
munge := ../../../arm/vdso/vdsomunge
hostprogs-y := $(munge)
hostprogs := $(munge)

c-obj-vdso := note.o
c-obj-vdso-gettimeofday := vgettimeofday.o
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ endif
drop-sections := .reginfo .mdebug .comment .note .pdr .options .MIPS.options
strip-flags := $(addprefix --remove-section=,$(drop-sections))

hostprogs-y := elf2ecoff
hostprogs := elf2ecoff

suffix-y := bin
suffix-$(CONFIG_KERNEL_BZIP2) := bz2
Expand Down
4 changes: 2 additions & 2 deletions arch/mips/boot/compressed/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ $(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.bin.z FORCE
HOSTCFLAGS_calc_vmlinuz_load_addr.o += $(LINUXINCLUDE)

# Calculate the load address of the compressed kernel image
hostprogs-y := calc_vmlinuz_load_addr
hostprogs := calc_vmlinuz_load_addr

ifneq ($(zload-y),)
VMLINUZ_LOAD_ADDRESS := $(zload-y)
Expand Down Expand Up @@ -112,7 +112,7 @@ ifdef CONFIG_MACH_DECSTATION
endif

# elf2ecoff can only handle 32bit image
hostprogs-y += ../elf2ecoff
hostprogs += ../elf2ecoff

ifdef CONFIG_32BIT
VMLINUZ = vmlinuz
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/boot/tools/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0

hostprogs-y += relocs
hostprogs += relocs
relocs-objs += relocs_32.o
relocs-objs += relocs_64.o
relocs-objs += relocs_main.o
Expand Down
4 changes: 2 additions & 2 deletions arch/mips/tools/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# SPDX-License-Identifier: GPL-2.0
hostprogs-y := elf-entry
hostprogs := elf-entry
PHONY += elf-entry
elf-entry: $(obj)/elf-entry
@:

hostprogs-$(CONFIG_CPU_LOONGSON3_WORKAROUNDS) += loongson3-llsc-check
hostprogs += loongson3-llsc-check
PHONY += loongson3-llsc-check
loongson3-llsc-check: $(obj)/loongson3-llsc-check
@:
2 changes: 1 addition & 1 deletion arch/mips/vdso/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ $(obj)/%.so.raw: OBJCOPYFLAGS := -S
$(obj)/%.so.raw: $(obj)/%.so.dbg.raw FORCE
$(call if_changed,objcopy)

hostprogs-y := genvdso
hostprogs := genvdso

quiet_cmd_genvdso = GENVDSO $@
define cmd_genvdso
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S FORCE
$(obj)/wrapper.a: $(obj-wlib) FORCE
$(call if_changed,bootar)

hostprogs-y := addnote hack-coff mktree
hostprogs := addnote hack-coff mktree

targets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a)
extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \
Expand Down Expand Up @@ -464,7 +464,7 @@ WRAPPER_BINDIR := /usr/sbin
INSTALL := install

extra-installed := $(patsubst $(obj)/%, $(DESTDIR)$(WRAPPER_OBJDIR)/%, $(extra-y))
hostprogs-installed := $(patsubst %, $(DESTDIR)$(WRAPPER_BINDIR)/%, $(hostprogs-y))
hostprogs-installed := $(patsubst %, $(DESTDIR)$(WRAPPER_BINDIR)/%, $(hostprogs))
wrapper-installed := $(DESTDIR)$(WRAPPER_BINDIR)/wrapper
dts-installed := $(patsubst $(dtstree)/%, $(DESTDIR)$(WRAPPER_DTSDIR)/%, $(wildcard $(dtstree)/*.dts))

Expand Down
4 changes: 2 additions & 2 deletions arch/s390/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ PHONY += kapi

kapi: $(kapi-hdrs-y)

hostprogs-y += gen_facilities
hostprogs-y += gen_opcode_table
hostprogs += gen_facilities
hostprogs += gen_opcode_table

HOSTCFLAGS_gen_facilities.o += $(LINUXINCLUDE)

Expand Down
2 changes: 1 addition & 1 deletion arch/sparc/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ROOT_IMG := /usr/src/root.img
ELFTOAOUT := elftoaout

hostprogs-y := piggyback
hostprogs := piggyback
targets := tftpboot.img image zImage vmlinux.aout
clean-files := System.map

Expand Down
2 changes: 1 addition & 1 deletion arch/sparc/vdso/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
$(call if_changed,vdso)

HOST_EXTRACFLAGS += -I$(srctree)/tools/include
hostprogs-y += vdso2c
hostprogs += vdso2c

quiet_cmd_vdso2c = VDSO2C $@
cmd_vdso2c = $(obj)/vdso2c $< $(<:%.dbg=%) $@
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ setup-y += video-vesa.o
setup-y += video-bios.o

targets += $(setup-y)
hostprogs-y := tools/build
hostprogs-$(CONFIG_X86_FEATURE_NAMES) += mkcpustr
hostprogs := tools/build
hostprogs += mkcpustr

HOST_EXTRACFLAGS += -I$(srctree)/tools/include \
-include include/generated/autoconf.h \
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/boot/compressed/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
endif
LDFLAGS_vmlinux := -T

hostprogs-y := mkpiggy
hostprogs := mkpiggy
HOST_EXTRACFLAGS += -I$(srctree)/tools/include

sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p'
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/entry/vdso/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
$(call if_changed,vdso_and_check)

HOST_EXTRACFLAGS += -I$(srctree)/tools/include -I$(srctree)/include/uapi -I$(srctree)/arch/$(SUBARCH)/include/uapi
hostprogs-y += vdso2c
hostprogs += vdso2c

quiet_cmd_vdso2c = VDSO2C $@
cmd_vdso2c = $(obj)/vdso2c $< $(<:%.dbg=%) $@
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/realmode/rm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OBJECT_FILES_NON_STANDARD := y
# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
KCOV_INSTRUMENT := n

always := realmode.bin realmode.relocs
always-y := realmode.bin realmode.relocs

wakeup-objs := wakeup_asm.o wakemain.o video-mode.o
wakeup-objs += copy.o bioscall.o regs.o
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ posttest: $(obj)/insn_decoder_test vmlinux $(obj)/insn_sanity
$(call cmd,posttest)
$(call cmd,sanitytest)

hostprogs-y += insn_decoder_test insn_sanity
hostprogs += insn_decoder_test insn_sanity

# -I needed for generated C source and C source which in the kernel tree.
HOSTCFLAGS_insn_decoder_test.o := -Wall -I$(objtree)/arch/x86/lib/ -I$(srctree)/arch/x86/include/uapi/ -I$(srctree)/arch/x86/include/ -I$(srctree)/arch/x86/lib/ -I$(srctree)/include/uapi/
Expand All @@ -39,7 +39,7 @@ $(obj)/insn_decoder_test.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/l
$(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c

HOST_EXTRACFLAGS += -I$(srctree)/tools/include
hostprogs-y += relocs
hostprogs += relocs
relocs-objs := relocs_32.o relocs_64.o relocs_common.o
PHONY += relocs
relocs: $(obj)/relocs
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/radeon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

ccflags-y := -Idrivers/gpu/drm/amd/include

hostprogs-y := mkregtable
hostprogs := mkregtable
clean-files := rn50_reg_safe.h r100_reg_safe.h r200_reg_safe.h rv515_reg_safe.h r300_reg_safe.h r420_reg_safe.h rs600_reg_safe.h r600_reg_safe.h evergreen_reg_safe.h cayman_reg_safe.h

quiet_cmd_mkregtable = MKREGTABLE $@
Expand Down
2 changes: 1 addition & 1 deletion drivers/tty/vt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
# Files generated that shall be removed upon make clean
clean-files := consolemap_deftbl.c defkeymap.c

hostprogs-y += conmakehash
hostprogs += conmakehash

quiet_cmd_conmk = CONMK $@
cmd_conmk = $(obj)/conmakehash $< > $@
Expand Down
2 changes: 1 addition & 1 deletion drivers/video/logo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ obj-$(CONFIG_SPU_BASE) += logo_spe_clut224.o

# How to generate logo's

hostprogs-y := pnmtologo
hostprogs := pnmtologo

# Create commands like "pnmtologo -t mono -n logo_mac_mono -o ..."
quiet_cmd_logo = LOGO $@
Expand Down
2 changes: 1 addition & 1 deletion drivers/zorro/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ obj-$(CONFIG_ZORRO) += zorro.o zorro-driver.o zorro-sysfs.o
obj-$(CONFIG_PROC_FS) += proc.o
obj-$(CONFIG_ZORRO_NAMES) += names.o

hostprogs-y := gen-devlist
hostprogs := gen-devlist

# Files generated that shall be removed upon make clean
clean-files := devlist.h
Expand Down
2 changes: 1 addition & 1 deletion fs/unicode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ $(obj)/utf8data.h: $(src)/utf8data.h_shipped FORCE
endif

targets += utf8data.h
hostprogs-y += mkutf8data
hostprogs += mkutf8data
Loading

0 comments on commit 5f2fb52

Please sign in to comment.