Blame sofort/ccenv/ccenv.sh

dee5ee
# ccenv.sh: sofort's tool-finding bits,
dee5ee
# invoked from within the project-agnostic configure script.
dee5ee
dbd589
# this file is covered by COPYING.SOFORT.
dbd589
dee5ee
# invocation and names of binary tools:
dee5ee
# agnostic names (ar, nm, objdump, ...);
dee5ee
# target-prefixed agnostic names (x86_64-nt64-midipix-ar, ...);
dee5ee
# branded names (llvm-ar, llvm-nm, llvm-objdump, ...);
dee5ee
# target-prefixed branded names (x86_64-linux-gnu-gcc-ar, ...);
dee5ee
# target-specifying branded tools (llvm-ar --target=x86_64-linux, ...).
dee5ee
dee5ee
# cross-compilation: default search order:
dee5ee
# target-prefixed agnostic tools;
dee5ee
# target-prefixed branded tools, starting with the prefix
dee5ee
# most commonly associated with the selected compiler (that is,
dee5ee
# ``gcc'' when using gcc, and ``llvm'' when using clang);
dee5ee
# target-speficying branded tools, starting once again with the
dee5ee
# prefix most commonly associated with the selected compiler.
dee5ee
dee5ee
# internal variables of interest:
dee5ee
# ccenv_cfgtype: the type of host being tested (host/native)
dee5ee
# ccenv_cfgfile: the configuration file for the host being tested
dee5ee
# ccenv_cflags:  the comprehensive cflags for the host being tested
dee5ee
# ccenv_cchost:  the host being tested, as reported by -dumpmachine
dee5ee
dee5ee
dee5ee
ccenv_usage()
dee5ee
{
dee5ee
	cat "$mb_project_dir"/sofort/ccenv/ccenv.usage
dee5ee
	exit 0
dee5ee
}
dee5ee
dee5ee
dee5ee
ccenv_newline()
dee5ee
{
dee5ee
	printf '\n' >> "$ccenv_cfgfile"
dee5ee
}
dee5ee
dee5ee
dee5ee
ccenv_comment()
dee5ee
{
dee5ee
	ccenv_internal_str='#'
dee5ee
dee5ee
	for ccenv_internal_arg ; do
dee5ee
		ccenv_internal_str="$ccenv_internal_str $ccenv_internal_arg"
dee5ee
	done
dee5ee
dee5ee
	printf '%s\n' "$ccenv_internal_str" >> "$ccenv_cfgfile"
dee5ee
}
dee5ee
dee5ee
1b8de4
ccenv_tool_prolog()
1b8de4
{
20c7a4
	ccenv_line_dots='.....................................'
ba353e
	ccenv_tool_desc=" == checking for ${1}"
1b8de4
	ccenv_tool_dlen="${#ccenv_line_dots}"
1b8de4
db226e
	printf '\n%s\n' '________________________' >&3
db226e
	printf "ccenv: checking for ${1}\n\n" >&3
1b8de4
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s" \
20c7a4
		"${ccenv_tool_desc}  ${mb_line_dots}"
1b8de4
}
1b8de4
1b8de4
1b8de4
ccenv_tool_epilog()
1b8de4
{
1b8de4
	ccenv_line_dots='................................'
1b8de4
	ccenv_tool_dlen="$((${#ccenv_line_dots} - ${#1}))"
1b8de4
a7ffa2
	case ${ccenv_tool_dlen} in
a7ffa2
		0 | -* )
a7ffa2
			ccenv_tool_dlen='3' ;;
a7ffa2
	esac
a7ffa2
20c7a4
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
1b8de4
		"${ccenv_line_dots}" "${1}"
db226e
db226e
	if [ "${1}" = 'false' ]; then
db226e
		printf '\n\nccenv: not (yet) found.\n' >&3
db226e
	else
db226e
		printf "\n\nccenv : found $(command -v ${1}).\n" >&3
db226e
	fi
db226e
db226e
	printf '%s\n' '------------------------' >&3
1b8de4
}
1b8de4
1b8de4
381345
ccenv_tool_variant_epilog()
381345
{
381345
	ccenv_expr=${1}='${'${1}':-false}'
381345
	eval "$ccenv_expr"
381345
381345
	ccenv_expr='${'${1}'}'
381345
	eval ccenv_tool_epilog "$ccenv_expr"
381345
}
381345
381345
1b8de4
ccenv_attr_prolog()
1b8de4
{
20c7a4
	ccenv_line_dots=' .....................................'
20c7a4
	ccenv_attr_desc=" == detect ${ccenv_cfgtype} ${1}"
1b8de4
	ccenv_attr_dlen="${#ccenv_line_dots}"
1b8de4
1b8de4
	printf "%${ccenv_attr_dlen}.${ccenv_attr_dlen}s" \
1b8de4
		"${ccenv_attr_desc} ${ccenv_line_dots}"
db226e
db226e
	printf '\n%s\n' '________________________' >&3
db226e
	printf "ccenv: detecting ${1}\n\n" >&3
1b8de4
}
1b8de4
1b8de4
1b8de4
ccenv_attr_epilog()
1b8de4
{
db226e
	ccenv_line_dots='................................'
20c7a4
	ccenv_tool_dlen="$((${#ccenv_line_dots} - 1 - ${#1}))"
db226e
a7ffa2
	case ${ccenv_tool_dlen} in
a7ffa2
		0 | -* )
a7ffa2
			ccenv_tool_dlen='3' ;;
a7ffa2
	esac
a7ffa2
20c7a4
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
db226e
		"${ccenv_line_dots}" "${1}"
db226e
db226e
	printf '\n\nccenv: detected result: %s\n' "${1}" >&3
db226e
	printf '%s\n' '------------------------' >&3
