[pacman-dev] [PATCH v2] meson: make our symlinking script more portable

Eli Schwartz eschwartz at archlinux.org
Tue Apr 20 02:25:51 UTC 2021


We do not need the --relative case as it is dead code (we only ever link
a filename without directory components).

For the rest, GNU-specific ln -T does two things:

- if the link name is an existing directory, ln fails instead of
  creating a surprising link inside the directory
- if the link name is a symlink to a directory, ln treats it as a file,
  and due to -f, unlinks it

The second case can be portably solved by ln -n, and both cases can be
solved by doing what the original autotools Makefile did: rm -f && ln -s

If the file exists, it will be removed. If it cannot be removed, it must
be an ordinary directory, and the script aborts with an error.

Signed-off-by: Eli Schwartz <eschwartz at archlinux.org>
---

v2: autotools had an elegant way to solve this which is very portable
and also super simple.

 build-aux/meson-make-symlink.sh | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/build-aux/meson-make-symlink.sh b/build-aux/meson-make-symlink.sh
index 501cd43d4..3e3aa7ba2 100644
--- a/build-aux/meson-make-symlink.sh
+++ b/build-aux/meson-make-symlink.sh
@@ -5,8 +5,6 @@ set -eu
 # and we need to create the target directory...
 
 mkdir -vp "$(dirname "${DESTDIR:-}$2")"
-if [ "$(dirname $1)" = . ]; then
-        ln -vfs -T "$1" "${DESTDIR:-}$2"
-else
-        ln -vfs -T --relative "${DESTDIR:-}$1" "${DESTDIR:-}$2"
-fi
+
+rm -f "${DESTDIR:-}$2"
+ln -vs "$1" "${DESTDIR:-}$2"
-- 
2.31.1


More information about the pacman-dev mailing list