Blame sofort/tools/srctree.sh

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