Blame sofort/ccenv/ccenv.sh

fd9ebd
ac2c20
# ccenv.sh: sofort's tool-finding bits,
ac2c20
# invoked from within the project-agnostic configure script.
ac2c20
7a3ffb
# this file is covered by COPYING.SOFORT.
7a3ffb
ac2c20
# invocation and names of binary tools:
ac2c20
# agnostic names (ar, nm, objdump, ...);
ac2c20
# target-prefixed agnostic names (x86_64-nt64-midipix-ar, ...);
ac2c20
# branded names (llvm-ar, llvm-nm, llvm-objdump, ...);
ac2c20
# target-prefixed branded names (x86_64-linux-gnu-gcc-ar, ...);
ac2c20
# target-specifying branded tools (llvm-ar --target=x86_64-linux, ...).
ac2c20
ac2c20
# cross-compilation: default search order:
ac2c20
# target-prefixed agnostic tools;
ac2c20
# target-prefixed branded tools, starting with the prefix
ac2c20
# most commonly associated with the selected compiler (that is,
ac2c20
# ``gcc'' when using gcc, and ``llvm'' when using clang);
ac2c20
# target-speficying branded tools, starting once again with the
ac2c20
# prefix most commonly associated with the selected compiler.
ac2c20
ac2c20
# internal variables of interest:
ac2c20
# ccenv_cfgtype: the type of host being tested (host/native)
ac2c20
# ccenv_cfgfile: the configuration file for the host being tested
ac2c20
# ccenv_cflags:  the comprehensive cflags for the host being tested
ac2c20
# ccenv_cchost:  the host being tested, as reported by -dumpmachine
ac2c20
fd9ebd
# variables available to cfgdefs.sh and cfgfini.sh:
fd9ebd
# ccenv_host_cflags:    expanded cflags, valid for the host compiler
fd9ebd
# ccenv_host_ldflags:   expanded ldflags, valid for the host compiler
48f78a
# ccenv_host_sysroot:   host sysroot, as reported by the host compiler
fd9ebd
# ccenv_native_cflags:  expanded cflags, valid for the native compiler
fd9ebd
# ccenv_native_ldflags: expanded ldflags, valid for the native compiler
48f78a
# ccenv_native_sysroot: native sysroot, as reported by the native compiler
ac2c20
ac2c20
ccenv_usage()
ac2c20
{
ac2c20
	cat "$mb_project_dir"/sofort/ccenv/ccenv.usage
ac2c20
	exit 0
ac2c20
}
ac2c20
ac2c20
ac2c20
ccenv_newline()
ac2c20
{
ac2c20
	printf '\n' >> "$ccenv_cfgfile"
ac2c20
}
ac2c20
ac2c20
ac2c20
ccenv_comment()
ac2c20
{
ac2c20
	ccenv_internal_str='#'
ac2c20
ac2c20
	for ccenv_internal_arg ; do
ac2c20
		ccenv_internal_str="$ccenv_internal_str $ccenv_internal_arg"
ac2c20
	done
ac2c20
ac2c20
	printf '%s\n' "$ccenv_internal_str" >> "$ccenv_cfgfile"
ac2c20
}
ac2c20
ac2c20
8be87f
ccenv_tool_prolog()
8be87f
{
c21b29
	ccenv_line_dots='.....................................'
14a1b5
	ccenv_tool_desc=" == checking for ${1}"
8be87f
	ccenv_tool_dlen="${#ccenv_line_dots}"
8be87f
9d19fd
	printf '\n%s\n' '________________________' >&3
9d19fd
	printf "ccenv: checking for ${1}\n\n" >&3
8be87f
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s" \
c21b29
		"${ccenv_tool_desc}  ${mb_line_dots}"
8be87f
}
8be87f
8be87f
8be87f
ccenv_tool_epilog()
8be87f
{
8be87f
	ccenv_line_dots='................................'
8be87f
	ccenv_tool_dlen="$((${#ccenv_line_dots} - ${#1}))"
8be87f
58ca8a
	case ${ccenv_tool_dlen} in
58ca8a
		0 | -* )
58ca8a
			ccenv_tool_dlen='3' ;;
58ca8a
	esac
58ca8a
c21b29
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
8be87f
		"${ccenv_line_dots}" "${1}"
9d19fd
9d19fd
	if [ "${1}" = 'false' ]; then
9d19fd
		printf '\n\nccenv: not (yet) found.\n' >&3
9d19fd
	else
9d19fd
		printf "\n\nccenv : found $(command -v ${1}).\n" >&3
9d19fd
	fi
9d19fd
9d19fd
	printf '%s\n' '------------------------' >&3
8be87f
}
8be87f
8be87f
136198
ccenv_tool_variant_epilog()
136198
{
136198
	ccenv_expr=${1}='${'${1}':-false}'
136198
	eval "$ccenv_expr"
136198
136198
	ccenv_expr='${'${1}'}'
136198
	eval ccenv_tool_epilog "$ccenv_expr"
136198
}
136198
136198
8be87f
ccenv_attr_prolog()
8be87f
{
c21b29
	ccenv_line_dots=' .....................................'
c21b29
	ccenv_attr_desc=" == detect ${ccenv_cfgtype} ${1}"
8be87f
	ccenv_attr_dlen="${#ccenv_line_dots}"
8be87f
8be87f
	printf "%${ccenv_attr_dlen}.${ccenv_attr_dlen}s" \
8be87f
		"${ccenv_attr_desc} ${ccenv_line_dots}"
9d19fd
9d19fd
	printf '\n%s\n' '________________________' >&3
9d19fd
	printf "ccenv: detecting ${1}\n\n" >&3
8be87f
}
8be87f
8be87f
8be87f
ccenv_attr_epilog()
8be87f
{
9d19fd
	ccenv_line_dots='................................'
c21b29
	ccenv_tool_dlen="$((${#ccenv_line_dots} - 1 - ${#1}))"
9d19fd
58ca8a
	case ${ccenv_tool_dlen} in
58ca8a
		0 | -* )
58ca8a
			ccenv_tool_dlen='3' ;;
58ca8a
	esac
58ca8a
c21b29
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
9d19fd
		"${ccenv_line_dots}" "${1}"
9d19fd
9d19fd
	printf '\n\nccenv: detected result: %s\n' "${1}" >&3
9d19fd
	printf '%s\n' '------------------------' >&3
