Skip to content

Commit

Permalink
kbuild: fix up substitutions in makefiles to allow for tristate checker
Browse files Browse the repository at this point in the history
The tristate checker, like the Makefile.modbuiltin that preceded it,
relies on running the makefiles with some CONFIG_ variables set to
uppercase values ('Y' or 'M').  Large portions of the core build system
assume that these values are lowercase, but we mostly don't care about
those because they are only involved in actual building, and make
tristatecheck doesn't build anything (the parts that do need changing so
that recursion etc still worked were changed as part of the tristate
commit).

But some makefiles that are not part of the core build system also
contain assumptions that CONFIG_ variables are always lowercase (every
one of these was also broken wrt the old modules.builtin machinery, but
now this is part of a verifier, the problems are more obvious).  In most
cases this is just something like

obj-$(subst m,y,$(CONFIG_FOO)) += blah.o

to indicate that blah.o is always built in even if CONFIG_FOO is a
module.  There is a new macro to help this relatively common case, which
should now be rewritten as

obj-$(call always_built_in,$(CONFIG_FOO)) += blah.o

One other case we handle is that in net/dccp where things are built as
modules iff any member of some other set are modular; this is now
handled like so:

obj-$(call module_if_any_modular,$(CONFIG_IP_DCCP)$(CONFIG_IPV6)) += dccp_ipv6.o
dccp_ipv6-$(call module_if_any_modular,$(CONFIG_IP_DCCP)$(CONFIG_IPV6)) := ipv6.o

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
  • Loading branch information
nickalcock committed Nov 25, 2022
1 parent 39db0ad commit 9d3658a
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion drivers/Makefile
Expand Up @@ -159,7 +159,7 @@ obj-$(CONFIG_SOUNDWIRE) += soundwire/

# Virtualization drivers
obj-$(CONFIG_VIRT_DRIVERS) += virt/
obj-$(subst m,y,$(CONFIG_HYPERV)) += hv/
obj-$(call always_built_in,$(CONFIG_HYPERV)) += hv/

obj-$(CONFIG_PM_DEVFREQ) += devfreq/
obj-$(CONFIG_EXTCON) += extcon/
Expand Down
2 changes: 1 addition & 1 deletion drivers/hv/Makefile
Expand Up @@ -13,4 +13,4 @@ hv_vmbus-$(CONFIG_HYPERV_TESTING) += hv_debugfs.o
hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o hv_utils_transport.o

# Code that must be built-in
obj-$(subst m,y,$(CONFIG_HYPERV)) += hv_common.o
obj-$(call always_built_in,$(CONFIG_HYPERV)) += hv_common.o
2 changes: 1 addition & 1 deletion drivers/mmc/Makefile
Expand Up @@ -4,4 +4,4 @@
#

obj-$(CONFIG_MMC) += core/
obj-$(subst m,y,$(CONFIG_MMC)) += host/
obj-$(call always_built_in,$(CONFIG_MMC)) += host/
2 changes: 1 addition & 1 deletion drivers/net/wireless/silabs/wfx/Makefile
Expand Up @@ -20,6 +20,6 @@ wfx-y := \
debug.o
wfx-$(CONFIG_SPI) += bus_spi.o
# When CONFIG_MMC == m, append to 'wfx-y' (and not to 'wfx-m')
wfx-$(subst m,y,$(CONFIG_MMC)) += bus_sdio.o
wfx-$(call always_built_in,$(CONFIG_MMC)) += bus_sdio.o

obj-$(CONFIG_WFX) += wfx.o
2 changes: 1 addition & 1 deletion drivers/s390/char/Makefile
Expand Up @@ -34,7 +34,7 @@ obj-$(CONFIG_SCLP_VT220_TTY) += sclp_vt220.o

obj-$(CONFIG_PCI) += sclp_pci.o

obj-$(subst m,y,$(CONFIG_ZCRYPT)) += sclp_ap.o
obj-$(call always_built_in,$(CONFIG_ZCRYPT)) += sclp_ap.o

obj-$(CONFIG_VMLOGRDR) += vmlogrdr.o
obj-$(CONFIG_VMCP) += vmcp.o
Expand Down
2 changes: 1 addition & 1 deletion drivers/s390/crypto/Makefile
Expand Up @@ -4,7 +4,7 @@
#

