Skip to content

Commit

Permalink
Centralize variable substitution
Browse files Browse the repository at this point in the history
A bunch of places need to edit files to incorporate the configured paths
i.e. bindir, sbindir etc. Move this logic into a common file.

Create arc_summary by copying arc_summary[23] as appropriate at build
time instead of install time.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Arvind Sankar <[email protected]>
Closes #10559
  • Loading branch information
nivedita76 authored and behlendorf committed Jul 15, 2020
1 parent bdb518c commit 38e2e9c
Show file tree
Hide file tree
Showing 38 changed files with 155 additions and 288 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ CLEANFILES = $(GITREV)

PHONY = gitrev
gitrev:
ZFS_GITREV=$$(cd $(top_srcdir) && \
$(AM_V_GEN)ZFS_GITREV=$$(cd $(top_srcdir) && \
git describe --always --long --dirty 2>/dev/null); \
ZFS_GITREV=$${ZFS_GITREV:-unknown}; \
printf '#define\tZFS_META_GITREV "%s"\n' \
Expand Down
1 change: 1 addition & 0 deletions cmd/arc_summary/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
arc_summary
13 changes: 6 additions & 7 deletions cmd/arc_summary/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
transform = $(program_transform_name)
bin_SCRIPTS = arc_summary

CLEANFILES = arc_summary
EXTRA_DIST = arc_summary2 arc_summary3

if USING_PYTHON_2
SCRIPT = arc_summary2
else
SCRIPT = arc_summary3
endif

dist_bin_SCRIPTS = $(SCRIPT)

install-exec-hook:
before=$$(echo $(SCRIPT) | sed '$(transform)'); \
after=$$(echo arc_summary | sed '$(transform)'); \
mv "$(DESTDIR)$(bindir)/$$before" "$(DESTDIR)$(bindir)/$$after"
arc_summary: $(SCRIPT)
cp $< $@
1 change: 1 addition & 0 deletions cmd/arcstat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
arcstat
16 changes: 4 additions & 12 deletions cmd/arcstat/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
dist_bin_SCRIPTS = arcstat
include $(top_srcdir)/config/Substfiles.am

#
# The arcstat script is compatible with both Python 2.6 and 3.4.
# As such the python 3 shebang can be replaced at install time when
# targeting a python 2 system. This allows us to maintain a single
# version of the source.
#
if USING_PYTHON_2
install-exec-hook:
$(SED) ${ac_inplace} -e 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
$(DESTDIR)$(bindir)/arcstat
endif
bin_SCRIPTS = arcstat

SUBSTFILES += $(bin_SCRIPTS)
2 changes: 1 addition & 1 deletion cmd/arcstat/arcstat → cmd/arcstat/arcstat.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env @PYTHON_SHEBANG@
#
# Print out ZFS ARC Statistics exported via kstat(1)
# For a definition of fields, or usage, use arcstat -v
Expand Down
1 change: 1 addition & 0 deletions cmd/dbufstat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dbufstat
16 changes: 4 additions & 12 deletions cmd/dbufstat/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
dist_bin_SCRIPTS = dbufstat
include $(top_srcdir)/config/Substfiles.am

#
# The dbufstat script is compatible with both Python 2.6 and 3.4.
# As such the python 3 shebang can be replaced at install time when
# targeting a python 2 system. This allows us to maintain a single
# version of the source.
#
if USING_PYTHON_2
install-exec-hook:
$(SED) ${ac_inplace} -e 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
$(DESTDIR)$(bindir)/dbufstat
endif
bin_SCRIPTS = dbufstat

SUBSTFILES += $(bin_SCRIPTS)
2 changes: 1 addition & 1 deletion cmd/dbufstat/dbufstat → cmd/dbufstat/dbufstat.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env @PYTHON_SHEBANG@
#
# Print out statistics for all cached dmu buffers. This information
# is available through the dbufs kstat and may be post-processed as
Expand Down
12 changes: 3 additions & 9 deletions cmd/zed/zed.d/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
include $(top_srcdir)/config/Rules.am
include $(top_srcdir)/config/Substfiles.am

EXTRA_DIST = \
README \
history_event-zfs-list-cacher.sh.in
EXTRA_DIST += README

zedconfdir = $(sysconfdir)/zfs/zed.d

Expand All @@ -29,12 +28,7 @@ dist_zedexec_SCRIPTS = \

nodist_zedexec_SCRIPTS = history_event-zfs-list-cacher.sh

$(nodist_zedexec_SCRIPTS): %: %.in
-$(SED) -e 's,@bindir\@,$(bindir),g' \
-e 's,@runstatedir\@,$(runstatedir),g' \
-e 's,@sbindir\@,$(sbindir),g' \
-e 's,@sysconfdir\@,$(sysconfdir),g' \
$< >'$@'
SUBSTFILES += $(nodist_zedexec_SCRIPTS)

zedconfdefaults = \
all-syslog.sh \
Expand Down
34 changes: 34 additions & 0 deletions config/Substfiles.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
subst_sed_cmd = \
-e 's|@bindir[@]|$(bindir)|g' \
-e 's|@sbindir[@]|$(sbindir)|g' \
-e 's|@datadir[@]|$(datadir)|g' \
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
-e 's|@runstatedir[@]|$(runstatedir)|g' \
-e 's|@initconfdir[@]|$(initconfdir)|g' \
-e 's|@initdir[@]|$(initdir)|g' \
-e 's|@mounthelperdir[@]|$(mounthelperdir)|g' \
-e 's|@systemdgeneratordir[@]|$(systemdgeneratordir)|g' \
-e 's|@systemdunitdir[@]|$(systemdunitdir)|g' \
-e 's|@udevdir[@]|$(udevdir)|g' \
-e 's|@udevruledir[@]|$(udevruledir)|g' \
-e 's|@zfsexecdir[@]|$(zfsexecdir)|g' \
-e 's|@PYTHON[@]|$(PYTHON)|g' \
-e 's|@PYTHON_SHEBANG[@]|$(PYTHON_SHEBANG)|g' \
-e 's|@DEFAULT_INIT_NFS_SERVER[@]|$(DEFAULT_INIT_NFS_SERVER)|g' \
-e 's|@DEFAULT_INIT_SHELL[@]|$(DEFAULT_INIT_SHELL)|g'

SUBSTFILES =
CLEANFILES = $(SUBSTFILES)
EXTRA_DIST = $(SUBSTFILES:=.in)

$(SUBSTFILES):%:%.in Makefile
$(AM_V_GEN)set -e; \
$(MKDIR_P) $$(dirname $@); \
$(RM) $@~; \
$(SED) $(subst_sed_cmd) $< >$@~; \
if grep -E '@[a-zA-Z0-9_]+@' $@~ >&2; then \
echo "Undefined substitution" >&2; \
exit 1; \
else test $$? -eq 1; fi; \
test -x $< && chmod +x $@~; \
mv -f $@~ $@
4 changes: 4 additions & 0 deletions config/always-python.m4
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYTHON], [
AM_CONDITIONAL([USING_PYTHON_2], [test "x${PYTHON_VERSION%%\.*}" = x2])
AM_CONDITIONAL([USING_PYTHON_3], [test "x${PYTHON_VERSION%%\.*}" = x3])
AM_COND_IF([USING_PYTHON_2],
[AC_SUBST([PYTHON_SHEBANG], [python2])],
[AC_SUBST([PYTHON_SHEBANG], [python3])])
dnl #
dnl # Request that packages be built for a specific Python version.
dnl #
Expand Down
58 changes: 39 additions & 19 deletions config/zfs-build.m4
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ AC_DEFUN([ZFS_AC_RPM], [
RPM_DEFINE_COMMON=${RPM_DEFINE_COMMON}' --define "$(DEBUG_KMEM_TRACKING_ZFS) 1"'
RPM_DEFINE_COMMON=${RPM_DEFINE_COMMON}' --define "$(ASAN_ZFS) 1"'
RPM_DEFINE_UTIL=' --define "_initconfdir $(DEFAULT_INITCONF_DIR)"'
RPM_DEFINE_UTIL=' --define "_initconfdir $(initconfdir)"'
dnl # Make the next three RPM_DEFINE_UTIL additions conditional, since
dnl # their values may not be set when running:
Expand Down Expand Up @@ -469,13 +469,13 @@ AC_DEFUN([ZFS_AC_DEFAULT_PACKAGE], [
AC_MSG_CHECKING([default init directory])
case "$VENDOR" in
freebsd) DEFAULT_INIT_DIR=$sysconfdir/rc.d ;;
*) DEFAULT_INIT_DIR=$sysconfdir/init.d;;
freebsd) initdir=$sysconfdir/rc.d ;;
*) initdir=$sysconfdir/init.d;;
esac
AC_MSG_RESULT([$DEFAULT_INIT_DIR])
AC_SUBST(DEFAULT_INIT_DIR)
AC_MSG_RESULT([$initdir])
AC_SUBST(initdir)
AC_MSG_CHECKING([default init script type])
AC_MSG_CHECKING([default init script type and shell])
case "$VENDOR" in
toss) DEFAULT_INIT_SCRIPT=redhat ;;
redhat) DEFAULT_INIT_SCRIPT=redhat ;;
Expand All @@ -491,24 +491,44 @@ AC_DEFUN([ZFS_AC_DEFAULT_PACKAGE], [
freebsd) DEFAULT_INIT_SCRIPT=freebsd;;
*) DEFAULT_INIT_SCRIPT=lsb ;;
esac
AC_MSG_RESULT([$DEFAULT_INIT_SCRIPT])
# On gentoo, it's possible that OpenRC isn't installed. Check if
# /sbin/openrc-run exists, and if not, fall back to generic defaults.
DEFAULT_INIT_SHELL="/bin/sh"
AS_IF([test "$DEFAULT_INIT_SCRIPT" = "openrc"], [
AS_IF([test -x "/sbin/openrc-run"],
[DEFAULT_INIT_SHELL="/sbin/openrc-run"],
[DEFAULT_INIT_SCRIPT=lsb])
])
AC_MSG_RESULT([$DEFAULT_INIT_SCRIPT:$DEFAULT_INIT_SHELL])
AC_SUBST(DEFAULT_INIT_SCRIPT)
AC_SUBST(DEFAULT_INIT_SHELL)
AC_MSG_CHECKING([default nfs server init script])
AS_IF([test "$VENDOR" = "debian"],
[DEFAULT_INIT_NFS_SERVER="nfs-kernel-server"],
[DEFAULT_INIT_NFS_SERVER="nfs"]
)
AC_MSG_RESULT([$DEFAULT_INIT_NFS_SERVER])
AC_SUBST(DEFAULT_INIT_NFS_SERVER)
AC_MSG_CHECKING([default init config directory])
case "$VENDOR" in
alpine) DEFAULT_INITCONF_DIR=/etc/conf.d ;;
gentoo) DEFAULT_INITCONF_DIR=/etc/conf.d ;;
toss) DEFAULT_INITCONF_DIR=/etc/sysconfig ;;
redhat) DEFAULT_INITCONF_DIR=/etc/sysconfig ;;
fedora) DEFAULT_INITCONF_DIR=/etc/sysconfig ;;
sles) DEFAULT_INITCONF_DIR=/etc/sysconfig ;;
ubuntu) DEFAULT_INITCONF_DIR=/etc/default ;;
debian) DEFAULT_INITCONF_DIR=/etc/default ;;
freebsd) DEFAULT_INITCONF_DIR=$sysconfdir/rc.conf.d;;
*) DEFAULT_INITCONF_DIR=/etc/default ;;
alpine) initconfdir=/etc/conf.d ;;
gentoo) initconfdir=/etc/conf.d ;;
toss) initconfdir=/etc/sysconfig ;;
redhat) initconfdir=/etc/sysconfig ;;
fedora) initconfdir=/etc/sysconfig ;;
sles) initconfdir=/etc/sysconfig ;;
ubuntu) initconfdir=/etc/default ;;
debian) initconfdir=/etc/default ;;
freebsd) initconfdir=$sysconfdir/rc.conf.d;;
*) initconfdir=/etc/default ;;
esac
AC_MSG_RESULT([$DEFAULT_INITCONF_DIR])
AC_SUBST(DEFAULT_INITCONF_DIR)
AC_MSG_RESULT([$initconfdir])
AC_SUBST(initconfdir)
AC_MSG_CHECKING([whether initramfs-tools is available])
if test -d /usr/share/initramfs-tools ; then
Expand Down
17 changes: 3 additions & 14 deletions contrib/dracut/02zfsexpandknowledge/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
include $(top_srcdir)/config/Substfiles.am

