]> granicus.if.org Git - zfs/commitdiff
Detect if sed supports --in-place
authorRyan Moeller <ryan@freqlabs.com>
Thu, 17 Oct 2019 02:19:48 +0000 (22:19 -0400)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 17 Oct 2019 02:19:48 +0000 (19:19 -0700)
Not all versions of sed have the --in-place flag. Detect support for
the flag during ./configure and provide a fallback mechanism for those
systems where sed's behavior differs. The autoconf variable
${ac_inplace} can be used to choose the correct flags for editing a
file in place with sed.

Replace violating usages in Makefile.am with ${ac_inplace}.

Reviewed-by: Chris Dunlop <chris@onthe.net.au>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
Closes #9463

cmd/arcstat/Makefile.am
cmd/dbufstat/Makefile.am
config/always-sed.m4 [new file with mode: 0644]
config/zfs-build.m4
tests/test-runner/bin/Makefile.am

index 8166778a13e37c7ceb5038489aa5e44af5f96a2a..4b79f4bdd0fb26d593bea6a02fc79007bed996f7 100644 (file)
@@ -8,6 +8,6 @@ dist_bin_SCRIPTS = arcstat
 #
 if USING_PYTHON_2
 install-exec-hook:
-       sed --in-place 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
+       sed ${ac_inplace} -e 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
            $(DESTDIR)$(bindir)/arcstat
 endif
index a3f0c6e50d734601b574022e8481cc5b0af0a477..10c9fbabbf89950b889e7fa7ef95085ec936cfd2 100644 (file)
@@ -8,6 +8,6 @@ dist_bin_SCRIPTS = dbufstat
 #
 if USING_PYTHON_2
 install-exec-hook:
-       sed --in-place 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
+       sed ${ac_inplace} -e 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
            $(DESTDIR)$(bindir)/dbufstat
 endif
diff --git a/config/always-sed.m4 b/config/always-sed.m4
new file mode 100644 (file)
index 0000000..b9c7afd
--- /dev/null
@@ -0,0 +1,16 @@
+dnl #
+dnl # Set the flags used for sed in-place edits.
+dnl #
+AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_SED], [
+       ac_inplace=""
+       AC_CACHE_CHECK([for sed --in-place], [ac_cv_path_SED],
+               [AC_PATH_PROGS_FEATURE_CHECK([SED], [sed],
+                       [[tmpfile=$(mktemp)
+                         echo foo > $tmpfile
+                         $ac_path_SED --in-place 's#foo#bar#' $tmpfile \
+                         && ac_cv_path_SED=$ac_path_SED
+                         rm $tmpfile]],
+                       [ac_inplace="-i ''"])])
+       AS_IF([test "x$ac_inplace" = "x"], [ac_inplace="--in-place"])
+       AC_SUBST([ac_inplace])
+])
index f0c2066af4a28fca238f0ba52e98688c1058c859..91fe04844501c87d1c87c6fad659fc0eefee3aac 100644 (file)
@@ -164,6 +164,7 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [
        ZFS_AC_CONFIG_ALWAYS_ARCH
        ZFS_AC_CONFIG_ALWAYS_PYTHON
        ZFS_AC_CONFIG_ALWAYS_PYZFS
+       ZFS_AC_CONFIG_ALWAYS_SED
 ])
 
 AC_DEFUN([ZFS_AC_CONFIG], [
index 2c031f7455039b7d2f3dbff437322f4dd2e78558..e7838e43d3f8130496394587e46b6e2c0025da52 100644 (file)
@@ -9,7 +9,7 @@ dist_pkgdata_SCRIPTS = \
 #
 if USING_PYTHON_2
 install-data-hook:
-       sed --in-place 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
+       sed ${ac_inplace} -e 's|^#!/usr/bin/env python3|#!/usr/bin/env python2|' \
            $(DESTDIR)$(pkgdatadir)/test-runner.py \
            $(DESTDIR)$(pkgdatadir)/zts-report.py
 endif