Blame sofort/ccenv/ccenv.sh

f3088e
711507
# ccenv.sh: sofort's tool-finding bits,
711507
# invoked from within the project-agnostic configure script.
711507
b3423c
# this file is covered by COPYING.SOFORT.
b3423c
711507
# invocation and names of binary tools:
711507
# agnostic names (ar, nm, objdump, ...);
711507
# target-prefixed agnostic names (x86_64-nt64-midipix-ar, ...);
711507
# branded names (llvm-ar, llvm-nm, llvm-objdump, ...);
711507
# target-prefixed branded names (x86_64-linux-gnu-gcc-ar, ...);
711507
# target-specifying branded tools (llvm-ar --target=x86_64-linux, ...).
711507
711507
# cross-compilation: default search order:
711507
# target-prefixed agnostic tools;
711507
# target-prefixed branded tools, starting with the prefix
711507
# most commonly associated with the selected compiler (that is,
711507
# ``gcc'' when using gcc, and ``llvm'' when using clang);
711507
# target-speficying branded tools, starting once again with the
711507
# prefix most commonly associated with the selected compiler.
711507
711507
# internal variables of interest:
711507
# ccenv_cfgtype: the type of host being tested (host/native)
711507
# ccenv_cfgfile: the configuration file for the host being tested
711507
# ccenv_cflags:  the comprehensive cflags for the host being tested
711507
# ccenv_cchost:  the host being tested, as reported by -dumpmachine
711507
f3088e
# variables available to cfgdefs.sh and cfgfini.sh:
f3088e
# ccenv_host_cflags:    expanded cflags, valid for the host compiler
f3088e
# ccenv_host_ldflags:   expanded ldflags, valid for the host compiler
64c67f
# ccenv_host_sysroot:   host sysroot, as reported by the host compiler
f3088e
# ccenv_native_cflags:  expanded cflags, valid for the native compiler
f3088e
# ccenv_native_ldflags: expanded ldflags, valid for the native compiler
64c67f
# ccenv_native_sysroot: native sysroot, as reported by the native compiler
711507
711507
ccenv_usage()
711507
{
711507
	cat "$mb_project_dir"/sofort/ccenv/ccenv.usage
711507
	exit 0
711507
}
711507
711507
711507
ccenv_newline()
711507
{
711507
	printf '\n' >> "$ccenv_cfgfile"
711507
}
711507
711507
711507
ccenv_comment()
711507
{
711507
	ccenv_internal_str='#'
711507
711507
	for ccenv_internal_arg ; do
711507
		ccenv_internal_str="$ccenv_internal_str $ccenv_internal_arg"
711507
	done
711507
711507
	printf '%s\n' "$ccenv_internal_str" >> "$ccenv_cfgfile"
711507
}
711507
711507
188a79
ccenv_tool_prolog()
188a79
{
a94557
	ccenv_line_dots='.....................................'
b7c699
	ccenv_tool_desc=" == checking for ${1}"
188a79
	ccenv_tool_dlen="${#ccenv_line_dots}"
188a79
bbde52
	printf '\n%s\n' '________________________' >&3
bbde52
	printf "ccenv: checking for ${1}\n\n" >&3
188a79
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s" \
a94557
		"${ccenv_tool_desc}  ${mb_line_dots}"
188a79
}
188a79
188a79
188a79
ccenv_tool_epilog()
188a79
{
188a79
	ccenv_line_dots='................................'
188a79
	ccenv_tool_dlen="$((${#ccenv_line_dots} - ${#1}))"
188a79
b0b2af
	case ${ccenv_tool_dlen} in
b0b2af
		0 | -* )
b0b2af
			ccenv_tool_dlen='3' ;;
b0b2af
	esac
b0b2af
a94557
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
188a79
		"${ccenv_line_dots}" "${1}"
bbde52
bbde52
	if [ "${1}" = 'false' ]; then
bbde52
		printf '\n\nccenv: not (yet) found.\n' >&3
bbde52
	else
bbde52
		printf "\n\nccenv : found $(command -v ${1}).\n" >&3
bbde52
	fi
bbde52
bbde52
	printf '%s\n' '------------------------' >&3
188a79
}
188a79
188a79
4a5a8c
ccenv_tool_variant_epilog()
4a5a8c
{
4a5a8c
	ccenv_expr=${1}='${'${1}':-false}'
4a5a8c
	eval "$ccenv_expr"
4a5a8c
4a5a8c
	ccenv_expr='${'${1}'}'
4a5a8c
	eval ccenv_tool_epilog "$ccenv_expr"
4a5a8c
}
4a5a8c
4a5a8c
188a79
ccenv_attr_prolog()
188a79
{
a94557
	ccenv_line_dots=' .....................................'
a94557
	ccenv_attr_desc=" == detect ${ccenv_cfgtype} ${1}"
188a79
	ccenv_attr_dlen="${#ccenv_line_dots}"
188a79
188a79
	printf "%${ccenv_attr_dlen}.${ccenv_attr_dlen}s" \
188a79
		"${ccenv_attr_desc} ${ccenv_line_dots}"
bbde52
bbde52
	printf '\n%s\n' '________________________' >&3
bbde52
	printf "ccenv: detecting ${1}\n\n" >&3
188a79
}
188a79
188a79
188a79
ccenv_attr_epilog()
188a79
{
bbde52
	ccenv_line_dots='................................'
a94557
	ccenv_tool_dlen="$((${#ccenv_line_dots} - 1 - ${#1}))"
bbde52
b0b2af
	case ${ccenv_tool_dlen} in
b0b2af
		0 | -* )
b0b2af
			ccenv_tool_dlen='3' ;;
b0b2af
	esac
b0b2af
a94557
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
bbde52
		"${ccenv_line_dots}" "${1}"
bbde52
bbde52
	printf '\n\nccenv: detected result: %s\n' "${1}" >&3
bbde52
	printf '%s\n' '------------------------' >&3