pkgdracutdir = $(dracutdir)/modules.d/02zfsexpandknowledge
pkgdracut_SCRIPTS = \
module-setup.sh

EXTRA_DIST = \
module-setup.sh.in

$(pkgdracut_SCRIPTS):%:%.in
-$(SED) -e 's,@bindir\@,$(bindir),g' \
-e 's,@sbindir\@,$(sbindir),g' \
-e 's,@datadir\@,$(datadir),g' \
-e 's,@dracutdir\@,$(dracutdir),g' \
-e 's,@udevdir\@,$(udevdir),g' \
-e 's,@udevruledir\@,$(udevruledir),g' \
-e 's,@sysconfdir\@,$(sysconfdir),g' \
$< >'$@'

CLEANFILES = $(pkgdracut_SCRIPTS)
SUBSTFILES += $(pkgdracut_SCRIPTS)
27 changes: 3 additions & 24 deletions contrib/dracut/90zfs/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include $(top_srcdir)/config/Substfiles.am

pkgdracutdir = $(dracutdir)/modules.d/90zfs
pkgdracut_SCRIPTS = \
export-zfs.sh \
Expand All @@ -14,27 +16,4 @@ pkgdracut_DATA = \
zfs-snapshot-bootfs.service \
zfs-rollback-bootfs.service