8be87f
}
8be87f
8be87f
ac2c20
ccenv_find_tool()
ac2c20
{
ac2c20
	if [ -z "$ccenv_prefixes" ]; then
0f630f
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
6aee35
			ccenv_cmd_args="${@:-}"
6aee35
6aee35
			if [ -z "$ccenv_cmd_args" ]; then
5c16e6
				if command -v "$ccenv_candidate" > /dev/null; then
5c16e6
					ccenv_tool="$ccenv_candidate"
c95142
					return 0
71b476
				fi
c95142
			else
5c16e6
				if command -v "$ccenv_candidate" > /dev/null; then
9d19fd
					if "$ccenv_candidate" $@ > /dev/null 2>&3; then
5c16e6
						ccenv_tool="$ccenv_candidate"
c95142
						return 0
71b476
					fi
71b476
				fi
c95142
			fi
ac2c20
		done
ac2c20
ac2c20
		ccenv_tool=false
ac2c20
ac2c20
		return 0
ac2c20
	fi
ac2c20
0f630f
	for ccenv_prefix in $(printf '%s' "$ccenv_prefixes"); do
0f630f
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
ac2c20
			ccenv_tool="$ccenv_prefix$ccenv_candidate"
71b476
71b476
			if command -v "$ccenv_tool" > /dev/null; then
71b476
				return 0
71b476
			fi
ac2c20
		done
ac2c20
	done
ac2c20
0f630f
	for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
5c16e6
		if command -v "$ccenv_candidate" > /dev/null; then
5c16e6
			ccenv_tool="$ccenv_candidate"
71b476
			return 0
71b476
		fi
ac2c20
	done
ac2c20
ac2c20
	ccenv_tool=false
ac2c20
ac2c20
	return 0
ac2c20
}
ac2c20
ac2c20
ac2c20
ccenv_set_primary_tools()
ac2c20
{
ac2c20
	ccenv_core_tools="ar nm objdump ranlib size strip strings objcopy"
7bea32
	ccenv_hack_tools="addr2line cov elfedit readelf readobj otool"
c3a670
	ccenv_peep_tools="perk mdso dlltool windmc windres pkgconf"
ac2c20
0f630f
	for __tool in $(printf '%s' "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do
8be87f
		ccenv_tool_prolog "$__tool"
8be87f
ac2c20
		if [ -n "$mb_agnostic" ]; then
ac2c20
			ccenv_candidates=" $__tool"
ac2c20
ac2c20
		elif [ -n "$mb_zealous" ]; then
ac2c20
			ccenv_candidates="$mb_zealous-$__tool"
ac2c20
ac2c20
		elif [ "$mb_toolchain" = 'gcc' ]; then
ac2c20
			ccenv_candidates="gcc-$__tool"
ac2c20
			ccenv_candidates="$ccenv_candidates $__tool"
ac2c20
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
ac2c20
ac2c20
		elif [ "$mb_toolchain" = 'llvm' ]; then
ac2c20
			ccenv_candidates="llvm-$__tool"
ac2c20
			ccenv_candidates="$ccenv_candidates $__tool"
ac2c20
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
ac2c20
ac2c20
		elif [ -n "$mb_toolchain" ]; then
ac2c20
			ccenv_candidates="$mb_toolchain-$__tool"
ac2c20
			ccenv_candidates="$ccenv_candidates $__tool"
ac2c20
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
ac2c20
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
ac2c20
c538e9
		elif [ "$__tool" = 'pkgconf' ]; then
c538e9
			ccenv_candidates="$__tool pkg-config"
c538e9
ac2c20
		else
ac2c20
			ccenv_candidates="$__tool"
ac2c20
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
ac2c20
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
ac2c20
		fi
ac2c20
ac2c20
		if [ "$ccenv_cfgtype" = 'host' ]; then
ac2c20
			ccenv_var_prefix='mb_'
ac2c20
		else
ac2c20
			ccenv_var_prefix='mb_native_'
ac2c20
		fi
ac2c20
e3a3b8
		ccenv_tool=
ac2c20
		ccenv_var_name=$ccenv_var_prefix$__tool
ac2c20
		ccenv_var_expr='${'$ccenv_var_name':-}'
ac2c20
		eval ccenv_var_val=$ccenv_var_expr
ac2c20
ac2c20
		if [ -n "$ccenv_var_val" ]; then
ac2c20
			eval ccenv_$__tool="$ccenv_var_val"
e3a3b8
			ccenv_tool="$ccenv_var_val"
ac2c20
		else
ac2c20
			ccenv_find_tool
ac2c20
			eval ccenv_$__tool="$ccenv_tool"
ac2c20
		fi
8be87f
8be87f
		ccenv_tool_epilog "$ccenv_tool"
ac2c20
	done
ac2c20
ac2c20
	# windrc
ac2c20
	ccenv_windrc="$ccenv_windres"
f44ee3
f44ee3
	# archive format preamble
f863c9
	if [ -n "$ccenv_dumpmachine_switch" ]; then
c83bce
		ccenv_libgcc_path=$($ccenv_cc -print-file-name=libgcc.a \
c83bce
			2>/dev/null)
c83bce
c83bce
		if [ -n "$ccenv_libgcc_path" ]; then
c83bce
			ccenv_libgcc_a_header=$(od -b -N8             \
c83bce
				$($ccenv_cc -print-file-name=libgcc.a) \
c83bce
				| head -n1)
c83bce
		else
c83bce
			ccenv_libgcc_a_header=
c83bce
		fi
f863c9
	else
f863c9
		ccenv_libgcc_a_header=
f863c9
	fi
f863c9
f863c9
	# ar (default)
f44ee3
	ccenv_cc_arfmt='common'
f44ee3
f44ee3
	# ar (big)
f44ee3
	ccenv_bigaf_header=$(printf '%s\n' '<bigaf>' | od -b | head -n1)
f44ee3
f44ee3
	if [ "$ccenv_libgcc_a_header" = "$ccenv_bigaf_header" ]; then
f44ee3
		ccenv_cc_arfmt='bigaf'
f44ee3
f44ee3
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
f44ee3
			ccenv_var_name=ccenv_$__tool
f44ee3
			ccenv_var_expr='${'$ccenv_var_name':-}'
f44ee3
			eval ccenv_var_val="$ccenv_var_expr"
f44ee3
f44ee3
			if [ "$ccenv_var_val" != false ]; then
f44ee3
				ccenv_var_val="$ccenv_var_val -X64"
f44ee3
				ccenv_var_expr='${ccenv_var_val:-}'
f44ee3
				eval ccenv_$__tool="$ccenv_var_expr"
f44ee3
			fi
f44ee3
		done
f44ee3
	fi
f44ee3
f44ee3
	# ar (small)
f44ee3
	ccenv_aiaff_header=$(printf '%s\n' '<aiaff>' | od -b | head -n1)
f44ee3
f44ee3
	if [ "$ccenv_libgcc_a_header" = "$ccenv_aiaff_header" ]; then
f44ee3
		ccenv_cc_arfmt='aiaff'
f44ee3
f44ee3
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
f44ee3
			ccenv_var_name=ccenv_$__tool
f44ee3
			ccenv_var_expr='${'$ccenv_var_name':-}'
f44ee3
			eval ccenv_var_val="$ccenv_var_expr"
f44ee3
f44ee3
			if [ "$ccenv_var_val" != false ]; then
f44ee3
				ccenv_var_val="$ccenv_var_val -X32"
f44ee3
				ccenv_var_expr='${ccenv_var_val:-}'
f44ee3
				eval ccenv_$__tool="$ccenv_var_expr"
f44ee3
			fi
f44ee3
		done
f44ee3
	fi
ac2c20
}
ac2c20
ac2c20
ccenv_set_tool_variants()
ac2c20
{
ac2c20
	# as (asm)
8be87f
	ccenv_tool_prolog 'as (asm)'
ac2c20
	ccenv_candidates=as
ac2c20
	ccenv_find_tool
ac2c20
ac2c20
	if [ "$ccenv_tool" = false ]; then
ac2c20
		ccenv_as_asm=
ac2c20
	else
1df990
		$ccenv_tool --help 2>&1 | grep -i '.bc assembler' \
ac2c20
		|| ccenv_as_asm="$ccenv_tool"
ac2c20
	fi
ac2c20
136198
	ccenv_tool_variant_epilog 'ccenv_as_asm'
8be87f
ac2c20
	# as (ll)
8be87f
	ccenv_tool_prolog 'as (ll)'
ac2c20
	ccenv_candidates=llvm-as
ac2c20
	ccenv_find_tool
ac2c20
ac2c20
	if [ "$ccenv_tool" != false ]; then
ac2c20
		ccenv_as_ll="$ccenv_tool"
ac2c20
	fi
ac2c20
136198
	ccenv_tool_variant_epilog 'ccenv_as_ll'
8be87f
ac2c20
	# as (mc)
8be87f
	ccenv_tool_prolog 'as (mc)'
ac2c20
	ccenv_candidates=llvm-mc
ac2c20
	ccenv_find_tool
ac2c20
ac2c20
	if [ "$ccenv_tool" != false ]; then
ac2c20
		ccenv_as_mc="$ccenv_tool"
ac2c20
	fi
ac2c20
136198
	ccenv_tool_variant_epilog 'ccenv_as_mc'
8be87f
ac2c20
	# ld (bfd)
8be87f
	ccenv_tool_prolog 'ld (bfd)'
ac2c20
	ccenv_candidates=ld.bfd
ac2c20
	ccenv_find_tool
ac2c20
ac2c20
	if [ "$ccenv_tool" != false ]; then
ac2c20
		ccenv_ld_bfd="$ccenv_tool"
ac2c20
	fi
ac2c20
136198
	ccenv_tool_variant_epilog 'ccenv_ld_bfd'
8be87f
ac2c20
	# ld (gold)
8be87f
	ccenv_tool_prolog 'ld (gold)'
ac2c20
	ccenv_candidates=ld.gold
ac2c20
	ccenv_find_tool
ac2c20
ac2c20
	if [ "$ccenv_tool" != false ]; then
ac2c20
		ccenv_ld_gold="$ccenv_tool"
ac2c20
	fi
ac2c20
136198
	ccenv_tool_variant_epilog 'ccenv_ld_gold'
8be87f
ac2c20
	# ld (lld)
8be87f
	ccenv_tool_prolog 'ld (lld)'
ac2c20
	ccenv_candidates=lld
ac2c20
	ccenv_find_tool
ac2c20
ac2c20
	if [ "$ccenv_tool" != false ]; then
ac2c20
		ccenv_ld_lld="$ccenv_tool"
ac2c20
	fi
ac2c20
136198
	ccenv_tool_variant_epilog 'ccenv_ld_lld'
8be87f
ac2c20
	# objdump (bfd)
8be87f
	ccenv_tool_prolog 'objdump (bfd)'
ac2c20
	ccenv_candidates=objdump
ac2c20
	ccenv_find_tool
ac2c20
c1b214
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
c1b214
		ccenv_objdump_bfd="$ccenv_tool"
c1b214
	fi
ac2c20
136198
	ccenv_tool_variant_epilog 'ccenv_objdump_bfd'
8be87f
ac2c20
	# objdump (llvm)
8be87f
	ccenv_tool_prolog 'objdump (llvm)'
ac2c20
	ccenv_candidates=llvm-objdump
ac2c20
	ccenv_find_tool
ac2c20
c1b214
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
c1b214
		ccenv_objdump_llvm="$ccenv_tool"
c1b214
	fi
ac2c20
136198
	ccenv_tool_variant_epilog 'ccenv_objdump_llvm'
8be87f
ac2c20
	# readelf (bfd)
8be87f
	ccenv_tool_prolog 'readelf (bfd)'
ac2c20
	ccenv_candidates=readelf
ac2c20
	ccenv_find_tool
ac2c20
c1b214
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
c1b214
		ccenv_readelf_bfd="$ccenv_tool"
c1b214
	fi
ac2c20
136198
	ccenv_tool_variant_epilog 'ccenv_readelf_bfd'
8be87f
ac2c20
	# readelf (llvm)
8be87f
	ccenv_tool_prolog 'readelf (llvm)'
ac2c20
	ccenv_candidates=llvm-readelf
ac2c20
	ccenv_find_tool
ac2c20
c1b214
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
c1b214
		ccenv_readelf_llvm="$ccenv_tool"
c1b214
	fi
ac2c20
136198
	ccenv_tool_variant_epilog 'ccenv_readelf_llvm'
8be87f
ac2c20
	# as
ac2c20
	if [ -n "$ccenv_cc" ]; then
a6b0ef
		ccenv_as='$('"$ccenv_makevar_prefix"'CC) -c -x assembler'
ac2c20
	elif [ -n "$mb_agnostic" ]; then
ac2c20
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
ac2c20
	elif [ "$mb_zealous" = 'gcc' ]; then
ac2c20
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
ac2c20
	elif [ -n "$mb_zealous" = 'llvm' ]; then
ac2c20
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
ac2c20
	elif [ "$mb_toolchain" = 'gcc' ]; then
ac2c20
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
ac2c20
	elif [ "$mb_toolchain" = 'llvm' ]; then
ac2c20
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
ac2c20
	fi
ac2c20
ac2c20
	# ld
ac2c20
	if [ -n "$ccenv_cc" ]; then
ac2c20
		ccenv_ld='$('"$ccenv_makevar_prefix"'CC) -nostdlib -nostartfiles'
ac2c20
	fi
ac2c20
}
ac2c20
ac2c20
ccenv_set_c_compiler_candidates()
ac2c20
{
ac2c20
	if   [ -n "$mb_compiler" ]; then
ac2c20
		ccenv_candidates="$mb_compiler"
ac2c20
ac2c20
	elif [ -n "$mb_agnostic" ]; then
ac2c20
		ccenv_candidates="c99 c11 cc"
ac2c20
ac2c20
	elif [ "$mb_zealous" = 'gcc' ]; then
ac2c20
		ccenv_candidates="gcc"
ac2c20
ac2c20
	elif [ "$mb_zealous" = 'llvm' ]; then
ac2c20
		ccenv_candidates="clang"
ac2c20
ac2c20
	elif [ "$mb_toolchain" = 'gcc' ]; then
ac2c20
		ccenv_candidates="gcc c99 c11 cc clang"
ac2c20
ac2c20
	elif [ "$mb_toolchain" = 'llvm' ]; then
ac2c20
		ccenv_candidates="clang c99 c11 cc gcc"
ac2c20
ac2c20
	elif [ -n "$mb_toolchain" ]; then
ac2c20
		ccenv_candidates="$mb_toolchain c99 c11 cc gcc clang"
ac2c20
ac2c20
	else
dbe2de
		ccenv_candidates="cc gcc clang c99 c11"
ac2c20
	fi
ac2c20
}
ac2c20
ac2c20
ac2c20
ccenv_set_cc()
ac2c20
{
8be87f
	ccenv_tool_prolog 'C compiler'
8be87f
ac2c20
	if [ -z "$ccenv_cc" ]; then
ac2c20
		ccenv_set_c_compiler_candidates
f863c9
		ccenv_find_tool
ac2c20
		ccenv_cc="$ccenv_tool"
ac2c20
	fi
ac2c20
f863c9
ac2c20
	if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
ac2c20
		ccenv_cc="$mb_compiler"
ac2c20
	fi
ac2c20
f863c9
	ccenv_tool_epilog "$ccenv_cc"
f863c9
f863c9
f863c9
	if [ $ccenv_cfgtype = 'host' ]; then
f863c9
		ccenv_host_cc="$ccenv_cc"
f863c9
		cfgtest_host_section
f863c9
		ccenv_host_cc=
f863c9
	else
f863c9
		ccenv_native_cc="$ccenv_cc"
f863c9
		cfgtest_native_section
f863c9
		ccenv_native_cc=
f863c9
	fi
f863c9
fc699b
	cfgtest_silent='yes'
fc699b
f863c9
	if cfgtest_compiler_switch -dumpmachine ; then
f863c9
		ccenv_dumpmachine_switch='-dumpmachine'
f863c9
	else
f863c9
		ccenv_dumpmachine_switch=
f863c9
	fi
f863c9
dde01a
	if cfgtest_code_snippet_asm 'typedef int dummy;' ; then
dde01a
		eval ccenv_${ccenv_cfgtype}_stdin_input='yes'
dde01a
	else
dde01a
		eval ccenv_${ccenv_cfgtype}_stdin_input='no'
dde01a
	fi
dde01a
fc699b
	unset cfgtest_silent
fc699b
ac2c20
	ccenv_cc_cmd="$ccenv_cc"
757ba9
	ccenv_errors=
ac2c20
ac2c20
	if [ "$ccenv_cfgtype" = 'native' ]; then
f3e672
		ccenv_host=
f3e672
3a1303
		if [ -n "$mb_native_host" ]; then
3a1303
			ccenv_host="$mb_native_host"
3a1303
3a1303
		elif [ -n "$ccenv_dumpmachine_switch" ]; then
f863c9
			ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
f863c9
				$ccenv_dumpmachine_switch 2>&3)
f3e672
f3e672
		elif command -v slibtool > /dev/null 2>&1; then
912a58
			ccenv=$(slibtool --dumpmachine 2>/dev/null || true)
f3e672
		fi
f3e672
f3e672
		if [ -z "$ccenv_host" ]; then
3a1303
			ccenv_machine=$(uname -m 2>/dev/null)
3a1303
			ccenv_system=$(uname -s 2>/dev/null)
3a1303
3a1303
			ccenv_machine="${ccenv_machine:-unknown}"
3a1303
			ccenv_system="${ccenv_system:-anyos}"
3a1303
3a1303
			ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \
4b6b85
				| tr '[[:upper:]]' '[[:lower:]]')
