1#!/bin/sh
2# SPDX-License-Identifier: LGPL-2.1-or-later
3# shellcheck disable=SC2154,SC2174
4set -eu
5
6i=1
7while [ $i -lt $# ] ; do
8    eval unitdir="\${$i}"
9    eval target="\${$((i + 1))}"
10    eval unit="\${$((i + 2))}"
11
12    if [ "${MESON_INSTALL_QUIET:-0}" = 1 ] ; then
13        VERBOSE=""
14    else
15        VERBOSE="v"
16    fi
17
18    case "$target" in
19        */?*) # a path, but not just a slash at the end
20            dir="${DESTDIR:-}${target}"
21            ;;
22        *)
23            dir="${DESTDIR:-}${unitdir}/${target}"
24            ;;
25    esac
26
27    unitpath="${DESTDIR:-}${unitdir}/${unit}"
28
29    case "$target" in
30        */)
31            mkdir -${VERBOSE}p -m 0755 "$dir"
32            ;;
33        *)
34            mkdir -${VERBOSE}p -m 0755 "$(dirname "$dir")"
35            ;;
36    esac
37
38    ln -${VERBOSE}fs --relative "$unitpath" "$dir"
39
40    i=$((i + 3))
41done
42