Search code examples
linuxbashln

"No such file or directory" while in link path


When compiling, I always place the build in a separate directory. For example:

mkdir build
cd ./build
(cd ..; ./bootstrap)
../configure
make

Since I have plenty of RAM the aim is to compile on a TMPFS.

The script gets the name of the project, uses it for the name for the directory created in $XDG_RUNTIME_DIR/build and finally links it.

# setup-build.sh

#!/usr/bin/bash
set -e

my_project_name=$(basename $(pwd))
my_project_build_dir="$XDG_RUNTIME_DIR/build/$my_project_name"
mkdir -p $my_project_build_dir
ln -s "$my_project_build_dir" "$(pwd)/build"

The script runs without a problem. But, when I do cd ./build; ../configure it returns an error: bash: ../configure: No such file or directory. The file most certainly does exist, but Bash can't find it!


Solution

  • I altered the script to this:

    #!/usr/bin/bash
    set -e
    
    my_project_src_dir="$(pwd)"
    my_project_name="$(basename $(pwd))"
    my_project_build_dir="$XDG_RUNTIME_DIR/build/$my_project_name"
    mkdir -p "$my_project_build_dir"
    ln -s "$my_project_build_dir" "$(pwd)/build"
    cd "$my_project_build_dir"
    echo "$my_project_src_dir" > "./project-src-dir.txt"
    

    To compile I have to type cd ./build; $(cat ./project-src-dir.txt)/configure; make. This causes Bash complete to partial break, though. As in I can't TAB complete file names from $my_project_src_dir with this method, but TAB completion for arguments works fine. Ifautoconf is needed: (cd $(cat ./project-src-dir.txt); ./bootstrap). If anyone has any other ideas I would still prefer to be able to just do ../configure, although this will have to do for now.

    Edit: Had to change my_project_name="$(basename '$my_project_src_dir') to my_project_name="$(basename $(pwd))" as it was taking '$my_project_src_dir' literally.