Blame sofort/tools/srctree.sh

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