Blame sofort/tools/srctree.sh

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