1b8de4
}
1b8de4
1b8de4
dee5ee
ccenv_find_tool()
dee5ee
{
dee5ee
	if [ -z "$ccenv_prefixes" ]; then
12a073
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
0bc3a4
			ccenv_cmd_args="${@:-}"
0bc3a4
0bc3a4
			if [ -z "$ccenv_cmd_args" ]; then
92b12d
				if command -v "$ccenv_candidate" > /dev/null; then
92b12d
					ccenv_tool="$ccenv_candidate"
7861a3
					return 0
b20945
				fi
7861a3
			else
92b12d
				if command -v "$ccenv_candidate" > /dev/null; then
db226e
					if "$ccenv_candidate" $@ > /dev/null 2>&3; then
92b12d
						ccenv_tool="$ccenv_candidate"
7861a3
						return 0
b20945
					fi
b20945
				fi
7861a3
			fi
dee5ee
		done
dee5ee
dee5ee
		ccenv_tool=false
dee5ee
dee5ee
		return 0
dee5ee
	fi
dee5ee
12a073
	for ccenv_prefix in $(printf '%s' "$ccenv_prefixes"); do
12a073
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
dee5ee
			ccenv_tool="$ccenv_prefix$ccenv_candidate"
b20945
b20945
			if command -v "$ccenv_tool" > /dev/null; then
b20945
				return 0
b20945
			fi
dee5ee
		done
dee5ee
	done
dee5ee
12a073
	for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
92b12d
		if command -v "$ccenv_candidate" > /dev/null; then
92b12d
			ccenv_tool="$ccenv_candidate"
b20945
			return 0
b20945
		fi
dee5ee
	done
dee5ee
dee5ee
	ccenv_tool=false
dee5ee
dee5ee
	return 0
dee5ee
}
dee5ee
dee5ee
dee5ee
ccenv_set_primary_tools()
dee5ee
{
dee5ee
	ccenv_core_tools="ar nm objdump ranlib size strip strings objcopy"
e41026
	ccenv_hack_tools="addr2line cov elfedit readelf readobj otool"
dee5ee
	ccenv_peep_tools="perk mdso dlltool windmc windres"
dee5ee
12a073
	for __tool in $(printf '%s' "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do
1b8de4
		ccenv_tool_prolog "$__tool"
1b8de4
dee5ee
		if [ -n "$mb_agnostic" ]; then
dee5ee
			ccenv_candidates=" $__tool"
dee5ee
dee5ee
		elif [ -n "$mb_zealous" ]; then
dee5ee
			ccenv_candidates="$mb_zealous-$__tool"
dee5ee
dee5ee
		elif [ "$mb_toolchain" = 'gcc' ]; then
dee5ee
			ccenv_candidates="gcc-$__tool"
dee5ee
			ccenv_candidates="$ccenv_candidates $__tool"
dee5ee
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
dee5ee
dee5ee
		elif [ "$mb_toolchain" = 'llvm' ]; then
dee5ee
			ccenv_candidates="llvm-$__tool"
dee5ee
			ccenv_candidates="$ccenv_candidates $__tool"
dee5ee
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
dee5ee
dee5ee
		elif [ -n "$mb_toolchain" ]; then
dee5ee
			ccenv_candidates="$mb_toolchain-$__tool"
dee5ee
			ccenv_candidates="$ccenv_candidates $__tool"
dee5ee
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
dee5ee
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
dee5ee
dee5ee
		else
dee5ee
			ccenv_candidates="$__tool"
dee5ee
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
dee5ee
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
dee5ee
		fi
dee5ee
dee5ee
		if [ "$ccenv_cfgtype" = 'host' ]; then
dee5ee
			ccenv_var_prefix='mb_'
dee5ee
		else
dee5ee
			ccenv_var_prefix='mb_native_'
dee5ee
		fi
dee5ee
dee5ee
		ccenv_var_name=$ccenv_var_prefix$__tool
dee5ee
		ccenv_var_expr='${'$ccenv_var_name':-}'
dee5ee
		eval ccenv_var_val=$ccenv_var_expr
dee5ee
dee5ee
		if [ -n "$ccenv_var_val" ]; then
dee5ee
			eval ccenv_$__tool="$ccenv_var_val"
dee5ee
		else
dee5ee
			ccenv_find_tool
dee5ee
			eval ccenv_$__tool="$ccenv_tool"
dee5ee
		fi
1b8de4
1b8de4
		ccenv_tool_epilog "$ccenv_tool"
dee5ee
	done
dee5ee
dee5ee
	# windrc
dee5ee
	ccenv_windrc="$ccenv_windres"
00a250
00a250
	# archive format preamble
65ead2
	if [ -n "$ccenv_dumpmachine_switch" ]; then
65ead2
		ccenv_libgcc_a_header=$(od -b -N8             \
65ead2
			$($ccenv_cc -print-file-name=libgcc.a) \
65ead2
			| head -n1)
65ead2
	else
65ead2
		ccenv_libgcc_a_header=
65ead2
	fi
65ead2
65ead2
	# ar (default)
00a250
	ccenv_cc_arfmt='common'
00a250
00a250
	# ar (big)
00a250
	ccenv_bigaf_header=$(printf '%s\n' '<bigaf>' | od -b | head -n1)
00a250
00a250
	if [ "$ccenv_libgcc_a_header" = "$ccenv_bigaf_header" ]; then
00a250
		ccenv_cc_arfmt='bigaf'
00a250
00a250
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
00a250
			ccenv_var_name=ccenv_$__tool
00a250
			ccenv_var_expr='${'$ccenv_var_name':-}'
00a250
			eval ccenv_var_val="$ccenv_var_expr"
00a250
00a250
			if [ "$ccenv_var_val" != false ]; then
00a250
				ccenv_var_val="$ccenv_var_val -X64"
00a250
				ccenv_var_expr='${ccenv_var_val:-}'
00a250
				eval ccenv_$__tool="$ccenv_var_expr"
00a250
			fi
00a250
		done
00a250
	fi
00a250
00a250
	# ar (small)
00a250
	ccenv_aiaff_header=$(printf '%s\n' '<aiaff>' | od -b | head -n1)
00a250
00a250
	if [ "$ccenv_libgcc_a_header" = "$ccenv_aiaff_header" ]; then
00a250
		ccenv_cc_arfmt='aiaff'
00a250
00a250
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
00a250
			ccenv_var_name=ccenv_$__tool
00a250
			ccenv_var_expr='${'$ccenv_var_name':-}'
00a250
			eval ccenv_var_val="$ccenv_var_expr"
00a250
00a250
			if [ "$ccenv_var_val" != false ]; then
00a250
				ccenv_var_val="$ccenv_var_val -X32"
00a250
				ccenv_var_expr='${ccenv_var_val:-}'
00a250
				eval ccenv_$__tool="$ccenv_var_expr"
00a250
			fi
00a250
		done
00a250
	fi
dee5ee
}
dee5ee
dee5ee
ccenv_set_tool_variants()
dee5ee
{
dee5ee
	# as (asm)
1b8de4
	ccenv_tool_prolog 'as (asm)'
dee5ee
	ccenv_candidates=as
dee5ee
	ccenv_find_tool
dee5ee
dee5ee
	if [ "$ccenv_tool" = false ]; then
dee5ee
		ccenv_as_asm=
dee5ee
	else
0a6b7a
		$ccenv_tool --help 2>&1 | grep -i '.bc assembler' \
dee5ee
		|| ccenv_as_asm="$ccenv_tool"
dee5ee
	fi
dee5ee
381345
	ccenv_tool_variant_epilog 'ccenv_as_asm'
1b8de4
dee5ee
	# as (ll)
1b8de4
	ccenv_tool_prolog 'as (ll)'
dee5ee
	ccenv_candidates=llvm-as
dee5ee
	ccenv_find_tool
dee5ee
dee5ee
	if [ "$ccenv_tool" != false ]; then
dee5ee
		ccenv_as_ll="$ccenv_tool"
dee5ee
	fi
dee5ee
381345
	ccenv_tool_variant_epilog 'ccenv_as_ll'
1b8de4
dee5ee
	# as (mc)
1b8de4
	ccenv_tool_prolog 'as (mc)'
dee5ee
	ccenv_candidates=llvm-mc
dee5ee
	ccenv_find_tool
dee5ee
dee5ee
	if [ "$ccenv_tool" != false ]; then
dee5ee
		ccenv_as_mc="$ccenv_tool"
dee5ee
	fi
dee5ee
381345
	ccenv_tool_variant_epilog 'ccenv_as_mc'
1b8de4
dee5ee
	# ld (bfd)
1b8de4
	ccenv_tool_prolog 'ld (bfd)'
dee5ee
	ccenv_candidates=ld.bfd
dee5ee
	ccenv_find_tool
dee5ee
dee5ee
	if [ "$ccenv_tool" != false ]; then
dee5ee
		ccenv_ld_bfd="$ccenv_tool"
dee5ee
	fi
dee5ee
381345
	ccenv_tool_variant_epilog 'ccenv_ld_bfd'
1b8de4
dee5ee
	# ld (gold)
1b8de4
	ccenv_tool_prolog 'ld (gold)'
dee5ee
	ccenv_candidates=ld.gold
dee5ee
	ccenv_find_tool
dee5ee
dee5ee
	if [ "$ccenv_tool" != false ]; then
dee5ee
		ccenv_ld_gold="$ccenv_tool"
dee5ee
	fi
dee5ee
381345
	ccenv_tool_variant_epilog 'ccenv_ld_gold'
1b8de4
dee5ee
	# ld (lld)
1b8de4
	ccenv_tool_prolog 'ld (lld)'
dee5ee
	ccenv_candidates=lld
dee5ee
	ccenv_find_tool
dee5ee
dee5ee
	if [ "$ccenv_tool" != false ]; then
dee5ee
		ccenv_ld_lld="$ccenv_tool"
dee5ee
	fi
dee5ee
381345
	ccenv_tool_variant_epilog 'ccenv_ld_lld'
1b8de4
dee5ee
	# objdump (bfd)
1b8de4
	ccenv_tool_prolog 'objdump (bfd)'
dee5ee
	ccenv_candidates=objdump
dee5ee
	ccenv_find_tool
dee5ee
f50b67
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
f50b67
		ccenv_objdump_bfd="$ccenv_tool"
f50b67
	fi
dee5ee
381345
	ccenv_tool_variant_epilog 'ccenv_objdump_bfd'
1b8de4
dee5ee
	# objdump (llvm)
1b8de4
	ccenv_tool_prolog 'objdump (llvm)'
dee5ee
	ccenv_candidates=llvm-objdump
dee5ee
	ccenv_find_tool
dee5ee
f50b67
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
f50b67
		ccenv_objdump_llvm="$ccenv_tool"
f50b67
	fi
dee5ee
381345
	ccenv_tool_variant_epilog 'ccenv_objdump_llvm'
1b8de4
dee5ee
	# readelf (bfd)
1b8de4
	ccenv_tool_prolog 'readelf (bfd)'
dee5ee
	ccenv_candidates=readelf
dee5ee
	ccenv_find_tool
dee5ee
f50b67
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
f50b67
		ccenv_readelf_bfd="$ccenv_tool"
f50b67
	fi
dee5ee
381345
	ccenv_tool_variant_epilog 'ccenv_readelf_bfd'
1b8de4
dee5ee
	# readelf (llvm)
1b8de4
	ccenv_tool_prolog 'readelf (llvm)'
dee5ee
	ccenv_candidates=llvm-readelf
dee5ee
	ccenv_find_tool
dee5ee
f50b67
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
f50b67
		ccenv_readelf_llvm="$ccenv_tool"
f50b67
	fi
dee5ee
381345
	ccenv_tool_variant_epilog 'ccenv_readelf_llvm'
1b8de4
dee5ee
	# as
dee5ee
	if [ -n "$ccenv_cc" ]; then
bf7915
		ccenv_as='$('"$ccenv_makevar_prefix"'CC) -c -x assembler'
dee5ee
	elif [ -n "$mb_agnostic" ]; then
dee5ee
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
dee5ee
	elif [ "$mb_zealous" = 'gcc' ]; then
dee5ee
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
dee5ee
	elif [ -n "$mb_zealous" = 'llvm' ]; then
dee5ee
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
dee5ee
	elif [ "$mb_toolchain" = 'gcc' ]; then
dee5ee
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
dee5ee
	elif [ "$mb_toolchain" = 'llvm' ]; then
dee5ee
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
dee5ee
	fi
dee5ee
dee5ee
	# ld
dee5ee
	if [ -n "$ccenv_cc" ]; then
dee5ee
		ccenv_ld='$('"$ccenv_makevar_prefix"'CC) -nostdlib -nostartfiles'
dee5ee
	fi
dee5ee
}
dee5ee
dee5ee
ccenv_set_c_compiler_candidates()
dee5ee
{
dee5ee
	if   [ -n "$mb_compiler" ]; then
dee5ee
		ccenv_candidates="$mb_compiler"
dee5ee
dee5ee
	elif [ -n "$mb_agnostic" ]; then
dee5ee
		ccenv_candidates="c99 c11 cc"
dee5ee
dee5ee
	elif [ "$mb_zealous" = 'gcc' ]; then
dee5ee
		ccenv_candidates="gcc"
dee5ee
dee5ee
	elif [ "$mb_zealous" = 'llvm' ]; then
dee5ee
		ccenv_candidates="clang"
dee5ee
dee5ee
	elif [ "$mb_toolchain" = 'gcc' ]; then
dee5ee
		ccenv_candidates="gcc c99 c11 cc clang"
dee5ee
dee5ee
	elif [ "$mb_toolchain" = 'llvm' ]; then
dee5ee
		ccenv_candidates="clang c99 c11 cc gcc"
dee5ee
dee5ee
	elif [ -n "$mb_toolchain" ]; then
dee5ee
		ccenv_candidates="$mb_toolchain c99 c11 cc gcc clang"
dee5ee
dee5ee
	else
36b558
		ccenv_candidates="cc gcc clang c99 c11"
dee5ee
	fi
dee5ee
}
dee5ee
dee5ee
dee5ee
ccenv_set_cc()
dee5ee
{
1b8de4
	ccenv_tool_prolog 'C compiler'
1b8de4
dee5ee
	if [ -z "$ccenv_cc" ]; then
dee5ee
		ccenv_set_c_compiler_candidates
65ead2
		ccenv_find_tool
dee5ee
		ccenv_cc="$ccenv_tool"
dee5ee
	fi
dee5ee
65ead2
dee5ee
	if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
dee5ee
		ccenv_cc="$mb_compiler"
dee5ee
	fi
dee5ee
65ead2
	ccenv_tool_epilog "$ccenv_cc"
65ead2
65ead2
65ead2
	if [ $ccenv_cfgtype = 'host' ]; then
65ead2
		ccenv_host_cc="$ccenv_cc"
65ead2
		cfgtest_host_section
65ead2
		ccenv_host_cc=
65ead2
	else
65ead2
		ccenv_native_cc="$ccenv_cc"
65ead2
		cfgtest_native_section
65ead2
		ccenv_native_cc=
65ead2
	fi
65ead2
b672aa
	cfgtest_silent='yes'
b672aa
65ead2
	if cfgtest_compiler_switch -dumpmachine ; then
65ead2
		ccenv_dumpmachine_switch='-dumpmachine'
65ead2
	else
65ead2
		ccenv_dumpmachine_switch=
65ead2
	fi
65ead2
6a2fd1
	if cfgtest_code_snippet_asm 'typedef int dummy;' ; then
6a2fd1
		eval ccenv_${ccenv_cfgtype}_stdin_input='yes'
6a2fd1
	else
6a2fd1
		eval ccenv_${ccenv_cfgtype}_stdin_input='no'
6a2fd1
	fi
6a2fd1
b672aa
	unset cfgtest_silent
b672aa
dee5ee
	ccenv_cc_cmd="$ccenv_cc"
87fc37
	ccenv_errors=
dee5ee
dee5ee
	if [ "$ccenv_cfgtype" = 'native' ]; then
65ead2
		if [ -n "$ccenv_dumpmachine_switch" ]; then
65ead2
			ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
65ead2
				$ccenv_dumpmachine_switch 2>&3)
65ead2
		else
b29b40
			ccenv_host=$(printf '%s' $(uname -m)-$(uname -p)-$(uname -o) \
b29b40
				| tr '[[:upper:]]' '[[:lower:]]')
65ead2
		fi
65ead2
b3a29a
		ccenv_cchost=$ccenv_host
dee5ee
		return 0
dee5ee
	fi
dee5ee
65ead2
dee5ee
	if [ -n "$mb_cchost" ]; then
dee5ee
		ccenv_host="$mb_cchost"
dee5ee
	elif [ -n "$mb_host" ]; then
dee5ee
		ccenv_host="$mb_host"
dee5ee
	else
dee5ee
		ccenv_host=
dee5ee
	fi
dee5ee
65ead2
	if [ -z "$ccenv_host" ] && [ -n "$ccenv_dumpmachine_switch" ]; then
65ead2
		ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
65ead2
			$ccenv_dumpmachine_switch 2>&3)
