Reicher82 / python / sbpython3

Forked from python/sbpython3 3 years ago
Clone

Blame sofort/tools/srctree.sh

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