[v2,4/4] RISC-V: Use an autoconf template to produce `preconfigure'

Message ID alpine.DEB.2.20.2205122303540.10833@tpp.orcam.me.uk
State Committed
Commit 7b1cfba79ee54221ffa7d7879433b7ee1728cd76
Headers
Series Avoid relying on autoconf internals in `preconfigure' scripts |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Maciej W. Rozycki May 12, 2022, 10:29 p.m. UTC
  Avoid fiddling with autoconf internals and use AC_DEFINE_UNQUOTED to 
define macros in the configuration headers rather than handcoding an 
equivalent shell sequence with the use of the `as_echo' undocumented 
variable.

Switch to using AC_MSG_ERROR rather than `echo' and `exit' directly for 
error handling.  Owing to the lack of any kind of error annotation it 
makes it difficult to spot the message in the flood in a parallel build 
and neither it is logged in `config.log'.
---
Changes from v1:

- Convert the script to an autoconf template and use AC_MSG_ERROR.

- Also handle configuration macro definitions, using AC_DEFINE_UNQUOTED.
---
 sysdeps/riscv/preconfigure    |   33 +++++++++++----------
 sysdeps/riscv/preconfigure.ac |   64 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 15 deletions(-)

glibc-riscv-preconfigure-as-fn-error.diff
  

Comments

Palmer Dabbelt May 12, 2022, 10:34 p.m. UTC | #1
On Thu, 12 May 2022 15:29:11 PDT (-0700), macro@embecosm.com wrote:
> Avoid fiddling with autoconf internals and use AC_DEFINE_UNQUOTED to
> define macros in the configuration headers rather than handcoding an
> equivalent shell sequence with the use of the `as_echo' undocumented
> variable.
>
> Switch to using AC_MSG_ERROR rather than `echo' and `exit' directly for
> error handling.  Owing to the lack of any kind of error annotation it
> makes it difficult to spot the message in the flood in a parallel build
> and neither it is logged in `config.log'.
> ---
> Changes from v1:
>
> - Convert the script to an autoconf template and use AC_MSG_ERROR.
>
> - Also handle configuration macro definitions, using AC_DEFINE_UNQUOTED.
> ---
>  sysdeps/riscv/preconfigure    |   33 +++++++++++----------
>  sysdeps/riscv/preconfigure.ac |   64 ++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 82 insertions(+), 15 deletions(-)
>
> glibc-riscv-preconfigure-as-fn-error.diff
> Index: glibc/sysdeps/riscv/preconfigure
> ===================================================================
> --- glibc.orig/sysdeps/riscv/preconfigure
> +++ glibc/sysdeps/riscv/preconfigure
> @@ -1,3 +1,6 @@
> +# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
> +# Local preconfigure fragment for sysdeps/riscv
> +
>  case "$machine" in
>  riscv*)
>      xlen=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __riscv_xlen \(.*\)/\1/p'`
> @@ -9,8 +12,7 @@ riscv*)
>      64 | 32)
>  	;;
>      *)
> -	echo "Unable to determine XLEN" >&2
> -	exit 1
> +	as_fn_error 1 "Unable to determine XLEN" "$LINENO" 5
>  	;;
>      esac
>
> @@ -20,15 +22,13 @@ riscv*)
>  	with_fp_cond=1
>  	;;
>      32)
> -	echo "glibc does not yet support systems with the F but not D extensions" >&2
> -	exit 1
> +	as_fn_error 1 "glibc does not yet support systems with the F but not D extensions" "$LINENO" 5
>  	;;
>      "")
>  	with_fp_cond=0
>  	;;
>      *)
> -	echo "Unable to determine FLEN" >&2
> -	exit 1
> +	as_fn_error 1 "Unable to determine FLEN" "$LINENO" 5
>  	;;
>      esac
>
> @@ -37,31 +37,34 @@ riscv*)
>  	abi_flen=0
>  	;;
>      single)
> -	echo "glibc does not yet support the single floating-point ABI" >&2
> -	exit 1
> +	as_fn_error 1 "glibc does not yet support the single floating-point ABI" "$LINENO" 5
>  	;;
>      double)
>  	abi_flen=64
>  	;;
>      *)
> -	echo "Unable to determine floating-point ABI" >&2
> -	exit 1
> +	as_fn_error 1 "Unable to determine floating-point ABI" "$LINENO" 5
>  	;;
>      esac
>
>      case "$atomic" in
>      __riscv_atomic)
> -        ;;
> +	;;
>      *)
> -        echo "glibc requires the A extension" >&2
> -	exit 1
> +	as_fn_error 1 "glibc requires the A extension" "$LINENO" 5
>  	;;
>      esac
>
>      base_machine=riscv
>      machine=riscv/rv$xlen/$float_machine
>
> -    $as_echo "#define RISCV_ABI_XLEN $xlen" >>confdefs.h
> -    $as_echo "#define RISCV_ABI_FLEN $abi_flen" >>confdefs.h
> +    cat >>confdefs.h <<_ACEOF
> +#define RISCV_ABI_XLEN $xlen
> +_ACEOF
> +
> +    cat >>confdefs.h <<_ACEOF
> +#define RISCV_ABI_FLEN $abi_flen
> +_ACEOF
> +
>      ;;
>  esac
> Index: glibc/sysdeps/riscv/preconfigure.ac
> ===================================================================
> --- /dev/null
> +++ glibc/sysdeps/riscv/preconfigure.ac
> @@ -0,0 +1,64 @@
> +GLIBC_PROVIDES[]dnl See aclocal.m4 in the top level source directory.
> +# Local preconfigure fragment for sysdeps/riscv
> +
> +case "$machine" in
> +riscv*)
> +    xlen=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __riscv_xlen \(.*\)/\1/p'`
> +    flen=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __riscv_flen \(.*\)/\1/p'`
> +    float_abi=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __riscv_float_abi_\([^ ]*\) .*/\1/p'`
> +    atomic=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | grep '#define __riscv_atomic' | cut -d' ' -f2`
> +
> +    case "$xlen" in
> +    64 | 32)
> +	;;
> +    *)
> +	AC_MSG_ERROR([Unable to determine XLEN], [1])
> +	;;
> +    esac
> +
> +    case "$flen" in
> +    64)
> +	float_machine=rvd
> +	with_fp_cond=1
> +	;;
> +    32)
> +	AC_MSG_ERROR([glibc does not yet support systems with the F but not D extensions], 1)
> +	;;
> +    "")
> +	with_fp_cond=0
> +	;;
> +    *)
> +	AC_MSG_ERROR([Unable to determine FLEN], [1])
> +	;;
> +    esac
> +
> +    case "$float_abi" in
> +    soft)
> +	abi_flen=0
> +	;;
> +    single)
> +	AC_MSG_ERROR([glibc does not yet support the single floating-point ABI], [1])
> +	;;
> +    double)
> +	abi_flen=64
> +	;;
> +    *)
> +	AC_MSG_ERROR([Unable to determine floating-point ABI], [1])
> +	;;
> +    esac
> +
> +    case "$atomic" in
> +    __riscv_atomic)
> +	;;
> +    *)
> +	AC_MSG_ERROR([glibc requires the A extension], [1])
> +	;;
> +    esac
> +
> +    base_machine=riscv
> +    machine=riscv/rv$xlen/$float_machine
> +
> +    AC_DEFINE_UNQUOTED([RISCV_ABI_XLEN], [$xlen])
> +    AC_DEFINE_UNQUOTED([RISCV_ABI_FLEN], [$abi_flen])
> +    ;;
> +esac

Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>

Thanks!
  

Patch

Index: glibc/sysdeps/riscv/preconfigure
===================================================================
--- glibc.orig/sysdeps/riscv/preconfigure
+++ glibc/sysdeps/riscv/preconfigure
@@ -1,3 +1,6 @@ 
+# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
+# Local preconfigure fragment for sysdeps/riscv
+
 case "$machine" in
 riscv*)
     xlen=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __riscv_xlen \(.*\)/\1/p'`
