commit ee3c838780070d083d51de75b7f020015d64f0c7
parent b8fa14f1a8ddabad414aae0e1eb04a8da303c958
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 15 Oct 2024 15:37:51 +0200
Correction of the Makefile
With some versions of GNU make, the build could fail when make was run
in parallel; the file descriptor used to display the value of a Makefile
macro was already reserved by GNU make to synchronise its tasks. This is
now avoided by executing the make command in the showvar shell function,
without any options, i.e. without using the jobserver, and therefore
without file descriptor conflicts. This is not a problem because the
Makefile created ‘on the fly’ is only there to print the value of a
macro defined in the config.mk file, and therefore does not need to be
run in parallel. Quite the contrary.
Diffstat:
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile
@@ -84,7 +84,7 @@ libssf.o: $(OBJ)
@echo "config done" > $@
.simd: make.sh config.mk
- @$(SHELL) make.sh config_simd $(MAKE) > $@
+ @$(SHELL) make.sh config_simd > $@
.SUFFIXES: .c .d .o
.c.d:
diff --git a/make.sh b/make.sh
@@ -23,15 +23,21 @@ set -e
# Print the value of a variable in config.mk
showvar()
{
- make="$1"
- # To avoid messages from Make being displayed instead of the value of the
- # queried variable, we redirect its output to /dev/null and open a new file
- # descriptor to stdout to print the variable
-<< EOF "${make}" -f 3>&1 1>/dev/null 2>&1 - || kill -HUP $$
+ # To avoid messages from Make being displayed instead of the value of
+ # the queried variable, we redirect its output to /dev/null and open a
+ # new file descriptor to stdout to print the variable.
+ #
+ # The MAKEFLAGS environment variable is cleared to prevent make
+ # defining options which reserve the file descriptor used to print the
+ # variable, which would result in a ‘wrong file descriptor’ error.
+ # This can be the case with certain versions of GNU make which, when
+ # run in parallel, use pipe file descriptors to synchronise with the
+ # jobserver.
+<< EOF MAKEFLAGS="" ${MAKE:-make} -f 3>&1 1>/dev/null 2>&1 - || kill -HUP $$
.POSIX:
include config.mk
showvar:
- @1>&3 echo \$($2)
+ @1>&3 echo \$($1)
EOF
exec 3<&- # Close file descriptor 3
}
@@ -47,9 +53,8 @@ check_cpuflag()
################################################################################
config_simd()
{
- make="$1"
- simd_width="$(showvar "${make}" SIMD_WIDTH)"
- pkg_config="$(showvar "${make}" PKG_CONFIG)"
+ simd_width="$(showvar SIMD_WIDTH)"
+ pkg_config="$(showvar PKG_CONFIG)"
avx="$(check_cpuflag avx)"
if [ -z "${simd_width}" ]; then
if ! ${pkg_config} --exists rsimd; then