dee5ee
		ccenv_cchost=$ccenv_host
65ead2
65ead2
	elif [ -z "$ccenv_host" ]; then
65ead2
		# assume that no -dumpmachine support means native build (fixme)
b29b40
		ccenv_host=$(printf '%s' $(uname -m)-$(uname -p)-$(uname -o) \
b29b40
			| tr '[[:upper:]]' '[[:lower:]]')
65ead2
		ccenv_cchost=$ccenv_host
65ead2
65ead2
	elif [ -n "$ccenv_dumpmachine_switch" ]; then
4fb916
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
dee5ee
		ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -"
dee5ee
dee5ee
		if [ -z "$mb_user_cc" ]; then
593a0e
			$(printf %s "$ccenv_cmd") < /dev/null > /dev/null \
dee5ee
				2>"$ccenv_tmp" || true
dee5ee
dee5ee
			ccenv_errors=$(cat "$ccenv_tmp")
dee5ee
dee5ee
			if [ -z "$ccenv_errors" ]; then
65ead2
				ccenv_tool_prolog 'C compiler for host'
dee5ee
				ccenv_tflags="--target=$ccenv_host"
dee5ee
				ccenv_cc="$ccenv_cc $ccenv_tflags"
65ead2
				ccenv_tool_epilog "$ccenv_cc"
db226e
			else
db226e
				printf '%s' "$ccenv_errors" >&3
dee5ee
			fi
dee5ee
		fi
dee5ee
4fb916
		rm -f "$ccenv_tmp"
4fb916
		unset ccenv_tmp
4fb916
65ead2
		ccenv_cchost=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
65ead2
			$ccenv_dumpmachine_switch 2>&3)
dee5ee
	fi
dee5ee
605c03
	if [ -z "$ccenv_dumpmachine_switch" ] && [ -n "$ccenv_host" ]; then
605c03
		ccenv_cchost="$ccenv_host"
605c03
605c03
	elif [ "$ccenv_cchost" != "$ccenv_host" ]; then
db226e
		printf 'error!\n' >&2
dee5ee
		printf 'ccenv:\n' >&2
dee5ee
		printf 'ccenv: ccenv_host:   %s \n' $ccenv_host >&2
dee5ee
		printf 'ccenv: ccenv_cchost: %s \n' $ccenv_cchost >&2
dee5ee
dee5ee
		if [ -z "$ccenv_tflags" ]; then
dee5ee
			printf 'ccenv:\n' >&2
dee5ee
			printf 'ccenv: ccenv_host and ccenv_cchost do not match, most likely because:\n' >&2
dee5ee
			printf 'ccenv: (1) you explicitly set CC (or passed --compiler=...)\n' >&2
dee5ee
			printf 'ccenv: (2) the selected compiler does not accept --target=...\n' >&2
dee5ee
			printf 'ccenv: (3) the host reported by -dumpmachine differs from the one you requested.\n' >&2
dee5ee
		fi
dee5ee
dee5ee
		if [ -n "$ccenv_errors" ]; then
dee5ee
			printf 'ccenv:\n' >&2
dee5ee
			printf 'ccenv: something went wrong, see the command and compiler message below.\n\n' >&2
dee5ee
			printf 'cmd: %s < /dev/null > /dev/null\n' "$ccenv_cmd" >&2
dee5ee
			printf '%s\n\n' "$ccenv_errors" >&2
dee5ee
		else
dee5ee
			printf 'ccenv:\n' >&2
dee5ee
			printf 'ccenv: something went wrong, bailing out.\n\n' >&2
dee5ee
		fi
dee5ee
dee5ee
		return 2
dee5ee
	fi
dee5ee
}
dee5ee
dee5ee
ccenv_set_cpp()
dee5ee
{
1b8de4
	ccenv_tool_prolog 'C pre-processor'
1b8de4
dee5ee
	case "$ccenv_cc_cmd" in
dee5ee
		cc | c99 | c11 | gcc)
dee5ee
			ccenv_cpp_prefix=
dee5ee
			ccenv_candidates="cpp" ;;
dee5ee
dee5ee
		clang )
dee5ee
			ccenv_cpp_prefix=
dee5ee
			ccenv_candidates="clang-cpp" ;;
dee5ee
dee5ee
		*-cc )
dee5ee
			ccenv_cpp_prefix=${ccenv_cc_cmd%-cc*}-
dee5ee
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
dee5ee
dee5ee
		*-c99 )
dee5ee
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c99*}-
dee5ee
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
dee5ee
dee5ee
		*-c11 )
