From 4ca6eb91c2faf550f251863429f333bfdbd89fec Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sun, 20 Sep 2020 01:31:41 +0300 Subject: Convert relative installation directory path to absolute in build scripts --- build-clang.bat | 4 ++++ build-mingw.bat | 4 ++++ build-msvc.bat | 7 ++++++- build.sh | 21 +++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/build-clang.bat b/build-clang.bat index f8b8f31..16cdae0 100644 --- a/build-clang.bat +++ b/build-clang.bat @@ -152,6 +152,10 @@ if "_%1_" == "__" ( set "cxx=%1" ) +rem Convert a relative path to an absolute. +rem +for /F "delims=|" %%D in ("%idir%") do set "idir=%%~dpnxD" + rem Certificate to trust. rem if not "_%trust%_" == "__" ( diff --git a/build-mingw.bat b/build-mingw.bat index 7e62685..21704b4 100644 --- a/build-mingw.bat +++ b/build-mingw.bat @@ -161,6 +161,10 @@ if not "_%3_" == "__" ( set "trust=%3" ) +rem Convert a relative path to an absolute. +rem +for /F "delims=|" %%D in ("%idir%") do set "idir=%%~dpnxD" + rem Certificate to trust. rem if not "_%trust%_" == "__" ( diff --git a/build-msvc.bat b/build-msvc.bat index 2f0ed6b..e9416a3 100644 --- a/build-msvc.bat +++ b/build-msvc.bat @@ -8,7 +8,8 @@ goto start :usage echo. -echo Usage: %0 [/?] [^] [^] +rem echo Usage: %0 [/?] [^] [^] +echo Usage: %0 [/?] [^] echo Options: echo --local Don't build from packages, only from local source. echo --install-dir ^ Alternative installation directory. @@ -140,6 +141,10 @@ rem ) else ( rem set "cxx=%1" rem ) +rem Convert a relative path to an absolute. +rem +for /F "delims=|" %%D in ("%idir%") do set "idir=%%~dpnxD" + rem Certificate to trust. rem if not "_%trust%_" == "__" ( diff --git a/build.sh b/build.sh index 9d83209..a1ba1cf 100755 --- a/build.sh +++ b/build.sh @@ -225,6 +225,12 @@ if test -n "$make"; then fi fi +# If the installation directory is unspecified, then assume it is /usr/local. +# Otherwise, if it is a relative path, then convert it to an absolute path, +# unless the realpath program is not present on the system or doesn't +# recognize any of the options we pass, in which case fail, advising to +# specify an absolute installation directory. +# if test -z "$idir"; then idir=/usr/local private=config.install.private=build2 @@ -235,6 +241,21 @@ if test -z "$idir"; then if test -z "$sudo"; then sudo="sudo" fi +elif test -n "$(echo "$idir" | sed -n 's#^[^/].*$#true#p')"; then + + if ! command -v realpath >/dev/null 2>&1; then + diag "error: unable to execute realpath: command not found" + diag " info: specify absolute installation directory path" + exit 1 + fi + + # Don't resolve symlinks and allow non-existent path components. + # + if ! idir="$(realpath -s -m "$idir" 2>/dev/null)"; then + diag "error: realpath does not recognize -s -m" + diag " info: specify absolute installation directory path" + exit 1 + fi fi if test "$sudo" = false; then -- cgit v1.1