188a79
}
188a79
188a79
711507
ccenv_find_tool()
711507
{
711507
	if [ -z "$ccenv_prefixes" ]; then
7d9a2d
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
be9f9d
			ccenv_cmd_args="${@:-}"
be9f9d
be9f9d
			if [ -z "$ccenv_cmd_args" ]; then
3a6b25
				if command -v "$ccenv_candidate" > /dev/null; then
3a6b25
					ccenv_tool="$ccenv_candidate"
c42cf9
					return 0
e4b2db
				fi
c42cf9
			else
3a6b25
				if command -v "$ccenv_candidate" > /dev/null; then
bbde52
					if "$ccenv_candidate" $@ > /dev/null 2>&3; then
3a6b25
						ccenv_tool="$ccenv_candidate"
c42cf9
						return 0
e4b2db
					fi
e4b2db
				fi
c42cf9
			fi
711507
		done
711507
711507
		ccenv_tool=false
711507
711507
		return 0
711507
	fi
711507
7d9a2d
	for ccenv_prefix in $(printf '%s' "$ccenv_prefixes"); do
7d9a2d
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
711507
			ccenv_tool="$ccenv_prefix$ccenv_candidate"
e4b2db
e4b2db
			if command -v "$ccenv_tool" > /dev/null; then
e4b2db
				return 0
e4b2db
			fi
711507
		done
711507
	done
711507
7d9a2d
	for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
3a6b25
		if command -v "$ccenv_candidate" > /dev/null; then
3a6b25
			ccenv_tool="$ccenv_candidate"
e4b2db
			return 0
e4b2db
		fi
711507
	done
711507
711507
	ccenv_tool=false
711507
711507
	return 0
711507
}
711507
711507
711507
ccenv_set_primary_tools()
711507
{
711507
	ccenv_core_tools="ar nm objdump ranlib size strip strings objcopy"
e6f0f0
	ccenv_hack_tools="addr2line cov elfedit readelf readobj otool"
ceb89e
	ccenv_peep_tools="perk mdso dlltool windmc windres pkgconf"
711507
7d9a2d
	for __tool in $(printf '%s' "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do
188a79
		ccenv_tool_prolog "$__tool"
188a79
711507
		if [ -n "$mb_agnostic" ]; then
711507
			ccenv_candidates=" $__tool"
711507
711507
		elif [ -n "$mb_zealous" ]; then
711507
			ccenv_candidates="$mb_zealous-$__tool"
711507
711507
		elif [ "$mb_toolchain" = 'gcc' ]; then
711507
			ccenv_candidates="gcc-$__tool"
711507
			ccenv_candidates="$ccenv_candidates $__tool"
711507
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
711507
711507
		elif [ "$mb_toolchain" = 'llvm' ]; then
711507
			ccenv_candidates="llvm-$__tool"
711507
			ccenv_candidates="$ccenv_candidates $__tool"
711507
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
711507
711507
		elif [ -n "$mb_toolchain" ]; then
711507
			ccenv_candidates="$mb_toolchain-$__tool"
711507
			ccenv_candidates="$ccenv_candidates $__tool"
711507
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
711507
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
711507
7d8bc4
		elif [ "$__tool" = 'pkgconf' ]; then
7d8bc4
			ccenv_candidates="$__tool pkg-config"
7d8bc4
711507
		else
711507
			ccenv_candidates="$__tool"
711507
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
711507
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
711507
		fi
711507
711507
		if [ "$ccenv_cfgtype" = 'host' ]; then
711507
			ccenv_var_prefix='mb_'
711507
		else
711507
			ccenv_var_prefix='mb_native_'
711507
		fi
711507
720ab1
		ccenv_tool=
711507
		ccenv_var_name=$ccenv_var_prefix$__tool
711507
		ccenv_var_expr='${'$ccenv_var_name':-}'
711507
		eval ccenv_var_val=$ccenv_var_expr
711507
711507
		if [ -n "$ccenv_var_val" ]; then
711507
			eval ccenv_$__tool="$ccenv_var_val"
720ab1
			ccenv_tool="$ccenv_var_val"
711507
		else
711507
			ccenv_find_tool
711507
			eval ccenv_$__tool="$ccenv_tool"
711507
		fi
188a79
188a79
		ccenv_tool_epilog "$ccenv_tool"
711507
	done
711507
711507
	# windrc
711507
	ccenv_windrc="$ccenv_windres"
bb082e
bb082e
	# archive format preamble
b99b40
	if [ -n "$ccenv_dumpmachine_switch" ]; then
1fba66
		ccenv_libgcc_path=$($ccenv_cc -print-file-name=libgcc.a \
1fba66
			2>/dev/null)
1fba66
1fba66
		if [ -n "$ccenv_libgcc_path" ]; then
1fba66
			ccenv_libgcc_a_header=$(od -b -N8             \
1fba66
				$($ccenv_cc -print-file-name=libgcc.a) \
1fba66
				| head -n1)
1fba66
		else
1fba66
			ccenv_libgcc_a_header=
1fba66
		fi
b99b40
	else
b99b40
		ccenv_libgcc_a_header=
b99b40
	fi
b99b40
b99b40
	# ar (default)
bb082e
	ccenv_cc_arfmt='common'
bb082e
bb082e
	# ar (big)
bb082e
	ccenv_bigaf_header=$(printf '%s\n' '<bigaf>' | od -b | head -n1)
bb082e
bb082e
	if [ "$ccenv_libgcc_a_header" = "$ccenv_bigaf_header" ]; then
bb082e
		ccenv_cc_arfmt='bigaf'
bb082e
bb082e
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
bb082e
			ccenv_var_name=ccenv_$__tool
bb082e
			ccenv_var_expr='${'$ccenv_var_name':-}'
bb082e
			eval ccenv_var_val="$ccenv_var_expr"
bb082e
bb082e
			if [ "$ccenv_var_val" != false ]; then
bb082e
				ccenv_var_val="$ccenv_var_val -X64"
bb082e
				ccenv_var_expr='${ccenv_var_val:-}'
bb082e
				eval ccenv_$__tool="$ccenv_var_expr"
bb082e
			fi
bb082e
		done
bb082e
	fi
bb082e
bb082e
	# ar (small)
bb082e
	ccenv_aiaff_header=$(printf '%s\n' '<aiaff>' | od -b | head -n1)
bb082e
bb082e
	if [ "$ccenv_libgcc_a_header" = "$ccenv_aiaff_header" ]; then
bb082e
		ccenv_cc_arfmt='aiaff'
bb082e
bb082e
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
bb082e
			ccenv_var_name=ccenv_$__tool
bb082e
			ccenv_var_expr='${'$ccenv_var_name':-}'
bb082e
			eval ccenv_var_val="$ccenv_var_expr"
bb082e
bb082e
			if [ "$ccenv_var_val" != false ]; then
bb082e
				ccenv_var_val="$ccenv_var_val -X32"
bb082e
				ccenv_var_expr='${ccenv_var_val:-}'
bb082e
				eval ccenv_$__tool="$ccenv_var_expr"
bb082e
			fi
bb082e
		done
bb082e
	fi
711507
}
711507
711507
ccenv_set_tool_variants()
711507
{
711507
	# as (asm)
188a79
	ccenv_tool_prolog 'as (asm)'
711507
	ccenv_candidates=as
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" = false ]; then
711507
		ccenv_as_asm=
711507
	else
4440ff
		$ccenv_tool --help 2>&1 | grep -i '.bc assembler' \
711507
		|| ccenv_as_asm="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_as_asm'
188a79
711507
	# as (ll)
188a79
	ccenv_tool_prolog 'as (ll)'
711507
	ccenv_candidates=llvm-as
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" != false ]; then
711507
		ccenv_as_ll="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_as_ll'
188a79
711507
	# as (mc)
188a79
	ccenv_tool_prolog 'as (mc)'
711507
	ccenv_candidates=llvm-mc
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" != false ]; then
711507
		ccenv_as_mc="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_as_mc'
188a79
711507
	# ld (bfd)
188a79
	ccenv_tool_prolog 'ld (bfd)'
711507
	ccenv_candidates=ld.bfd
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" != false ]; then
711507
		ccenv_ld_bfd="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_ld_bfd'
188a79
711507
	# ld (gold)
188a79
	ccenv_tool_prolog 'ld (gold)'
711507
	ccenv_candidates=ld.gold
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" != false ]; then
711507
		ccenv_ld_gold="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_ld_gold'
188a79
711507
	# ld (lld)
188a79
	ccenv_tool_prolog 'ld (lld)'
711507
	ccenv_candidates=lld
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" != false ]; then
711507
		ccenv_ld_lld="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_ld_lld'
188a79
711507
	# objdump (bfd)
188a79
	ccenv_tool_prolog 'objdump (bfd)'
711507
	ccenv_candidates=objdump
711507
	ccenv_find_tool
711507
ec40cb
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
ec40cb
		ccenv_objdump_bfd="$ccenv_tool"
ec40cb
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_objdump_bfd'
188a79
711507
	# objdump (llvm)
188a79
	ccenv_tool_prolog 'objdump (llvm)'
711507
	ccenv_candidates=llvm-objdump
711507
	ccenv_find_tool
711507
ec40cb
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
ec40cb
		ccenv_objdump_llvm="$ccenv_tool"
ec40cb
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_objdump_llvm'
188a79
711507
	# readelf (bfd)
188a79
	ccenv_tool_prolog 'readelf (bfd)'
711507
	ccenv_candidates=readelf
711507
	ccenv_find_tool
711507
ec40cb
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
ec40cb
		ccenv_readelf_bfd="$ccenv_tool"
ec40cb
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_readelf_bfd'
188a79
711507
	# readelf (llvm)
188a79
	ccenv_tool_prolog 'readelf (llvm)'
711507
	ccenv_candidates=llvm-readelf
711507
	ccenv_find_tool
711507
ec40cb
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
ec40cb
		ccenv_readelf_llvm="$ccenv_tool"
ec40cb
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_readelf_llvm'
188a79
711507
	# as
711507
	if [ -n "$ccenv_cc" ]; then
49b7fa
		ccenv_as='$('"$ccenv_makevar_prefix"'CC) -c -x assembler'
711507
	elif [ -n "$mb_agnostic" ]; then
711507
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
711507
	elif [ "$mb_zealous" = 'gcc' ]; then
711507
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
711507
	elif [ -n "$mb_zealous" = 'llvm' ]; then
711507
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
711507
	elif [ "$mb_toolchain" = 'gcc' ]; then
711507
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
711507
	elif [ "$mb_toolchain" = 'llvm' ]; then
711507
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
711507
	fi
711507
711507
	# ld
711507
	if [ -n "$ccenv_cc" ]; then
711507
		ccenv_ld='$('"$ccenv_makevar_prefix"'CC) -nostdlib -nostartfiles'
711507
	fi
711507
}
711507
711507
ccenv_set_c_compiler_candidates()
711507
{
711507
	if   [ -n "$mb_compiler" ]; then
711507
		ccenv_candidates="$mb_compiler"
711507
711507
	elif [ -n "$mb_agnostic" ]; then
711507
		ccenv_candidates="c99 c11 cc"
711507
711507
	elif [ "$mb_zealous" = 'gcc' ]; then
711507
		ccenv_candidates="gcc"
711507
711507
	elif [ "$mb_zealous" = 'llvm' ]; then
711507
		ccenv_candidates="clang"
711507
711507
	elif [ "$mb_toolchain" = 'gcc' ]; then
711507
		ccenv_candidates="gcc c99 c11 cc clang"
711507
711507
	elif [ "$mb_toolchain" = 'llvm' ]; then
711507
		ccenv_candidates="clang c99 c11 cc gcc"
711507
711507
	elif [ -n "$mb_toolchain" ]; then
711507
		ccenv_candidates="$mb_toolchain c99 c11 cc gcc clang"
711507
711507
	else
74db99
		ccenv_candidates="cc gcc clang c99 c11"
711507
	fi
711507
}
711507
711507
711507
ccenv_set_cc()
711507
{
188a79
	ccenv_tool_prolog 'C compiler'
188a79
711507
	if [ -z "$ccenv_cc" ]; then
711507
		ccenv_set_c_compiler_candidates
b99b40
		ccenv_find_tool
711507
		ccenv_cc="$ccenv_tool"
711507
	fi
711507
b99b40
711507
	if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
711507
		ccenv_cc="$mb_compiler"
711507
	fi
711507
b99b40
	ccenv_tool_epilog "$ccenv_cc"
b99b40
b99b40
b99b40
	if [ $ccenv_cfgtype = 'host' ]; then
b99b40
		ccenv_host_cc="$ccenv_cc"
b99b40
		cfgtest_host_section
b99b40
		ccenv_host_cc=
b99b40
	else
b99b40
		ccenv_native_cc="$ccenv_cc"
b99b40
		cfgtest_native_section
b99b40
		ccenv_native_cc=
b99b40
	fi
b99b40
7d09ba
	cfgtest_silent='yes'
7d09ba
b99b40
	if cfgtest_compiler_switch -dumpmachine ; then
b99b40
		ccenv_dumpmachine_switch='-dumpmachine'
b99b40
	else
b99b40
		ccenv_dumpmachine_switch=
b99b40
	fi
b99b40
9deaf6
	if cfgtest_code_snippet_asm 'typedef int dummy;' ; then
9deaf6
		eval ccenv_${ccenv_cfgtype}_stdin_input='yes'
9deaf6
	else
9deaf6
		eval ccenv_${ccenv_cfgtype}_stdin_input='no'
9deaf6
	fi
9deaf6
7d09ba
	unset cfgtest_silent
7d09ba
711507
	ccenv_cc_cmd="$ccenv_cc"
aeb703
	ccenv_errors=
711507
711507
	if [ "$ccenv_cfgtype" = 'native' ]; then
ed7828
		ccenv_host=
ed7828
8ed1b0
		if [ -n "$mb_native_host" ]; then
8ed1b0
			ccenv_host="$mb_native_host"
8ed1b0
8ed1b0
		elif [ -n "$ccenv_dumpmachine_switch" ]; then
b99b40
			ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
b99b40
				$ccenv_dumpmachine_switch 2>&3)
ed7828
ed7828
		elif command -v slibtool > /dev/null 2>&1; then
e46d1c
			ccenv=$(slibtool --dumpmachine 2>/dev/null || true)
ed7828
		fi
ed7828
ed7828
		if [ -z "$ccenv_host" ]; then
8ed1b0
			ccenv_machine=$(uname -m 2>/dev/null)
8ed1b0
			ccenv_system=$(uname -s 2>/dev/null)
8ed1b0
8ed1b0
			ccenv_machine="${ccenv_machine:-unknown}"
8ed1b0
			ccenv_system="${ccenv_system:-anyos}"
8ed1b0
8ed1b0
			ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \
b442cc
				| tr '[[:upper:]]' '[[:lower:]]')