f863c9
		fi
f863c9
5e5091
		ccenv_cchost=$ccenv_host
ac2c20
		return 0
ac2c20
	fi
ac2c20
f863c9
ac2c20
	if [ -n "$mb_cchost" ]; then
ac2c20
		ccenv_host="$mb_cchost"
ac2c20
	elif [ -n "$mb_host" ]; then
ac2c20
		ccenv_host="$mb_host"
ac2c20
	else
ac2c20
		ccenv_host=
ac2c20
	fi
ac2c20
f863c9
	if [ -z "$ccenv_host" ] && [ -n "$ccenv_dumpmachine_switch" ]; then
f863c9
		ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
f863c9
			$ccenv_dumpmachine_switch 2>&3)
ac2c20
		ccenv_cchost=$ccenv_host
f863c9
f863c9
	elif [ -z "$ccenv_host" ]; then
f3e672
		# no -dumpmachine support and no --host argument implies native build
f3e672
		if command -v slibtool > /dev/null 2>&1; then
912a58
			ccenv=$(slibtool --dumpmachine 2>/dev/null || true)
f3e672
		fi
3a1303
f3e672
		if [ -z "$ccenv_host" ]; then
f3e672
			ccenv_machine=$(uname -m 2>/dev/null)
f3e672
			ccenv_system=$(uname -s 2>/dev/null)
f3e672
f3e672
			ccenv_machine="${ccenv_machine:-unknown}"
f3e672
			ccenv_system="${ccenv_system:-anyos}"
3a1303
f3e672
			ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \
f3e672
				| tr '[[:upper:]]' '[[:lower:]]')
f3e672
		fi
3a1303
f863c9
		ccenv_cchost=$ccenv_host
f863c9
f863c9
	elif [ -n "$ccenv_dumpmachine_switch" ]; then
25df51
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
ac2c20
		ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -"
ac2c20
ac2c20
		if [ -z "$mb_user_cc" ]; then
1f75e6
			$(printf %s "$ccenv_cmd") < /dev/null > /dev/null \
ac2c20
				2>"$ccenv_tmp" || true
ac2c20
ac2c20
			ccenv_errors=$(cat "$ccenv_tmp")
ac2c20
ac2c20
			if [ -z "$ccenv_errors" ]; then
f863c9
				ccenv_tool_prolog 'C compiler for host'
ac2c20
				ccenv_tflags="--target=$ccenv_host"
ac2c20
				ccenv_cc="$ccenv_cc $ccenv_tflags"
f863c9
				ccenv_tool_epilog "$ccenv_cc"
9d19fd
			else
9d19fd
				printf '%s' "$ccenv_errors" >&3
ac2c20
			fi
ac2c20
		fi
ac2c20
25df51
		rm -f "$ccenv_tmp"
25df51
		unset ccenv_tmp
25df51
f863c9
		ccenv_cchost=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
f863c9
			$ccenv_dumpmachine_switch 2>&3)
ac2c20
	fi
ac2c20
ff3916
	if [ -z "$ccenv_dumpmachine_switch" ] && [ -n "$ccenv_host" ]; then
ff3916
		ccenv_cchost="$ccenv_host"
ff3916
ff3916
	elif [ "$ccenv_cchost" != "$ccenv_host" ]; then
9d19fd
		printf 'error!\n' >&2
ac2c20
		printf 'ccenv:\n' >&2
ac2c20
		printf 'ccenv: ccenv_host:   %s \n' $ccenv_host >&2
ac2c20
		printf 'ccenv: ccenv_cchost: %s \n' $ccenv_cchost >&2
ac2c20
ac2c20
		if [ -z "$ccenv_tflags" ]; then
ac2c20
			printf 'ccenv:\n' >&2
ac2c20
			printf 'ccenv: ccenv_host and ccenv_cchost do not match, most likely because:\n' >&2
ac2c20
			printf 'ccenv: (1) you explicitly set CC (or passed --compiler=...)\n' >&2
ac2c20
			printf 'ccenv: (2) the selected compiler does not accept --target=...\n' >&2
ac2c20
			printf 'ccenv: (3) the host reported by -dumpmachine differs from the one you requested.\n' >&2
ac2c20
		fi
ac2c20
ac2c20
		if [ -n "$ccenv_errors" ]; then
ac2c20
			printf 'ccenv:\n' >&2
ac2c20
			printf 'ccenv: something went wrong, see the command and compiler message below.\n\n' >&2
ac2c20
			printf 'cmd: %s < /dev/null > /dev/null\n' "$ccenv_cmd" >&2
ac2c20
			printf '%s\n\n' "$ccenv_errors" >&2
ac2c20
		else
ac2c20
			printf 'ccenv:\n' >&2
ac2c20
			printf 'ccenv: something went wrong, bailing out.\n\n' >&2
ac2c20
		fi
ac2c20
ac2c20
		return 2
ac2c20
	fi
ac2c20
}
ac2c20
ac2c20
ccenv_set_cpp()
ac2c20
{
8be87f
	ccenv_tool_prolog 'C pre-processor'
8be87f
ac2c20
	case "$ccenv_cc_cmd" in
ac2c20
		cc | c99 | c11 | gcc)
ac2c20
			ccenv_cpp_prefix=
ac2c20
			ccenv_candidates="cpp" ;;
ac2c20
ac2c20
		clang )
ac2c20
			ccenv_cpp_prefix=
ac2c20
			ccenv_candidates="clang-cpp" ;;
ac2c20
ac2c20
		*-cc )
ac2c20
			ccenv_cpp_prefix=${ccenv_cc_cmd%-cc*}-
ac2c20
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
ac2c20
ac2c20
		*-c99 )
ac2c20
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c99*}-
ac2c20
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
ac2c20
ac2c20
		*-c11 )
ac2c20
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c11*}-
ac2c20
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
ac2c20
ac2c20
		*-gcc )
ac2c20
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
ac2c20
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
ac2c20
ac2c20
		*-clang )
ac2c20
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
ac2c20
			ccenv_candidates="${ccenv_cpp_prefix}clang-cpp" ;;
ac2c20
ac2c20
		* )
ac2c20
			ccenv_cpp="$ccenv_cc -E"
8be87f
			ccenv_tool_epilog "$ccenv_cpp"
ac2c20
			return 0
ac2c20
	esac
ac2c20
ac2c20
	ccenv_find_tool
