Blame src/config.guess

2b9564
#!/bin/sh
2b9564
2b9564
# config.guess: an alternate implementation for modern (cross-)systems.
2b9564
# modern-hosts: native compiler must support the -dumpmachine argument.
2b9564
2b9564
# this file is covered by COPYING.BAUTOMAKE.
2b9564
2b9564
# the order of attempted things:
2b9564
#
2b9564
# $NATIVE_CC
2b9564
# $CC_FOR_BUILD
2b9564
# c99
2b9564
# cc
2b9564
# ucc
2b9564
# gcc
2b9564
# clang
2b9564
# cparser
2b9564
2b9564
2b9564
set -eu
2b9564
2b9564
mb_script="$0"
2b9564
mb_status=1
2b9564
mb_dstamp='2020-01-18'
2b9564
2b9564
mb_target=
2b9564
mb_extarg="${1:-}"
2b9564
2b9564
export LC_ALL=C
2b9564
2b9564
2b9564
config_usage()
2b9564
{
2b9564
	printf 'usage:\n'                                   >&2
2b9564
	printf '\t%s [OPTION]\n' "$mb_script"               >&2
2b9564
	printf '\t%s (cross-)target-alias\n\n' "$mb_script" >&2
2b9564
2b9564
	printf 'Options:\n' >&2
2b9564
	printf '\t%s\n'            \
2b9564
		'-h, --help'       \
2b9564
		'-t, --time-stamp' \
2b9564
		'-v, --version'    \
2b9564
		>&2
2b9564
2b9564
	printf '\nThis is an alternate config.guess implementation for modern (cross-)systems.' >&2
2b9564
	printf '\nThe priority native compiler must support the -dumpmachine argument.\n\n'    >&2
2b9564
2b9564
	printf 'Native compilers are tried in the following order:\n'                         >&2
2b9564
	printf '\t%s\n' '$NATIVE_CC' '$CC_FOR_BUILD' 'c99' 'cc' 'ucc' 'gcc' 'clang' 'cparser' >&2
2b9564
2b9564
	printf '\npkgsite: https://git.foss21.org/bautomake' >&2
2b9564
	printf '\npkgbugs: bugs.automake@foss21.org\n\n'     >&2
2b9564
2b9564
	exit ${mb_status}
2b9564
}
2b9564
2b9564
2b9564
config_output()
2b9564
{
2b9564
	printf '%s\n' "$mb_target"
2b9564
	exit 0
2b9564
}
2b9564
2b9564
2b9564
for arg ; do
2b9564
	case "$arg" in
2b9564
		-h | --help)
2b9564
			mb_status=0
2b9564
			config_usage
2b9564
			;;
2b9564
2b9564
		-t | --time-stamp)
2b9564
			printf '%s\n' "$mb_dstamp"
2b9564
			exit 0
2b9564
			;;
2b9564
2b9564
		-v | --version)
2b9564
			printf 'foss21.org config.guess (%s)\n' "$mb_dstamp"
2b9564
			exit 0
2b9564
			;;
2b9564
2b9564
		-*)
2b9564
			printf '%s: the argument `%s is not supported.\n\n' "$mb_script" "$arg'" >&2
2b9564
			exit 2
2b9564
	esac
2b9564
done
2b9564
2b9564
2b9564
# no unused arguments
2b9564
if [ -n "$mb_extarg" ]; then
2b9564
	mb_status=2
2b9564
	config_usage
2b9564
fi
2b9564
2b9564
2b9564
# explicit
2b9564
mb_native_cc="${NATIVE_CC:-false}"
2b9564
mb_cc_for_build="${CC_FOR_BUILD:-false}"
2b9564
2b9564
2b9564
# try
2b9564
for mb_cc_guess in "$mb_native_cc" "$mb_cc_for_build" c99 cc ucc gcc clang cparser; do
2b9564
	mb_target=$($mb_cc_guess -dumpmachine 2> /dev/null) || true
2b9564
2b9564
	if [ -n "$mb_target" ]; then
2b9564
		config_output
2b9564
	fi
2b9564
done
2b9564
2b9564
2b9564
# fail
2b9564
printf '%s: native compiler not found, or does not support -dumpmachine.\n\n' "$mb_script" >&2
2b9564
exit 2