orbea / zippy / sofort

Forked from zippy/sofort 2 years ago
Clone

Blame sofort/tools/srctree.sh

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