ac2c20
ac2c20
	if [ "$ccenv_tool" = false ]; then
ac2c20
		ccenv_cpp="$ccenv_cc -E"
ac2c20
	elif [ -n "$ccenv_tflags" ]; then
ac2c20
		ccenv_cpp="$ccenv_tool $ccenv_tflags"
ac2c20
	else
ac2c20
		ccenv_cpp="$ccenv_tool"
ac2c20
	fi
8be87f
8be87f
	ccenv_tool_epilog "$ccenv_cpp"
ac2c20
}
ac2c20
ac2c20
ccenv_set_cxx()
ac2c20
{
8be87f
	ccenv_tool_prolog 'C++ compiler'
8be87f
ac2c20
	case "$ccenv_cc_cmd" in
ac2c20
		cc | c99 | c11 )
ac2c20
			ccenv_cxx_prefix=
ac2c20
			ccenv_candidates="cxx c++" ;;
ac2c20
ac2c20
		gcc )
ac2c20
			ccenv_cxx_prefix=
ac2c20
			ccenv_candidates="g++" ;;
ac2c20
ac2c20
		clang )
ac2c20
			ccenv_cxx_prefix=
ac2c20
			ccenv_candidates="clang++" ;;
ac2c20
ac2c20
		*-gcc )
a2ba8d
			ccenv_cxx_prefix=${ccenv_cc_cmd%-gcc*}-
a2ba8d
			ccenv_candidates="${ccenv_cxx_prefix}g++" ;;
ac2c20
ac2c20
		*-clang )
a2ba8d
			ccenv_cxx_prefix=${ccenv_cc_cmd%-clang*}-
a2ba8d
			ccenv_candidates="${ccenv_cxx_prefix}clang++" ;;
