Blame sofort/tools/srctree.sh

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