Blame sofort/tools/srctree.sh

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