dee5ee
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c11*}-
dee5ee
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
dee5ee
dee5ee
		*-gcc )
dee5ee
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
dee5ee
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
dee5ee
dee5ee
		*-clang )
dee5ee
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
dee5ee
			ccenv_candidates="${ccenv_cpp_prefix}clang-cpp" ;;
dee5ee
dee5ee
		* )
dee5ee
			ccenv_cpp="$ccenv_cc -E"
1b8de4
			ccenv_tool_epilog "$ccenv_cpp"
dee5ee
			return 0
dee5ee
	esac
dee5ee
dee5ee
	ccenv_find_tool
dee5ee
dee5ee
	if [ "$ccenv_tool" = false ]; then
dee5ee
		ccenv_cpp="$ccenv_cc -E"
dee5ee
	elif [ -n "$ccenv_tflags" ]; then
dee5ee
		ccenv_cpp="$ccenv_tool $ccenv_tflags"
dee5ee
	else
dee5ee
		ccenv_cpp="$ccenv_tool"
dee5ee
	fi
1b8de4
1b8de4
	ccenv_tool_epilog "$ccenv_cpp"
dee5ee
}
dee5ee
dee5ee
ccenv_set_cxx()
dee5ee
{
1b8de4
	ccenv_tool_prolog 'C++ compiler'
1b8de4
dee5ee
	case "$ccenv_cc_cmd" in
dee5ee
		cc | c99 | c11 )
dee5ee
			ccenv_cxx_prefix=
dee5ee
			ccenv_candidates="cxx c++" ;;
dee5ee
dee5ee
		gcc )
dee5ee
			ccenv_cxx_prefix=
dee5ee
			ccenv_candidates="g++" ;;
dee5ee
dee5ee
		clang )
dee5ee
			ccenv_cxx_prefix=
dee5ee
			ccenv_candidates="clang++" ;;
dee5ee
dee5ee
		*-gcc )
4a5ee2
			ccenv_cxx_prefix=${ccenv_cc_cmd%-gcc*}-
4a5ee2
			ccenv_candidates="${ccenv_cxx_prefix}g++" ;;
dee5ee
dee5ee
		*-clang )
4a5ee2
			ccenv_cxx_prefix=${ccenv_cc_cmd%-clang*}-
4a5ee2
			ccenv_candidates="${ccenv_cxx_prefix}clang++" ;;
