diff --git a/meson.build b/meson.build index f4a05ba..8bf62d8 100644 --- a/meson.build +++ b/meson.build @@ -13,7 +13,7 @@ gnome = import('gnome') i18n = import('i18n') pkgconfig = import('pkgconfig') -meson_make_symlink = join_paths(meson.source_root(), 'tools', 'meson-make-symlink.sh') +meson_make_symlink = join_paths(meson.source_root(), 'tools', 'meson-make-symlink.py') po_dir = join_paths(meson.source_root(), 'po') prefix = get_option('prefix') diff --git a/tools/meson-make-symlink.py b/tools/meson-make-symlink.py new file mode 100644 index 0000000..36ff06e --- /dev/null +++ b/tools/meson-make-symlink.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +import os +import sys + +destdir = os.environ.get('DESTDIR') +source = sys.argv[1] +target = sys.argv[2] + +def prepend_destdir(path): + if destdir is not None: + if os.path.isabs(path): + return os.path.join(destdir, path[1:]) + else: + return os.path.join(destdir, path) + else: + return path + +def call_symlink(src, dst): + try: + os.remove(dst) + except: + pass + os.symlink(src, dst) + +os.makedirs(os.path.dirname(prepend_destdir(target)), exist_ok=True) +if os.path.dirname(source) == '.': + destdir_target = prepend_destdir(target) + call_symlink(source, destdir_target) +else: + destdir_source = prepend_destdir(source) + destdir_target = prepend_destdir(target) + destdir_target_dir = os.path.dirname(destdir_target) + relative_source = os.path.relpath(destdir_source, destdir_target_dir) + call_symlink(relative_source, destdir_target) diff --git a/tools/meson-make-symlink.sh b/tools/meson-make-symlink.sh deleted file mode 100755 index 501cd43..0000000 --- a/tools/meson-make-symlink.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -set -eu - -# this is needed mostly because $DESTDIR is provided as a variable, -# 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