09157951638 / compilers / bcparser

Forked from compilers/bcparser a year ago
Clone

Blame sofort/tools/srctree.sh

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