@@ -9,8 +12,7 @@  riscv*)
     64 | 32)
 	;;
     *)
-	echo "Unable to determine XLEN" >&2
-	exit 1
+	as_fn_error 1 "Unable to determine XLEN" "$LINENO" 5
 	;;
     esac
 
@@ -20,15 +22,13 @@  riscv*)
 	with_fp_cond=1
 	;;
     32)
-	echo "glibc does not yet support systems with the F but not D extensions" >&2
-	exit 1
+	as_fn_error 1 "glibc does not yet support systems with the F but not D extensions" "$LINENO" 5
 	;;
     "")
 	with_fp_cond=0
 	;;
     *)
-	echo "Unable to determine FLEN" >&2
-	exit 1
+	as_fn_error 1 "Unable to determine FLEN" "$LINENO" 5
 	;;
     esac
 
@@ -37,31 +37,34 @@  riscv*)
 	abi_flen=0
 	;;
     single)
-	echo "glibc does not yet support the single floating-point ABI" >&2
-	exit 1
+	as_fn_error 1 "glibc does not yet support the single floating-point ABI" "$LINENO" 5
 	;;
     double)
 	abi_flen=64
 	;;
     *)
-	echo "Unable to determine floating-point ABI" >&2
-	exit 1
+	as_fn_error 1 "Unable to determine floating-point ABI" "$LINENO" 5
 	;;
     esac
 
     case "$atomic" in
     __riscv_atomic)