EXTRA_DIST = \
export-zfs.sh.in \
module-setup.sh.in \
mount-zfs.sh.in \
parse-zfs.sh.in \
zfs-generator.sh.in \
zfs-load-key.sh.in \
zfs-needshutdown.sh.in \
zfs-lib.sh.in \
zfs-env-bootfs.service.in \
zfs-snapshot-bootfs.service.in \
zfs-rollback-bootfs.service.in

$(pkgdracut_SCRIPTS) $(pkgdracut_DATA) :%:%.in
-$(SED) -e 's,@bindir\@,$(bindir),g' \
-e 's,@sbindir\@,$(sbindir),g' \
-e 's,@udevdir\@,$(udevdir),g' \
-e 's,@udevruledir\@,$(udevruledir),g' \
-e 's,@sysconfdir\@,$(sysconfdir),g' \
-e 's,@systemdunitdir\@,$(systemdunitdir),g' \
-e 's,@mounthelperdir\@,$(mounthelperdir),g' \
$< >'$@'

CLEANFILES = $(pkgdracut_SCRIPTS) $(pkgdracut_DATA)
SUBSTFILES += $(pkgdracut_SCRIPTS) $(pkgdracut_DATA)
17 changes: 3 additions & 14 deletions contrib/initramfs/hooks/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
include $(top_srcdir)/config/Substfiles.am