ap-objs := ap_bus.o ap_card.o ap_queue.o
obj-$(subst m,y,$(CONFIG_ZCRYPT)) += ap.o
obj-$(call always_built_in,$(CONFIG_ZCRYPT)) += ap.o
# zcrypt_api.o and zcrypt_msgtype*.o depend on ap.o
zcrypt-objs := zcrypt_api.o zcrypt_card.o zcrypt_queue.o
zcrypt-objs += zcrypt_msgtype6.o zcrypt_msgtype50.o
Expand Down
2 changes: 1 addition & 1 deletion net/8021q/Makefile
Expand Up @@ -2,7 +2,7 @@
#
# Makefile for the Linux VLAN layer.
#
obj-$(subst m,y,$(CONFIG_VLAN_8021Q)) += vlan_core.o
obj-$(call always_built_in,$(CONFIG_VLAN_8021Q)) += vlan_core.o
obj-$(CONFIG_VLAN_8021Q) += 8021q.o

8021q-y := vlan.o vlan_dev.o vlan_netlink.o
Expand Down
2 changes: 1 addition & 1 deletion net/Makefile
Expand Up @@ -42,7 +42,7 @@ obj-$(CONFIG_PHONET) += phonet/
ifneq ($(CONFIG_VLAN_8021Q),)
obj-y += 8021q/
endif
obj-$(CONFIG_IP_DCCP) += dccp/
obj-$(call always_built_in,$(CONFIG_IP_DCCP)) += dccp/
obj-$(CONFIG_IP_SCTP) += sctp/
obj-$(CONFIG_RDS) += rds/
obj-$(CONFIG_WIRELESS) += wireless/
Expand Down
4 changes: 2 additions & 2 deletions net/bridge/Makefile
Expand Up @@ -12,10 +12,10 @@ bridge-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \

bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.o

bridge-$(subst m,y,$(CONFIG_BRIDGE_NETFILTER)) += br_nf_core.o
bridge-$(call always_built_in,$(CONFIG_BRIDGE_NETFILTER)) += br_nf_core.o

br_netfilter-y := br_netfilter_hooks.o
br_netfilter-$(subst m,y,$(CONFIG_IPV6)) += br_netfilter_ipv6.o
br_netfilter-$(call always_built_in,$(CONFIG_IPV6)) += br_netfilter_ipv6.o
obj-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o

bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o br_multicast_eht.o
Expand Down
4 changes: 2 additions & 2 deletions net/dccp/Makefile
Expand Up @@ -17,8 +17,8 @@ dccp-$(CONFIG_IP_DCCP_TFRC_LIB) += ccids/lib/tfrc.o \
dccp_ipv4-y := ipv4.o

# build dccp_ipv6 as module whenever either IPv6 or DCCP is a module
obj-$(subst y,$(CONFIG_IP_DCCP),$(CONFIG_IPV6)) += dccp_ipv6.o
dccp_ipv6-y := ipv6.o
obj-$(call module_if_any_modular,$(CONFIG_IP_DCCP)$(CONFIG_IPV6)) += dccp_ipv6.o
dccp_ipv6-$(call module_if_any_modular,$(CONFIG_IP_DCCP)$(CONFIG_IPV6)) := ipv6.o

obj-$(CONFIG_INET_DCCP_DIAG) += dccp_diag.o

Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/Makefile
Expand Up @@ -47,7 +47,7 @@ obj-y += addrconf_core.o exthdrs_core.o ip6_checksum.o ip6_icmp.o
obj-$(CONFIG_INET) += output_core.o protocol.o \
ip6_offload.o tcpv6_offload.o exthdrs_offload.o

obj-$(subst m,y,$(CONFIG_IPV6)) += inet6_hashtables.o
obj-$(call always_built_in,$(CONFIG_IPV6)) += inet6_hashtables.o

ifneq ($(CONFIG_IPV6),)
obj-$(CONFIG_NET_UDP_TUNNEL) += ip6_udp_tunnel.o
Expand Down
12 changes: 6 additions & 6 deletions net/l2tp/Makefile
Expand Up @@ -8,11 +8,11 @@ obj-$(CONFIG_L2TP) += l2tp_core.o
CFLAGS_l2tp_core.o += -I$(src)