b99b40
		fi
b99b40
5b51ca
		ccenv_cchost=$ccenv_host
711507
		return 0
711507
	fi
711507
b99b40
711507
	if [ -n "$mb_cchost" ]; then
711507
		ccenv_host="$mb_cchost"
711507
	elif [ -n "$mb_host" ]; then
711507
		ccenv_host="$mb_host"
711507
	else
711507
		ccenv_host=
711507
	fi
711507
b99b40
	if [ -z "$ccenv_host" ] && [ -n "$ccenv_dumpmachine_switch" ]; then
b99b40
		ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
b99b40
			$ccenv_dumpmachine_switch 2>&3)
711507
		ccenv_cchost=$ccenv_host
b99b40
b99b40
	elif [ -z "$ccenv_host" ]; then
ed7828
		# no -dumpmachine support and no --host argument implies native build
ed7828
		if command -v slibtool > /dev/null 2>&1; then
e46d1c
			ccenv=$(slibtool --dumpmachine 2>/dev/null || true)
ed7828
		fi
8ed1b0
ed7828
		if [ -z "$ccenv_host" ]; then
ed7828
			ccenv_machine=$(uname -m 2>/dev/null)
ed7828
			ccenv_system=$(uname -s 2>/dev/null)
ed7828
ed7828
			ccenv_machine="${ccenv_machine:-unknown}"
ed7828
			ccenv_system="${ccenv_system:-anyos}"
8ed1b0
ed7828
			ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \
ed7828
				| tr '[[:upper:]]' '[[:lower:]]')
ed7828
		fi
8ed1b0
b99b40
		ccenv_cchost=$ccenv_host
b99b40
b99b40
	elif [ -n "$ccenv_dumpmachine_switch" ]; then
1cc479
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
711507
		ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -"
711507
711507
		if [ -z "$mb_user_cc" ]; then
03b8d4
			$(printf %s "$ccenv_cmd") < /dev/null > /dev/null \
711507
				2>"$ccenv_tmp" || true
711507
711507
			ccenv_errors=$(cat "$ccenv_tmp")
711507
711507
			if [ -z "$ccenv_errors" ]; then
b99b40
				ccenv_tool_prolog 'C compiler for host'
711507
				ccenv_tflags="--target=$ccenv_host"
711507
				ccenv_cc="$ccenv_cc $ccenv_tflags"
b99b40
				ccenv_tool_epilog "$ccenv_cc"
bbde52
			else
bbde52
				printf '%s' "$ccenv_errors" >&3
711507
			fi
711507
		fi
711507
1cc479
		rm -f "$ccenv_tmp"
1cc479
		unset ccenv_tmp
1cc479
b99b40
		ccenv_cchost=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
b99b40
			$ccenv_dumpmachine_switch 2>&3)
711507
	fi
711507
053a3d
	if [ -z "$ccenv_dumpmachine_switch" ] && [ -n "$ccenv_host" ]; then
053a3d
		ccenv_cchost="$ccenv_host"
053a3d
053a3d
	elif [ "$ccenv_cchost" != "$ccenv_host" ]; then
bbde52
		printf 'error!\n' >&2
711507
		printf 'ccenv:\n' >&2
711507
		printf 'ccenv: ccenv_host:   %s \n' $ccenv_host >&2
711507
		printf 'ccenv: ccenv_cchost: %s \n' $ccenv_cchost >&2
711507
711507
		if [ -z "$ccenv_tflags" ]; then
711507
			printf 'ccenv:\n' >&2
711507
			printf 'ccenv: ccenv_host and ccenv_cchost do not match, most likely because:\n' >&2
711507
			printf 'ccenv: (1) you explicitly set CC (or passed --compiler=...)\n' >&2
711507
			printf 'ccenv: (2) the selected compiler does not accept --target=...\n' >&2
711507
			printf 'ccenv: (3) the host reported by -dumpmachine differs from the one you requested.\n' >&2
711507
		fi
711507
711507
		if [ -n "$ccenv_errors" ]; then
711507
			printf 'ccenv:\n' >&2
711507
			printf 'ccenv: something went wrong, see the command and compiler message below.\n\n' >&2
711507
			printf 'cmd: %s < /dev/null > /dev/null\n' "$ccenv_cmd" >&2
711507
			printf '%s\n\n' "$ccenv_errors" >&2
711507
		else
711507
			printf 'ccenv:\n' >&2
711507
			printf 'ccenv: something went wrong, bailing out.\n\n' >&2
711507
		fi
711507
711507
		return 2
711507
	fi
711507
}
711507
711507
ccenv_set_cpp()
711507
{
188a79
	ccenv_tool_prolog 'C pre-processor'
188a79
711507
	case "$ccenv_cc_cmd" in
711507
		cc | c99 | c11 | gcc)