hooksdir = /usr/share/initramfs-tools/hooks

hooks_SCRIPTS = \
zfs \
zfsunlock

EXTRA_DIST = \
zfs.in \
zfsunlock.in

$(hooks_SCRIPTS):%:%.in Makefile
-$(SED) -e 's,@sbindir\@,$(sbindir),g' \
-e 's,@sysconfdir\@,$(sysconfdir),g' \
-e 's,@udevdir\@,$(udevdir),g' \
-e 's,@udevruledir\@,$(udevruledir),g' \
-e 's,@mounthelperdir\@,$(mounthelperdir),g' \
-e 's,@DEFAULT_INITCONF_DIR\@,$(DEFAULT_INITCONF_DIR),g' \
$< >'$@'

CLEANFILES = $(hooks_SCRIPTS)
SUBSTFILES += $(hooks_SCRIPTS)
2 changes: 1 addition & 1 deletion contrib/initramfs/hooks/zfs.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ COPY_EXEC_LIST="@sbindir@/zdb @sbindir@/zpool @sbindir@/zfs"
COPY_EXEC_LIST="$COPY_EXEC_LIST @mounthelperdir@/mount.zfs @udevdir@/vdev_id"
COPY_EXEC_LIST="$COPY_EXEC_LIST @udevdir@/zvol_id"
COPY_FILE_LIST="/etc/hostid @sysconfdir@/zfs/zpool.cache"
COPY_FILE_LIST="$COPY_FILE_LIST @DEFAULT_INITCONF_DIR@/zfs"
COPY_FILE_LIST="$COPY_FILE_LIST @initconfdir@/zfs"
COPY_FILE_LIST="$COPY_FILE_LIST @sysconfdir@/zfs/zfs-functions"
COPY_FILE_LIST="$COPY_FILE_LIST @sysconfdir@/zfs/vdev_id.conf"
COPY_FILE_LIST="$COPY_FILE_LIST @udevruledir@/60-zvol.rules"
Expand Down
13 changes: 3 additions & 10 deletions etc/default/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
initconfdir = $(DEFAULT_INITCONF_DIR)
initconf_SCRIPTS = zfs

