Reicher82 / toolchain / sbmake

Forked from toolchain/sbmake 3 years ago
Clone

Blame sofort/tools/srctree.sh

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