ArcticaProject / nx-libs

nx-libs
Other
120 stars 39 forks source link

'. replace.sh' fails for POSIX shells (e.g. Bash as 'sh') #1071

Closed Apteryks closed 3 months ago

Apteryks commented 7 months ago

Hi,

I had the following problem attempting to build this project, setting the shell used for the build to Bash (5.x) provided sh, which behaves in a POSIX compatible fashion (see "info (bash) Bash Startup Files").

The error was:

# create a clean nx-X11/.build-exports space
rm -Rf nx-X11/.build-exports
mkdir -p nx-X11/.build-exports/include
mkdir -p nx-X11/.build-exports/lib
# copy headers (for libnx-x11-dev)
cp -aL nx-X11/exports/include/* nx-X11/.build-exports/include
# copy libs (for libnx-x11), we want the targets of the links
echo "PWD: $(pwd)"
PWD: /tmp/nx-libs-3.5.99.27
. replace.sh; set -x; find nx-X11/exports/lib/ -name "libNX*.so" | while read libpath; do \
    libfile=$(basename $libpath); \
    libdir=$(dirname $libpath); \
    link=$(readlink $libpath); \
\   
    mkdir -p "$(string_rep "$libdir" exports .build-exports)"; \
    cp -a "$(string_rep "$libpath" "$libfile" "$link")" "$(string_rep "$libdir" exports .build-exports)"; \
done;
/gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16/bin/sh: line 1: .: replace.sh: file not found
make: *** [Makefile:258: install-full] Error 1

This happens because replace.sh is looked up from PATH, where it's not found. Since we aren't using /bin/bash, the POSIX behaviors is to only look from PATH for relative file names. The solution is to use the absolute file name of the replace.sh shell "library", like so:

. ./replace.sh

Thanks to emanuele6 from #bash on libera.chat for the kind explanation.