Blame sofort/tools/srctree.sh

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