summaryrefslogtreecommitdiff
path: root/src/config.guess
blob: 34469b5cbadfc07a5a0c9610f0e5c2c58b2cbcbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/sh

# config.guess: an alternate implementation for modern (cross-)systems.
# modern-hosts: native compiler must support the -dumpmachine argument.

# this file is covered by COPYING.BAUTOMAKE.

# the order of attempted things:
#
# $NATIVE_CC
# $CC_FOR_BUILD
# c99
# cc
# ucc
# gcc
# clang
# cparser


set -eu

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

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

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 an alternate config.guess implementation for modern (cross-)systems.' >&2
	printf '\nThe priority native compiler must support the -dumpmachine argument.\n\n'    >&2

	printf 'Native compilers are tried in the following order:\n'                         >&2
	printf '\t%s\n' '$NATIVE_CC' '$CC_FOR_BUILD' 'c99' 'cc' 'ucc' 'gcc' 'clang' 'cparser' >&2

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

	exit ${mb_status}
}


config_output()
{
	printf '%s\n' "$mb_target"
	exit 0
}


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.guess (%s)\n' "$mb_dstamp"
			exit 0
			;;

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


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


# explicit
mb_native_cc="${NATIVE_CC:-false}"
mb_cc_for_build="${CC_FOR_BUILD:-false}"


# try
for mb_cc_guess in "$mb_native_cc" "$mb_cc_for_build" c99 cc ucc gcc clang cparser; do
	mb_target=$($mb_cc_guess -dumpmachine 2> /dev/null) || true

	if [ -n "$mb_target" ]; then
		config_output
	fi
done


# fail
printf '%s: native compiler not found, or does not support -dumpmachine.\n\n' "$mb_script" >&2
exit 2