[PATCH] Make the flags used for sed -i configurable

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH] Make the flags used for sed -i configurable

Alastair Hughes
Not all sed implementations on linux accept the --follow-symlinks
argument, so let the user configure the arguments passed to sed if
required.

Signed-off-by: Alastair Hughes <[hidden email]>
---
 configure.ac          | 14 ++++++++++----
 scripts/Makefile.am   |  3 ++-
 scripts/makepkg.sh.in |  4 ++--
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 57f068d3..babb8fad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -339,10 +339,10 @@ GCC_VISIBILITY_CC
 
 # Host-dependant definitions
 DEFAULT_DUFLAGS=" -sk --apparent-size"
+DEFAULT_SEDINPLACEFLAGS=" --follow-symlinks -i"
 INODECMD="stat -c '%i %n'"
 OWNERCMD="stat -c '%u:%g'"
 MODECMD="stat -c '%a'"
-SEDINPLACE="sed --follow-symlinks -i"
 STRIP_BINARIES="--strip-all"
 STRIP_SHARED="--strip-unneeded"
 STRIP_STATIC="--strip-debug"
@@ -351,7 +351,7 @@ case "${host_os}" in
  INODECMD="stat -f '%i %N'"
  OWNERCMD="stat -f '%u:%g'"
  MODECMD="stat -f '%Lp'"
- SEDINPLACE="sed -i \"\""
+ DEFAULT_SEDINPLACEFLAGS=" -i \"\""
  DEFAULT_DUFLAGS=" -sk"
  ;;
  darwin*)
@@ -359,7 +359,7 @@ case "${host_os}" in
  INODECMD="/usr/bin/stat -f '%i %N'"
  OWNERCMD="/usr/bin/stat -f '%u:%g'"
  MODECMD="/usr/bin/stat -f '%Lp'"
- SEDINPLACE="/usr/bin/sed -i ''"
+ DEFAULT_SEDINPLACEFLAGS=" -i ''"
  DEFAULT_DUFLAGS=" -sk"
  STRIP_BINARIES=""
  STRIP_SHARED="-S"
@@ -368,10 +368,10 @@ case "${host_os}" in
 esac
 AM_CONDITIONAL([DARWIN], test "x$host_os_darwin" = "xyes")
 AC_PATH_PROGS([DUPATH], [du], [du], [/usr/bin$PATH_SEPARATOR/bin] )
+AC_PATH_PROGS([SEDPATH], [sed], [sed], [/usr/bin$PATH_SEPARATOR/bin] )
 AC_SUBST(INODECMD)
 AC_SUBST(OWNERCMD)
 AC_SUBST(MODECMD)
-AC_SUBST(SEDINPLACE)
 AC_SUBST(STRIP_BINARIES)
 AC_SUBST(STRIP_SHARED)
 AC_SUBST(STRIP_STATIC)
@@ -382,6 +382,12 @@ if test "${DUFLAGS+set}" != "set"; then
 fi
 AC_ARG_VAR(DUFLAGS, [flags for du, overriding the default])
 
+# Flags for sed in place
+if test "${SEDINPLACEFLAGS+set}" != "set"; then
+    SEDINPLACEFLAGS="${DEFAULT_SEDINPLACEFLAGS}"
+fi
+AC_ARG_VAR(SEDINPLACEFLAGS, [flags for sed, overriding the default])
+
 # Variables plugged into makepkg.conf
 CARCH="${host%%-*}"
 CHOST="${host}"
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 4bb08a24..86e44cb6 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -152,7 +152,8 @@ edit = sed \
  -e "s|@OWNERCMD[@]|$(OWNERCMD)|g" \
  -e "s|@MODECMD[@]|$(MODECMD)|g" \
  -e 's|@SIZECMD[@]|$(SIZECMD)|g' \
- -e 's|@SEDINPLACE[@]|$(SEDINPLACE)|g' \
+ -e 's|@SEDINPLACEFLAGS[@]|$(SEDINPLACEFLAGS)|g' \
+ -e 's|@SEDPATH[@]|$(SEDPATH)|g' \
  -e 's|@DUFLAGS[@]|$(DUFLAGS)|g' \
  -e 's|@DUPATH[@]|$(DUPATH)|g' \
  -e 's|@SCRIPTNAME[@]|$@|g' \
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 20e9dd7e..65a9235f 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -189,12 +189,12 @@ update_pkgver() {
 
  if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then
  if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
- if ! @SEDINPLACE@ "s:^pkgver=[^ ]*:pkgver=$newpkgver:" "$BUILDFILE"; then
+ if ! @SEDPATH@ @SEDINPLACEFLAGS@ "s:^pkgver=[^ ]*:pkgver=$newpkgver:" "$BUILDFILE"; then
  error "$(gettext "Failed to update %s from %s to %s")" \
  "pkgver" "$pkgver" "$newpkgver"
  exit 1
  fi
- @SEDINPLACE@ "s:^pkgrel=[^ ]*:pkgrel=1:" "$BUILDFILE"
+ @SEDPATH@ @SEDINPLACEFLAGS@ "s:^pkgrel=[^ ]*:pkgrel=1:" "$BUILDFILE"
  source_safe "$BUILDFILE"
  local fullver=$(get_full_version)
  msg "$(gettext "Updated version: %s")" "$pkgbase $fullver"
--
2.14.0
Loading...