711507
			ccenv_cpp_prefix=
711507
			ccenv_candidates="cpp" ;;
711507
711507
		clang )
711507
			ccenv_cpp_prefix=
711507
			ccenv_candidates="clang-cpp" ;;
711507
711507
		*-cc )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-cc*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
711507
711507
		*-c99 )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c99*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
711507
711507
		*-c11 )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c11*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
711507
711507
		*-gcc )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
711507
711507
		*-clang )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}clang-cpp" ;;
711507
711507
		* )
711507
			ccenv_cpp="$ccenv_cc -E"
188a79
			ccenv_tool_epilog "$ccenv_cpp"
711507
			return 0
711507
	esac
711507
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" = false ]; then
711507
		ccenv_cpp="$ccenv_cc -E"
711507
	elif [ -n "$ccenv_tflags" ]; then
711507
		ccenv_cpp="$ccenv_tool $ccenv_tflags"
711507
	else
711507
		ccenv_cpp="$ccenv_tool"
711507
	fi
188a79
188a79
	ccenv_tool_epilog "$ccenv_cpp"
711507
}
711507
711507
ccenv_set_cxx()
711507
{
188a79
	ccenv_tool_prolog 'C++ compiler'
188a79
711507
	case "$ccenv_cc_cmd" in
711507
		cc | c99 | c11 )
711507
			ccenv_cxx_prefix=
711507
			ccenv_candidates="cxx c++" ;;
711507
711507
		gcc )
711507
			ccenv_cxx_prefix=
711507
			ccenv_candidates="g++" ;;
711507
711507
		clang )
711507
			ccenv_cxx_prefix=
711507
			ccenv_candidates="clang++" ;;
711507
711507
		*-gcc )
d07528
			ccenv_cxx_prefix=${ccenv_cc_cmd%-gcc*}-
d07528
			ccenv_candidates="${ccenv_cxx_prefix}g++" ;;
711507
711507
		*-clang )
d07528
			ccenv_cxx_prefix=${ccenv_cc_cmd%-clang*}-
d07528
			ccenv_candidates="${ccenv_cxx_prefix}clang++" ;;
