スクリプトには、ハードコードされた相対パスがいくつかあります。スクリプトの位置を基準にしてほしい。
他のプログラム(cmake)が必要とするため、スクリプトは現在のディレクトリを変更する必要があります。
スクリプトは引数としていくつかの(おそらく呼び出し元に関連する)パスを取り、それらをそのプログラムに渡します。それらは非相対化する必要があります。
質問はインラインです:
#!/bin/sh
# First arg should be Release or Debug
# TODO test for that.
if test -n "$1"; then # BTW how to test whether $1 is Debug or Release?
BUILD_TYPE="$1"
else
BUILD_TYPE="Release"
fi
# Set install prefix to current directory, unless second argument is given.
if test -n "$2"; then
INSTALL_PREFIX="$2" # How to derelativize this path argument?
else
INSTALL_PREFIX=bin # How to make this path relative to script location?
fi
# Make build directory and do cmake, make, make install.
mkdir -p build/${BUILD_TYPE} && # How to make this path relative to script location?
cd build/${BUILD_TYPE} &&
cmake -D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
-D CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \ # Possible relative to caller current directory.
../../ && # Relative to scrip position.
make -j4 &&
make install
それは一般的な問題ですか、それとも私は非標準的な方法で何かをしていますか?