Blame sofort/tools/srctree.sh

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