Redfoxmoon / cross / slibtool

Forked from cross/slibtool 11 months ago
Clone

Blame sofort/tools/srctree.sh

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