From 4313a5b4c51e2093f1b45ef9845fc77d32b09330 Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Wed, 16 Oct 2019 22:19:48 -0400 Subject: [PATCH] Detect if sed supports --in-place 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 Reviewed-by: Brian Behlendorf Signed-off-by: Ryan Moeller Closes #9463 --- cmd/arcstat/Makefile.am | 2 +- cmd/dbufstat/Makefile.am | 2 +- config/always-sed.m4 | 16 ++++++++++++++++ config/zfs-build.m4 | 1 + tests/test-runner/bin/Makefile.am | 2 +- 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 config/always-sed.m4 diff --git a/cmd/arcstat/Makefile.am b/cmd/arcstat/Makefile.am index 8166778a13..4b79f4bdd0 100644 --- a/cmd/arcstat/Makefile.am +++ b/cmd/arcstat/Makefile.am @@ -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 diff --git a/cmd/dbufstat/Makefile.am b/cmd/dbufstat/Makefile.am index a3f0c6e50d..10c9fbabbf 100644 --- a/cmd/dbufstat/Makefile.am +++ b/cmd/dbufstat/Makefile.am @@ -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 index 0000000000..b9c7afd63d --- /dev/null +++ b/config/always-sed.m4 @@ -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]) +]) diff --git a/config/zfs-build.m4 b/config/zfs-build.m4 index f0c2066af4..91fe048445 100644 --- a/config/zfs-build.m4 +++ b/config/zfs-build.m4 @@ -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], [ diff --git a/tests/test-runner/bin/Makefile.am b/tests/test-runner/bin/Makefile.am index 2c031f7455..e7838e43d3 100644 --- a/tests/test-runner/bin/Makefile.am +++ b/tests/test-runner/bin/Makefile.am @@ -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