-        ;;
+	;;
     *)
-        echo "glibc requires the A extension" >&2
-	exit 1
+	as_fn_error 1 "glibc requires the A extension" "$LINENO" 5
 	;;
     esac
 
     base_machine=riscv
     machine=riscv/rv$xlen/$float_machine
 
-    $as_echo "#define RISCV_ABI_XLEN $xlen" >>confdefs.h
-    $as_echo "#define RISCV_ABI_FLEN $abi_flen" >>confdefs.h
+    cat >>confdefs.h <<_ACEOF
+#define RISCV_ABI_XLEN $xlen
+_ACEOF
+
+    cat >>confdefs.h <<_ACEOF
+#define RISCV_ABI_FLEN $abi_flen
+_ACEOF
+
     ;;
 esac
Index: glibc/sysdeps/riscv/preconfigure.ac
===================================================================
--- /dev/null
+++ glibc/sysdeps/riscv/preconfigure.ac
@@ -0,0 +1,64 @@ 
+GLIBC_PROVIDES[]dnl See aclocal.m4 in the top level source directory.
+# Local preconfigure fragment for sysdeps/riscv
+
+case "$machine" in
+riscv*)
+    xlen=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __riscv_xlen \(.*\)/\1/p'`
+    flen=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __riscv_flen \(.*\)/\1/p'`
+    float_abi=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __riscv_float_abi_\([^ ]*\) .*/\1/p'`
+    atomic=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | grep '#define __riscv_atomic' | cut -d' ' -f2`
+
+    case "$xlen" in
+    64 | 32)
+	;;
+    *)
+	AC_MSG_ERROR([Unable to determine XLEN], [1])
+	;;
+    esac
+
+    case "$flen" in
+    64)
+	float_machine=rvd
+	with_fp_cond=1
+	;;
+    32)
+	AC_MSG_ERROR([glibc does not yet support systems with the F but not D extensions], 1)
+	;;
+    "")
+	with_fp_cond=0
+	;;
+    *)
+	AC_MSG_ERROR([Unable to determine FLEN], [1])
+	;;
+    esac
+
+    case "$float_abi" in
+    soft)
+	abi_flen=0
+	;;
+    single)
+	AC_MSG_ERROR([glibc does not yet support the single floating-point ABI], [1])
+	;;
+    double)
+	abi_flen=64
+	;;
+    *)
+	AC_MSG_ERROR([Unable to determine floating-point ABI], [1])
+	;;
+    esac
+
+    case "$atomic" in
+    __riscv_atomic)
+	;;
+    *)
+	AC_MSG_ERROR([glibc requires the A extension], [1])
+	;;
+    esac
+
+    base_machine=riscv
+    machine=riscv/rv$xlen/$float_machine
+
+    AC_DEFINE_UNQUOTED([RISCV_ABI_XLEN], [$xlen])
+    AC_DEFINE_UNQUOTED([RISCV_ABI_FLEN], [$abi_flen])
+    ;;
+esac