d07528
d07528
		/*cc | /*c99 | /*c11 )
d07528
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
d07528
			ccenv_candidates="${ccenv_cxx_prefix}/cxx"
d07528
			ccenv_candidates="${ccenv_candidates} ${ccenv_cxx_prefix}/c++" ;;
d07528
d07528
		/*gcc )
d07528
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
d07528
			ccenv_candidates="${ccenv_cxx_prefix}/g++" ;;
711507
d07528
		/*clang )
d07528
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
d07528
			ccenv_candidates="${ccenv_cxx_prefix}/clang++" ;;
711507
711507
		* )
711507
			ccenv_cxx="$ccenv_cc -xc++"
188a79
			ccenv_tool_epilog "$ccenv_cxx"
711507
			return 0
711507
	esac
711507
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" = false ]; then
711507
		ccenv_cxx="$ccenv_cc -xc++"
711507
	elif [ -n "$ccenv_tflags" ]; then
711507
		ccenv_cxx="$ccenv_tool $ccenv_tflags"
711507
	else
711507
		ccenv_cxx="$ccenv_tool"
711507
	fi
188a79
188a79
	ccenv_tool_epilog "$ccenv_cxx"
711507
}
711507
711507
ccenv_set_cc_host()
711507
{
2628b5
	ccenv_attr_prolog 'system'
711507
	ccenv_cc_host="$ccenv_cchost"
188a79
	ccenv_attr_epilog "$ccenv_cc_host"
711507
}
711507
711507
ccenv_set_cc_bits()
711507
{
188a79
	ccenv_attr_prolog 'bits'
188a79
711507
	ccenv_internal_size=
711507
	ccenv_internal_type='void *'
711507
	ccenv_internal_test='char x[(sizeof(%s) == %s/8) ? 1 : -1];'
711507
711507
	for ccenv_internal_guess in 64 32 128; do
20aac4
		if [ -z "${ccenv_internal_size:-}" ]; then
470dc7
			ccenv_internal_str=$(printf "$ccenv_internal_test"  \
470dc7
				"$ccenv_internal_type"                      \
711507
				"$ccenv_internal_guess")
711507
86d780
			ccenv_expr='ccenv_stdin_input=$ccenv_'${ccenv_cfgtype}'_stdin_input'
86d780
			eval ${ccenv_expr}
86d780
86d780
			if [ "$ccenv_stdin_input" = 'yes' ]; then
ba095a
				printf '%s' "$ccenv_internal_str"                   \
ba095a
						| eval $ccenv_cc -S -xc - -o -      \
ba095a
						  $(printf '%s' "$ccenv_cflags")    \
ba095a
					> /dev/null 2>&3                            \
ba095a
				&& ccenv_internal_size=$ccenv_internal_guess
ba095a
			else
ba095a
				ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
ba095a
ba095a
				printf '%s' "$ccenv_internal_str" \
ba095a
					> "$ccenv_tmpname"
ba095a
ba095a
				$ccenv_cc -c "$ccenv_tmpname" -o a.out \
ba095a
					> /dev/null 2>&3                \
ba095a
				&& ccenv_internal_size=$ccenv_internal_guess
ba095a
ba095a
				rm "$ccenv_tmpname"
ba095a
			fi
711507
		fi
711507
	done
711507
711507
	ccenv_cc_bits=$ccenv_internal_size
188a79
188a79
	ccenv_attr_epilog "$ccenv_cc_bits"
711507
}
711507
711507
ccenv_set_cc_underscore()
711507
{
188a79
	ccenv_attr_prolog 'prepended underscores'
188a79
711507
	ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe'
711507
	ccenv_fn_code='int %s(void){return 0;}'
711507
d3e147
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
d3e147
d3e147
	printf "$ccenv_fn_code" $ccenv_fn_name \
d3e147
		> "$ccenv_tmpname"
d3e147
d3e147
	$ccenv_cc -c "$ccenv_tmpname" -o a.out \
d3e147
		> /dev/null 2>&3
d3e147
d3e147
	if "$ccenv_nm" a.out | grep          \
d3e147
			-e "^_$ccenv_fn_name" \
d3e147
			-e " _$ccenv_fn_name"  \
d3e147
			> /dev/null; then
ec40cb
		ccenv_cc_underscore='_'
188a79
		ccenv_attr_epilog 'yes'
d3e147
	else
d3e147
		ccenv_attr_epilog 'no'
ec40cb
	fi
711507
d3e147
	rm "$ccenv_tmpname"
d3e147
	rm a.out
188a79
711507
	return 0
711507
}
711507
711507
ccenv_create_framework_executable()
711507
{
baa9be
	if [ "$ccenv_cfgtype" = 'host' ]; then
baa9be
		if [ "$mb_freestanding" = 'yes' ]; then
baa9be
			return 1
baa9be
		fi
baa9be
	fi
baa9be
711507
	if [ -f $ccenv_image ]; then
711507
		mv $ccenv_image $ccenv_image.tmp
711507
		rm -f $ccenv_image.tmp
711507
	fi
711507
4c2b1d
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
4c2b1d
711507
	printf 'int main(void){return 0;}'  \
4c2b1d
		> "$ccenv_tmpname"
711507
4c2b1d
	if $ccenv_cc "$ccenv_tmpname" -o $ccenv_image 2>&3; then
4c2b1d
		ccenv_ret=0
baa9be
		ccenv_cc_environment='hosted'
4c2b1d
	else
4c2b1d
		ccenv_ret=1
4c2b1d
	fi
4c2b1d
4c2b1d
	rm "$ccenv_tmpname"
4c2b1d
4c2b1d
	return $ccenv_ret
711507
}
711507
711507
ccenv_create_freestanding_executable()
711507
{
711507
	if [ -f $ccenv_image ]; then
711507
		mv $ccenv_image $ccenv_image.tmp
711507
		rm -f $ccenv_image.tmp
711507
	fi
711507
711507
	if [ -z "ccenv_cc_underscore" ]; then
711507
		ccenv_start_fn='_start'
711507
	else
711507
		ccenv_start_fn='start'
711507
	fi
711507
4c2b1d
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
711507
4c2b1d
	printf 'int %s(void){return 0;}' "$ccenv_start_fn" \
4c2b1d
		> "$ccenv_tmpname"
711507
4c2b1d
	if $ccenv_cc "$ccenv_tmpname"         \
4c2b1d
			-ffreestanding         \
4c2b1d
			-nostdlib -nostartfiles \
4c2b1d
			-o $ccenv_image          \
4c2b1d
			2>&3; then
4c2b1d
		ccenv_ret=0
baa9be
		ccenv_cc_environment='freestanding'
4c2b1d
	else
4c2b1d
		ccenv_ret=1
4c2b1d
	fi
4c2b1d
4c2b1d
	rm "$ccenv_tmpname"
4c2b1d
4c2b1d
	return $ccenv_ret
711507
}
711507
188a79
ccenv_set_cc_binfmt_error()
188a79
{
188a79
	ccenv_attr_epilog '(unable to create executable)'
188a79
}
188a79
711507
ccenv_set_cc_binfmt()
711507
{
711507
	ccenv_use_perk=
e6f0f0
	ccenv_use_otool=
711507
	ccenv_use_readelf=
711507
	ccenv_use_readobj=
711507
	ccenv_use_bfd_objdump=
711507
	ccenv_use_llvm_objdump=
711507
188a79
	ccenv_attr_prolog 'binary format'
188a79
711507
	ccenv_create_framework_executable               \
711507
		|| ccenv_create_freestanding_executable \
188a79
		|| ccenv_set_cc_binfmt_error            \
711507
		|| return 0
711507
711507
	# PE / perk
711507
	if [ -n "$ccenv_perk" ]; then
bbde52
		if $ccenv_perk $ccenv_image 2>&3; then
ec40cb
			ccenv_cc_binfmt='PE'
ec40cb
			ccenv_use_perk=yes
ec40cb
		fi
711507
	fi
711507
711507
	# ELF / readelf
711507
	if [ -n "$ccenv_readelf" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_readelf -h $ccenv_image 2>&3               \
ec40cb
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
ec40cb
				| grep 'Magic:7f454c46'              \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='ELF'
ec40cb
			ccenv_use_readelf=yes
ec40cb
		fi
711507
	fi
711507
711507
	# a marble of astonishing design:
711507
	# llvm-readelf also parses PE and Mach-O
711507
711507
	if [ -n "$ccenv_readelf_llvm" ]; then
711507
		ccenv_readany="$ccenv_readelf_llvm"
711507
	else
711507
		ccenv_readany="$ccenv_readelf"
711507
	fi
711507
711507
	# PE / readelf
711507
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_readany -h $ccenv_image 2>&3               \
ec40cb
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
ec40cb
				| grep 'Magic:MZ'                    \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='PE'
ec40cb
			ccenv_use_readelf=yes
ec40cb
		fi
711507
	fi
711507
e6f0f0
	# MACHO-64 / otool
e6f0f0
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_otool -hv $ccenv_image 2>&3        \
ec40cb
				| grep -i 'MH_MAGIC_64'      \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_otool=yes
ec40cb
		fi
e6f0f0
	fi
e6f0f0
e6f0f0
	# MACHO-32 / otool
e6f0f0
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_otool -hv $ccenv_image 2>&3        \
ec40cb
				| grep -i 'MH_MAGIC'         \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_otool=yes
ec40cb
		fi
e6f0f0
	fi
e6f0f0
711507
	# MACHO-64 / readelf
711507
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_readany -h $ccenv_image 2>&3                    \
ec40cb
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
ec40cb
				| grep -i '(0xfeedfacf)'                  \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_readelf=yes
ec40cb
		fi
711507
	fi
711507
711507
	# MACHO-32 / readelf
711507
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_readany -h $ccenv_image 2>&3                    \
ec40cb
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
ec40cb
				| grep -i '(0xcafebabe)'                  \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_readelf=yes
ec40cb
		fi
711507
	fi
711507
711507
	# MACHO / readobj
711507
	if [ -n "$ccenv_readobj" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_readobj $ccenv_image 2>&3                  \
fa64c0
				| grep -i 'Format:'                  \
fa64c0
				| sed  -e 's/ /_/g'                  \
ec40cb
				| grep -i '_Mach-O_'                 \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_readobj=yes
ec40cb
		fi
711507
	fi
711507
711507
	# MACHO / objdump (llvm)
711507
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
ec40cb
		if $ccenv_objdump -section-headers $ccenv_image  \
bbde52
					2>&3                     \
ec40cb
				| grep -i 'file format Mach-O'   \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_objdump=yes
ec40cb
		fi
711507
	fi
711507
711507
	# MACHO / objdump (bfd)
711507
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		$ccenv_objdump -h  $ccenv_image 2>&3              \
711507
			| grep -i 'file format Mach-O'            \
711507
				> /dev/null                       \
711507
		&& ccenv_cc_binfmt='MACHO'                        \
711507
		&& ccenv_use_objdump=yes
711507
	fi
711507
711507
	# PE / objdump (bfd)
711507
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_objdump -h  $ccenv_image 2>&3        \
ec40cb
				| grep -i 'file format pei-'   \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='PE'
ec40cb
			ccenv_use_bfd_objdump=yes
ec40cb
		fi
711507
	fi
188a79
188a79
	ccenv_attr_epilog "$ccenv_cc_binfmt"
711507
}
711507
711507
ccenv_set_os_pe()
711507
{
baa9be
	if [ "$ccenv_cc_environment" = 'freestanding' ]; then
711507
		case "$ccenv_cchost" in
711507
			*-midipix | *-midipix-* )
711507
				ccenv_os='midipix' ;;
711507
			*-mingw | *-mingw32 | *-mingw64 )
711507
				ccenv_os='mingw' ;;
711507
			*-mingw-* | *-mingw32-* | *-mingw64 )
711507
				ccenv_os='mingw' ;;
711507
			*-msys | *-msys2 | *-msys-* | *-msys2-* )
711507
				ccenv_os='msys' ;;
711507
			*-cygwin | *-cygwin-* )
711507
				ccenv_os='cygwin' ;;
711507
		esac
711507
	fi
711507
711507
	if [ -n "$ccenv_os" ]; then
711507
		return 0
711507
	fi
711507
711507
	if [ -n "$ccenv_use_perk" ]; then
711507
		ccenv_framework=$($ccenv_perk -y $ccenv_image)
711507
		ccenv_os=${ccenv_framework#*-*-*-*}
711507
	fi
711507
711507
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
711507
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
711507
			| grep 'cygwin1.dll' > /dev/null                \
711507
		&& ccenv_os='cygwin'
711507
	fi
711507
711507
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
711507
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
711507
			| grep 'msys-2.0.dll' > /dev/null               \
711507
		&& ccenv_os='msys'
711507
	fi
711507
711507
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
711507
		$ccenv_objdump_bfd -x $ccenv_image          \
711507
			| grep -i 'DLL Name' | grep '.CRT'  \
711507
				> /dev/null                 \
711507
		&& $ccenv_objdump_bfd -x $ccenv_image       \
711507
			| grep -i 'DLL Name' | grep '.bss'  \
711507
				> /dev/null                 \
711507
		&& $ccenv_objdump_bfd -x $ccenv_image       \
711507
			| grep -i 'DLL Name' | grep '.tls'  \
711507
				> /dev/null                 \
711507
		&& ccenv_os='mingw'
711507
	fi
711507
}
711507
711507
ccenv_set_os_macho()
711507
{
711507
	case "$ccenv_cchost" in
711507
		*-apple-darwin* )
711507
			ccenv_os='darwin' ;;
711507
	esac
711507
}
711507
711507
ccenv_set_os()
711507
{
188a79
	ccenv_attr_prolog 'os name'
188a79
711507
	case "$ccenv_cc_binfmt" in
711507
		PE )
711507
			ccenv_set_os_pe ;;
711507
		MACHO )
711507
			ccenv_set_os_macho ;;
711507
	esac
711507
711507
	if [ -n "$ccenv_os" ]; then
188a79
		ccenv_attr_epilog "$ccenv_os"
711507
		return 0
711507
	fi
711507
711507
	case "$ccenv_cchost" in
711507
		*-*-*-* )
80c2c2
			ccenv_tip=${ccenv_cchost%-*}
711507
			ccenv_os=${ccenv_tip#*-*-}
711507
			;;
80c2c2
		*-*-musl | *-*-gnu )
80c2c2
			ccenv_tip=${ccenv_cchost%-*}
711507
			ccenv_os=${ccenv_tip#*-}
711507
			;;
80c2c2
		*-*-* )
80c2c2
			ccenv_os=${ccenv_cchost#*-*-}
80c2c2
			;;
80c2c2
		*-* )
80c2c2
			ccenv_os=${ccenv_cchost#*-}
80c2c2
			;;
711507
	esac
711507
711507
	if [ -z "$ccenv_os" ]; then
711507
		ccenv_os='anyos'
711507
	fi
188a79
188a79
	ccenv_attr_epilog "$ccenv_os"
711507
}
711507
711507
ccenv_set_os_flags()
711507
{
711507
	case "$ccenv_os" in
711507
		darwin )
711507
			ccenv_cflags_os='-D_DARWIN_C_SOURCE'
711507
			ccenv_cflags_pic='-fPIC'
711507
			;;
711507
		midipix )
711507
			ccenv_cflags_os=
711507
			ccenv_cflags_pic='-fPIC'
711507
			;;
711507
		cygwin )
711507
			ccenv_cflags_os=
711507
			ccenv_cflags_pic=
711507
			;;
711507
		msys | msys* | mingw | mingw* )
711507
			ccenv_cflags_os='-U__STRICT_ANSI__'
711507
			ccenv_cflags_pic=
711507
			;;
711507
		* )
711507
			ccenv_cflags_os=
711507
			ccenv_cflags_pic='-fPIC'
711507
			;;
711507
	esac
711507
}
711507
711507
ccenv_set_os_semantics()
711507
{
711507
	# binary_format - core_api - ex_api - dependency_resolution
711507
188a79
	ccenv_attr_prolog 'os semantics'
188a79
711507
	case "$ccenv_os" in
711507
		linux )
711507
			ccenv_os_semantics='elf-posix-linux-ldso'
711507
			;;
711507
		bsd )
711507
			ccenv_os_semantics='elf-posix-bsd-ldso'
711507
			;;
711507
		darwin )
711507
			ccenv_os_semantics='macho-posix-osx-ldso'
711507
			;;
711507
		midipix )
711507
			ccenv_os_semantics='pe-posix-winnt-ldso'
711507
			;;
711507
		cygwin )
711507
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
711507
			;;
711507
		msys )
711507
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
711507
			;;
711507
		mingw )
711507
			ccenv_os_semantics='pe-win32-winnt-unsafe'
711507
			;;
711507
	esac
711507
711507
	if [ -n "$ccenv_os_semantics" ]; then
188a79
		ccenv_attr_epilog "$ccenv_os_semantics"
711507
		return 0
711507
	fi
711507
711507
	if [ -n "$ccenv_cc_binfmt" ]; then
711507
		ccenv_os_semantics_pattern='%s-posix-anyos-unknown'
711507
		ccenv_os_semantics=$(printf                   \
711507
				"$ccenv_os_semantics_pattern"  \
711507
				"$ccenv_cc_binfmt"              \
711507
			| tr '[:upper:]' '[:lower:]')
711507
	else
711507
		ccenv_os_semantics='unknown-posix-anyos-unknown'
711507
	fi
188a79
188a79
	ccenv_attr_epilog "$ccenv_os_semantics"
711507
}
711507
89ad20
ccenv_set_os_dso_format()
89ad20
{
89ad20
	ccenv_attr_prolog 'os dso format'
89ad20
89ad20
	case "$ccenv_cc_arfmt" in
89ad20
		common )
89ad20
			ccenv_cc_sofmt="$ccenv_cc_binfmt"
89ad20
			;;
89ad20
89ad20
		bigaf )
89ad20
			ccenv_libgcc_s_a_header=$(od -b -N8             \
89ad20
				$($ccenv_cc -print-file-name=libgcc_s.a) \
89ad20
					2>/dev/null                       \
89ad20
					| head -n1)
89ad20
89ad20
			ccenv_libgcc_s_so_header=$(od -b -N8             \
89ad20
				$($ccenv_cc -print-file-name=libgcc_s.so) \
89ad20
					2>/dev/null                        \
89ad20
					| head -n1)
89ad20
89ad20
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_bigaf_header" ]; then
89ad20
				ccenv_cc_sofmt='bigaf'
89ad20
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_bigaf_header" ]; then
89ad20
				ccenv_cc_sofmt='bigaf'
89ad20
			else
89ad20
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
89ad20
			fi
89ad20
			;;
89ad20
89ad20
		aiaff )
89ad20
			ccenv_libgcc_s_a_header=$(od -b -N8               \
89ad20
				$($ccenv_cc -print-file-name=libgcc_s.a) \
89ad20
					| head -n1)
89ad20
89ad20
			ccenv_libgcc_s_so_header=$(od -b -N8               \
89ad20
				$($ccenv_cc -print-file-name=libgcc_s.so) \
89ad20
					| head -n1)
89ad20
89ad20
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_aiaff_header" ]; then
89ad20
				ccenv_cc_sofmt='aiaff'
89ad20
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_aiaff_header" ]; then
89ad20
				ccenv_cc_sofmt='aiaff'
89ad20
			else
89ad20
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
89ad20
			fi
89ad20
			;;
89ad20
	esac
89ad20
da740f
	if [ "$ccenv_cfgtype" = 'host' ]; then
da740f
		case "$ccenv_cc_sofmt" in
da740f
			bigaf | aiaff )
da740f
				mb_shared_lib_cmd='$(AR) -rcs'
da740f
				mb_shared_lib_ldflags=
da740f
				;;
da740f
da740f
			* )
da740f
				mb_shared_lib_cmd='$(CC) -shared -o'
da740f
				mb_shared_lib_ldflags='$(LDFLAGS_SHARED)'
da740f
				;;
da740f
		esac
da740f
	fi
da740f
89ad20
	ccenv_attr_epilog "$ccenv_cc_sofmt"
89ad20
}
89ad20
711507
ccenv_set_os_dso_exrules()
711507
{
188a79
	ccenv_attr_prolog 'os dso exrules'
188a79
711507
	case "$ccenv_os" in
711507
		midipix )
711507
			ccenv_os_dso_exrules='pe-mdso'
711507
			;;
711507
		* )
711507
			if [ "$ccenv_cc_binfmt" = 'PE' ]; then
711507
				ccenv_os_dso_exrules='pe-dlltool'
711507
			else
711507
				ccenv_os_dso_exrules='default'
711507
			fi
711507
	esac
188a79
188a79
	ccenv_attr_epilog "$ccenv_os_dso_exrules"
711507
}
711507
711507
ccenv_set_os_dso_linkage()
711507
{
711507
	# todo: PIC, PIE, and friends
188a79
	ccenv_attr_prolog 'os linkage'
711507
	ccenv_os_dso_linkage='default'
188a79
	ccenv_attr_epilog "$ccenv_os_dso_linkage"
711507
}
711507
711507
ccenv_set_os_dso_patterns_darwin()
711507
{
711507
	ccenv_os_app_prefix=
711507
	ccenv_os_app_suffix=
711507
711507
	ccenv_os_lib_prefix=lib
711507
	ccenv_os_lib_suffix=.dylib
711507
711507
	ccenv_os_implib_ext=.invalid
711507
	ccenv_os_libdef_ext=.invalid
711507
711507
	ccenv_os_archive_ext=.a
711507
	ccenv_os_soname=symlink
711507
711507
	ccenv_os_lib_prefixed_suffix=
711507
	ccenv_os_lib_suffixed_suffix='$(OS_LIB_SUFFIX)'
711507
}
711507
711507
ccenv_set_os_dso_patterns_mdso()
711507
{
711507
	ccenv_os_app_prefix=
711507
	ccenv_os_app_suffix=
711507
711507
	ccenv_os_lib_prefix=lib
711507
	ccenv_os_lib_suffix=.so
711507
711507
	ccenv_os_implib_ext=.lib.a
711507
	ccenv_os_libdef_ext=.so.def
711507
711507
	ccenv_os_archive_ext=.a
711507
	ccenv_os_soname=symlink
711507
711507
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
711507
	ccenv_os_lib_suffixed_suffix=
711507
}
711507
711507
ccenv_set_os_dso_patterns_dlltool()
711507
{
711507
	ccenv_os_app_prefix=
711507
	ccenv_os_app_suffix=.exe
711507
711507
	ccenv_os_lib_prefix=lib
711507
	ccenv_os_lib_suffix=.dll
711507
711507
	ccenv_os_implib_ext=.dll.a
711507
	ccenv_os_libdef_ext=.def
711507
711507
	ccenv_os_archive_ext=.a
711507
	ccenv_os_soname=copy
711507
711507
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
711507
	ccenv_os_lib_suffixed_suffix=
711507
}
711507
711507
ccenv_set_os_dso_patterns_default()
711507
{
711507
	ccenv_os_app_prefix=
711507
	ccenv_os_app_suffix=
711507
711507
	ccenv_os_lib_prefix=lib
711507
	ccenv_os_lib_suffix=.so
711507
711507
	ccenv_os_implib_ext=.invalid
711507
	ccenv_os_libdef_ext=.invalid
711507
711507
	ccenv_os_archive_ext=.a
711507
	ccenv_os_soname=symlink
711507
711507
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
711507
	ccenv_os_lib_suffixed_suffix=
711507
}
711507
711507
ccenv_set_os_dso_patterns()
711507
{
711507
	# sover: .so.x.y.z
711507
	# verso: .x.y.z.so
711507
711507
	case "$ccenv_os" in
711507
		darwin )
711507
			ccenv_set_os_dso_patterns_darwin
711507
			;;
711507
		midipix )
711507
			ccenv_set_os_dso_patterns_mdso
711507
			;;
711507
		cygwin | msys | mingw )
711507
			ccenv_set_os_dso_patterns_dlltool
711507
			;;
711507
		* )
711507
			ccenv_set_os_dso_patterns_default
711507
			;;
711507
	esac
711507
}
711507
ad1be2
ccenv_set_os_pe_switches()
ad1be2
{
3ffbfe
	if [ "$ccenv_cc_binfmt" = 'PE' ] && [ -z "$ccenv_pe_subsystem" ]; then
ad1be2
		case "$ccenv_os" in
ad1be2
			midipix | mingw )
ad1be2
				ccenv_pe_subsystem='windows'
ad1be2
				;;
ad1be2
			* )
ad1be2
				ccenv_pe_subsystem='console'
ad1be2
				;;
ad1be2
		esac
ad1be2
	fi
ad1be2
}
ad1be2
711507
ccenv_output_defs()
711507
{
711507
	ccenv_in="$mb_project_dir/sofort/ccenv/ccenv.in"
711507
	ccenv_mk="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
a9069f
	ccenv_tmp=
711507
ad1be2
	if [ "$ccenv_cc_binfmt" = 'PE' ]; then
ad1be2
		ccenv_pe="$mb_project_dir/sofort/ccenv/pedefs.in"
ad1be2
		ccenv_in="$ccenv_in $ccenv_pe"
ad1be2
	fi
ad1be2
711507
	if [ $ccenv_cfgtype = 'native' ]; then
711507
1cc479
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
711507
4ab906
		sed                                      \
801bf0
				-e 's/^[[:space:]]*$/@/g' \
4ab906
				-e 's/^/NATIVE_/'          \
4ab906
				-e 's/NATIVE_@//g'          \
4ab906
				-e 's/NATIVE_#/#/g'          \
4ab906
				-e 's/       =/=/g'           \
4ab906
				-e 's/       +=/+=/g'          \
43465b
			$(printf '%s ' $ccenv_in)               \
43465b
				> "$ccenv_tmp"
711507
711507
		ccenv_in="$ccenv_tmp"
1cc479
	else
a9069f
		unset ccenv_tmp
711507
	fi
711507
e17e46
	ccenv_var_defs=
55da10
	ccenv_sed_substs="-e s/@ccenv_cfgtype@/${ccenv_cfgtype}/g"
e17e46
711507
	ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
e17e46
		| grep -v '^#');
711507
55da10
	ccenv_exvars="ccenv_makevar_prefix"
711507
e17e46
	for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do
e17e46
		ccenv_sed_subst=$(printf '%s %s%s%s' \
e17e46
				'-e' "'s^@$__var@"    \
e17e46
				"^___${__var}___"      \
e17e46
				"^g'")
e17e46
e17e46
		ccenv_sed_substs="$ccenv_sed_substs $ccenv_sed_subst"
e17e46
e17e46
		ccenv_var_def=$(printf '%s%s="${%s}"' "-D" "___${__var}___" "${__var}")
e17e46
		eval ccenv_var_defs='"$ccenv_var_defs "$ccenv_var_def'
e17e46
	done
711507
e17e46
	eval sed $ccenv_sed_substs $(printf '%s ' $ccenv_in) \
e17e46
			| eval m4 $ccenv_var_defs -           \
e17e46
			| sed -e 's/[[:blank:]]*$//g'          \
711507
		> "$ccenv_mk"
711507
8fd818
	if [ "$ccenv_cfgtype" = 'host' ]; then
7d9a2d
		for __var in $(printf '%s' "$ccenv_vars"); do
8fd818
			ccenv_src_var=$__var
8fd818
			ccenv_dst_var=mb_${__var#*ccenv_}
8fd818
			ccenv_var_expr='${'$ccenv_src_var':-}'
8fd818
			eval $ccenv_dst_var=$ccenv_var_expr
8fd818
8fd818
		done
8fd818
8fd818
		mb_host=$ccenv_host
8fd818
		mb_cchost=$ccenv_cchost
8fd818
	else
7d9a2d
		for __var in $(printf '%s' "$ccenv_vars"); do
8fd818
			ccenv_src_var=$__var
8fd818
			ccenv_dst_var=mb_native_${__var#*ccenv_}
8fd818
			ccenv_var_expr='${'$ccenv_src_var':-}'
8fd818
			eval "$ccenv_dst_var=$ccenv_var_expr"
8fd818
		done
8fd818
8fd818
		mb_native_host=$ccenv_host
8fd818
		mb_native_cchost=$ccenv_cchost
8fd818
	fi
1cc479
1cc479
	if [ -n "${ccenv_tmp:-}" ]; then
1cc479
		rm -f "$ccenv_tmp"
1cc479
		unset ccenv_tmp
1cc479
	fi
ca04b4
f3088e
f3088e
	if [ "${ccenv_cfgtype}" = 'host' ]; then
f3088e
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-host)
f3088e
		ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-host)
f3088e
	else
f3088e
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-native)
f3088e
		ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-native)
f3088e
	fi
f3088e
f3088e
	ccenv_cflags="${ccenv_cflags#*: }"
f3088e
	ccenv_ldflags="${ccenv_ldflags#*: }"
f3088e
64c67f
	ccenv_sysroot=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
64c67f
		-print-sysroot 2>/dev/null || true)
64c67f
f3088e
	eval 'ccenv_'${ccenv_cfgtype}'_cflags'=\'$ccenv_cflags\'
f3088e
	eval 'ccenv_'${ccenv_cfgtype}'_ldflags'=\'$ccenv_ldflags\'
64c67f
	eval 'ccenv_'${ccenv_cfgtype}'_sysroot'=\'$ccenv_sysroot\'
f3088e
ca04b4
	eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\'
2752f5
	eval 'ccenv_'${ccenv_cfgtype}'_cc_environment'=\'$ccenv_cc_environment\'
0f6f7d
	eval 'ccenv_'${ccenv_cfgtype}'_dumpmachine_switch'=\'$ccenv_dumpmachine_switch\'
c45256
	eval 'ccenv_'${ccenv_cfgtype}'_pkgconf'=\'$ccenv_pkgconf\'
f3088e
711507
}
711507
edb877
ccenv_set_cc_sysroot_vars()
edb877
{
edb877
	if [ "$ccenv_cfgtype" = 'native' ] || [ -z "$mb_sysroot" ]; then
edb877
		return 0
edb877
	fi
edb877
edb877
	cfgtest_host_section
edb877
	ccenv_switch_var="--sysroot=${mb_sysroot}"
edb877
edb877
	if cfgtest_compiler_switch_arg "${ccenv_switch_var}"; then
edb877
		printf '\n# %s sysroot: cflags and ldflags\n' "$ccenv_cfgtype" \
edb877
			>> "$ccenv_mk"
edb877
edb877
		for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do
edb877
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
edb877
				>> "$ccenv_mk"
edb877
		done
edb877
	else
edb877
		printf '\n# %s sysroot: cflags and ldflags %s\n' "$ccenv_cfgtype" \
edb877
			'(not supported: see config.log)'                          \
edb877
			>> "$ccenv_mk"
edb877
edb877
		for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do
edb877
			printf '%-40s=\n' "${ccenv_make_var}" \
edb877
				>> "$ccenv_mk"
edb877
		done
edb877
	fi
edb877
}
edb877
1af58a
ccenv_set_cc_switch_vars()
1af58a
{
4c75ca
	printf '\n# %s cflags: supported compiler switches\n' "$ccenv_cfgtype" \
4c75ca
		>> "$ccenv_mk"
4c75ca
1af58a
	if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
dda1c8
		ccenv_switch_vars=$(cat                            \
1af58a
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
1af58a
			$mb_project_dir/project/config/ccswitch.strs \
dda1c8
		| grep -v -e '^#' -e '^-Wl,'                          \
dda1c8
		| sort -u)
1af58a
	else
725875
		ccenv_switch_vars=$(grep -v -e '^#' -e '^-Wl,'     \
1af58a
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
1af58a
			| sort -u)
1af58a
	fi
1af58a
1af58a
	if [ $ccenv_cfgtype = 'host' ]; then
1af58a
		ccenv_makevar_prefix='_CFLAGS_'
1af58a
		cfgtest_host_section
1af58a
	else
1af58a
		ccenv_makevar_prefix='_NATIVE_CFLAGS_'
1af58a
		cfgtest_native_section
1af58a
	fi
1af58a
1af58a
	for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
1af58a
		ccenv_make_var=${ccenv_switch_var%=}
1af58a
		ccenv_make_var=${ccenv_make_var%,}
1af58a
1af58a
		ccenv_make_var=${ccenv_make_var##---}
1af58a
		ccenv_make_var=${ccenv_make_var##--}
1af58a
		ccenv_make_var=${ccenv_make_var##-}
1af58a
1af58a
		ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
1af58a
			| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
1af58a
1af58a
		ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
1af58a
1af58a
		if cfgtest_compiler_switch "$ccenv_switch_var"; then
1af58a
			ccenv_switch_var=${ccenv_switch_var%=}
1af58a
			ccenv_switch_var=${ccenv_switch_var%,}
1af58a
132626
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
1af58a
				>> "$ccenv_mk"
1af58a
		else
132626
			printf '%-40s=\n' "${ccenv_make_var}" \
1af58a
				>> "$ccenv_mk"
1af58a
		fi
1af58a
	done
1af58a
}
1af58a
725875
ccenv_set_cc_linker_switch_vars()
725875
{
725875
	printf '\n# %s ldflags: supported compiler switches\n' "$ccenv_cfgtype" \
725875
		>> "$ccenv_mk"
725875
725875
	if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
dda1c8
		ccenv_switch_vars=$(cat                            \
725875
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
725875
			$mb_project_dir/project/config/ccswitch.strs \
dda1c8
			| grep -e '^-Wl,'                             \
725875
			| sort -u)
725875
	else
725875
		ccenv_switch_vars=$(grep -e '^-Wl,'                \
725875
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
725875
			| sort -u)
725875
	fi
725875
725875
	if [ $ccenv_cfgtype = 'host' ]; then
725875
		ccenv_makevar_prefix='_LDFLAGS_'
725875
		cfgtest_host_section
725875
	else
725875
		ccenv_makevar_prefix='_NATIVE_LDFLAGS_'
725875
		cfgtest_native_section
725875
	fi
725875
725875
	for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
725875
		ccenv_make_var=${ccenv_switch_var%=}
725875
		ccenv_make_var=${ccenv_make_var%,}
725875
725875
		ccenv_make_var=${ccenv_make_var##---}
725875
		ccenv_make_var=${ccenv_make_var##--}
725875
		ccenv_make_var=${ccenv_make_var##-}
725875
725875
		ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
725875
			| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
725875
725875
		ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
725875
725875
		if cfgtest_compiler_switch "$ccenv_switch_var"; then
725875
			ccenv_switch_var=${ccenv_switch_var%=}
725875
			ccenv_switch_var=${ccenv_switch_var%,}
725875
725875
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
725875
				>> "$ccenv_mk"
725875
		else
725875
			printf '%-40s=\n' "${ccenv_make_var}" \
725875
				>> "$ccenv_mk"
725875
		fi
725875
	done
725875
}
725875
5dbfba
ccenv_dso_verify()
5dbfba
{
5dbfba
	ccenv_str='int foo(int x){return ++x;}'
5dbfba
	ccenv_cmd="$ccenv_cc -xc - -shared -o a.out"
5dbfba
5dbfba
	rm -f a.out
5dbfba
03b8d4
	printf '%s' "$ccenv_str" | $(printf %s "$ccenv_cmd") \
bbde52
		> /dev/null 2>&3              \
5dbfba
	|| mb_disable_shared=yes
5dbfba
5dbfba
	rm -f a.out
5dbfba
}
5dbfba
711507
ccenv_clean_up()
711507
{
711507
	rm -f $ccenv_image
711507
}
711507
711507
ccenv_common_init()
711507
{
711507
	. "$mb_project_dir/sofort/ccenv/ccenv.vars"
711507
711507
	ccenv_cfgtype=$1
711507
	ccenv_cfgfile="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
5b51ca
	ccenv_cchost=
711507
711507
	if [ $ccenv_cfgtype = 'native' ]; then
711507
		ccenv_makevar_prefix='NATIVE_'
711507
		ccenv_image='./ccenv/native.a.out'
711507
	else
711507
		ccenv_makevar_prefix=
711507
		ccenv_image='./ccenv/host.a.out'
711507
	fi
711507
711507
	if [ $ccenv_cfgtype = 'native' ]; then
711507
		ccenv_prefixes=
711507
	elif [ -n "$mb_cross_compile" ]; then
711507
		ccenv_prefixes="$mb_cross_compile"
711507
	elif [ -n "$mb_host" ]; then
711507
		ccenv_prefixes="$mb_host-"
711507
	else
711507
		ccenv_prefixes=
711507
	fi
711507
711507
	if [ $ccenv_cfgtype = 'host' ]; then
711507
		ccenv_tflags=
8b174a
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
2e3df6
			OS_DSO_EXRULES=default                          \
2e3df6
			OS_SONAME=symlink                                \
1a7e55
			OS_ARCHIVE_EXT='.a'                               \
2e3df6
			.cflags-host)
1541ba
8b174a
		ccenv_cflags="${ccenv_cflags#*: }"
8b174a
711507
		ccenv_cc="$mb_user_cc"
711507
		ccenv_cpp="$mb_user_cpp"
711507
		ccenv_cxx="$mb_user_cxx"
ad1be2
ad1be2
		ccenv_pe_subsystem="$mb_pe_subsystem"
ad1be2
		ccenv_pe_image_base="$mb_pe_image_base"
711507
	else
711507
		ccenv_tflags=
8b174a
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
2e3df6
			OS_DSO_EXRULES=default                          \
2e3df6
			OS_SONAME=symlink                                \
1a7e55
			OS_ARCHIVE_EXT='.a'                               \
2e3df6
			.cflags-native)
2e3df6
8b174a
		ccenv_cflags="${ccenv_cflags#*: }"
8b174a
711507
		ccenv_cc="$mb_native_cc"
711507
		ccenv_cpp="$mb_native_cpp"
711507
		ccenv_cxx="$mb_native_cxx"
ad1be2
ad1be2
		ccenv_pe_subsystem="$mb_native_pe_subsystem"
ad1be2
		ccenv_pe_image_base="$mb_native_pe_image_base"
711507
	fi
711507
}
711507
711507
ccenv_set_characteristics()
711507
{
711507
	ccenv_set_cc_host
711507
	ccenv_set_cc_bits
711507
	ccenv_set_cc_binfmt
188a79
	ccenv_set_cc_underscore
711507
}
711507
711507
ccenv_set_toolchain_variables()
711507
{
711507
	ccenv_common_init $1
711507
	ccenv_set_cc
711507
	ccenv_set_cpp
711507
	ccenv_set_cxx
711507
	ccenv_set_primary_tools
711507
	ccenv_set_tool_variants
711507
	ccenv_set_characteristics
711507
711507
	ccenv_set_os
711507
	ccenv_set_os_flags
711507
	ccenv_set_os_semantics
89ad20
	ccenv_set_os_dso_format
711507
	ccenv_set_os_dso_exrules
711507
	ccenv_set_os_dso_linkage
711507
	ccenv_set_os_dso_patterns
ad1be2
	ccenv_set_os_pe_switches
711507
711507
	ccenv_output_defs
711507
	ccenv_clean_up
1af58a
edb877
	ccenv_set_cc_sysroot_vars
1af58a
	ccenv_set_cc_switch_vars
725875
	ccenv_set_cc_linker_switch_vars
711507
}
711507
711507
ccenv_set_host_variables()
711507
{
188a79
	output_script_status ${mb_script} \
7df17c
		'detect and query host (targeted) system'
188a79
711507
	ccenv_set_toolchain_variables 'host'
5dbfba
	ccenv_dso_verify
711507
}
711507
711507
ccenv_set_native_variables()
711507
{
188a79
	output_script_status ${mb_script} \
7df17c
		'detect and query native (local build) system'
188a79
b28199
	if [ _$mb_ccenv_skip_native != _yes ]; then
b28199
		ccenv_set_toolchain_variables 'native'
b28199
	fi
711507
}