Blame sofort/ccenv/ccenv.sh

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