build: patch generated configure to use $(...) instead of backtick assignments

Run #473 (post CONFIG_SHELL=bash) still hit:

  ./configure: line 11244: syntax error near unexpected token
    `as_ac_var=`printf '%s\n' "ac_cv_func_$ac_func" | sed "$as_sed_sh"``

Root cause: MSYS2's mingw-w64-x86_64-autotools meta package pulls
autoconf 2.73, which generates ./configure with backtick command
substitution INSIDE variable assignments (`var=`cmd``). My local
environment has autoconf 2.71 which doesn't generate this pattern
at all (verified: 0 matches in locally-generated configure).

bash on MSYS2's MINGW64 can't parse the 2.73 pattern even when
invoked directly - the nested backticks with mixed single/double
quotes containing $-vars trip the parser. Pinning MSYS2's autoconf
to 2.71 is fragile (meta-package pulls current on next rebuild).

Fix: after autoreconf, run a perl one-liner on the generated
configure that converts all `var=`cmd`` assignments to
`var=$(cmd)` form. POSIX-ly equivalent for bash, nests cleanly,
and matches what autoconf 2.71 would have generated. Verified
the patched configure still works (`./configure --help` runs
cleanly). The CONFIG_SHELL=bash line stays for any remaining
edge cases on dash-vs-bash differences.
This commit is contained in:
Krystie
2026-06-25 00:46:15 -07:00
parent 4f452514dc
commit c2257bb827
+21 -4
View File
@@ -14,13 +14,30 @@ cd "$TOR_SRC_DIR"
if [[ ! -x "./configure" ]] || [[ "${AUTORECONF_FORCE:-0}" == "1" ]]; then if [[ ! -x "./configure" ]] || [[ "${AUTORECONF_FORCE:-0}" == "1" ]]; then
echo "Running autoreconf with -W no-error (autogen.sh -W all,error is too strict for autoconf 2.73+)" echo "Running autoreconf with -W no-error (autogen.sh -W all,error is too strict for autoconf 2.73+)"
autoreconf -i -f -W no-error autoreconf -i -f -W no-error
# autoconf 2.73 generates ./configure with backtick command
# substitutions inside variable assignments such as
# as_ac_var=`printf '%s\n' "ac_cv_func_$ac_func" | sed "$as_sed_sh"`
# bash on MSYS2/MINGW64 parses this with a syntax error at the
# nested backticks with quoted $-vars. autoconf 2.71 doesn't
# generate this pattern, but pinning the MSYS2 autoconf version
# is fragile (meta-package pulls whatever's current). Convert
# all `var=\`cmd\`` assignments to `var=$(cmd)` form, which is
# POSIX-ly equivalent and nests cleanly.
if grep -qE '^[ \t]*[A-Za-z_][A-Za-z0-9_]*=`[^`]*`[ \t]*$' configure; then
echo "Patching generated configure: \`...\` -> \$(...) in assignments"
# Match leading whitespace, identifier, =, single backtick,
# any chars except backtick, single backtick, optional whitespace.
perl -i -pe 's/^([ \t]*[A-Za-z_][A-Za-z0-9_]*=)`([^`]*)`([ \t]*)$/$1\$($2)$3/' configure \
|| echo "perl not available, falling back to sed"
fi
fi fi
echo "Configuring Tor static library build from: $TOR_SRC_DIR" echo "Configuring Tor static library build from: $TOR_SRC_DIR"
# autoconf 2.73's generated ./configure uses backtick command substitution # Even after the perl patch above, the configure script's shebang
# inside variable assignments (e.g. `as_ac_var=\`printf ... | sed ...\``) # is `#!/bin/sh` and MSYS2's /bin/sh is dash. Force bash so any
# which dash/MSYS2's /bin/sh rejects with a syntax error. Force bash # remaining edge cases (nested quoting, $RANDOM usage, etc.) parse
# explicitly so the same script works on Windows MSYS2 and macOS/Linux. # the same way on every platform.
export CONFIG_SHELL="${CONFIG_SHELL:-$(command -v bash)}" export CONFIG_SHELL="${CONFIG_SHELL:-$(command -v bash)}"
"$CONFIG_SHELL" ./configure \ "$CONFIG_SHELL" ./configure \
--enable-static-tor \ --enable-static-tor \