Blame sofort/tools/srctree.sh

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