EXTRA_DIST = \
zfs.in
include $(top_srcdir)/config/Substfiles.am

$(initconf_SCRIPTS):%:%.in Makefile
$(SED) \
-e 's,@sysconfdir\@,$(sysconfdir),g' \
$< >'$@'
initconf_SCRIPTS = zfs

CLEANFILES = $(initconf_SCRIPTS)
SUBSTFILES += $(initconf_SCRIPTS)
39 changes: 4 additions & 35 deletions etc/init.d/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
initdir = $(DEFAULT_INIT_DIR)
init_SCRIPTS = zfs-import zfs-mount zfs-share zfs-zed

initconfdir = $(DEFAULT_INITCONF_DIR)
include $(top_srcdir)/config/Substfiles.am

EXTRA_DIST = \
zfs-share.in \
zfs-import.in \
zfs-mount.in \
zfs-zed.in \
README.md
EXTRA_DIST += README.md

$(init_SCRIPTS):%:%.in Makefile
-(if [ -e /etc/debian_version ]; then \
NFS_SRV=nfs-kernel-server; \
else \
NFS_SRV=nfs; \
fi; \
if [ -e /sbin/openrc-run ]; then \
SHELL=/sbin/openrc-run; \
else \
SHELL=/bin/sh; \
fi; \
$(SED) \
-e 's,@bindir\@,$(bindir),g' \
-e 's,@sbindir\@,$(sbindir),g' \
-e 's,@udevdir\@,$(udevdir),g' \
-e 's,@udevruledir\@,$(udevruledir),g' \
-e 's,@sysconfdir\@,$(sysconfdir),g' \
-e 's,@initconfdir\@,$(initconfdir),g' \
-e 's,@initdir\@,$(initdir),g' \
-e 's,@runstatedir\@,$(runstatedir),g' \
-e "s,@SHELL\@,$$SHELL,g" \
-e "s,@NFS_SRV\@,$$NFS_SRV,g" \
$< >'$@'; \
chmod +x '$@')
init_SCRIPTS = zfs-import zfs-mount zfs-share zfs-zed

CLEANFILES = $(init_SCRIPTS)
SUBSTFILES += $(init_SCRIPTS)
2 changes: 1 addition & 1 deletion etc/init.d/zfs-import.in
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!@SHELL@
#!@DEFAULT_INIT_SHELL@
#
# zfs-import This script will import ZFS pools
#
Expand Down
Loading

0 comments on commit 38e2e9c

Please sign in to comment.