4a5ee2
4a5ee2
		/*cc | /*c99 | /*c11 )
4a5ee2
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
4a5ee2
			ccenv_candidates="${ccenv_cxx_prefix}/cxx"
4a5ee2
			ccenv_candidates="${ccenv_candidates} ${ccenv_cxx_prefix}/c++" ;;
4a5ee2
4a5ee2
		/*gcc )
4a5ee2
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
4a5ee2
			ccenv_candidates="${ccenv_cxx_prefix}/g++" ;;
dee5ee
4a5ee2
		/*clang )
4a5ee2
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
4a5ee2
			ccenv_candidates="${ccenv_cxx_prefix}/clang++" ;;
dee5ee
dee5ee
		* )
dee5ee
			ccenv_cxx="$ccenv_cc -xc++"
1b8de4
			ccenv_tool_epilog "$ccenv_cxx"
dee5ee
			return 0
dee5ee
	esac
dee5ee
dee5ee
	ccenv_find_tool
dee5ee
dee5ee
	if [ "$ccenv_tool" = false ]; then
dee5ee
		ccenv_cxx="$ccenv_cc -xc++"
dee5ee
	elif [ -n "$ccenv_tflags" ]; then
dee5ee
		ccenv_cxx="$ccenv_tool $ccenv_tflags"
dee5ee
	else
dee5ee
		ccenv_cxx="$ccenv_tool"
dee5ee
	fi
1b8de4
1b8de4
	ccenv_tool_epilog "$ccenv_cxx"
dee5ee
}
dee5ee
dee5ee
ccenv_set_cc_host()
dee5ee
{
86aa73
	ccenv_attr_prolog 'system'
dee5ee
	ccenv_cc_host="$ccenv_cchost"
1b8de4
	ccenv_attr_epilog "$ccenv_cc_host"
dee5ee
}
dee5ee
dee5ee
ccenv_set_cc_bits()
dee5ee
{
1b8de4
	ccenv_attr_prolog 'bits'
1b8de4
dee5ee
	ccenv_internal_size=
dee5ee
	ccenv_internal_type='void *'
dee5ee
	ccenv_internal_test='char x[(sizeof(%s) == %s/8) ? 1 : -1];'
dee5ee
dee5ee
	for ccenv_internal_guess in 64 32 128; do
24188a
		if [ -z "${ccenv_internal_size:-}" ]; then
47fc84
			ccenv_internal_str=$(printf "$ccenv_internal_test"  \
47fc84
				"$ccenv_internal_type"                      \
dee5ee
				"$ccenv_internal_guess")
dee5ee
9a28a2
			ccenv_expr='ccenv_stdin_input=$ccenv_'${ccenv_cfgtype}'_stdin_input'
9a28a2
			eval ${ccenv_expr}
9a28a2
9a28a2
			if [ "$ccenv_stdin_input" = 'yes' ]; then
32fae0
				printf '%s' "$ccenv_internal_str"                   \
32fae0
						| eval $ccenv_cc -S -xc - -o -      \
32fae0
						  $(printf '%s' "$ccenv_cflags")    \
32fae0
					> /dev/null 2>&3                            \
32fae0
				&& ccenv_internal_size=$ccenv_internal_guess
32fae0
			else
32fae0
				ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
32fae0
32fae0
				printf '%s' "$ccenv_internal_str" \
32fae0
					> "$ccenv_tmpname"
32fae0
32fae0
				$ccenv_cc -c "$ccenv_tmpname" -o a.out \
32fae0
					> /dev/null 2>&3                \
32fae0
				&& ccenv_internal_size=$ccenv_internal_guess
32fae0
32fae0
				rm "$ccenv_tmpname"
32fae0
			fi
dee5ee
		fi
dee5ee
	done
dee5ee
dee5ee
	ccenv_cc_bits=$ccenv_internal_size
1b8de4
1b8de4
	ccenv_attr_epilog "$ccenv_cc_bits"
dee5ee
}
dee5ee
dee5ee
ccenv_set_cc_underscore()
dee5ee
{
1b8de4
	ccenv_attr_prolog 'prepended underscores'
1b8de4
dee5ee
	ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe'
dee5ee
	ccenv_fn_code='int %s(void){return 0;}'
dee5ee
22f6f0
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
22f6f0
22f6f0
	printf "$ccenv_fn_code" $ccenv_fn_name \
22f6f0
		> "$ccenv_tmpname"
22f6f0
22f6f0
	$ccenv_cc -c "$ccenv_tmpname" -o a.out \
22f6f0
		> /dev/null 2>&3
22f6f0
22f6f0
	if "$ccenv_nm" a.out | grep          \
22f6f0
			-e "^_$ccenv_fn_name" \
22f6f0
			-e " _$ccenv_fn_name"  \
22f6f0
			> /dev/null; then
f50b67
		ccenv_cc_underscore='_'
1b8de4
		ccenv_attr_epilog 'yes'
22f6f0
	else
22f6f0
		ccenv_attr_epilog 'no'
f50b67
	fi
dee5ee
22f6f0
	rm "$ccenv_tmpname"
22f6f0
	rm a.out
1b8de4
dee5ee
	return 0
dee5ee
}
dee5ee
dee5ee
ccenv_create_framework_executable()
dee5ee
{
9922c7
	if [ "$ccenv_cfgtype" = 'host' ]; then
9922c7
		if [ "$mb_freestanding" = 'yes' ]; then
9922c7
			return 1
9922c7
		fi
9922c7
	fi
9922c7
dee5ee
	if [ -f $ccenv_image ]; then
dee5ee
		mv $ccenv_image $ccenv_image.tmp
dee5ee
		rm -f $ccenv_image.tmp
dee5ee
	fi
dee5ee
a50316
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
a50316
dee5ee
	printf 'int main(void){return 0;}'  \
a50316
		> "$ccenv_tmpname"
dee5ee
a50316
	if $ccenv_cc "$ccenv_tmpname" -o $ccenv_image 2>&3; then
a50316
		ccenv_ret=0
9922c7
		ccenv_cc_environment='hosted'
a50316
	else
a50316
		ccenv_ret=1
a50316
	fi
a50316
a50316
	rm "$ccenv_tmpname"
a50316
a50316
	return $ccenv_ret
dee5ee
}
dee5ee
dee5ee
ccenv_create_freestanding_executable()
dee5ee
{
dee5ee
	if [ -f $ccenv_image ]; then
dee5ee
		mv $ccenv_image $ccenv_image.tmp
dee5ee
		rm -f $ccenv_image.tmp
dee5ee
	fi
dee5ee
dee5ee
	if [ -z "ccenv_cc_underscore" ]; then
dee5ee
		ccenv_start_fn='_start'
dee5ee
	else
dee5ee
		ccenv_start_fn='start'
dee5ee
	fi
dee5ee
a50316
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
dee5ee
a50316
	printf 'int %s(void){return 0;}' "$ccenv_start_fn" \
a50316
		> "$ccenv_tmpname"
dee5ee
a50316
	if $ccenv_cc "$ccenv_tmpname"         \
a50316
			-ffreestanding         \
a50316
			-nostdlib -nostartfiles \
a50316
			-o $ccenv_image          \
a50316
			2>&3; then
a50316
		ccenv_ret=0
9922c7
		ccenv_cc_environment='freestanding'
a50316
	else
a50316
		ccenv_ret=1
a50316
	fi
a50316
a50316
	rm "$ccenv_tmpname"
a50316
a50316
	return $ccenv_ret
dee5ee
}
dee5ee
1b8de4
ccenv_set_cc_binfmt_error()
1b8de4
{
1b8de4
	ccenv_attr_epilog '(unable to create executable)'
1b8de4
}
1b8de4
dee5ee
ccenv_set_cc_binfmt()
dee5ee
{
dee5ee
	ccenv_use_perk=
e41026
	ccenv_use_otool=
dee5ee
	ccenv_use_readelf=
dee5ee
	ccenv_use_readobj=
dee5ee
	ccenv_use_bfd_objdump=
dee5ee
	ccenv_use_llvm_objdump=
dee5ee
1b8de4
	ccenv_attr_prolog 'binary format'
1b8de4
dee5ee
	ccenv_create_framework_executable               \
dee5ee
		|| ccenv_create_freestanding_executable \
1b8de4
		|| ccenv_set_cc_binfmt_error            \
dee5ee
		|| return 0
dee5ee
dee5ee
	# PE / perk
dee5ee
	if [ -n "$ccenv_perk" ]; then
db226e
		if $ccenv_perk $ccenv_image 2>&3; then
f50b67
			ccenv_cc_binfmt='PE'
f50b67
			ccenv_use_perk=yes
f50b67
		fi
dee5ee
	fi
dee5ee
dee5ee
	# ELF / readelf
dee5ee
	if [ -n "$ccenv_readelf" ] && [ -z "$ccenv_cc_binfmt" ]; then
db226e
		if $ccenv_readelf -h $ccenv_image 2>&3               \
f50b67
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
f50b67
				| grep 'Magic:7f454c46'              \
f50b67
					> /dev/null; then
f50b67
			ccenv_cc_binfmt='ELF'
f50b67
			ccenv_use_readelf=yes
f50b67
		fi
dee5ee
	fi
dee5ee
dee5ee
	# a marble of astonishing design:
dee5ee
	# llvm-readelf also parses PE and Mach-O
dee5ee
dee5ee
	if [ -n "$ccenv_readelf_llvm" ]; then
dee5ee
		ccenv_readany="$ccenv_readelf_llvm"
dee5ee
	else
dee5ee
		ccenv_readany="$ccenv_readelf"
dee5ee
	fi
dee5ee
dee5ee
	# PE / readelf
dee5ee
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
db226e
		if $ccenv_readany -h $ccenv_image 2>&3               \
f50b67
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
f50b67
				| grep 'Magic:MZ'                    \
f50b67
					> /dev/null; then
f50b67
			ccenv_cc_binfmt='PE'
f50b67
			ccenv_use_readelf=yes
f50b67
		fi
dee5ee
	fi
dee5ee
e41026
	# MACHO-64 / otool
e41026
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
db226e
		if $ccenv_otool -hv $ccenv_image 2>&3        \
f50b67
				| grep -i 'MH_MAGIC_64'      \
f50b67
					> /dev/null; then
f50b67
			ccenv_cc_binfmt='MACHO'
f50b67
			ccenv_use_otool=yes
f50b67
		fi
e41026
	fi
e41026
e41026
	# MACHO-32 / otool
e41026
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
db226e
		if $ccenv_otool -hv $ccenv_image 2>&3        \
f50b67
				| grep -i 'MH_MAGIC'         \
f50b67
					> /dev/null; then
f50b67
			ccenv_cc_binfmt='MACHO'
f50b67
			ccenv_use_otool=yes
f50b67
		fi
e41026
	fi
e41026
dee5ee
	# MACHO-64 / readelf
dee5ee
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
db226e
		if $ccenv_readany -h $ccenv_image 2>&3                    \
f50b67
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
f50b67
				| grep -i '(0xfeedfacf)'                  \
f50b67
					> /dev/null; then
f50b67
			ccenv_cc_binfmt='MACHO'
f50b67
			ccenv_use_readelf=yes
f50b67
		fi
dee5ee
	fi
dee5ee
dee5ee
	# MACHO-32 / readelf
dee5ee
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
db226e
		if $ccenv_readany -h $ccenv_image 2>&3                    \
f50b67
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
f50b67
				| grep -i '(0xcafebabe)'                  \
f50b67
					> /dev/null; then
f50b67
			ccenv_cc_binfmt='MACHO'
f50b67
			ccenv_use_readelf=yes
f50b67
		fi
dee5ee
	fi
dee5ee
dee5ee
	# MACHO / readobj
dee5ee
	if [ -n "$ccenv_readobj" ] && [ -z "$ccenv_cc_binfmt" ]; then
db226e
		if $ccenv_readobj $ccenv_image 2>&3                  \
1fb10f
				| grep -i 'Format:'                  \
1fb10f
				| sed  -e 's/ /_/g'                  \
f50b67
				| grep -i '_Mach-O_'                 \
f50b67
					> /dev/null; then
f50b67
			ccenv_cc_binfmt='MACHO'
f50b67
			ccenv_use_readobj=yes
f50b67
		fi
dee5ee
	fi
dee5ee
dee5ee
	# MACHO / objdump (llvm)
dee5ee
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
f50b67
		if $ccenv_objdump -section-headers $ccenv_image  \
db226e
					2>&3                     \
f50b67
				| grep -i 'file format Mach-O'   \
f50b67
					> /dev/null; then
f50b67
			ccenv_cc_binfmt='MACHO'
f50b67
			ccenv_use_objdump=yes
f50b67
		fi
dee5ee
	fi
dee5ee
dee5ee
	# MACHO / objdump (bfd)
dee5ee
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
db226e
		$ccenv_objdump -h  $ccenv_image 2>&3              \
dee5ee
			| grep -i 'file format Mach-O'            \
dee5ee
				> /dev/null                       \
dee5ee
		&& ccenv_cc_binfmt='MACHO'                        \
dee5ee
		&& ccenv_use_objdump=yes
dee5ee
	fi
dee5ee
dee5ee
	# PE / objdump (bfd)
dee5ee
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
db226e
		if $ccenv_objdump -h  $ccenv_image 2>&3        \
f50b67
				| grep -i 'file format pei-'   \
f50b67
					> /dev/null; then
f50b67
			ccenv_cc_binfmt='PE'
f50b67
			ccenv_use_bfd_objdump=yes
f50b67
		fi
dee5ee
	fi
1b8de4
1b8de4
	ccenv_attr_epilog "$ccenv_cc_binfmt"
dee5ee
}
dee5ee
dee5ee
ccenv_set_os_pe()
dee5ee
{
9922c7
	if [ "$ccenv_cc_environment" = 'freestanding' ]; then
dee5ee
		case "$ccenv_cchost" in
dee5ee
			*-midipix | *-midipix-* )
dee5ee
				ccenv_os='midipix' ;;
dee5ee
			*-mingw | *-mingw32 | *-mingw64 )
dee5ee
				ccenv_os='mingw' ;;
dee5ee
			*-mingw-* | *-mingw32-* | *-mingw64 )
dee5ee
				ccenv_os='mingw' ;;
dee5ee
			*-msys | *-msys2 | *-msys-* | *-msys2-* )
dee5ee
				ccenv_os='msys' ;;
dee5ee
			*-cygwin | *-cygwin-* )
dee5ee
				ccenv_os='cygwin' ;;
dee5ee
		esac
dee5ee
	fi
dee5ee
dee5ee
	if [ -n "$ccenv_os" ]; then
dee5ee
		return 0
dee5ee
	fi
dee5ee
dee5ee
	if [ -n "$ccenv_use_perk" ]; then
dee5ee
		ccenv_framework=$($ccenv_perk -y $ccenv_image)
dee5ee
		ccenv_os=${ccenv_framework#*-*-*-*}
dee5ee
	fi
dee5ee
dee5ee
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
dee5ee
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
dee5ee
			| grep 'cygwin1.dll' > /dev/null                \
dee5ee
		&& ccenv_os='cygwin'
dee5ee
	fi
dee5ee
dee5ee
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
dee5ee
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
dee5ee
			| grep 'msys-2.0.dll' > /dev/null               \
dee5ee
		&& ccenv_os='msys'
dee5ee
	fi
dee5ee
dee5ee
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
dee5ee
		$ccenv_objdump_bfd -x $ccenv_image          \
dee5ee
			| grep -i 'DLL Name' | grep '.CRT'  \
dee5ee
				> /dev/null                 \
dee5ee
		&& $ccenv_objdump_bfd -x $ccenv_image       \
dee5ee
			| grep -i 'DLL Name' | grep '.bss'  \
dee5ee
				> /dev/null                 \
dee5ee
		&& $ccenv_objdump_bfd -x $ccenv_image       \
dee5ee
			| grep -i 'DLL Name' | grep '.tls'  \
dee5ee
				> /dev/null                 \
dee5ee
		&& ccenv_os='mingw'
dee5ee
	fi
dee5ee
}
dee5ee
dee5ee
ccenv_set_os_macho()
dee5ee
{
dee5ee
	case "$ccenv_cchost" in
dee5ee
		*-apple-darwin* )
dee5ee
			ccenv_os='darwin' ;;
dee5ee
	esac
dee5ee
}
dee5ee
dee5ee
ccenv_set_os()
dee5ee
{
1b8de4
	ccenv_attr_prolog 'os name'
1b8de4
dee5ee
	case "$ccenv_cc_binfmt" in
dee5ee
		PE )
dee5ee
			ccenv_set_os_pe ;;
dee5ee
		MACHO )
dee5ee
			ccenv_set_os_macho ;;
dee5ee
	esac
dee5ee
dee5ee
	if [ -n "$ccenv_os" ]; then
1b8de4
		ccenv_attr_epilog "$ccenv_os"
dee5ee
		return 0
dee5ee
	fi
dee5ee
dee5ee
	case "$ccenv_cchost" in
dee5ee
		*-*-*-* )
900b9d
			ccenv_tip=${ccenv_cchost%-*}
dee5ee
			ccenv_os=${ccenv_tip#*-*-}
dee5ee
			;;
900b9d
		*-*-musl | *-*-gnu )
900b9d
			ccenv_tip=${ccenv_cchost%-*}
dee5ee
			ccenv_os=${ccenv_tip#*-}
dee5ee
			;;
900b9d
		*-*-* )
900b9d
			ccenv_os=${ccenv_cchost#*-*-}
900b9d
			;;
900b9d
		*-* )
900b9d
			ccenv_os=${ccenv_cchost#*-}
900b9d
			;;
dee5ee
	esac
dee5ee
dee5ee
	if [ -z "$ccenv_os" ]; then
dee5ee
		ccenv_os='anyos'
dee5ee
	fi
1b8de4
1b8de4
	ccenv_attr_epilog "$ccenv_os"
dee5ee
}
dee5ee
dee5ee
ccenv_set_os_flags()
dee5ee
{
dee5ee
	case "$ccenv_os" in
dee5ee
		darwin )
dee5ee
			ccenv_cflags_os='-D_DARWIN_C_SOURCE'
dee5ee
			ccenv_cflags_pic='-fPIC'
dee5ee
			;;
dee5ee
		midipix )
dee5ee
			ccenv_cflags_os=
dee5ee
			ccenv_cflags_pic='-fPIC'
dee5ee
			;;
dee5ee
		cygwin )
dee5ee
			ccenv_cflags_os=
dee5ee
			ccenv_cflags_pic=
dee5ee
			;;
dee5ee
		msys | msys* | mingw | mingw* )
dee5ee
			ccenv_cflags_os='-U__STRICT_ANSI__'
dee5ee
			ccenv_cflags_pic=
dee5ee
			;;
dee5ee
		* )
dee5ee
			ccenv_cflags_os=
dee5ee
			ccenv_cflags_pic='-fPIC'
dee5ee
			;;
dee5ee
	esac
dee5ee
}
dee5ee
dee5ee
ccenv_set_os_semantics()
dee5ee
{
dee5ee
	# binary_format - core_api - ex_api - dependency_resolution
dee5ee
1b8de4
	ccenv_attr_prolog 'os semantics'
1b8de4
dee5ee
	case "$ccenv_os" in
dee5ee
		linux )
dee5ee
			ccenv_os_semantics='elf-posix-linux-ldso'
dee5ee
			;;
dee5ee
		bsd )
dee5ee
			ccenv_os_semantics='elf-posix-bsd-ldso'
dee5ee
			;;
dee5ee
		darwin )
dee5ee
			ccenv_os_semantics='macho-posix-osx-ldso'
dee5ee
			;;
dee5ee
		midipix )
dee5ee
			ccenv_os_semantics='pe-posix-winnt-ldso'
dee5ee
			;;
dee5ee
		cygwin )
dee5ee
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
dee5ee
			;;
dee5ee
		msys )
dee5ee
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
dee5ee
			;;
dee5ee
		mingw )
dee5ee
			ccenv_os_semantics='pe-win32-winnt-unsafe'
dee5ee
			;;
dee5ee
	esac
dee5ee
dee5ee
	if [ -n "$ccenv_os_semantics" ]; then
1b8de4
		ccenv_attr_epilog "$ccenv_os_semantics"
dee5ee
		return 0
dee5ee
	fi
dee5ee
dee5ee
	if [ -n "$ccenv_cc_binfmt" ]; then
dee5ee
		ccenv_os_semantics_pattern='%s-posix-anyos-unknown'
dee5ee
		ccenv_os_semantics=$(printf                   \
dee5ee
				"$ccenv_os_semantics_pattern"  \
dee5ee
				"$ccenv_cc_binfmt"              \
dee5ee
			| tr '[:upper:]' '[:lower:]')
dee5ee
	else
dee5ee
		ccenv_os_semantics='unknown-posix-anyos-unknown'
dee5ee
	fi
1b8de4
1b8de4
	ccenv_attr_epilog "$ccenv_os_semantics"
dee5ee
}
dee5ee
882922
ccenv_set_os_dso_format()
882922
{
882922
	ccenv_attr_prolog 'os dso format'
882922
882922
	case "$ccenv_cc_arfmt" in
882922
		common )
882922
			ccenv_cc_sofmt="$ccenv_cc_binfmt"
882922
			;;
882922
882922
		bigaf )
882922
			ccenv_libgcc_s_a_header=$(od -b -N8             \
882922
				$($ccenv_cc -print-file-name=libgcc_s.a) \
882922
					2>/dev/null                       \
882922
					| head -n1)
882922
882922
			ccenv_libgcc_s_so_header=$(od -b -N8             \
882922
				$($ccenv_cc -print-file-name=libgcc_s.so) \
882922
					2>/dev/null                        \
882922
					| head -n1)
882922
882922
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_bigaf_header" ]; then
882922
				ccenv_cc_sofmt='bigaf'
882922
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_bigaf_header" ]; then
882922
				ccenv_cc_sofmt='bigaf'
882922
			else
882922
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
882922
			fi
882922
			;;
882922
882922
		aiaff )
882922
			ccenv_libgcc_s_a_header=$(od -b -N8               \
882922
				$($ccenv_cc -print-file-name=libgcc_s.a) \
882922
					| head -n1)
882922
882922
			ccenv_libgcc_s_so_header=$(od -b -N8               \
882922
				$($ccenv_cc -print-file-name=libgcc_s.so) \
882922
					| head -n1)
882922
882922
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_aiaff_header" ]; then
882922
				ccenv_cc_sofmt='aiaff'
882922
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_aiaff_header" ]; then
882922
				ccenv_cc_sofmt='aiaff'
882922
			else
882922
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
882922
			fi
882922
			;;
882922
	esac
882922
e2f6d2
	if [ "$ccenv_cfgtype" = 'host' ]; then
e2f6d2
		case "$ccenv_cc_sofmt" in
e2f6d2
			bigaf | aiaff )
e2f6d2
				mb_shared_lib_cmd='$(AR) -rcs'
e2f6d2
				mb_shared_lib_ldflags=
e2f6d2
				;;
e2f6d2
e2f6d2
			* )
e2f6d2
				mb_shared_lib_cmd='$(CC) -shared -o'
e2f6d2
				mb_shared_lib_ldflags='$(LDFLAGS_SHARED)'
e2f6d2
				;;
e2f6d2
		esac
e2f6d2
	fi
e2f6d2
882922
	ccenv_attr_epilog "$ccenv_cc_sofmt"
882922
}
882922
dee5ee
ccenv_set_os_dso_exrules()
dee5ee
{
1b8de4
	ccenv_attr_prolog 'os dso exrules'
1b8de4
dee5ee
	case "$ccenv_os" in
dee5ee
		midipix )
dee5ee
			ccenv_os_dso_exrules='pe-mdso'
dee5ee
			;;
dee5ee
		* )
dee5ee
			if [ "$ccenv_cc_binfmt" = 'PE' ]; then
dee5ee
				ccenv_os_dso_exrules='pe-dlltool'
dee5ee
			else
dee5ee
				ccenv_os_dso_exrules='default'
dee5ee
			fi
dee5ee
	esac
1b8de4
1b8de4
	ccenv_attr_epilog "$ccenv_os_dso_exrules"
dee5ee
}
dee5ee
dee5ee
ccenv_set_os_dso_linkage()
dee5ee
{
dee5ee
	# todo: PIC, PIE, and friends
1b8de4
	ccenv_attr_prolog 'os linkage'
dee5ee
	ccenv_os_dso_linkage='default'
1b8de4
	ccenv_attr_epilog "$ccenv_os_dso_linkage"
dee5ee
}
dee5ee
dee5ee
ccenv_set_os_dso_patterns_darwin()
dee5ee
{
dee5ee
	ccenv_os_app_prefix=
dee5ee
	ccenv_os_app_suffix=
dee5ee
dee5ee
	ccenv_os_lib_prefix=lib
dee5ee
	ccenv_os_lib_suffix=.dylib
dee5ee
dee5ee
	ccenv_os_implib_ext=.invalid
dee5ee
	ccenv_os_libdef_ext=.invalid
dee5ee
dee5ee
	ccenv_os_archive_ext=.a
dee5ee
	ccenv_os_soname=symlink
dee5ee
dee5ee
	ccenv_os_lib_prefixed_suffix=
dee5ee
	ccenv_os_lib_suffixed_suffix='$(OS_LIB_SUFFIX)'
dee5ee
}
dee5ee
dee5ee
ccenv_set_os_dso_patterns_mdso()
dee5ee
{
dee5ee
	ccenv_os_app_prefix=
dee5ee
	ccenv_os_app_suffix=
dee5ee
dee5ee
	ccenv_os_lib_prefix=lib
dee5ee
	ccenv_os_lib_suffix=.so
dee5ee
dee5ee
	ccenv_os_implib_ext=.lib.a
dee5ee
	ccenv_os_libdef_ext=.so.def
dee5ee
dee5ee
	ccenv_os_archive_ext=.a
dee5ee
	ccenv_os_soname=symlink
dee5ee
dee5ee
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
dee5ee
	ccenv_os_lib_suffixed_suffix=
dee5ee
}
dee5ee
dee5ee
ccenv_set_os_dso_patterns_dlltool()
dee5ee
{
dee5ee
	ccenv_os_app_prefix=
dee5ee
	ccenv_os_app_suffix=.exe
dee5ee
dee5ee
	ccenv_os_lib_prefix=lib
dee5ee
	ccenv_os_lib_suffix=.dll
dee5ee
dee5ee
	ccenv_os_implib_ext=.dll.a
dee5ee
	ccenv_os_libdef_ext=.def
dee5ee
dee5ee
	ccenv_os_archive_ext=.a
dee5ee
	ccenv_os_soname=copy
dee5ee
dee5ee
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
dee5ee
	ccenv_os_lib_suffixed_suffix=
dee5ee
}
dee5ee
dee5ee
ccenv_set_os_dso_patterns_default()
dee5ee
{
dee5ee
	ccenv_os_app_prefix=
dee5ee
	ccenv_os_app_suffix=
dee5ee
dee5ee
	ccenv_os_lib_prefix=lib
dee5ee
	ccenv_os_lib_suffix=.so
dee5ee
dee5ee
	ccenv_os_implib_ext=.invalid
dee5ee
	ccenv_os_libdef_ext=.invalid
dee5ee
dee5ee
	ccenv_os_archive_ext=.a
dee5ee
	ccenv_os_soname=symlink
dee5ee
dee5ee
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
dee5ee
	ccenv_os_lib_suffixed_suffix=
dee5ee
}
dee5ee
dee5ee
ccenv_set_os_dso_patterns()
dee5ee
{
dee5ee
	# sover: .so.x.y.z
dee5ee
	# verso: .x.y.z.so
dee5ee
dee5ee
	case "$ccenv_os" in
dee5ee
		darwin )
dee5ee
			ccenv_set_os_dso_patterns_darwin
dee5ee
			;;
dee5ee
		midipix )
dee5ee
			ccenv_set_os_dso_patterns_mdso
dee5ee
			;;
dee5ee
		cygwin | msys | mingw )
dee5ee
			ccenv_set_os_dso_patterns_dlltool
dee5ee
			;;
dee5ee
		* )
dee5ee
			ccenv_set_os_dso_patterns_default
dee5ee
			;;
dee5ee
	esac
dee5ee
}
dee5ee
2732d1
ccenv_set_os_pe_switches()
2732d1
{
f18b3a
	if [ "$ccenv_cc_binfmt" = 'PE' ] && [ -z "$ccenv_pe_subsystem" ]; then
2732d1
		case "$ccenv_os" in
2732d1
			midipix | mingw )
2732d1
				ccenv_pe_subsystem='windows'
2732d1
				;;
2732d1
			* )
2732d1
				ccenv_pe_subsystem='console'
2732d1
				;;
2732d1
		esac
2732d1
	fi
2732d1
}
2732d1
dee5ee
ccenv_output_defs()
dee5ee
{
dee5ee
	ccenv_in="$mb_project_dir/sofort/ccenv/ccenv.in"
dee5ee
	ccenv_mk="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
856efe
	ccenv_tmp=
dee5ee
2732d1
	if [ "$ccenv_cc_binfmt" = 'PE' ]; then
2732d1
		ccenv_pe="$mb_project_dir/sofort/ccenv/pedefs.in"
2732d1
		ccenv_in="$ccenv_in $ccenv_pe"
2732d1
	fi
2732d1
dee5ee
	if [ $ccenv_cfgtype = 'native' ]; then
dee5ee
4fb916
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
dee5ee
7a5693
		sed                                      \
84bac9
				-e 's/^[[:space:]]*$/@/g' \
7a5693
				-e 's/^/NATIVE_/'          \
7a5693
				-e 's/NATIVE_@//g'          \
7a5693
				-e 's/NATIVE_#/#/g'          \
7a5693
				-e 's/       =/=/g'           \
7a5693
				-e 's/       +=/+=/g'          \
d4c555
			$(printf '%s ' $ccenv_in)               \
d4c555
				> "$ccenv_tmp"
dee5ee
dee5ee
		ccenv_in="$ccenv_tmp"
4fb916
	else
856efe
		unset ccenv_tmp
dee5ee
	fi
dee5ee
0a7c6e
	ccenv_var_defs=
5b6753
	ccenv_sed_substs="-e s/@ccenv_cfgtype@/${ccenv_cfgtype}/g"
0a7c6e
dee5ee
	ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
0a7c6e
		| grep -v '^#');
dee5ee
5b6753
	ccenv_exvars="ccenv_makevar_prefix"
dee5ee
0a7c6e
	for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do
0a7c6e
		ccenv_sed_subst=$(printf '%s %s%s%s' \
0a7c6e
				'-e' "'s^@$__var@"    \
0a7c6e
				"^___${__var}___"      \
0a7c6e
				"^g'")
0a7c6e
0a7c6e
		ccenv_sed_substs="$ccenv_sed_substs $ccenv_sed_subst"
0a7c6e
0a7c6e
		ccenv_var_def=$(printf '%s%s="${%s}"' "-D" "___${__var}___" "${__var}")
0a7c6e
		eval ccenv_var_defs='"$ccenv_var_defs "$ccenv_var_def'
0a7c6e
	done
dee5ee
0a7c6e
	eval sed $ccenv_sed_substs $(printf '%s ' $ccenv_in) \
0a7c6e
			| eval m4 $ccenv_var_defs -           \
0a7c6e
			| sed -e 's/[[:blank:]]*$//g'          \
dee5ee
		> "$ccenv_mk"
dee5ee
0d6a7c
	if [ "$ccenv_cfgtype" = 'host' ]; then
12a073
		for __var in $(printf '%s' "$ccenv_vars"); do
0d6a7c
			ccenv_src_var=$__var
0d6a7c
			ccenv_dst_var=mb_${__var#*ccenv_}
0d6a7c
			ccenv_var_expr='${'$ccenv_src_var':-}'
0d6a7c
			eval $ccenv_dst_var=$ccenv_var_expr
0d6a7c
0d6a7c
		done
0d6a7c
0d6a7c
		mb_host=$ccenv_host
0d6a7c
		mb_cchost=$ccenv_cchost
0d6a7c
	else
12a073
		for __var in $(printf '%s' "$ccenv_vars"); do
0d6a7c
			ccenv_src_var=$__var
0d6a7c
			ccenv_dst_var=mb_native_${__var#*ccenv_}
0d6a7c
			ccenv_var_expr='${'$ccenv_src_var':-}'
0d6a7c
			eval "$ccenv_dst_var=$ccenv_var_expr"
0d6a7c
		done
0d6a7c
0d6a7c
		mb_native_host=$ccenv_host
0d6a7c
		mb_native_cchost=$ccenv_cchost
0d6a7c
	fi
4fb916
4fb916
	if [ -n "${ccenv_tmp:-}" ]; then
4fb916
		rm -f "$ccenv_tmp"
4fb916
		unset ccenv_tmp
4fb916
	fi
beeb0a
beeb0a
	eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\'
e38ae0
	eval 'ccenv_'${ccenv_cfgtype}'_cc_environment'=\'$ccenv_cc_environment\'
dee5ee
}
dee5ee
b62a6f
ccenv_set_cc_switch_vars()
b62a6f
{
13fb2a
	printf '\n# %s cflags: supported compiler switches\n' "$ccenv_cfgtype" \
13fb2a
		>> "$ccenv_mk"
13fb2a
b62a6f
	if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
01eda1
		ccenv_switch_vars=$(cat                            \
b62a6f
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
b62a6f
			$mb_project_dir/project/config/ccswitch.strs \
01eda1
		| grep -v -e '^#' -e '^-Wl,'                          \
01eda1
		| sort -u)
b62a6f
	else
40216d
		ccenv_switch_vars=$(grep -v -e '^#' -e '^-Wl,'     \
b62a6f
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
b62a6f
			| sort -u)
b62a6f
	fi
b62a6f
b62a6f
	if [ $ccenv_cfgtype = 'host' ]; then
b62a6f
		ccenv_makevar_prefix='_CFLAGS_'
b62a6f
		cfgtest_host_section
b62a6f
	else
b62a6f
		ccenv_makevar_prefix='_NATIVE_CFLAGS_'
b62a6f
		cfgtest_native_section
b62a6f
	fi
b62a6f
b62a6f
	for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
b62a6f
		ccenv_make_var=${ccenv_switch_var%=}
b62a6f
		ccenv_make_var=${ccenv_make_var%,}
b62a6f
b62a6f
		ccenv_make_var=${ccenv_make_var##---}
b62a6f
		ccenv_make_var=${ccenv_make_var##--}
b62a6f
		ccenv_make_var=${ccenv_make_var##-}
b62a6f
b62a6f
		ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
b62a6f
			| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
b62a6f
b62a6f
		ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
b62a6f
b62a6f
		if cfgtest_compiler_switch "$ccenv_switch_var"; then
b62a6f
			ccenv_switch_var=${ccenv_switch_var%=}
b62a6f
			ccenv_switch_var=${ccenv_switch_var%,}
b62a6f
734765
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
b62a6f
				>> "$ccenv_mk"
b62a6f
		else
734765
			printf '%-40s=\n' "${ccenv_make_var}" \
b62a6f
				>> "$ccenv_mk"
b62a6f
		fi
b62a6f
	done
b62a6f
}
b62a6f
40216d
ccenv_set_cc_linker_switch_vars()
40216d
{
40216d
	printf '\n# %s ldflags: supported compiler switches\n' "$ccenv_cfgtype" \
40216d
		>> "$ccenv_mk"
40216d
40216d
	if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
01eda1
		ccenv_switch_vars=$(cat                            \
40216d
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
40216d
			$mb_project_dir/project/config/ccswitch.strs \
01eda1
			| grep -e '^-Wl,'                             \
40216d
			| sort -u)
40216d
	else
40216d
		ccenv_switch_vars=$(grep -e '^-Wl,'                \
40216d
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
40216d
			| sort -u)
40216d
	fi
40216d
40216d
	if [ $ccenv_cfgtype = 'host' ]; then
40216d
		ccenv_makevar_prefix='_LDFLAGS_'
40216d
		cfgtest_host_section
40216d
	else
40216d
		ccenv_makevar_prefix='_NATIVE_LDFLAGS_'
40216d
		cfgtest_native_section
40216d
	fi
40216d
40216d
	for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
40216d
		ccenv_make_var=${ccenv_switch_var%=}
40216d
		ccenv_make_var=${ccenv_make_var%,}
40216d
40216d
		ccenv_make_var=${ccenv_make_var##---}
40216d
		ccenv_make_var=${ccenv_make_var##--}
40216d
		ccenv_make_var=${ccenv_make_var##-}
40216d
40216d
		ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
40216d
			| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
40216d
40216d
		ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
40216d
40216d
		if cfgtest_compiler_switch "$ccenv_switch_var"; then
40216d
			ccenv_switch_var=${ccenv_switch_var%=}
40216d
			ccenv_switch_var=${ccenv_switch_var%,}
40216d
40216d
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
40216d
				>> "$ccenv_mk"
40216d
		else
40216d
			printf '%-40s=\n' "${ccenv_make_var}" \
40216d
				>> "$ccenv_mk"
40216d
		fi
40216d
	done
40216d
}
40216d
37ea13
ccenv_dso_verify()
37ea13
{
37ea13
	ccenv_str='int foo(int x){return ++x;}'
37ea13
	ccenv_cmd="$ccenv_cc -xc - -shared -o a.out"
37ea13
37ea13
	rm -f a.out
37ea13
593a0e
	printf '%s' "$ccenv_str" | $(printf %s "$ccenv_cmd") \
db226e
		> /dev/null 2>&3              \
37ea13
	|| mb_disable_shared=yes
37ea13
37ea13
	rm -f a.out
37ea13
}
37ea13
dee5ee
ccenv_clean_up()
dee5ee
{
dee5ee
	rm -f $ccenv_image
dee5ee
}
dee5ee
dee5ee
ccenv_common_init()
dee5ee
{
dee5ee
	. "$mb_project_dir/sofort/ccenv/ccenv.vars"
dee5ee
dee5ee
	ccenv_cfgtype=$1
dee5ee
	ccenv_cfgfile="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
b3a29a
	ccenv_cchost=
dee5ee
dee5ee
	if [ $ccenv_cfgtype = 'native' ]; then
dee5ee
		ccenv_makevar_prefix='NATIVE_'
dee5ee
		ccenv_image='./ccenv/native.a.out'
dee5ee
	else
dee5ee
		ccenv_makevar_prefix=
dee5ee
		ccenv_image='./ccenv/host.a.out'
dee5ee
	fi
dee5ee
dee5ee
	if [ $ccenv_cfgtype = 'native' ]; then
dee5ee
		ccenv_prefixes=
dee5ee
	elif [ -n "$mb_cross_compile" ]; then
dee5ee
		ccenv_prefixes="$mb_cross_compile"
dee5ee
	elif [ -n "$mb_host" ]; then
dee5ee
		ccenv_prefixes="$mb_host-"
dee5ee
	else
dee5ee
		ccenv_prefixes=
dee5ee
	fi
dee5ee
dee5ee
	if [ $ccenv_cfgtype = 'host' ]; then
dee5ee
		ccenv_tflags=
c84578
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
c15e41
			OS_DSO_EXRULES=default                          \
c15e41
			OS_SONAME=symlink                                \
9c1192
			OS_ARCHIVE_EXT='.a'                               \
c15e41
			.cflags-host)
ed2d0a
c84578
		ccenv_cflags="${ccenv_cflags#*: }"
c84578
dee5ee
		ccenv_cc="$mb_user_cc"
dee5ee
		ccenv_cpp="$mb_user_cpp"
dee5ee
		ccenv_cxx="$mb_user_cxx"
2732d1
2732d1
		ccenv_pe_subsystem="$mb_pe_subsystem"
2732d1
		ccenv_pe_image_base="$mb_pe_image_base"
dee5ee
	else
dee5ee
		ccenv_tflags=
c84578
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
c15e41
			OS_DSO_EXRULES=default                          \
c15e41
			OS_SONAME=symlink                                \
9c1192
			OS_ARCHIVE_EXT='.a'                               \
c15e41
			.cflags-native)
c15e41
c84578
		ccenv_cflags="${ccenv_cflags#*: }"
c84578
dee5ee
		ccenv_cc="$mb_native_cc"
dee5ee
		ccenv_cpp="$mb_native_cpp"
dee5ee
		ccenv_cxx="$mb_native_cxx"
2732d1
2732d1
		ccenv_pe_subsystem="$mb_native_pe_subsystem"
2732d1
		ccenv_pe_image_base="$mb_native_pe_image_base"
dee5ee
	fi
dee5ee
}
dee5ee
dee5ee
ccenv_set_characteristics()
dee5ee
{
dee5ee
	ccenv_set_cc_host
dee5ee
	ccenv_set_cc_bits
dee5ee
	ccenv_set_cc_binfmt
1b8de4
	ccenv_set_cc_underscore
dee5ee
}
dee5ee
dee5ee
ccenv_set_toolchain_variables()
dee5ee
{
dee5ee
	ccenv_common_init $1
dee5ee
	ccenv_set_cc
dee5ee
	ccenv_set_cpp
dee5ee
	ccenv_set_cxx
dee5ee
	ccenv_set_primary_tools
dee5ee
	ccenv_set_tool_variants
dee5ee
	ccenv_set_characteristics
dee5ee
dee5ee
	ccenv_set_os
dee5ee
	ccenv_set_os_flags
dee5ee
	ccenv_set_os_semantics
882922
	ccenv_set_os_dso_format
dee5ee
	ccenv_set_os_dso_exrules
dee5ee
	ccenv_set_os_dso_linkage
dee5ee
	ccenv_set_os_dso_patterns
2732d1
	ccenv_set_os_pe_switches
dee5ee
dee5ee
	ccenv_output_defs
dee5ee
	ccenv_clean_up
b62a6f
b62a6f
	ccenv_set_cc_switch_vars
40216d
	ccenv_set_cc_linker_switch_vars
dee5ee
}
dee5ee
dee5ee
ccenv_set_host_variables()
dee5ee
{
1b8de4
	output_script_status ${mb_script} \
28e2a9
		'detect and query host (targeted) system'
1b8de4
dee5ee
	ccenv_set_toolchain_variables 'host'
37ea13
	ccenv_dso_verify
dee5ee
}
dee5ee
dee5ee
ccenv_set_native_variables()
dee5ee
{
1b8de4
	output_script_status ${mb_script} \
28e2a9
		'detect and query native (local build) system'
1b8de4
a53d6c
	if [ _$mb_ccenv_skip_native != _yes ]; then
a53d6c
		ccenv_set_toolchain_variables 'native'
a53d6c
	fi
dee5ee
}