From 05ebe494ddc0e9c582e9ece0065f03f52d9080c8 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Tue, 3 Dec 2024 02:04:46 +0200 Subject: [PATCH] configure: avoid non-POSIX: test ... -a/-o ... Shells do support those, and typically simple forms do work, but these were removed in POSIX 2024 because they are notoriously hard to parse correctly, and shells don't always agree on the result. Instead, use standard forms which all shells support identically. Extreme high level overview of quotes in POSIX shell: - WORDs without $... or glob don't need quotes (echo, =, no, x86, ...). - a= b=foo c=$... and case $d in ... all don't need quotes. - IFS/glob affect command and arguments (not assignments or case..in): - IFS only splits direct result of $..., quotes will prevent that. - Glob then splits/matches *?[] and quotes will prevent that. POSIX "test" (see Application Usage), and shell language (quotes): https://pubs.opengroup.org/onlinepubs/9799919799/utilities/test.html https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html My own quick guide: https://gist.github.com/avih/6752ad1e20b334b56fef120cd09c766e --- configure | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/configure b/configure index 88d8bf89..d8ef57c6 100755 --- a/configure +++ b/configure @@ -210,7 +210,7 @@ default() # set variable unless already set { local v eval v=\"\$$1\" - test -z "$v" -a -n "$2" && eval $1=\"$2\" + test -z "$v" && test -n "$2" && eval $1=\"$2\" } default_conf() # add to confvars unless already present @@ -219,7 +219,7 @@ default_conf() # add to confvars unless already present test "${confvars%$v*}" = "${confvars}" && confvars="$confvars $1" } -if test -z "$source_path" -o "$source_path" = "." ; then +if test -z "${source_path#.}" ; then source_path=$(pwd) source_path_used="no" else @@ -254,9 +254,10 @@ fi default cpu "$cpu_sys" # check for crpss build -if test "$cpu" != "$cpu_sys" \ - -o "$targetos" != "$buildos" \ - -o -n "$cross_prefix" ; then +if test "$cpu" != "$cpu_sys" || + test "$targetos" != "$buildos" || + test -n "$cross_prefix" +then build_cross="yes" cc="${cross_prefix}${cc}" ar="${cross_prefix}${ar}" @@ -337,7 +338,7 @@ case $targetos in fi fi # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely - if test "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then + if test "$cpu" = x86_64 && test "$cpu_sys" = arm64; then CFLAGS="$CFLAGS -arch $cpu" LDFLAGS="$LDFLAGS -arch $cpu" fi @@ -422,17 +423,17 @@ if test -z "$build_cross"; then _triplet="$($CONFTEST triplet)" fi if test "$mingw32" = "no" ; then - if test -z "$triplet" -a -n "$_triplet"; then + if test -z "$triplet" && test -n "$_triplet"; then if test -f "/usr/lib/$_triplet/crti.o"; then triplet="$_triplet" fi fi if test -z "$triplet"; then - if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then + case $cpu in x86_64|arm64|riscv64) if test -f "/usr/lib64/crti.o" ; then tcc_lddir="lib64" fi - fi + esac fi if test "$suggest" = "yes"; then if test -f "/lib/ld-uClibc.so.0" ; then