summaryrefslogtreecommitdiff
path: root/sofort/tools/srctree.sh
blob: 90a1d890e2607207ab0703d5bfbc3c3fd410de5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh

# srctree.sh: support for out-of-tree builds in posix make mode.
# this file is covered by COPYING.SOFORT.

set -eu

usage()
{
cat << EOF >&2

Usage:
  --help              show this HELP message
  --srctree=SRCTREE   set source directory

EOF
exit 1
}


# one
workdir=$(pwd -P)
srctree=
argloop=


for arg ; do
	case "$arg" in
		--help)
			usage
			;;

		--srctree=*)
			srctree=${arg#*=}
			;;

		--)
			argloop='done'
			;;

		*)
			if [ -z "$argloop" ]; then
				printf 'Invalid option: %s\n' "$arg" >&2
				usage
			fi
			;;
	esac
done


# two
if [ -z "$srctree" ] ; then
	usage
fi

cd -- "$srctree"
srctree=$(pwd -P)
cd -- "$workdir"

if [ "$srctree" = "$workdir" ]; then
	exit 0
fi


# three
for arg ; do
	case "$arg" in
		--srctree=*)
			;;

		--)
			;;

		*)
			stat "$arg" > /dev/null 2>&1 \
				|| ln -s -- "$srctree/$arg" "$arg"
			;;
	esac
done


# all done
exit 0