a2ba8d
a2ba8d
		/*cc | /*c99 | /*c11 )
a2ba8d
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
a2ba8d
			ccenv_candidates="${ccenv_cxx_prefix}/cxx"
a2ba8d
			ccenv_candidates="${ccenv_candidates} ${ccenv_cxx_prefix}/c++" ;;
a2ba8d
a2ba8d
		/*gcc )
a2ba8d
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
a2ba8d
			ccenv_candidates="${ccenv_cxx_prefix}/g++" ;;
ac2c20
a2ba8d
		/*clang )
a2ba8d
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
a2ba8d
			ccenv_candidates="${ccenv_cxx_prefix}/clang++" ;;
ac2c20
ac2c20
		* )
ac2c20
			ccenv_cxx="$ccenv_cc -xc++"
8be87f
			ccenv_tool_epilog "$ccenv_cxx"
ac2c20
			return 0
ac2c20
	esac
ac2c20
ac2c20
	ccenv_find_tool
ac2c20
ac2c20
	if [ "$ccenv_tool" = false ]; then
ac2c20
		ccenv_cxx="$ccenv_cc -xc++"
ac2c20
	elif [ -n "$ccenv_tflags" ]; then
ac2c20
		ccenv_cxx="$ccenv_tool $ccenv_tflags"
ac2c20
	else
ac2c20
		ccenv_cxx="$ccenv_tool"
ac2c20
	fi
8be87f
8be87f
	ccenv_tool_epilog "$ccenv_cxx"
ac2c20
}
ac2c20
ac2c20
ccenv_set_cc_host()
ac2c20
{
36c502
	ccenv_attr_prolog 'system'
ac2c20
	ccenv_cc_host="$ccenv_cchost"
8be87f
	ccenv_attr_epilog "$ccenv_cc_host"
ac2c20
}
ac2c20
ac2c20
ccenv_set_cc_bits()
ac2c20
{
8be87f
	ccenv_attr_prolog 'bits'
8be87f
ac2c20
	ccenv_internal_size=
ac2c20
	ccenv_internal_type='void *'
ac2c20
	ccenv_internal_test='char x[(sizeof(%s) == %s/8) ? 1 : -1];'
ac2c20
ac2c20
	for ccenv_internal_guess in 64 32 128; do
7ebdd5
		if [ -z "${ccenv_internal_size:-}" ]; then
9bdf41
			ccenv_internal_str=$(printf "$ccenv_internal_test"  \
9bdf41
				"$ccenv_internal_type"                      \
ac2c20
				"$ccenv_internal_guess")
ac2c20
5b8b14
			ccenv_expr='ccenv_stdin_input=$ccenv_'${ccenv_cfgtype}'_stdin_input'
5b8b14
			eval ${ccenv_expr}
5b8b14
5b8b14
			if [ "$ccenv_stdin_input" = 'yes' ]; then
f1798d
				printf '%s' "$ccenv_internal_str"                   \
f1798d
						| eval $ccenv_cc -S -xc - -o -      \
f1798d
						  $(printf '%s' "$ccenv_cflags")    \
f1798d
					> /dev/null 2>&3                            \
f1798d
				&& ccenv_internal_size=$ccenv_internal_guess
f1798d
			else
f1798d
				ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
f1798d
f1798d
				printf '%s' "$ccenv_internal_str" \
f1798d
					> "$ccenv_tmpname"
f1798d
f1798d
				$ccenv_cc -c "$ccenv_tmpname" -o a.out \
f1798d
					> /dev/null 2>&3                \
f1798d
				&& ccenv_internal_size=$ccenv_internal_guess
f1798d
f1798d
				rm "$ccenv_tmpname"
f1798d
			fi
ac2c20
		fi
ac2c20
	done
ac2c20
ac2c20
	ccenv_cc_bits=$ccenv_internal_size
8be87f
8be87f
	ccenv_attr_epilog "$ccenv_cc_bits"
ac2c20
}
ac2c20
ac2c20
ccenv_set_cc_underscore()
ac2c20
{
8be87f
	ccenv_attr_prolog 'prepended underscores'
8be87f
ac2c20
	ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe'
ac2c20
	ccenv_fn_code='int %s(void){return 0;}'
ac2c20
eb2694
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
eb2694
eb2694
	printf "$ccenv_fn_code" $ccenv_fn_name \
eb2694
		> "$ccenv_tmpname"
eb2694
eb2694
	$ccenv_cc -c "$ccenv_tmpname" -o a.out \
eb2694
		> /dev/null 2>&3
eb2694
eb2694
	if "$ccenv_nm" a.out | grep          \
eb2694
			-e "^_$ccenv_fn_name" \
eb2694
			-e " _$ccenv_fn_name"  \
eb2694
			> /dev/null; then
c1b214
		ccenv_cc_underscore='_'
8be87f
		ccenv_attr_epilog 'yes'
eb2694
	else
eb2694
		ccenv_attr_epilog 'no'
c1b214
	fi
ac2c20
eb2694
	rm "$ccenv_tmpname"
eb2694
	rm a.out
8be87f
ac2c20
	return 0
ac2c20
}
ac2c20
ac2c20
ccenv_create_framework_executable()
ac2c20
{
4b14b8
	if [ "$ccenv_cfgtype" = 'host' ]; then
4b14b8
		if [ "$mb_freestanding" = 'yes' ]; then
4b14b8
			return 1
4b14b8
		fi
4b14b8
	fi
4b14b8
ac2c20
	if [ -f $ccenv_image ]; then
ac2c20
		mv $ccenv_image $ccenv_image.tmp
ac2c20
		rm -f $ccenv_image.tmp
ac2c20
	fi
ac2c20
ce7269
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
ce7269
ac2c20
	printf 'int main(void){return 0;}'  \
ce7269
		> "$ccenv_tmpname"
ac2c20
ce7269
	if $ccenv_cc "$ccenv_tmpname" -o $ccenv_image 2>&3; then
ce7269
		ccenv_ret=0
4b14b8
		ccenv_cc_environment='hosted'
ce7269
	else
ce7269
		ccenv_ret=1
ce7269
	fi
ce7269
ce7269
	rm "$ccenv_tmpname"
ce7269
ce7269
	return $ccenv_ret
ac2c20
}
ac2c20
ac2c20
ccenv_create_freestanding_executable()
ac2c20
{
ac2c20
	if [ -f $ccenv_image ]; then
ac2c20
		mv $ccenv_image $ccenv_image.tmp
ac2c20
		rm -f $ccenv_image.tmp
ac2c20
	fi
ac2c20
ac2c20
	if [ -z "ccenv_cc_underscore" ]; then
ac2c20
		ccenv_start_fn='_start'
ac2c20
	else
ac2c20
		ccenv_start_fn='start'
ac2c20
	fi
ac2c20
ce7269
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
ac2c20
ce7269
	printf 'int %s(void){return 0;}' "$ccenv_start_fn" \
ce7269
		> "$ccenv_tmpname"
ac2c20
ce7269
	if $ccenv_cc "$ccenv_tmpname"         \
ce7269
			-ffreestanding         \
ce7269
			-nostdlib -nostartfiles \
ce7269
			-o $ccenv_image          \
ce7269
			2>&3; then
ce7269
		ccenv_ret=0
4b14b8
		ccenv_cc_environment='freestanding'
ce7269
	else
ce7269
		ccenv_ret=1
ce7269
	fi
ce7269
ce7269
	rm "$ccenv_tmpname"
ce7269
ce7269
	return $ccenv_ret
ac2c20
}
ac2c20
8be87f
ccenv_set_cc_binfmt_error()
8be87f
{
8be87f
	ccenv_attr_epilog '(unable to create executable)'
8be87f
}
8be87f
ac2c20
ccenv_set_cc_binfmt()
ac2c20
{
ac2c20
	ccenv_use_perk=
7bea32
	ccenv_use_otool=
ac2c20
	ccenv_use_readelf=
ac2c20
	ccenv_use_readobj=
ac2c20
	ccenv_use_bfd_objdump=
ac2c20
	ccenv_use_llvm_objdump=
ac2c20
8be87f
	ccenv_attr_prolog 'binary format'
8be87f
ac2c20
	ccenv_create_framework_executable               \
ac2c20
		|| ccenv_create_freestanding_executable \
8be87f
		|| ccenv_set_cc_binfmt_error            \
ac2c20
		|| return 0
ac2c20
ac2c20
	# PE / perk
ac2c20
	if [ -n "$ccenv_perk" ]; then
9d19fd
		if $ccenv_perk $ccenv_image 2>&3; then
c1b214
			ccenv_cc_binfmt='PE'
c1b214
			ccenv_use_perk=yes
c1b214
		fi
ac2c20
	fi
ac2c20
ac2c20
	# ELF / readelf
ac2c20
	if [ -n "$ccenv_readelf" ] && [ -z "$ccenv_cc_binfmt" ]; then
9d19fd
		if $ccenv_readelf -h $ccenv_image 2>&3               \
c1b214
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
c1b214
				| grep 'Magic:7f454c46'              \
c1b214
					> /dev/null; then
c1b214
			ccenv_cc_binfmt='ELF'
c1b214
			ccenv_use_readelf=yes
c1b214
		fi
ac2c20
	fi
ac2c20
ac2c20
	# a marble of astonishing design:
ac2c20
	# llvm-readelf also parses PE and Mach-O
ac2c20
ac2c20
	if [ -n "$ccenv_readelf_llvm" ]; then
ac2c20
		ccenv_readany="$ccenv_readelf_llvm"
ac2c20
	else
ac2c20
		ccenv_readany="$ccenv_readelf"
ac2c20
	fi
ac2c20
ac2c20
	# PE / readelf
ac2c20
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
9d19fd
		if $ccenv_readany -h $ccenv_image 2>&3               \
c1b214
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
c1b214
				| grep 'Magic:MZ'                    \
c1b214
					> /dev/null; then
c1b214
			ccenv_cc_binfmt='PE'
c1b214
			ccenv_use_readelf=yes
c1b214
		fi
ac2c20
	fi
ac2c20
7bea32
	# MACHO-64 / otool
7bea32
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
9d19fd
		if $ccenv_otool -hv $ccenv_image 2>&3        \
c1b214
				| grep -i 'MH_MAGIC_64'      \
c1b214
					> /dev/null; then
c1b214
			ccenv_cc_binfmt='MACHO'
c1b214
			ccenv_use_otool=yes
c1b214
		fi
7bea32
	fi
7bea32
7bea32
	# MACHO-32 / otool
7bea32
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
9d19fd
		if $ccenv_otool -hv $ccenv_image 2>&3        \
c1b214
				| grep -i 'MH_MAGIC'         \
c1b214
					> /dev/null; then
c1b214
			ccenv_cc_binfmt='MACHO'
c1b214
			ccenv_use_otool=yes
c1b214
		fi
7bea32
	fi
7bea32
ac2c20
	# MACHO-64 / readelf
ac2c20
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
9d19fd
		if $ccenv_readany -h $ccenv_image 2>&3                    \
c1b214
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
c1b214
				| grep -i '(0xfeedfacf)'                  \
c1b214
					> /dev/null; then
c1b214
			ccenv_cc_binfmt='MACHO'
c1b214
			ccenv_use_readelf=yes
c1b214
		fi
ac2c20
	fi
ac2c20
ac2c20
	# MACHO-32 / readelf
ac2c20
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
9d19fd
		if $ccenv_readany -h $ccenv_image 2>&3                    \
c1b214
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
c1b214
				| grep -i '(0xcafebabe)'                  \
c1b214
					> /dev/null; then
c1b214
			ccenv_cc_binfmt='MACHO'
c1b214
			ccenv_use_readelf=yes
c1b214
		fi
ac2c20
	fi
ac2c20
ac2c20
	# MACHO / readobj
ac2c20
	if [ -n "$ccenv_readobj" ] && [ -z "$ccenv_cc_binfmt" ]; then
9d19fd
		if $ccenv_readobj $ccenv_image 2>&3                  \
b0a0eb
				| grep -i 'Format:'                  \
b0a0eb
				| sed  -e 's/ /_/g'                  \
c1b214
				| grep -i '_Mach-O_'                 \
c1b214
					> /dev/null; then
c1b214
			ccenv_cc_binfmt='MACHO'
c1b214
			ccenv_use_readobj=yes
c1b214
		fi
ac2c20
	fi
ac2c20
ac2c20
	# MACHO / objdump (llvm)
ac2c20
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
c1b214
		if $ccenv_objdump -section-headers $ccenv_image  \
9d19fd
					2>&3                     \
c1b214
				| grep -i 'file format Mach-O'   \
c1b214
					> /dev/null; then
c1b214
			ccenv_cc_binfmt='MACHO'
c1b214
			ccenv_use_objdump=yes
c1b214
		fi
ac2c20
	fi
ac2c20
ac2c20
	# MACHO / objdump (bfd)
ac2c20
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
9d19fd
		$ccenv_objdump -h  $ccenv_image 2>&3              \
ac2c20
			| grep -i 'file format Mach-O'            \
ac2c20
				> /dev/null                       \
ac2c20
		&& ccenv_cc_binfmt='MACHO'                        \
ac2c20
		&& ccenv_use_objdump=yes
ac2c20
	fi
ac2c20
ac2c20
	# PE / objdump (bfd)
ac2c20
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
9d19fd
		if $ccenv_objdump -h  $ccenv_image 2>&3        \
c1b214
				| grep -i 'file format pei-'   \
c1b214
					> /dev/null; then
c1b214
			ccenv_cc_binfmt='PE'
c1b214
			ccenv_use_bfd_objdump=yes
c1b214
		fi
ac2c20
	fi
8be87f
8be87f
	ccenv_attr_epilog "$ccenv_cc_binfmt"
ac2c20
}
ac2c20
ac2c20
ccenv_set_os_pe()
ac2c20
{
4b14b8
	if [ "$ccenv_cc_environment" = 'freestanding' ]; then
ac2c20
		case "$ccenv_cchost" in
ac2c20
			*-midipix | *-midipix-* )
ac2c20
				ccenv_os='midipix' ;;
ac2c20
			*-mingw | *-mingw32 | *-mingw64 )
ac2c20
				ccenv_os='mingw' ;;
ac2c20
			*-mingw-* | *-mingw32-* | *-mingw64 )
ac2c20
				ccenv_os='mingw' ;;
ac2c20
			*-msys | *-msys2 | *-msys-* | *-msys2-* )
ac2c20
				ccenv_os='msys' ;;
ac2c20
			*-cygwin | *-cygwin-* )
ac2c20
				ccenv_os='cygwin' ;;
ac2c20
		esac
ac2c20
	fi
ac2c20
ac2c20
	if [ -n "$ccenv_os" ]; then
ac2c20
		return 0
ac2c20
	fi
ac2c20
ac2c20
	if [ -n "$ccenv_use_perk" ]; then
ac2c20
		ccenv_framework=$($ccenv_perk -y $ccenv_image)
ac2c20
		ccenv_os=${ccenv_framework#*-*-*-*}
ac2c20
	fi
ac2c20
ac2c20
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
ac2c20
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
ac2c20
			| grep 'cygwin1.dll' > /dev/null                \
ac2c20
		&& ccenv_os='cygwin'
ac2c20
	fi
ac2c20
ac2c20
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
ac2c20
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
ac2c20
			| grep 'msys-2.0.dll' > /dev/null               \
ac2c20
		&& ccenv_os='msys'
ac2c20
	fi
ac2c20
ac2c20
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
ac2c20
		$ccenv_objdump_bfd -x $ccenv_image          \
ac2c20
			| grep -i 'DLL Name' | grep '.CRT'  \
ac2c20
				> /dev/null                 \
ac2c20
		&& $ccenv_objdump_bfd -x $ccenv_image       \
ac2c20
			| grep -i 'DLL Name' | grep '.bss'  \
ac2c20
				> /dev/null                 \
ac2c20
		&& $ccenv_objdump_bfd -x $ccenv_image       \
ac2c20
			| grep -i 'DLL Name' | grep '.tls'  \
ac2c20
				> /dev/null                 \
ac2c20
		&& ccenv_os='mingw'
ac2c20
	fi
ac2c20
}
ac2c20
ac2c20
ccenv_set_os_macho()
ac2c20
{
ac2c20
	case "$ccenv_cchost" in
ac2c20
		*-apple-darwin* )
ac2c20
			ccenv_os='darwin' ;;
ac2c20
	esac
ac2c20
}
ac2c20
ac2c20
ccenv_set_os()
ac2c20
{
8be87f
	ccenv_attr_prolog 'os name'
8be87f
ac2c20
	case "$ccenv_cc_binfmt" in
ac2c20
		PE )
ac2c20
			ccenv_set_os_pe ;;
ac2c20
		MACHO )
ac2c20
			ccenv_set_os_macho ;;
ac2c20
	esac
ac2c20
ac2c20
	if [ -n "$ccenv_os" ]; then
8be87f
		ccenv_attr_epilog "$ccenv_os"
ac2c20
		return 0
ac2c20
	fi
ac2c20
ac2c20
	case "$ccenv_cchost" in
54c6c8
		*-*-musl | *-*-gnu )
54c6c8
			ccenv_tip=${ccenv_cchost%-*}
ac2c20
			ccenv_os=${ccenv_tip#*-}
ac2c20
			;;
5a5c4b
		*-*-solaris* )
5a5c4b
			ccenv_os='solaris'
5a5c4b
			;;
bf5fe6
		*-*-*bsd* | *-*-dragonfly* )
bf5fe6
			ccenv_os='bsd'
bf5fe6
			;;
bf5fe6
		*-*-*-* )
bf5fe6
			ccenv_tip=${ccenv_cchost%-*}
bf5fe6
			ccenv_os=${ccenv_tip#*-*-}
bf5fe6
			;;
54c6c8
		*-*-* )
54c6c8
			ccenv_os=${ccenv_cchost#*-*-}
54c6c8
			;;
54c6c8
		*-* )
54c6c8
			ccenv_os=${ccenv_cchost#*-}
54c6c8
			;;
ac2c20
	esac
ac2c20
ac2c20
	if [ -z "$ccenv_os" ]; then
ac2c20
		ccenv_os='anyos'
ac2c20
	fi
8be87f
8be87f
	ccenv_attr_epilog "$ccenv_os"
ac2c20
}
ac2c20
ac2c20
ccenv_set_os_flags()
ac2c20
{
ac2c20
	case "$ccenv_os" in
ac2c20
		darwin )
ac2c20
			ccenv_cflags_os='-D_DARWIN_C_SOURCE'
ac2c20
			ccenv_cflags_pic='-fPIC'
ac2c20
			;;
ac2c20
		midipix )
ac2c20
			ccenv_cflags_os=
ac2c20
			ccenv_cflags_pic='-fPIC'
ac2c20
			;;
ac2c20
		cygwin )
ac2c20
			ccenv_cflags_os=
ac2c20
			ccenv_cflags_pic=
ac2c20
			;;
ac2c20
		msys | msys* | mingw | mingw* )
ac2c20
			ccenv_cflags_os='-U__STRICT_ANSI__'
ac2c20
			ccenv_cflags_pic=
ac2c20
			;;
ac2c20
		* )
ac2c20
			ccenv_cflags_os=
ac2c20
			ccenv_cflags_pic='-fPIC'
ac2c20
			;;
ac2c20
	esac
ac2c20
}
ac2c20
ac2c20
ccenv_set_os_semantics()
ac2c20
{
ac2c20
	# binary_format - core_api - ex_api - dependency_resolution
ac2c20
8be87f
	ccenv_attr_prolog 'os semantics'
8be87f
ac2c20
	case "$ccenv_os" in
ac2c20
		linux )
ac2c20
			ccenv_os_semantics='elf-posix-linux-ldso'
ac2c20
			;;
ac2c20
		bsd )
ac2c20
			ccenv_os_semantics='elf-posix-bsd-ldso'
ac2c20
			;;
ac2c20
		darwin )
ac2c20
			ccenv_os_semantics='macho-posix-osx-ldso'
ac2c20
			;;
ac2c20
		midipix )
ac2c20
			ccenv_os_semantics='pe-posix-winnt-ldso'
ac2c20
			;;
ac2c20
		cygwin )
ac2c20
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
ac2c20
			;;
ac2c20
		msys )
ac2c20
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
ac2c20
			;;
ac2c20
		mingw )
ac2c20
			ccenv_os_semantics='pe-win32-winnt-unsafe'
ac2c20
			;;
ac2c20
	esac
ac2c20
ac2c20
	if [ -n "$ccenv_os_semantics" ]; then
8be87f
		ccenv_attr_epilog "$ccenv_os_semantics"
ac2c20
		return 0
ac2c20
	fi
ac2c20
ac2c20
	if [ -n "$ccenv_cc_binfmt" ]; then
ac2c20
		ccenv_os_semantics_pattern='%s-posix-anyos-unknown'
ac2c20
		ccenv_os_semantics=$(printf                   \
ac2c20
				"$ccenv_os_semantics_pattern"  \
ac2c20
				"$ccenv_cc_binfmt"              \
ac2c20
			| tr '[:upper:]' '[:lower:]')
ac2c20
	else
ac2c20
		ccenv_os_semantics='unknown-posix-anyos-unknown'
ac2c20
	fi
8be87f
8be87f
	ccenv_attr_epilog "$ccenv_os_semantics"
ac2c20
}
ac2c20
cffad0
ccenv_set_os_dso_format()
cffad0
{
cffad0
	ccenv_attr_prolog 'os dso format'
cffad0
cffad0
	case "$ccenv_cc_arfmt" in
cffad0
		common )
cffad0
			ccenv_cc_sofmt="$ccenv_cc_binfmt"
cffad0
			;;
cffad0
cffad0
		bigaf )
cffad0
			ccenv_libgcc_s_a_header=$(od -b -N8             \
cffad0
				$($ccenv_cc -print-file-name=libgcc_s.a) \
cffad0
					2>/dev/null                       \
cffad0
					| head -n1)
cffad0
cffad0
			ccenv_libgcc_s_so_header=$(od -b -N8             \
cffad0
				$($ccenv_cc -print-file-name=libgcc_s.so) \
cffad0
					2>/dev/null                        \
cffad0
					| head -n1)
cffad0
cffad0
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_bigaf_header" ]; then
cffad0
				ccenv_cc_sofmt='bigaf'
cffad0
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_bigaf_header" ]; then
cffad0
				ccenv_cc_sofmt='bigaf'
cffad0
			else
cffad0
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
cffad0
			fi
cffad0
			;;
cffad0
cffad0
		aiaff )
cffad0
			ccenv_libgcc_s_a_header=$(od -b -N8               \
cffad0
				$($ccenv_cc -print-file-name=libgcc_s.a) \
cffad0
					| head -n1)
cffad0
cffad0
			ccenv_libgcc_s_so_header=$(od -b -N8               \
cffad0
				$($ccenv_cc -print-file-name=libgcc_s.so) \
cffad0
					| head -n1)
cffad0
cffad0
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_aiaff_header" ]; then
cffad0
				ccenv_cc_sofmt='aiaff'
cffad0
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_aiaff_header" ]; then
cffad0
				ccenv_cc_sofmt='aiaff'
cffad0
			else
cffad0
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
cffad0
			fi
cffad0
			;;
cffad0
	esac
cffad0
819e8d
	if [ "$ccenv_cfgtype" = 'host' ]; then
819e8d
		case "$ccenv_cc_sofmt" in
819e8d
			bigaf | aiaff )
819e8d
				mb_shared_lib_cmd='$(AR) -rcs'
819e8d
				mb_shared_lib_ldflags=
819e8d
				;;
819e8d
819e8d
			* )
819e8d
				mb_shared_lib_cmd='$(CC) -shared -o'
819e8d
				mb_shared_lib_ldflags='$(LDFLAGS_SHARED)'
819e8d
				;;
819e8d
		esac
819e8d
	fi
819e8d
cffad0
	ccenv_attr_epilog "$ccenv_cc_sofmt"
cffad0
}
cffad0
ac2c20
ccenv_set_os_dso_exrules()
ac2c20
{
8be87f
	ccenv_attr_prolog 'os dso exrules'
8be87f
ac2c20
	case "$ccenv_os" in
ac2c20
		midipix )
ac2c20
			ccenv_os_dso_exrules='pe-mdso'
ac2c20
			;;
ac2c20
		* )
ac2c20
			if [ "$ccenv_cc_binfmt" = 'PE' ]; then
ac2c20
				ccenv_os_dso_exrules='pe-dlltool'
ac2c20
			else
ac2c20
				ccenv_os_dso_exrules='default'
ac2c20
			fi
ac2c20
	esac
8be87f
8be87f
	ccenv_attr_epilog "$ccenv_os_dso_exrules"
ac2c20
}
ac2c20
ac2c20
ccenv_set_os_dso_linkage()
ac2c20
{
ac2c20
	# todo: PIC, PIE, and friends
8be87f
	ccenv_attr_prolog 'os linkage'
ac2c20
	ccenv_os_dso_linkage='default'
8be87f
	ccenv_attr_epilog "$ccenv_os_dso_linkage"
ac2c20
}
ac2c20
ac2c20
ccenv_set_os_dso_patterns_darwin()
ac2c20
{
ac2c20
	ccenv_os_app_prefix=
ac2c20
	ccenv_os_app_suffix=
ac2c20
ac2c20
	ccenv_os_lib_prefix=lib
ac2c20
	ccenv_os_lib_suffix=.dylib
ac2c20
ac2c20
	ccenv_os_implib_ext=.invalid
ac2c20
	ccenv_os_libdef_ext=.invalid
ac2c20
ac2c20
	ccenv_os_archive_ext=.a
ac2c20
	ccenv_os_soname=symlink
ac2c20
ac2c20
	ccenv_os_lib_prefixed_suffix=
ac2c20
	ccenv_os_lib_suffixed_suffix='$(OS_LIB_SUFFIX)'
ac2c20
}
ac2c20
ac2c20
ccenv_set_os_dso_patterns_mdso()
ac2c20
{
ac2c20
	ccenv_os_app_prefix=
ac2c20
	ccenv_os_app_suffix=
ac2c20
ac2c20
	ccenv_os_lib_prefix=lib
ac2c20
	ccenv_os_lib_suffix=.so
ac2c20
ac2c20
	ccenv_os_implib_ext=.lib.a
ac2c20
	ccenv_os_libdef_ext=.so.def
ac2c20
ac2c20
	ccenv_os_archive_ext=.a
ac2c20
	ccenv_os_soname=symlink
ac2c20
ac2c20
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
ac2c20
	ccenv_os_lib_suffixed_suffix=
ac2c20
}
ac2c20
ac2c20
ccenv_set_os_dso_patterns_dlltool()
ac2c20
{
ac2c20
	ccenv_os_app_prefix=
ac2c20
	ccenv_os_app_suffix=.exe
ac2c20
ac2c20
	ccenv_os_lib_prefix=lib
ac2c20
	ccenv_os_lib_suffix=.dll
ac2c20
ac2c20
	ccenv_os_implib_ext=.dll.a
ac2c20
	ccenv_os_libdef_ext=.def
ac2c20
ac2c20
	ccenv_os_archive_ext=.a
ac2c20
	ccenv_os_soname=copy
ac2c20
ac2c20
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
ac2c20
	ccenv_os_lib_suffixed_suffix=
ac2c20
}
ac2c20
ac2c20
ccenv_set_os_dso_patterns_default()
ac2c20
{
ac2c20
	ccenv_os_app_prefix=
ac2c20
	ccenv_os_app_suffix=
ac2c20
ac2c20
	ccenv_os_lib_prefix=lib
ac2c20
	ccenv_os_lib_suffix=.so
ac2c20
ac2c20
	ccenv_os_implib_ext=.invalid
ac2c20
	ccenv_os_libdef_ext=.invalid
ac2c20
ac2c20
	ccenv_os_archive_ext=.a
ac2c20
	ccenv_os_soname=symlink
ac2c20
ac2c20
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
ac2c20
	ccenv_os_lib_suffixed_suffix=
ac2c20
}
ac2c20
ac2c20
ccenv_set_os_dso_patterns()
ac2c20
{
ac2c20
	# sover: .so.x.y.z
ac2c20
	# verso: .x.y.z.so
ac2c20
ac2c20
	case "$ccenv_os" in
ac2c20
		darwin )
ac2c20
			ccenv_set_os_dso_patterns_darwin
ac2c20
			;;
ac2c20
		midipix )
ac2c20
			ccenv_set_os_dso_patterns_mdso
ac2c20
			;;
ac2c20
		cygwin | msys | mingw )
ac2c20
			ccenv_set_os_dso_patterns_dlltool
ac2c20
			;;
ac2c20
		* )
ac2c20
			ccenv_set_os_dso_patterns_default
ac2c20
			;;
ac2c20
	esac
ac2c20
}
ac2c20
ef618e
ccenv_set_os_pe_switches()
ef618e
{
1a6368
	if [ "$ccenv_cc_binfmt" = 'PE' ] && [ -z "$ccenv_pe_subsystem" ]; then
ef618e
		case "$ccenv_os" in
ef618e
			midipix | mingw )
ef618e
				ccenv_pe_subsystem='windows'
ef618e
				;;
ef618e
			* )
ef618e
				ccenv_pe_subsystem='console'
ef618e
				;;
ef618e
		esac
ef618e
	fi
73595a
73595a
	if [ "$ccenv_cc_binfmt" = 'PE' ]; then
73595a
		if ! cfgtest_macro_definition '__PE__'; then
73595a
			ccenv_cflags_os="${ccenv_cflags_os} -D__PE__"
73595a
		fi
73595a
73595a
		if ! cfgtest_macro_definition '__dllexport'; then
73595a
			ccenv_cflags_os="${ccenv_cflags_os} -D__dllexport=__attribute__\(\(__dllexport__\)\)"
73595a
		fi
73595a
73595a
		if ! cfgtest_macro_definition '__dllimport'; then
73595a
			ccenv_cflags_os="${ccenv_cflags_os} -D__dllimport=__attribute__\(\(__dllimport__\)\)"
73595a
		fi
73595a
	fi
ef618e
}
ef618e
5a5c4b
ccenv_set_os_gate_switches()
5a5c4b
{
5a5c4b
	if [ "$ccenv_os" = 'solaris' ]; then
5a5c4b
		if ! cfgtest_macro_definition 'AT_FDCWD'; then
5a5c4b
			ccenv_cflags_os="${ccenv_cflags_os} -D__EXTENSIONS__"
5a5c4b
		fi
5a5c4b
	fi
5a5c4b
}
5a5c4b
bf5fe6
ccenv_set_os_bsd_switches()
bf5fe6
{
bf5fe6
	if [ "$ccenv_os" = 'bsd' ]; then
bf5fe6
		mb_cfgtest_headers='sys/mman.h'
bf5fe6
bf5fe6
		if ! cfgtest_macro_definition 'MAP_ANON'; then
bf5fe6
			ccenv_cflags_os="${ccenv_cflags_os} -D__BSD_VISIBLE"
bf5fe6
		fi
bf5fe6
bf5fe6
		mb_cfgtest_headers=
bf5fe6
	fi
bf5fe6
}
bf5fe6
ac2c20
ccenv_output_defs()
ac2c20
{
ac2c20
	ccenv_in="$mb_project_dir/sofort/ccenv/ccenv.in"
ac2c20
	ccenv_mk="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
19088f
	ccenv_tmp=
ac2c20
ef618e
	if [ "$ccenv_cc_binfmt" = 'PE' ]; then
ef618e
		ccenv_pe="$mb_project_dir/sofort/ccenv/pedefs.in"
ef618e
		ccenv_in="$ccenv_in $ccenv_pe"
ef618e
	fi
ef618e
ac2c20
	if [ $ccenv_cfgtype = 'native' ]; then
ac2c20
25df51
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
ac2c20
6ad4aa
		sed                                      \
f0a5ff
				-e 's/^[[:space:]]*$/@/g' \
6ad4aa
				-e 's/^/NATIVE_/'          \
6ad4aa
				-e 's/NATIVE_@//g'          \
6ad4aa
				-e 's/NATIVE_#/#/g'          \
6ad4aa
				-e 's/       =/=/g'           \
6ad4aa
				-e 's/       +=/+=/g'          \
d1e13f
			$(printf '%s ' $ccenv_in)               \
d1e13f
				> "$ccenv_tmp"
ac2c20
ac2c20
		ccenv_in="$ccenv_tmp"
25df51
	else
19088f
		unset ccenv_tmp
ac2c20
	fi
ac2c20
ceb7e9
	ccenv_var_defs=
2b8e36
	ccenv_sed_substs="-e s/@ccenv_cfgtype@/${ccenv_cfgtype}/g"
ceb7e9
ac2c20
	ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
ceb7e9
		| grep -v '^#');
ac2c20
2b8e36
	ccenv_exvars="ccenv_makevar_prefix"
ac2c20
ceb7e9
	for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do
ceb7e9
		ccenv_sed_subst=$(printf '%s %s%s%s' \
ceb7e9
				'-e' "'s^@$__var@"    \
ceb7e9
				"^___${__var}___"      \
ceb7e9
				"^g'")
ceb7e9
ceb7e9
		ccenv_sed_substs="$ccenv_sed_substs $ccenv_sed_subst"
ceb7e9
ceb7e9
		ccenv_var_def=$(printf '%s%s="${%s}"' "-D" "___${__var}___" "${__var}")
ceb7e9
		eval ccenv_var_defs='"$ccenv_var_defs "$ccenv_var_def'
ceb7e9
	done
ac2c20
ceb7e9
	eval sed $ccenv_sed_substs $(printf '%s ' $ccenv_in) \
ceb7e9
			| eval m4 $ccenv_var_defs -           \
ceb7e9
			| sed -e 's/[[:blank:]]*$//g'          \
ac2c20
		> "$ccenv_mk"
ac2c20
209f53
	if [ "$ccenv_cfgtype" = 'host' ]; then
0f630f
		for __var in $(printf '%s' "$ccenv_vars"); do
209f53
			ccenv_src_var=$__var
209f53
			ccenv_dst_var=mb_${__var#*ccenv_}
209f53
			ccenv_var_expr='${'$ccenv_src_var':-}'
209f53
			eval $ccenv_dst_var=$ccenv_var_expr
209f53
209f53
		done
209f53
209f53
		mb_host=$ccenv_host
209f53
		mb_cchost=$ccenv_cchost
209f53
	else
0f630f
		for __var in $(printf '%s' "$ccenv_vars"); do
209f53
			ccenv_src_var=$__var
209f53
			ccenv_dst_var=mb_native_${__var#*ccenv_}
209f53
			ccenv_var_expr='${'$ccenv_src_var':-}'
209f53
			eval "$ccenv_dst_var=$ccenv_var_expr"
209f53
		done
209f53
209f53
		mb_native_host=$ccenv_host
209f53
		mb_native_cchost=$ccenv_cchost
209f53
	fi
25df51
25df51
	if [ -n "${ccenv_tmp:-}" ]; then
25df51
		rm -f "$ccenv_tmp"
25df51
		unset ccenv_tmp
25df51
	fi
62fa14
fd9ebd
fd9ebd
	if [ "${ccenv_cfgtype}" = 'host' ]; then
fd9ebd
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-host)
fd9ebd
		ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-host)
fd9ebd
	else
fd9ebd
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-native)
fd9ebd
		ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-native)
fd9ebd
	fi
fd9ebd
fd9ebd
	ccenv_cflags="${ccenv_cflags#*: }"
fd9ebd
	ccenv_ldflags="${ccenv_ldflags#*: }"
fd9ebd
48f78a
	ccenv_sysroot=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
48f78a
		-print-sysroot 2>/dev/null || true)
48f78a
fd9ebd
	eval 'ccenv_'${ccenv_cfgtype}'_cflags'=\'$ccenv_cflags\'
fd9ebd
	eval 'ccenv_'${ccenv_cfgtype}'_ldflags'=\'$ccenv_ldflags\'
48f78a
	eval 'ccenv_'${ccenv_cfgtype}'_sysroot'=\'$ccenv_sysroot\'
fd9ebd
62fa14
	eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\'
a18969
	eval 'ccenv_'${ccenv_cfgtype}'_cc_environment'=\'$ccenv_cc_environment\'
a9076b
	eval 'ccenv_'${ccenv_cfgtype}'_dumpmachine_switch'=\'$ccenv_dumpmachine_switch\'
6880f9
	eval 'ccenv_'${ccenv_cfgtype}'_pkgconf'=\'$ccenv_pkgconf\'
fd9ebd
ac2c20
}
ac2c20
99013d
ccenv_set_cc_sysroot_vars()
99013d
{
99013d
	if [ "$ccenv_cfgtype" = 'native' ] || [ -z "$mb_sysroot" ]; then
99013d
		return 0
99013d
	fi
99013d
99013d
	cfgtest_host_section
99013d
	ccenv_switch_var="--sysroot=${mb_sysroot}"
99013d
99013d
	if cfgtest_compiler_switch_arg "${ccenv_switch_var}"; then
99013d
		printf '\n# %s sysroot: cflags and ldflags\n' "$ccenv_cfgtype" \
99013d
			>> "$ccenv_mk"
99013d
99013d
		for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do
99013d
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
99013d
				>> "$ccenv_mk"
99013d
		done
99013d
	else
99013d
		printf '\n# %s sysroot: cflags and ldflags %s\n' "$ccenv_cfgtype" \
99013d
			'(not supported: see config.log)'                          \
99013d
			>> "$ccenv_mk"
99013d
99013d
		for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do
99013d
			printf '%-40s=\n' "${ccenv_make_var}" \
99013d
				>> "$ccenv_mk"
99013d
		done
99013d
	fi
99013d
}
99013d
fbaa20
ccenv_set_cc_switch_vars()
fbaa20
{
2aae4e
	printf '\n# %s cflags: supported compiler switches\n' "$ccenv_cfgtype" \
2aae4e
		>> "$ccenv_mk"
2aae4e
fbaa20
	if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
99cee0
		ccenv_switch_vars=$(cat                            \
fbaa20
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
fbaa20
			$mb_project_dir/project/config/ccswitch.strs \
99cee0
		| grep -v -e '^#' -e '^-Wl,'                          \
99cee0
		| sort -u)
fbaa20
	else
5450df
		ccenv_switch_vars=$(grep -v -e '^#' -e '^-Wl,'     \
fbaa20
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
fbaa20
			| sort -u)
fbaa20
	fi
fbaa20
fbaa20
	if [ $ccenv_cfgtype = 'host' ]; then
fbaa20
		ccenv_makevar_prefix='_CFLAGS_'
fbaa20
		cfgtest_host_section
fbaa20
	else
fbaa20
		ccenv_makevar_prefix='_NATIVE_CFLAGS_'
fbaa20
		cfgtest_native_section
fbaa20
	fi
fbaa20
fbaa20
	for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
fbaa20
		ccenv_make_var=${ccenv_switch_var%=}
fbaa20
		ccenv_make_var=${ccenv_make_var%,}
fbaa20
fbaa20
		ccenv_make_var=${ccenv_make_var##---}
fbaa20
		ccenv_make_var=${ccenv_make_var##--}
fbaa20
		ccenv_make_var=${ccenv_make_var##-}
fbaa20
fbaa20
		ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
fbaa20
			| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
fbaa20
fbaa20
		ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
fbaa20
fbaa20
		if cfgtest_compiler_switch "$ccenv_switch_var"; then
fbaa20
			ccenv_switch_var=${ccenv_switch_var%=}
fbaa20
			ccenv_switch_var=${ccenv_switch_var%,}
fbaa20
6297e4
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
fbaa20
				>> "$ccenv_mk"
fbaa20
		else
6297e4
			printf '%-40s=\n' "${ccenv_make_var}" \
fbaa20
				>> "$ccenv_mk"
fbaa20
		fi
fbaa20
	done
fbaa20
}
fbaa20
5450df
ccenv_set_cc_linker_switch_vars()
5450df
{
5450df
	printf '\n# %s ldflags: supported compiler switches\n' "$ccenv_cfgtype" \
5450df
		>> "$ccenv_mk"
5450df
5450df
	if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
99cee0
		ccenv_switch_vars=$(cat                            \
5450df
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
5450df
			$mb_project_dir/project/config/ccswitch.strs \
99cee0
			| grep -e '^-Wl,'                             \
5450df
			| sort -u)
5450df
	else
5450df
		ccenv_switch_vars=$(grep -e '^-Wl,'                \
5450df
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
5450df
			| sort -u)
5450df
	fi
5450df
5450df
	if [ $ccenv_cfgtype = 'host' ]; then
5450df
		ccenv_makevar_prefix='_LDFLAGS_'
5450df
		cfgtest_host_section
5450df
	else
5450df
		ccenv_makevar_prefix='_NATIVE_LDFLAGS_'
5450df
		cfgtest_native_section
5450df
	fi
5450df
5450df
	for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
5450df
		ccenv_make_var=${ccenv_switch_var%=}
5450df
		ccenv_make_var=${ccenv_make_var%,}
5450df
5450df
		ccenv_make_var=${ccenv_make_var##---}
5450df
		ccenv_make_var=${ccenv_make_var##--}
5450df
		ccenv_make_var=${ccenv_make_var##-}
5450df
5450df
		ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
5450df
			| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
5450df
5450df
		ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
5450df
5450df
		if cfgtest_compiler_switch "$ccenv_switch_var"; then
5450df
			ccenv_switch_var=${ccenv_switch_var%=}
5450df
			ccenv_switch_var=${ccenv_switch_var%,}
5450df
5450df
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
5450df
				>> "$ccenv_mk"
5450df
		else
5450df
			printf '%-40s=\n' "${ccenv_make_var}" \
5450df
				>> "$ccenv_mk"
5450df
		fi
5450df
	done
5450df
}
5450df
d089ce
ccenv_set_cc_attr_visibility_vars()
d089ce
{
d089ce
	if cfgtest_attr_visibility 'default'; then
d089ce
		ccenv_attr_visibility_default="$mb_cfgtest_attr"
d089ce
	fi
d089ce
d089ce
	if cfgtest_attr_visibility 'hidden'; then
d089ce
		ccenv_attr_visibility_hidden="$mb_cfgtest_attr"
d089ce
	fi
d089ce
d089ce
	if cfgtest_attr_visibility 'internal'; then
d089ce
		ccenv_attr_visibility_internal="$mb_cfgtest_attr"
d089ce
	fi
d089ce
d089ce
	if cfgtest_attr_visibility 'protected'; then
d089ce
		ccenv_attr_visibility_protected="$mb_cfgtest_attr"
d089ce
	fi
d089ce
}
d089ce
f2ee7e
ccenv_dso_verify()
f2ee7e
{
f2ee7e
	ccenv_str='int foo(int x){return ++x;}'
f2ee7e
	ccenv_cmd="$ccenv_cc -xc - -shared -o a.out"
f2ee7e
f2ee7e
	rm -f a.out
f2ee7e
1f75e6
	printf '%s' "$ccenv_str" | $(printf %s "$ccenv_cmd") \
9d19fd
		> /dev/null 2>&3              \
f2ee7e
	|| mb_disable_shared=yes
f2ee7e
f2ee7e
	rm -f a.out
f2ee7e
}
f2ee7e
ac2c20
ccenv_clean_up()
ac2c20
{
ac2c20
	rm -f $ccenv_image
ac2c20
}
ac2c20
ac2c20
ccenv_common_init()
ac2c20
{
ac2c20
	. "$mb_project_dir/sofort/ccenv/ccenv.vars"
ac2c20
ac2c20
	ccenv_cfgtype=$1
ac2c20
	ccenv_cfgfile="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
5e5091
	ccenv_cchost=
ac2c20
ac2c20
	if [ $ccenv_cfgtype = 'native' ]; then
ac2c20
		ccenv_makevar_prefix='NATIVE_'
ac2c20
		ccenv_image='./ccenv/native.a.out'
ac2c20
	else
ac2c20
		ccenv_makevar_prefix=
ac2c20
		ccenv_image='./ccenv/host.a.out'
ac2c20
	fi
ac2c20
ac2c20
	if [ $ccenv_cfgtype = 'native' ]; then
ac2c20
		ccenv_prefixes=
ac2c20
	elif [ -n "$mb_cross_compile" ]; then
ac2c20
		ccenv_prefixes="$mb_cross_compile"
ac2c20
	elif [ -n "$mb_host" ]; then
ac2c20
		ccenv_prefixes="$mb_host-"
ac2c20
	else
ac2c20
		ccenv_prefixes=
ac2c20
	fi
ac2c20
ac2c20
	if [ $ccenv_cfgtype = 'host' ]; then
ac2c20
		ccenv_tflags=
372312
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
c8826f
			OS_DSO_EXRULES=default                          \
c8826f
			OS_SONAME=symlink                                \
a79798
			OS_ARCHIVE_EXT='.a'                               \
c8826f
			.cflags-host)
52ad96
372312
		ccenv_cflags="${ccenv_cflags#*: }"
372312
ac2c20
		ccenv_cc="$mb_user_cc"
ac2c20
		ccenv_cpp="$mb_user_cpp"
ac2c20
		ccenv_cxx="$mb_user_cxx"
ef618e
ef618e
		ccenv_pe_subsystem="$mb_pe_subsystem"
ef618e
		ccenv_pe_image_base="$mb_pe_image_base"
ac2c20
	else
ac2c20
		ccenv_tflags=
372312
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
c8826f
			OS_DSO_EXRULES=default                          \
c8826f
			OS_SONAME=symlink                                \
a79798
			OS_ARCHIVE_EXT='.a'                               \
c8826f
			.cflags-native)
c8826f
372312
		ccenv_cflags="${ccenv_cflags#*: }"
372312
ac2c20
		ccenv_cc="$mb_native_cc"
ac2c20
		ccenv_cpp="$mb_native_cpp"
ac2c20
		ccenv_cxx="$mb_native_cxx"
ef618e
ef618e
		ccenv_pe_subsystem="$mb_native_pe_subsystem"
ef618e
		ccenv_pe_image_base="$mb_native_pe_image_base"
ac2c20
	fi
ac2c20
}
ac2c20
ac2c20
ccenv_set_characteristics()
ac2c20
{
ac2c20
	ccenv_set_cc_host
ac2c20
	ccenv_set_cc_bits
ac2c20
	ccenv_set_cc_binfmt
8be87f
	ccenv_set_cc_underscore
ac2c20
}
ac2c20
ac2c20
ccenv_set_toolchain_variables()
ac2c20
{
ac2c20
	ccenv_common_init $1
ac2c20
	ccenv_set_cc
ac2c20
	ccenv_set_cpp
ac2c20
	ccenv_set_cxx
ac2c20
	ccenv_set_primary_tools
ac2c20
	ccenv_set_tool_variants
ac2c20
	ccenv_set_characteristics
ac2c20
ac2c20
	ccenv_set_os
ac2c20
	ccenv_set_os_flags
ac2c20
	ccenv_set_os_semantics
cffad0
	ccenv_set_os_dso_format
ac2c20
	ccenv_set_os_dso_exrules
ac2c20
	ccenv_set_os_dso_linkage
ac2c20
	ccenv_set_os_dso_patterns
ef618e
	ccenv_set_os_pe_switches
5a5c4b
	ccenv_set_os_gate_switches
bf5fe6
	ccenv_set_os_bsd_switches
d089ce
	ccenv_set_cc_attr_visibility_vars
ac2c20
ac2c20
	ccenv_output_defs
ac2c20
	ccenv_clean_up
fbaa20
99013d
	ccenv_set_cc_sysroot_vars
fbaa20
	ccenv_set_cc_switch_vars
5450df
	ccenv_set_cc_linker_switch_vars
ac2c20
}
ac2c20
ac2c20
ccenv_set_host_variables()
ac2c20
{
8be87f
	output_script_status ${mb_script} \
5a0267
		'detect and query host (targeted) system'
8be87f
ac2c20
	ccenv_set_toolchain_variables 'host'
f2ee7e
	ccenv_dso_verify
ac2c20
}
ac2c20
ac2c20
ccenv_set_native_variables()
ac2c20
{
8be87f
	output_script_status ${mb_script} \
5a0267
		'detect and query native (local build) system'
8be87f
2d55ea
	if [ _$mb_ccenv_skip_native != _yes ]; then
2d55ea
		ccenv_set_toolchain_variables 'native'
2d55ea
	fi
ac2c20
}