From 918f141758cbfab1f8f3cf0d67d420f070e34a4d Mon Sep 17 00:00:00 2001 From: Luke Mewburn Date: Sun, 5 Jul 2020 12:58:46 +1000 Subject: [PATCH] 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. --- lib/m4sugar/m4sh.m4 | 4 +++- tests/m4sh.at | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletions(-) diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index af28685..7ef43f6 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. +# Ensure HEADER-COMMENT contains the basename of __file__ 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 9fd8455..a18277a 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. ## ## ------------------- ## -- 1.7.1