Blame sofort/tools/srctree.sh

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