# Build l2tp as modules if L2TP is M
obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_PPPOL2TP)) += l2tp_ppp.o
obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_IP)) += l2tp_ip.o
obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_V3)) += l2tp_netlink.o
obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_ETH)) += l2tp_eth.o
obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_DEBUGFS)) += l2tp_debugfs.o
obj-$(subst Y,$(CONFIG_L2TP),$(subst y,$(CONFIG_L2TP),$(CONFIG_PPPOL2TP))) += l2tp_ppp.o
obj-$(subst Y,$(CONFIG_L2TP),$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_IP))) += l2tp_ip.o
obj-$(subst Y,$(CONFIG_L2TP),$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_V3))) += l2tp_netlink.o
obj-$(subst Y,$(CONFIG_L2TP),$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_ETH))) += l2tp_eth.o
obj-$(subst Y,$(CONFIG_L2TP),$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_DEBUGFS))) += l2tp_debugfs.o
ifneq ($(CONFIG_IPV6),)
obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_IP)) += l2tp_ip6.o
obj-$(subst Y,$(CONFIG_L2TP),$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_IP))) += l2tp_ip6.o
endif
2 changes: 1 addition & 1 deletion net/netfilter/Makefile
Expand Up @@ -6,7 +6,7 @@ nf_conntrack-y := nf_conntrack_core.o nf_conntrack_standalone.o nf_conntrack_exp
nf_conntrack_proto_icmp.o \
nf_conntrack_extend.o nf_conntrack_acct.o nf_conntrack_seqadj.o

nf_conntrack-$(subst m,y,$(CONFIG_IPV6)) += nf_conntrack_proto_icmpv6.o
nf_conntrack-$(call always_built_in,$(CONFIG_IPV6)) += nf_conntrack_proto_icmpv6.o
nf_conntrack-$(CONFIG_NF_CONNTRACK_TIMEOUT) += nf_conntrack_timeout.o
nf_conntrack-$(CONFIG_NF_CONNTRACK_TIMESTAMP) += nf_conntrack_timestamp.o
nf_conntrack-$(CONFIG_NF_CONNTRACK_EVENTS) += nf_conntrack_ecache.o
Expand Down
2 changes: 1 addition & 1 deletion net/netlabel/Makefile
Expand Up @@ -13,4 +13,4 @@ obj-y += netlabel_mgmt.o
# protocol modules
obj-y += netlabel_unlabeled.o
obj-y += netlabel_cipso_v4.o
obj-$(subst m,y,$(CONFIG_IPV6)) += netlabel_calipso.o
obj-$(call always_built_in,$(CONFIG_IPV6)) += netlabel_calipso.o
2 changes: 1 addition & 1 deletion net/sctp/Makefile
Expand Up @@ -21,4 +21,4 @@ sctp-$(CONFIG_SCTP_DBG_OBJCNT) += objcnt.o
sctp-$(CONFIG_PROC_FS) += proc.o
sctp-$(CONFIG_SYSCTL) += sysctl.o

sctp-$(subst m,y,$(CONFIG_IPV6)) += ipv6.o
sctp-$(call always_built_in,$(CONFIG_IPV6)) += ipv6.o
15 changes: 15 additions & 0 deletions scripts/Kbuild.include
Expand Up @@ -188,6 +188,21 @@ cmd_and_fixdep = \
# and if so will execute $(rule_foo).
if_changed_rule = $(if $(if-changed-cond),$(rule_$(1)),@:)

# Usage. $(call always-built-in,CONFIG_VAR)
# Expands to y if CONFIG_VAR is m, suitable for always-built-in pieces
# of things that otherwise may be modular.
always_built_in = $(subst M,Y,$(subst m,y,$(1)))

# Usage, obj-$(call module_if_any_modular,$(CONATENATED)$(CONFIG)$(VARS))
# Expands to m if any of the concatenated config vars are m, otherwise
# y if any of them are y, otherwise n
module_if_any_modular = $(strip \
$(if $(findstring m,$(subst M,m,$(1))), \
$(if $(findstring M,$(1)),M,m), \
$(if $(findstring y,$(subst Y,y,$(1))), \
$(if $(findstring Y,$(1)),Y,y), \
$(if $(findstring N,$(1)),N,n))))

###
# why - tell why a target got built
# enabled by make V=2
Expand Down

0 comments on commit 9d3658a

Please sign in to comment.