Blame sofort/tools/srctree.sh

5a1203
#!/bin/sh
5a1203
5a1203
# srctree.sh: support for out-of-tree builds in posix make mode.
5a1203
# this file is covered by COPYING.SOFORT.
5a1203
5a1203
set -eu
5a1203
5a1203
usage()
5a1203
{
5a1203
cat << EOF >&2
5a1203
5a1203
Usage:
5a1203
  --help              show this HELP message
5a1203
  --srctree=SRCTREE   set source directory
5a1203
5a1203
EOF
5a1203
exit 1
5a1203
}
5a1203
5a1203
5a1203
# one
5a1203
workdir=$(pwd -P)
5a1203
srctree=
5a1203
argloop=
5a1203
5a1203
5a1203
for arg ; do
5a1203
	case "$arg" in
5a1203
		--help)
5a1203
			usage
5a1203
			;;
5a1203
5a1203
		--srctree=*)
5a1203
			srctree=${arg#*=}
5a1203
			;;
5a1203
5a1203
		--)
5a1203
			argloop='done'
5a1203
			;;
5a1203
5a1203
		*)
5a1203
			if [ -z "$argloop" ]; then
5a1203
				printf 'Invalid option: %s\n' "$arg" >&2
5a1203
				usage
5a1203
			fi
5a1203
			;;
5a1203
	esac
5a1203
done
5a1203
5a1203
5a1203
# two
5a1203
if [ -z "$srctree" ] ; then
5a1203
	usage
5a1203
fi
5a1203
5a1203
cd -- "$srctree"
5a1203
srctree=$(pwd -P)
5a1203
cd -- "$workdir"
5a1203
5a1203
if [ "$srctree" = "$workdir" ]; then
5a1203
	exit 0
5a1203
fi
5a1203
5a1203
5a1203
# three
5a1203
for arg ; do
5a1203
	case "$arg" in
5a1203
		--srctree=*)
5a1203
			;;
5a1203
5a1203
		--)
5a1203
			;;
5a1203
5a1203
		*)
5a1203
			stat "$arg" > /dev/null 2>&1 \
5a1203
				|| ln -s -- "$srctree/$arg" "$arg"
5a1203
			;;
5a1203
	esac
5a1203
done
5a1203
5a1203
5a1203
# all done
5a1203
exit 0