Blame sofort/tools/srctree.sh

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