Blob Blame History Raw
#!/bin/sh

# config.sub: a neutral implementation for modern (cross-)systems.
# any-target: all are assumed to be supported, no door-keeper failures.

# this file is covered by COPYING.BAUTOMAKE.


set -eu

mb_script="$0"
mb_status=1
mb_dstamp='2020-01-18'

mb_target="${1:-}"
mb_extarg="${2:-}"

export LC_ALL=C


config_usage()
{
	printf 'usage:\n'                                   >&2
	printf '\t%s [OPTION]\n' "$mb_script"               >&2
	printf '\t%s (cross-)target-alias\n\n' "$mb_script" >&2

	printf 'Options:\n' >&2
	printf '\t%s\n'            \
		'-h, --help'       \
		'-t, --time-stamp' \
		'-v, --version'    \
		>&2

	printf '\nThis is a neutral config.sub implementation for modern (cross-)systems.' >&2
	printf '\nAll (cross-)targets are assumed to be supported, and there are no door-keeper failures.\n\n' >&2

	printf 'pkgsite: https://git.foss21.org/bautomake\n' >&2
	printf 'pkgbugs: bugs.automake@foss21.org\n'         >&2

	exit ${mb_status}
}


for arg ; do
	case "$arg" in
		-h | --help)
			mb_status=0
			config_usage
			;;

		-t | --time-stamp)
			printf '%s\n' "$mb_dstamp"
			exit 0
			;;

		-v | --version)
			printf 'foss21.org config.sub (%s)\n' "$mb_dstamp"
			exit 0
			;;

		-*)
			printf '%s: the argument `%s is not supported.\n\n' "$mb_script" "$arg'" >&2
			exit 2
	esac
done


# required target argument
if [ -z "$mb_target" ]; then
	config_usage
fi

# no unused arguments
if [ -n "$mb_extarg" ]; then
	mb_status=2
	config_usage
fi

# validation
if [ "$mb_target" != ${mb_target%% *} ]; then
	printf '%s: input error: target alias may not contain spaces.\n\n' "$mb_script" >&2
	exit 2
fi

# compatible output
printf '%s\n' "$mb_target"

# all done
exit 0