Lasse Collin wrote:

> Maybe. The current way was used because it was the laziest and had a low
> risk of new build system bugs.

Makes sense.  Just for kicks, here's a try based on advice from
<http://www.gnu.org/s/hello/manual/automake/Scripts.html>.  It
probably makes more sense to use the "AC_CONFIG_FILE([src/my_script],
[chmod +x src/my_script])" approach.

> I haven't merged your patch to v5.0 yet. I haven't decided if the test
> script is safe enough there yet. It would be annoying if someone got a
> test failure in a stable release just because the test script uses a
> wrong shell.

No need to hurry.  I don't mind if you merge the fix without the test. :)

-- >8 --
Subject: Build: Generate scripts in the Makefile, not the configure script

As the automake manual explains, directory variables such as
$(datadir) are not fully expanded by AC_SUBST when they refer to other
directory variables.  xz's scripts don't use any such variables yet,
but it seems best to be prepared.

Side benefit: The scripts are marked executable and can be used
directly by tests.  (Another way to achieve that would have been to
mark the scripts executable directly in a script fragment passed as
the second parameter to AC_CONFIG_FILES.)
---
 configure.ac            |    4 ----
 src/scripts/Makefile.am |   19 ++++++++++++++++++-
 tests/test_scripts.sh   |    8 ++++----
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5247c979..a4baf9c4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -716,10 +716,6 @@ AC_CONFIG_FILES([
        src/xzdec/Makefile
        src/lzmainfo/Makefile
        src/scripts/Makefile
-       src/scripts/xzdiff
-       src/scripts/xzgrep
-       src/scripts/xzmore
-       src/scripts/xzless
        tests/Makefile
        debug/Makefile
 ])
diff --git a/src/scripts/Makefile.am b/src/scripts/Makefile.am
index 29bdbcd7..9d9b2586 100644
--- a/src/scripts/Makefile.am
+++ b/src/scripts/Makefile.am
@@ -5,7 +5,12 @@
 ## You can do whatever you want with this file.
 ##
 
-nodist_bin_SCRIPTS = xzdiff xzgrep xzmore xzless
+SUFFIXES = .in
+
+bin_SCRIPTS = xzdiff xzgrep xzmore xzless
+CLEANFILES = $(bin_SCRIPTS)
+EXTRA_DIST = xzdiff.in xzgrep.in xzmore.in xzless.in
+
 dist_man_MANS = xzdiff.1 xzgrep.1 xzmore.1 xzless.1
 
 links = \
@@ -24,6 +29,18 @@ links += \
        xzless-lzless
 endif
 
+do_subst = sed -e 's|[@]PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' \
+               -e 's|[@]PACKAGE_BUGREPORT[@]|$(PACKAGE_BUGREPORT)|g' \
+               -e 's|[@]VERSION[@]|$(VERSION)|g' \
+               -e 's|[@]POSIX_SHELL[@]|$(POSIX_SHELL)|g' \
+               -e 's|[@]xz[@]|$(xz)|g'
+
+.in:
+       rm -f $@-t $@
+       $(do_subst) < $< > $@-t
+       chmod +x $@-t
+       mv -f $@-t $@
+
 install-exec-hook:
        cd $(DESTDIR)$(bindir) && \
        for pair in $(links); do \
diff --git a/tests/test_scripts.sh b/tests/test_scripts.sh
index 891fc76a..293929e6 100755
--- a/tests/test_scripts.sh
+++ b/tests/test_scripts.sh
@@ -13,7 +13,7 @@
 XZ=../src/xz/xz
 XZDIFF=../src/scripts/xzdiff
 test -x "$XZ" || XZ=
-test -r "$XZDIFF" || XZDIFF=
+test -x "$XZDIFF" || XZDIFF=
 if test -z "$XZ" || test -z "$XZDIFF"; then
        (exit 77)
        exit 77
@@ -26,7 +26,7 @@ preimage=$srcdir/files/good-1-check-crc32.xz
 samepostimage=$srcdir/files/good-1-check-crc64.xz
 otherpostimage=$srcdir/files/good-1-lzma2-1.xz
 
-sh "$XZDIFF" "$preimage" "$samepostimage" >/dev/null
+"$XZDIFF" "$preimage" "$samepostimage" >/dev/null
 status=$?
 if test "$status" != 0 ; then
        echo "xzdiff with no changes exited with status $status != 0"
@@ -34,7 +34,7 @@ if test "$status" != 0 ; then
        exit 1
 fi
 
-sh "$XZDIFF" "$preimage" "$otherpostimage" >/dev/null
+"$XZDIFF" "$preimage" "$otherpostimage" >/dev/null
 status=$?
 if test "$status" != 1 ; then
        echo "xzdiff with changes exited with status $status != 1"
@@ -42,7 +42,7 @@ if test "$status" != 1 ; then
        exit 1
 fi
 
-sh "$XZDIFF" "$preimage" "$srcdir/files/missing.xz" >/dev/null 2>&1
+"$XZDIFF" "$preimage" "$srcdir/files/missing.xz" >/dev/null 2>&1
 status=$?
 if test "$status" != 2 ; then
        echo "xzdiff with missing operand exited with status $status != 2"
-- 
1.7.6


Reply via email to