Blame sofort/tools/srctree.sh

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