summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Mewburn <luke@mewburn.net>2020-07-05 12:58:46 +1000
committerZack Weinberg <zackw@panix.com>2020-07-05 09:45:52 -0400
commitc6daae41276a49b52a9d5e2f70c95651364ed619 (patch)
treeca7f3d22fd193e9a693fd18d852c71d271150ce3
parentd0acdabdeca8a396ae2d0877d3b802581ccef83d (diff)
downloadautoconf-c6daae41276a49b52a9d5e2f70c95651364ed619.tar.gz
AS_INIT: basename __file__
Fix AS_INIT to encode the basename of __file__ instead of the full path to the source directory. Allows for reproducible builds.
-rw-r--r--lib/m4sugar/m4sh.m44
-rw-r--r--tests/m4sh.at19
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index af286857..c9e86246 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -2139,9 +2139,11 @@ m4_provide([AS_INIT])
m4_pattern_forbid([^_?AS_])
# Bangshe and minimal initialization.
+# Put only the basename of __file__ into HEADER-COMMENT, so that the
+# path to the source directory is not embedded in the output file.
m4_divert_text([BINSH], [@%:@! /bin/sh])
m4_divert_text([HEADER-COMMENT],
- [@%:@ Generated from __file__ by m4_PACKAGE_STRING.])
+ [@%:@ Generated from m4_bpatsubst(__file__,[^.*/\([^/]*\)$],[[\1]]) by m4_PACKAGE_STRING.])
m4_divert_text([M4SH-SANITIZE], [_AS_SHELL_SANITIZE])
m4_divert_text([M4SH-INIT-FN], [m4_text_box([M4sh Shell Functions.])])
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 9fd84558..a18277ac 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -1868,6 +1868,25 @@ cleanup 1
AT_CLEANUP
+## -------------------------- ##
+## AS_INIT basename __file__. ##
+## -------------------------- ##
+
+AT_SETUP([AS@&t@_INIT basename __@&t@file__])
+AT_KEYWORDS([m4sh])
+
+AT_CHECK([mkdir sub || exit 77])
+AT_DATA_M4SH([sub/script.as], [[dnl
+AS_INIT
+]])
+AT_CHECK_AUTOM4TE([--language=m4sh sub/script.as -o script])
+AT_CHECK([grep '^# Generated from' script], [0], [dnl
+# Generated from script.as by ]m4_PACKAGE_STRING[.
+])
+
+AT_CLEANUP
+
+
## ------------------- ##
## AS_INIT_GENERATED. ##
## ------------------- ##