Blame sofort/tools/srctree.sh

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