Blame src/config.guess

2b9564
#!/bin/sh
2b9564
2b9564
# config.guess: an alternate implementation for modern (cross-)systems.
799bfa
# modern-hosts: machine detection either via slibtool's --dumpmachine
799bfa
#               output, or by way of a native compiler that implements
799bfa
#               the -dumpmachine switch.
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
799bfa
mb_dstamp='2021-06-11'
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
799bfa
	printf '\nA native system is identified either via `slibtool --dumpmachine`, or by way' >&2
799bfa
	printf '\n  of the -dumpmachine output of its priority native compiler.\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
799bfa
# try slibtool
799bfa
if command -v slibtool > /dev/null 2>&1; then
799bfa
	mb_target=$(slibtool --dumpmachine 2>/dev/null || true)
799bfa
799bfa
	if [ -n "$mb_target" ]; then
799bfa
		config_output
799bfa
	fi
799bfa
fi
799bfa
799bfa
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
f081b6
	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