Blame sofort/tools/srctree.sh

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