Blame sofort/ccenv/ccenv.sh

027376
38579a
# ccenv.sh: sofort's tool-finding bits,
38579a
# invoked from within the project-agnostic configure script.
38579a
8360a8
# this file is covered by COPYING.SOFORT.
8360a8
38579a
# invocation and names of binary tools:
38579a
# agnostic names (ar, nm, objdump, ...);
38579a
# target-prefixed agnostic names (x86_64-nt64-midipix-ar, ...);
38579a
# branded names (llvm-ar, llvm-nm, llvm-objdump, ...);
38579a
# target-prefixed branded names (x86_64-linux-gnu-gcc-ar, ...);
38579a
# target-specifying branded tools (llvm-ar --target=x86_64-linux, ...).
38579a
38579a
# cross-compilation: default search order:
38579a
# target-prefixed agnostic tools;
38579a
# target-prefixed branded tools, starting with the prefix
38579a
# most commonly associated with the selected compiler (that is,
38579a
# ``gcc'' when using gcc, and ``llvm'' when using clang);
38579a
# target-speficying branded tools, starting once again with the
38579a
# prefix most commonly associated with the selected compiler.
38579a
38579a
# internal variables of interest:
38579a
# ccenv_cfgtype: the type of host being tested (host/native)
38579a
# ccenv_cfgfile: the configuration file for the host being tested
38579a
# ccenv_cflags:  the comprehensive cflags for the host being tested
38579a
# ccenv_cchost:  the host being tested, as reported by -dumpmachine
38579a
027376
# variables available to cfgdefs.sh and cfgfini.sh:
027376
# ccenv_host_cflags:    expanded cflags, valid for the host compiler
027376
# ccenv_host_ldflags:   expanded ldflags, valid for the host compiler
c5a7c7
# ccenv_host_sysroot:   host sysroot, as reported by the host compiler
027376
# ccenv_native_cflags:  expanded cflags, valid for the native compiler
027376
# ccenv_native_ldflags: expanded ldflags, valid for the native compiler
c5a7c7
# ccenv_native_sysroot: native sysroot, as reported by the native compiler
38579a
38579a
ccenv_usage()
38579a
{
38579a
	cat "$mb_project_dir"/sofort/ccenv/ccenv.usage
38579a
	exit 0
38579a
}
38579a
38579a
38579a
ccenv_newline()
38579a
{
38579a
	printf '\n' >> "$ccenv_cfgfile"
38579a
}
38579a
38579a
38579a
ccenv_comment()
38579a
{
38579a
	ccenv_internal_str='#'
38579a
38579a
	for ccenv_internal_arg ; do
38579a
		ccenv_internal_str="$ccenv_internal_str $ccenv_internal_arg"
38579a
	done
38579a
38579a
	printf '%s\n' "$ccenv_internal_str" >> "$ccenv_cfgfile"
38579a
}
38579a
38579a
82c35d
ccenv_tool_prolog()
82c35d
{
480842
	ccenv_line_dots='.....................................'
6df457
	ccenv_tool_desc=" == checking for ${1}"
82c35d
	ccenv_tool_dlen="${#ccenv_line_dots}"
82c35d
ba10e0
	printf '\n%s\n' '________________________' >&3
ba10e0
	printf "ccenv: checking for ${1}\n\n" >&3
82c35d
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s" \
480842
		"${ccenv_tool_desc}  ${mb_line_dots}"
82c35d
}
82c35d
82c35d
82c35d
ccenv_tool_epilog()
82c35d
{
82c35d
	ccenv_line_dots='................................'
82c35d
	ccenv_tool_dlen="$((${#ccenv_line_dots} - ${#1}))"
82c35d
9f0292
	case ${ccenv_tool_dlen} in
9f0292
		0 | -* )
9f0292
			ccenv_tool_dlen='3' ;;
9f0292
	esac
9f0292
480842
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
82c35d
		"${ccenv_line_dots}" "${1}"
ba10e0
ba10e0
	if [ "${1}" = 'false' ]; then
ba10e0
		printf '\n\nccenv: not (yet) found.\n' >&3
ba10e0
	else
ba10e0
		printf "\n\nccenv : found $(command -v ${1}).\n" >&3
ba10e0
	fi
ba10e0
ba10e0
	printf '%s\n' '------------------------' >&3
82c35d
}
82c35d
82c35d
b72ea9
ccenv_tool_variant_epilog()
b72ea9
{
b72ea9
	ccenv_expr=${1}='${'${1}':-false}'
b72ea9
	eval "$ccenv_expr"
b72ea9
b72ea9
	ccenv_expr='${'${1}'}'
b72ea9
	eval ccenv_tool_epilog "$ccenv_expr"
b72ea9
}
b72ea9
b72ea9
82c35d
ccenv_attr_prolog()
82c35d
{
480842
	ccenv_line_dots=' .....................................'
480842
	ccenv_attr_desc=" == detect ${ccenv_cfgtype} ${1}"
82c35d
	ccenv_attr_dlen="${#ccenv_line_dots}"
82c35d
82c35d
	printf "%${ccenv_attr_dlen}.${ccenv_attr_dlen}s" \
82c35d
		"${ccenv_attr_desc} ${ccenv_line_dots}"
ba10e0
ba10e0
	printf '\n%s\n' '________________________' >&3
ba10e0
	printf "ccenv: detecting ${1}\n\n" >&3
82c35d
}
82c35d
82c35d
82c35d
ccenv_attr_epilog()
82c35d
{
ba10e0
	ccenv_line_dots='................................'
480842
	ccenv_tool_dlen="$((${#ccenv_line_dots} - 1 - ${#1}))"
ba10e0
9f0292
	case ${ccenv_tool_dlen} in
9f0292
		0 | -* )
9f0292
			ccenv_tool_dlen='3' ;;
9f0292
	esac
9f0292
480842
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
ba10e0
		"${ccenv_line_dots}" "${1}"
ba10e0
ba10e0
	printf '\n\nccenv: detected result: %s\n' "${1}" >&3
ba10e0
	printf '%s\n' '------------------------' >&3
82c35d
}
82c35d
82c35d
38579a
ccenv_find_tool()
38579a
{
38579a
	if [ -z "$ccenv_prefixes" ]; then
38579a
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
3da3ba
			ccenv_cmd_args="${@:-}"
3da3ba
3da3ba
			if [ -z "$ccenv_cmd_args" ]; then
38579a
				if command -v "$ccenv_candidate" > /dev/null; then
38579a
					ccenv_tool="$ccenv_candidate"
38579a
					return 0
38579a
				fi
38579a
			else
38579a
				if command -v "$ccenv_candidate" > /dev/null; then
ba10e0
					if "$ccenv_candidate" $@ > /dev/null 2>&3; then
38579a
						ccenv_tool="$ccenv_candidate"
38579a
						return 0
38579a
					fi
38579a
				fi
38579a
			fi
38579a
		done
38579a
38579a
		ccenv_tool=false
38579a
38579a
		return 0
38579a
	fi
38579a
38579a
	for ccenv_prefix in $(printf '%s' "$ccenv_prefixes"); do
38579a
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
38579a
			ccenv_tool="$ccenv_prefix$ccenv_candidate"
38579a
38579a
			if command -v "$ccenv_tool" > /dev/null; then
38579a
				return 0
38579a
			fi
38579a
		done
38579a
	done
38579a
38579a
	for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
38579a
		if command -v "$ccenv_candidate" > /dev/null; then
38579a
			ccenv_tool="$ccenv_candidate"
38579a
			return 0
38579a
		fi
38579a
	done
38579a
38579a
	ccenv_tool=false
38579a
38579a
	return 0
38579a
}
38579a
38579a
38579a
ccenv_set_primary_tools()
38579a
{
38579a
	ccenv_core_tools="ar nm objdump ranlib size strip strings objcopy"
38579a
	ccenv_hack_tools="addr2line cov elfedit readelf readobj otool"
53f987
	ccenv_peep_tools="perk mdso dlltool windmc windres pkgconf"
38579a
38579a
	for __tool in $(printf '%s' "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do
82c35d
		ccenv_tool_prolog "$__tool"
82c35d
38579a
		if [ -n "$mb_agnostic" ]; then
38579a
			ccenv_candidates=" $__tool"
38579a
38579a
		elif [ -n "$mb_zealous" ]; then
38579a
			ccenv_candidates="$mb_zealous-$__tool"
38579a
38579a
		elif [ "$mb_toolchain" = 'gcc' ]; then
38579a
			ccenv_candidates="gcc-$__tool"
38579a
			ccenv_candidates="$ccenv_candidates $__tool"
38579a
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
38579a
38579a
		elif [ "$mb_toolchain" = 'llvm' ]; then
38579a
			ccenv_candidates="llvm-$__tool"
38579a
			ccenv_candidates="$ccenv_candidates $__tool"
38579a
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
38579a
38579a
		elif [ -n "$mb_toolchain" ]; then
38579a
			ccenv_candidates="$mb_toolchain-$__tool"
38579a
			ccenv_candidates="$ccenv_candidates $__tool"
38579a
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
38579a
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
38579a
328bb4
		elif [ "$__tool" = 'pkgconf' ]; then
328bb4
			ccenv_candidates="$__tool pkg-config"
328bb4
38579a
		else
38579a
			ccenv_candidates="$__tool"
38579a
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
38579a
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
38579a
		fi
38579a
38579a
		if [ "$ccenv_cfgtype" = 'host' ]; then
38579a
			ccenv_var_prefix='mb_'
38579a
		else
38579a
			ccenv_var_prefix='mb_native_'
38579a
		fi
38579a
7aed42
		ccenv_tool=
38579a
		ccenv_var_name=$ccenv_var_prefix$__tool
38579a
		ccenv_var_expr='${'$ccenv_var_name':-}'
38579a
		eval ccenv_var_val=$ccenv_var_expr
38579a
38579a
		if [ -n "$ccenv_var_val" ]; then
38579a
			eval ccenv_$__tool="$ccenv_var_val"
7aed42
			ccenv_tool="$ccenv_var_val"
38579a
		else
38579a
			ccenv_find_tool
38579a
			eval ccenv_$__tool="$ccenv_tool"
38579a
		fi
82c35d
82c35d
		ccenv_tool_epilog "$ccenv_tool"
38579a
	done
38579a
38579a
	# windrc
38579a
	ccenv_windrc="$ccenv_windres"
20c5c2
20c5c2
	# archive format preamble
8dfb0c
	if [ -n "$ccenv_dumpmachine_switch" ]; then
378c34
		ccenv_libgcc_path=$($ccenv_cc -print-file-name=libgcc.a \
378c34
			2>/dev/null)
378c34
378c34
		if [ -n "$ccenv_libgcc_path" ]; then
378c34
			ccenv_libgcc_a_header=$(od -b -N8             \
378c34
				$($ccenv_cc -print-file-name=libgcc.a) \
378c34
				| head -n1)
378c34
		else
378c34
			ccenv_libgcc_a_header=
378c34
		fi
8dfb0c
	else
8dfb0c
		ccenv_libgcc_a_header=
8dfb0c
	fi
8dfb0c
8dfb0c
	# ar (default)
20c5c2
	ccenv_cc_arfmt='common'
20c5c2
20c5c2
	# ar (big)
20c5c2
	ccenv_bigaf_header=$(printf '%s\n' '<bigaf>' | od -b | head -n1)
20c5c2
20c5c2
	if [ "$ccenv_libgcc_a_header" = "$ccenv_bigaf_header" ]; then
20c5c2
		ccenv_cc_arfmt='bigaf'
20c5c2
20c5c2
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
20c5c2
			ccenv_var_name=ccenv_$__tool
20c5c2
			ccenv_var_expr='${'$ccenv_var_name':-}'
20c5c2
			eval ccenv_var_val="$ccenv_var_expr"
20c5c2
20c5c2
			if [ "$ccenv_var_val" != false ]; then
20c5c2
				ccenv_var_val="$ccenv_var_val -X64"
20c5c2
				ccenv_var_expr='${ccenv_var_val:-}'
20c5c2
				eval ccenv_$__tool="$ccenv_var_expr"
20c5c2
			fi
20c5c2
		done
20c5c2
	fi
20c5c2
20c5c2
	# ar (small)
20c5c2
	ccenv_aiaff_header=$(printf '%s\n' '<aiaff>' | od -b | head -n1)
20c5c2
20c5c2
	if [ "$ccenv_libgcc_a_header" = "$ccenv_aiaff_header" ]; then
20c5c2
		ccenv_cc_arfmt='aiaff'
20c5c2
20c5c2
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
20c5c2
			ccenv_var_name=ccenv_$__tool
20c5c2
			ccenv_var_expr='${'$ccenv_var_name':-}'
20c5c2
			eval ccenv_var_val="$ccenv_var_expr"
20c5c2
20c5c2
			if [ "$ccenv_var_val" != false ]; then
20c5c2
				ccenv_var_val="$ccenv_var_val -X32"
20c5c2
				ccenv_var_expr='${ccenv_var_val:-}'
20c5c2
				eval ccenv_$__tool="$ccenv_var_expr"
20c5c2
			fi
20c5c2
		done
20c5c2
	fi
38579a
}
38579a
38579a
ccenv_set_tool_variants()
38579a
{
38579a
	# as (asm)
82c35d
	ccenv_tool_prolog 'as (asm)'
38579a
	ccenv_candidates=as
38579a
	ccenv_find_tool
38579a
38579a
	if [ "$ccenv_tool" = false ]; then
38579a
		ccenv_as_asm=
38579a
	else
367b41
		$ccenv_tool --help 2>&1 | grep -i '.bc assembler' \
38579a
		|| ccenv_as_asm="$ccenv_tool"
38579a
	fi
38579a
b72ea9
	ccenv_tool_variant_epilog 'ccenv_as_asm'
82c35d
38579a
	# as (ll)
82c35d
	ccenv_tool_prolog 'as (ll)'
38579a
	ccenv_candidates=llvm-as
38579a
	ccenv_find_tool
38579a
38579a
	if [ "$ccenv_tool" != false ]; then
38579a
		ccenv_as_ll="$ccenv_tool"
38579a
	fi
38579a
b72ea9
	ccenv_tool_variant_epilog 'ccenv_as_ll'
82c35d
38579a
	# as (mc)
82c35d
	ccenv_tool_prolog 'as (mc)'
38579a
	ccenv_candidates=llvm-mc
38579a
	ccenv_find_tool
38579a
38579a
	if [ "$ccenv_tool" != false ]; then
38579a
		ccenv_as_mc="$ccenv_tool"
38579a
	fi
38579a
b72ea9
	ccenv_tool_variant_epilog 'ccenv_as_mc'
82c35d
38579a
	# ld (bfd)
82c35d
	ccenv_tool_prolog 'ld (bfd)'
38579a
	ccenv_candidates=ld.bfd
38579a
	ccenv_find_tool
38579a
38579a
	if [ "$ccenv_tool" != false ]; then
38579a
		ccenv_ld_bfd="$ccenv_tool"
38579a
	fi
38579a
b72ea9
	ccenv_tool_variant_epilog 'ccenv_ld_bfd'
82c35d
38579a
	# ld (gold)
82c35d
	ccenv_tool_prolog 'ld (gold)'
38579a
	ccenv_candidates=ld.gold
38579a
	ccenv_find_tool
38579a
38579a
	if [ "$ccenv_tool" != false ]; then
38579a
		ccenv_ld_gold="$ccenv_tool"
38579a
	fi
38579a
b72ea9
	ccenv_tool_variant_epilog 'ccenv_ld_gold'
82c35d
38579a
	# ld (lld)
82c35d
	ccenv_tool_prolog 'ld (lld)'
38579a
	ccenv_candidates=lld
38579a
	ccenv_find_tool
38579a
38579a
	if [ "$ccenv_tool" != false ]; then
38579a
		ccenv_ld_lld="$ccenv_tool"
38579a
	fi
38579a
b72ea9
	ccenv_tool_variant_epilog 'ccenv_ld_lld'
82c35d
38579a
	# objdump (bfd)
82c35d
	ccenv_tool_prolog 'objdump (bfd)'
38579a
	ccenv_candidates=objdump
38579a
	ccenv_find_tool
38579a
38579a
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
38579a
		ccenv_objdump_bfd="$ccenv_tool"
38579a
	fi
38579a
b72ea9
	ccenv_tool_variant_epilog 'ccenv_objdump_bfd'
82c35d
38579a
	# objdump (llvm)
82c35d
	ccenv_tool_prolog 'objdump (llvm)'
38579a
	ccenv_candidates=llvm-objdump
38579a
	ccenv_find_tool
38579a
38579a
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
38579a
		ccenv_objdump_llvm="$ccenv_tool"
38579a
	fi
38579a
b72ea9
	ccenv_tool_variant_epilog 'ccenv_objdump_llvm'
82c35d
38579a
	# readelf (bfd)
82c35d
	ccenv_tool_prolog 'readelf (bfd)'
38579a
	ccenv_candidates=readelf
38579a
	ccenv_find_tool
38579a
38579a
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
38579a
		ccenv_readelf_bfd="$ccenv_tool"
38579a
	fi
38579a
b72ea9
	ccenv_tool_variant_epilog 'ccenv_readelf_bfd'
82c35d
38579a
	# readelf (llvm)
82c35d
	ccenv_tool_prolog 'readelf (llvm)'
38579a
	ccenv_candidates=llvm-readelf
38579a
	ccenv_find_tool
38579a
38579a
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
38579a
		ccenv_readelf_llvm="$ccenv_tool"
38579a
	fi
38579a
b72ea9
	ccenv_tool_variant_epilog 'ccenv_readelf_llvm'
82c35d
38579a
	# as
38579a
	if [ -n "$ccenv_cc" ]; then
38579a
		ccenv_as='$('"$ccenv_makevar_prefix"'CC) -c -x assembler'
38579a
	elif [ -n "$mb_agnostic" ]; then
38579a
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
38579a
	elif [ "$mb_zealous" = 'gcc' ]; then
38579a
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
38579a
	elif [ -n "$mb_zealous" = 'llvm' ]; then
38579a
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
38579a
	elif [ "$mb_toolchain" = 'gcc' ]; then
38579a
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
38579a
	elif [ "$mb_toolchain" = 'llvm' ]; then
38579a
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
38579a
	fi
38579a
38579a
	# ld
38579a
	if [ -n "$ccenv_cc" ]; then
38579a
		ccenv_ld='$('"$ccenv_makevar_prefix"'CC) -nostdlib -nostartfiles'
38579a
	fi
38579a
}
38579a
38579a
ccenv_set_c_compiler_candidates()
38579a
{
38579a
	if   [ -n "$mb_compiler" ]; then
38579a
		ccenv_candidates="$mb_compiler"
38579a
38579a
	elif [ -n "$mb_agnostic" ]; then
38579a
		ccenv_candidates="c99 c11 cc"
38579a
38579a
	elif [ "$mb_zealous" = 'gcc' ]; then
38579a
		ccenv_candidates="gcc"
38579a
38579a
	elif [ "$mb_zealous" = 'llvm' ]; then
38579a
		ccenv_candidates="clang"
38579a
38579a
	elif [ "$mb_toolchain" = 'gcc' ]; then
38579a
		ccenv_candidates="gcc c99 c11 cc clang"
38579a
38579a
	elif [ "$mb_toolchain" = 'llvm' ]; then
38579a
		ccenv_candidates="clang c99 c11 cc gcc"
38579a
38579a
	elif [ -n "$mb_toolchain" ]; then
38579a
		ccenv_candidates="$mb_toolchain c99 c11 cc gcc clang"
38579a
38579a
	else
c4564a
		ccenv_candidates="cc gcc clang c99 c11"
38579a
	fi
38579a
}
38579a
38579a
38579a
ccenv_set_cc()
38579a
{
82c35d
	ccenv_tool_prolog 'C compiler'
82c35d
38579a
	if [ -z "$ccenv_cc" ]; then
38579a
		ccenv_set_c_compiler_candidates
8dfb0c
		ccenv_find_tool
38579a
		ccenv_cc="$ccenv_tool"
38579a
	fi
38579a
8dfb0c
38579a
	if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
38579a
		ccenv_cc="$mb_compiler"
38579a
	fi
38579a
8dfb0c
	ccenv_tool_epilog "$ccenv_cc"
8dfb0c
8dfb0c
8dfb0c
	if [ $ccenv_cfgtype = 'host' ]; then
8dfb0c
		ccenv_host_cc="$ccenv_cc"
8dfb0c
		cfgtest_host_section
8dfb0c
		ccenv_host_cc=
8dfb0c
	else
8dfb0c
		ccenv_native_cc="$ccenv_cc"
8dfb0c
		cfgtest_native_section
8dfb0c
		ccenv_native_cc=
8dfb0c
	fi
8dfb0c
5f885e
	cfgtest_silent='yes'
5f885e
8dfb0c
	if cfgtest_compiler_switch -dumpmachine ; then
8dfb0c
		ccenv_dumpmachine_switch='-dumpmachine'
8dfb0c
	else
8dfb0c
		ccenv_dumpmachine_switch=
8dfb0c
	fi
8dfb0c
3bf7da
	if cfgtest_code_snippet_asm 'typedef int dummy;' ; then
3bf7da
		eval ccenv_${ccenv_cfgtype}_stdin_input='yes'
3bf7da
	else
3bf7da
		eval ccenv_${ccenv_cfgtype}_stdin_input='no'
3bf7da
	fi
3bf7da
5f885e
	unset cfgtest_silent
5f885e
38579a
	ccenv_cc_cmd="$ccenv_cc"
2076fd
	ccenv_errors=
38579a
38579a
	if [ "$ccenv_cfgtype" = 'native' ]; then
51a332
		ccenv_host=
51a332
67a565
		if [ -n "$mb_native_host" ]; then
67a565
			ccenv_host="$mb_native_host"
67a565
67a565
		elif [ -n "$ccenv_dumpmachine_switch" ]; then
8dfb0c
			ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
8dfb0c
				$ccenv_dumpmachine_switch 2>&3)
51a332
51a332
		elif command -v slibtool > /dev/null 2>&1; then
2af060
			ccenv=$(slibtool --dumpmachine 2>/dev/null || true)
51a332
		fi
51a332
51a332
		if [ -z "$ccenv_host" ]; then
67a565
			ccenv_machine=$(uname -m 2>/dev/null)
67a565
			ccenv_system=$(uname -s 2>/dev/null)
67a565
67a565
			ccenv_machine="${ccenv_machine:-unknown}"
67a565
			ccenv_system="${ccenv_system:-anyos}"
67a565
67a565
			ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \
4157dc
				| tr '[[:upper:]]' '[[:lower:]]')
8dfb0c
		fi
8dfb0c
38579a
		ccenv_cchost=$ccenv_host
38579a
		return 0
38579a
	fi
38579a
8dfb0c
38579a
	if [ -n "$mb_cchost" ]; then
38579a
		ccenv_host="$mb_cchost"
38579a
	elif [ -n "$mb_host" ]; then
38579a
		ccenv_host="$mb_host"
38579a
	else
38579a
		ccenv_host=
38579a
	fi
38579a
8dfb0c
	if [ -z "$ccenv_host" ] && [ -n "$ccenv_dumpmachine_switch" ]; then
8dfb0c
		ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
8dfb0c
			$ccenv_dumpmachine_switch 2>&3)
38579a
		ccenv_cchost=$ccenv_host
8dfb0c
8dfb0c
	elif [ -z "$ccenv_host" ]; then
51a332
		# no -dumpmachine support and no --host argument implies native build
51a332
		if command -v slibtool > /dev/null 2>&1; then
2af060
			ccenv=$(slibtool --dumpmachine 2>/dev/null || true)
51a332
		fi
67a565
51a332
		if [ -z "$ccenv_host" ]; then
51a332
			ccenv_machine=$(uname -m 2>/dev/null)
51a332
			ccenv_system=$(uname -s 2>/dev/null)
51a332
51a332
			ccenv_machine="${ccenv_machine:-unknown}"
51a332
			ccenv_system="${ccenv_system:-anyos}"
67a565
51a332
			ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \
51a332
				| tr '[[:upper:]]' '[[:lower:]]')
51a332
		fi
67a565
8dfb0c
		ccenv_cchost=$ccenv_host
8dfb0c
8dfb0c
	elif [ -n "$ccenv_dumpmachine_switch" ]; then
38579a
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
38579a
		ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -"
38579a
38579a
		if [ -z "$mb_user_cc" ]; then
72557f
			$(printf %s "$ccenv_cmd") < /dev/null > /dev/null \
38579a
				2>"$ccenv_tmp" || true
38579a
38579a
			ccenv_errors=$(cat "$ccenv_tmp")
38579a
38579a
			if [ -z "$ccenv_errors" ]; then
8dfb0c
				ccenv_tool_prolog 'C compiler for host'
38579a
				ccenv_tflags="--target=$ccenv_host"
38579a
				ccenv_cc="$ccenv_cc $ccenv_tflags"
8dfb0c
				ccenv_tool_epilog "$ccenv_cc"
ba10e0
			else
ba10e0
				printf '%s' "$ccenv_errors" >&3
38579a
			fi
38579a
		fi
38579a
38579a
		rm -f "$ccenv_tmp"
38579a
		unset ccenv_tmp
38579a
8dfb0c
		ccenv_cchost=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
8dfb0c
			$ccenv_dumpmachine_switch 2>&3)
38579a
	fi
38579a
4cc73a
	if [ -z "$ccenv_dumpmachine_switch" ] && [ -n "$ccenv_host" ]; then
4cc73a
		ccenv_cchost="$ccenv_host"
4cc73a
4cc73a
	elif [ "$ccenv_cchost" != "$ccenv_host" ]; then
ba10e0
		printf 'error!\n' >&2
38579a
		printf 'ccenv:\n' >&2
38579a
		printf 'ccenv: ccenv_host:   %s \n' $ccenv_host >&2
38579a
		printf 'ccenv: ccenv_cchost: %s \n' $ccenv_cchost >&2
38579a
38579a
		if [ -z "$ccenv_tflags" ]; then
38579a
			printf 'ccenv:\n' >&2
38579a
			printf 'ccenv: ccenv_host and ccenv_cchost do not match, most likely because:\n' >&2
38579a
			printf 'ccenv: (1) you explicitly set CC (or passed --compiler=...)\n' >&2
38579a
			printf 'ccenv: (2) the selected compiler does not accept --target=...\n' >&2
38579a
			printf 'ccenv: (3) the host reported by -dumpmachine differs from the one you requested.\n' >&2
38579a
		fi
38579a
38579a
		if [ -n "$ccenv_errors" ]; then
38579a
			printf 'ccenv:\n' >&2
38579a
			printf 'ccenv: something went wrong, see the command and compiler message below.\n\n' >&2
38579a
			printf 'cmd: %s < /dev/null > /dev/null\n' "$ccenv_cmd" >&2
38579a
			printf '%s\n\n' "$ccenv_errors" >&2
38579a
		else
38579a
			printf 'ccenv:\n' >&2
38579a
			printf 'ccenv: something went wrong, bailing out.\n\n' >&2
38579a
		fi
38579a
38579a
		return 2
38579a
	fi
38579a
}
38579a
38579a
ccenv_set_cpp()
38579a
{
82c35d
	ccenv_tool_prolog 'C pre-processor'
82c35d
38579a
	case "$ccenv_cc_cmd" in
38579a
		cc | c99 | c11 | gcc)
38579a
			ccenv_cpp_prefix=
38579a
			ccenv_candidates="cpp" ;;
38579a
38579a
		clang )
38579a
			ccenv_cpp_prefix=
38579a
			ccenv_candidates="clang-cpp" ;;
38579a
38579a
		*-cc )
38579a
			ccenv_cpp_prefix=${ccenv_cc_cmd%-cc*}-
38579a
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
38579a
38579a
		*-c99 )
38579a
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c99*}-
38579a
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
38579a
38579a
		*-c11 )
38579a
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c11*}-
38579a
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
38579a
38579a
		*-gcc )
38579a
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
38579a
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
38579a
38579a
		*-clang )
38579a
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
38579a
			ccenv_candidates="${ccenv_cpp_prefix}clang-cpp" ;;
38579a
38579a
		* )
38579a
			ccenv_cpp="$ccenv_cc -E"
82c35d
			ccenv_tool_epilog "$ccenv_cpp"
38579a
			return 0
38579a
	esac
38579a
38579a
	ccenv_find_tool
38579a
38579a
	if [ "$ccenv_tool" = false ]; then
38579a
		ccenv_cpp="$ccenv_cc -E"
38579a
	elif [ -n "$ccenv_tflags" ]; then
38579a
		ccenv_cpp="$ccenv_tool $ccenv_tflags"
38579a
	else
38579a
		ccenv_cpp="$ccenv_tool"
38579a
	fi
82c35d
82c35d
	ccenv_tool_epilog "$ccenv_cpp"
38579a
}
38579a
38579a
ccenv_set_cxx()
38579a
{
82c35d
	ccenv_tool_prolog 'C++ compiler'
82c35d
38579a
	case "$ccenv_cc_cmd" in
38579a
		cc | c99 | c11 )
38579a
			ccenv_cxx_prefix=
38579a
			ccenv_candidates="cxx c++" ;;
38579a
38579a
		gcc )
38579a
			ccenv_cxx_prefix=
38579a
			ccenv_candidates="g++" ;;
38579a
38579a
		clang )
38579a
			ccenv_cxx_prefix=
38579a
			ccenv_candidates="clang++" ;;
38579a
38579a
		*-gcc )
14be9d
			ccenv_cxx_prefix=${ccenv_cc_cmd%-gcc*}-
14be9d
			ccenv_candidates="${ccenv_cxx_prefix}g++" ;;
38579a
38579a
		*-clang )
14be9d
			ccenv_cxx_prefix=${ccenv_cc_cmd%-clang*}-
14be9d
			ccenv_candidates="${ccenv_cxx_prefix}clang++" ;;
14be9d
14be9d
		/*cc | /*c99 | /*c11 )
14be9d
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
14be9d
			ccenv_candidates="${ccenv_cxx_prefix}/cxx"
14be9d
			ccenv_candidates="${ccenv_candidates} ${ccenv_cxx_prefix}/c++" ;;
14be9d
14be9d
		/*gcc )
14be9d
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
14be9d
			ccenv_candidates="${ccenv_cxx_prefix}/g++" ;;
38579a
14be9d
		/*clang )
14be9d
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
14be9d
			ccenv_candidates="${ccenv_cxx_prefix}/clang++" ;;
38579a
38579a
		* )
38579a
			ccenv_cxx="$ccenv_cc -xc++"
82c35d
			ccenv_tool_epilog "$ccenv_cxx"
38579a
			return 0
38579a
	esac
38579a
38579a
	ccenv_find_tool
38579a
38579a
	if [ "$ccenv_tool" = false ]; then
38579a
		ccenv_cxx="$ccenv_cc -xc++"
38579a
	elif [ -n "$ccenv_tflags" ]; then
38579a
		ccenv_cxx="$ccenv_tool $ccenv_tflags"
38579a
	else
38579a
		ccenv_cxx="$ccenv_tool"
38579a
	fi
82c35d
82c35d
	ccenv_tool_epilog "$ccenv_cxx"
38579a
}
38579a
38579a
ccenv_set_cc_host()
38579a
{
f06bc0
	ccenv_attr_prolog 'system'
38579a
	ccenv_cc_host="$ccenv_cchost"
82c35d
	ccenv_attr_epilog "$ccenv_cc_host"
38579a
}
38579a
38579a
ccenv_set_cc_bits()
38579a
{
82c35d
	ccenv_attr_prolog 'bits'
82c35d
38579a
	ccenv_internal_size=
38579a
	ccenv_internal_type='void *'
38579a
	ccenv_internal_test='char x[(sizeof(%s) == %s/8) ? 1 : -1];'
38579a
38579a
	for ccenv_internal_guess in 64 32 128; do
c6762e
		if [ -z "${ccenv_internal_size:-}" ]; then
2b49ac
			ccenv_internal_str=$(printf "$ccenv_internal_test"  \
2b49ac
				"$ccenv_internal_type"                      \
38579a
				"$ccenv_internal_guess")
38579a
b47160
			ccenv_expr='ccenv_stdin_input=$ccenv_'${ccenv_cfgtype}'_stdin_input'
b47160
			eval ${ccenv_expr}
b47160
b47160
			if [ "$ccenv_stdin_input" = 'yes' ]; then
1b4168
				printf '%s' "$ccenv_internal_str"                   \
1b4168
						| eval $ccenv_cc -S -xc - -o -      \
1b4168
						  $(printf '%s' "$ccenv_cflags")    \
1b4168
					> /dev/null 2>&3                            \
1b4168
				&& ccenv_internal_size=$ccenv_internal_guess
1b4168
			else
1b4168
				ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
1b4168
1b4168
				printf '%s' "$ccenv_internal_str" \
1b4168
					> "$ccenv_tmpname"
1b4168
1b4168
				$ccenv_cc -c "$ccenv_tmpname" -o a.out \
1b4168
					> /dev/null 2>&3                \
1b4168
				&& ccenv_internal_size=$ccenv_internal_guess
1b4168
1b4168
				rm "$ccenv_tmpname"
1b4168
			fi
38579a
		fi
38579a
	done
38579a
38579a
	ccenv_cc_bits=$ccenv_internal_size
82c35d
82c35d
	ccenv_attr_epilog "$ccenv_cc_bits"
38579a
}
38579a
38579a
ccenv_set_cc_underscore()
38579a
{
82c35d
	ccenv_attr_prolog 'prepended underscores'
82c35d
38579a
	ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe'
38579a
	ccenv_fn_code='int %s(void){return 0;}'
38579a
c2db85
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
c2db85
c2db85
	printf "$ccenv_fn_code" $ccenv_fn_name \
c2db85
		> "$ccenv_tmpname"
c2db85
c2db85
	$ccenv_cc -c "$ccenv_tmpname" -o a.out \
c2db85
		> /dev/null 2>&3
c2db85
c2db85
	if "$ccenv_nm" a.out | grep          \
c2db85
			-e "^_$ccenv_fn_name" \
c2db85
			-e " _$ccenv_fn_name"  \
c2db85
			> /dev/null; then
38579a
		ccenv_cc_underscore='_'
82c35d
		ccenv_attr_epilog 'yes'
c2db85
	else
c2db85
		ccenv_attr_epilog 'no'
38579a
	fi
38579a
c2db85
	rm "$ccenv_tmpname"
c2db85
	rm a.out
82c35d
38579a
	return 0
38579a
}
38579a
38579a
ccenv_create_framework_executable()
38579a
{
88d762
	if [ "$ccenv_cfgtype" = 'host' ]; then
88d762
		if [ "$mb_freestanding" = 'yes' ]; then
88d762
			return 1
88d762
		fi
88d762
	fi
88d762
38579a
	if [ -f $ccenv_image ]; then
38579a
		mv $ccenv_image $ccenv_image.tmp
38579a
		rm -f $ccenv_image.tmp
38579a
	fi
38579a
3eab3a
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
3eab3a
38579a
	printf 'int main(void){return 0;}'  \
3eab3a
		> "$ccenv_tmpname"
38579a
3eab3a
	if $ccenv_cc "$ccenv_tmpname" -o $ccenv_image 2>&3; then
3eab3a
		ccenv_ret=0
88d762
		ccenv_cc_environment='hosted'
3eab3a
	else
3eab3a
		ccenv_ret=1
3eab3a
	fi
3eab3a
3eab3a
	rm "$ccenv_tmpname"
3eab3a
3eab3a
	return $ccenv_ret
38579a
}
38579a
38579a
ccenv_create_freestanding_executable()
38579a
{
38579a
	if [ -f $ccenv_image ]; then
38579a
		mv $ccenv_image $ccenv_image.tmp
38579a
		rm -f $ccenv_image.tmp
38579a
	fi
38579a
38579a
	if [ -z "ccenv_cc_underscore" ]; then
38579a
		ccenv_start_fn='_start'
38579a
	else
38579a
		ccenv_start_fn='start'
38579a
	fi
38579a
3eab3a
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
38579a
3eab3a
	printf 'int %s(void){return 0;}' "$ccenv_start_fn" \
3eab3a
		> "$ccenv_tmpname"
38579a
3eab3a
	if $ccenv_cc "$ccenv_tmpname"         \
3eab3a
			-ffreestanding         \
3eab3a
			-nostdlib -nostartfiles \
3eab3a
			-o $ccenv_image          \
3eab3a
			2>&3; then
3eab3a
		ccenv_ret=0
88d762
		ccenv_cc_environment='freestanding'
3eab3a
	else
3eab3a
		ccenv_ret=1
3eab3a
	fi
3eab3a
3eab3a
	rm "$ccenv_tmpname"
3eab3a
3eab3a
	return $ccenv_ret
38579a
}
38579a
82c35d
ccenv_set_cc_binfmt_error()
82c35d
{
82c35d
	ccenv_attr_epilog '(unable to create executable)'
82c35d
}
82c35d
38579a
ccenv_set_cc_binfmt()
38579a
{
38579a
	ccenv_use_perk=
38579a
	ccenv_use_otool=
38579a
	ccenv_use_readelf=
38579a
	ccenv_use_readobj=
38579a
	ccenv_use_bfd_objdump=
38579a
	ccenv_use_llvm_objdump=
38579a
82c35d
	ccenv_attr_prolog 'binary format'
82c35d
38579a
	ccenv_create_framework_executable               \
38579a
		|| ccenv_create_freestanding_executable \
82c35d
		|| ccenv_set_cc_binfmt_error            \
38579a
		|| return 0
38579a
38579a
	# PE / perk
38579a
	if [ -n "$ccenv_perk" ]; then
ba10e0
		if $ccenv_perk $ccenv_image 2>&3; then
38579a
			ccenv_cc_binfmt='PE'
38579a
			ccenv_use_perk=yes
38579a
		fi
38579a
	fi
38579a
38579a
	# ELF / readelf
38579a
	if [ -n "$ccenv_readelf" ] && [ -z "$ccenv_cc_binfmt" ]; then
ba10e0
		if $ccenv_readelf -h $ccenv_image 2>&3               \
38579a
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
38579a
				| grep 'Magic:7f454c46'              \
38579a
					> /dev/null; then
38579a
			ccenv_cc_binfmt='ELF'
38579a
			ccenv_use_readelf=yes
38579a
		fi
38579a
	fi
38579a
38579a
	# a marble of astonishing design:
38579a
	# llvm-readelf also parses PE and Mach-O
38579a
38579a
	if [ -n "$ccenv_readelf_llvm" ]; then
38579a
		ccenv_readany="$ccenv_readelf_llvm"
38579a
	else
38579a
		ccenv_readany="$ccenv_readelf"
38579a
	fi
38579a
38579a
	# PE / readelf
38579a
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
ba10e0
		if $ccenv_readany -h $ccenv_image 2>&3               \
38579a
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
38579a
				| grep 'Magic:MZ'                    \
38579a
					> /dev/null; then
38579a
			ccenv_cc_binfmt='PE'
38579a
			ccenv_use_readelf=yes
38579a
		fi
38579a
	fi
38579a
38579a
	# MACHO-64 / otool
38579a
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
ba10e0
		if $ccenv_otool -hv $ccenv_image 2>&3        \
38579a
				| grep -i 'MH_MAGIC_64'      \
38579a
					> /dev/null; then
38579a
			ccenv_cc_binfmt='MACHO'
38579a
			ccenv_use_otool=yes
38579a
		fi
38579a
	fi
38579a
38579a
	# MACHO-32 / otool
38579a
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
ba10e0
		if $ccenv_otool -hv $ccenv_image 2>&3        \
38579a
				| grep -i 'MH_MAGIC'         \
38579a
					> /dev/null; then
38579a
			ccenv_cc_binfmt='MACHO'
38579a
			ccenv_use_otool=yes
38579a
		fi
38579a
	fi
38579a
38579a
	# MACHO-64 / readelf
38579a
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
ba10e0
		if $ccenv_readany -h $ccenv_image 2>&3                    \
38579a
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
38579a
				| grep -i '(0xfeedfacf)'                  \
38579a
					> /dev/null; then
38579a
			ccenv_cc_binfmt='MACHO'
38579a
			ccenv_use_readelf=yes
38579a
		fi
38579a
	fi
38579a
38579a
	# MACHO-32 / readelf
38579a
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
ba10e0
		if $ccenv_readany -h $ccenv_image 2>&3                    \
38579a
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
38579a
				| grep -i '(0xcafebabe)'                  \
38579a
					> /dev/null; then
38579a
			ccenv_cc_binfmt='MACHO'
38579a
			ccenv_use_readelf=yes
38579a
		fi
38579a
	fi
38579a
38579a
	# MACHO / readobj
38579a
	if [ -n "$ccenv_readobj" ] && [ -z "$ccenv_cc_binfmt" ]; then
ba10e0
		if $ccenv_readobj $ccenv_image 2>&3                  \
76e334
				| grep -i 'Format:'                  \
76e334
				| sed  -e 's/ /_/g'                  \
38579a
				| grep -i '_Mach-O_'                 \
38579a
					> /dev/null; then
38579a
			ccenv_cc_binfmt='MACHO'
38579a
			ccenv_use_readobj=yes
38579a
		fi
38579a
	fi
38579a
38579a
	# MACHO / objdump (llvm)
38579a
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
38579a
		if $ccenv_objdump -section-headers $ccenv_image  \
ba10e0
					2>&3                     \
38579a
				| grep -i 'file format Mach-O'   \
38579a
					> /dev/null; then
38579a
			ccenv_cc_binfmt='MACHO'
38579a
			ccenv_use_objdump=yes
38579a
		fi
38579a
	fi
38579a
38579a
	# MACHO / objdump (bfd)
38579a
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
ba10e0
		$ccenv_objdump -h  $ccenv_image 2>&3              \
38579a
			| grep -i 'file format Mach-O'            \
38579a
				> /dev/null                       \
38579a
		&& ccenv_cc_binfmt='MACHO'                        \
38579a
		&& ccenv_use_objdump=yes
38579a
	fi
38579a
38579a
	# PE / objdump (bfd)
38579a
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
ba10e0
		if $ccenv_objdump -h  $ccenv_image 2>&3        \
38579a
				| grep -i 'file format pei-'   \
38579a
					> /dev/null; then
38579a
			ccenv_cc_binfmt='PE'
38579a
			ccenv_use_bfd_objdump=yes
38579a
		fi
38579a
	fi
82c35d
82c35d
	ccenv_attr_epilog "$ccenv_cc_binfmt"
38579a
}
38579a
38579a
ccenv_set_os_pe()
38579a
{
88d762
	if [ "$ccenv_cc_environment" = 'freestanding' ]; then
38579a
		case "$ccenv_cchost" in
38579a
			*-midipix | *-midipix-* )
38579a
				ccenv_os='midipix' ;;
38579a
			*-mingw | *-mingw32 | *-mingw64 )
38579a
				ccenv_os='mingw' ;;
38579a
			*-mingw-* | *-mingw32-* | *-mingw64 )
38579a
				ccenv_os='mingw' ;;
38579a
			*-msys | *-msys2 | *-msys-* | *-msys2-* )
38579a
				ccenv_os='msys' ;;
38579a
			*-cygwin | *-cygwin-* )
38579a
				ccenv_os='cygwin' ;;
38579a
		esac
38579a
	fi
38579a
38579a
	if [ -n "$ccenv_os" ]; then
38579a
		return 0
38579a
	fi
38579a
38579a
	if [ -n "$ccenv_use_perk" ]; then
38579a
		ccenv_framework=$($ccenv_perk -y $ccenv_image)
38579a
		ccenv_os=${ccenv_framework#*-*-*-*}
38579a
	fi
38579a
38579a
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
38579a
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
38579a
			| grep 'cygwin1.dll' > /dev/null                \
38579a
		&& ccenv_os='cygwin'
38579a
	fi
38579a
38579a
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
38579a
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
38579a
			| grep 'msys-2.0.dll' > /dev/null               \
38579a
		&& ccenv_os='msys'
38579a
	fi
38579a
38579a
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
38579a
		$ccenv_objdump_bfd -x $ccenv_image          \
38579a
			| grep -i 'DLL Name' | grep '.CRT'  \
38579a
				> /dev/null                 \
38579a
		&& $ccenv_objdump_bfd -x $ccenv_image       \
38579a
			| grep -i 'DLL Name' | grep '.bss'  \
38579a
				> /dev/null                 \
38579a
		&& $ccenv_objdump_bfd -x $ccenv_image       \
38579a
			| grep -i 'DLL Name' | grep '.tls'  \
38579a
				> /dev/null                 \
38579a
		&& ccenv_os='mingw'
38579a
	fi
38579a
}
38579a
38579a
ccenv_set_os_macho()
38579a
{
38579a
	case "$ccenv_cchost" in
38579a
		*-apple-darwin* )
38579a
			ccenv_os='darwin' ;;
38579a
	esac
38579a
}
38579a
38579a
ccenv_set_os()
38579a
{
82c35d
	ccenv_attr_prolog 'os name'
82c35d
38579a
	case "$ccenv_cc_binfmt" in
38579a
		PE )
38579a
			ccenv_set_os_pe ;;
38579a
		MACHO )
38579a
			ccenv_set_os_macho ;;
38579a
	esac
38579a
38579a
	if [ -n "$ccenv_os" ]; then
82c35d
		ccenv_attr_epilog "$ccenv_os"
38579a
		return 0
38579a
	fi
38579a
38579a
	case "$ccenv_cchost" in
38579a
		*-*-*-* )
38579a
			ccenv_tip=${ccenv_cchost%-*}
38579a
			ccenv_os=${ccenv_tip#*-*-}
38579a
			;;
38579a
		*-*-musl | *-*-gnu )
38579a
			ccenv_tip=${ccenv_cchost%-*}
38579a
			ccenv_os=${ccenv_tip#*-}
38579a
			;;
38579a
		*-*-* )
38579a
			ccenv_os=${ccenv_cchost#*-*-}
38579a
			;;
38579a
		*-* )
38579a
			ccenv_os=${ccenv_cchost#*-}
38579a
			;;
38579a
	esac
38579a
38579a
	if [ -z "$ccenv_os" ]; then
38579a
		ccenv_os='anyos'
38579a
	fi
82c35d
82c35d
	ccenv_attr_epilog "$ccenv_os"
38579a
}
38579a
38579a
ccenv_set_os_flags()
38579a
{
38579a
	case "$ccenv_os" in
38579a
		darwin )
38579a
			ccenv_cflags_os='-D_DARWIN_C_SOURCE'
38579a
			ccenv_cflags_pic='-fPIC'
38579a
			;;
38579a
		midipix )
38579a
			ccenv_cflags_os=
38579a
			ccenv_cflags_pic='-fPIC'
38579a
			;;
38579a
		cygwin )
38579a
			ccenv_cflags_os=
38579a
			ccenv_cflags_pic=
38579a
			;;
38579a
		msys | msys* | mingw | mingw* )
38579a
			ccenv_cflags_os='-U__STRICT_ANSI__'
38579a
			ccenv_cflags_pic=
38579a
			;;
38579a
		* )
38579a
			ccenv_cflags_os=
38579a
			ccenv_cflags_pic='-fPIC'
38579a
			;;
38579a
	esac
38579a
}
38579a
38579a
ccenv_set_os_semantics()
38579a
{
38579a
	# binary_format - core_api - ex_api - dependency_resolution
38579a
82c35d
	ccenv_attr_prolog 'os semantics'
82c35d
38579a
	case "$ccenv_os" in
38579a
		linux )
38579a
			ccenv_os_semantics='elf-posix-linux-ldso'
38579a
			;;
38579a
		bsd )
38579a
			ccenv_os_semantics='elf-posix-bsd-ldso'
38579a
			;;
38579a
		darwin )
38579a
			ccenv_os_semantics='macho-posix-osx-ldso'
38579a
			;;
38579a
		midipix )
38579a
			ccenv_os_semantics='pe-posix-winnt-ldso'
38579a
			;;
38579a
		cygwin )
38579a
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
38579a
			;;
38579a
		msys )
38579a
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
38579a
			;;
38579a
		mingw )
38579a
			ccenv_os_semantics='pe-win32-winnt-unsafe'
38579a
			;;
38579a
	esac
38579a
38579a
	if [ -n "$ccenv_os_semantics" ]; then
82c35d
		ccenv_attr_epilog "$ccenv_os_semantics"
38579a
		return 0
38579a
	fi
38579a
38579a
	if [ -n "$ccenv_cc_binfmt" ]; then
38579a
		ccenv_os_semantics_pattern='%s-posix-anyos-unknown'
38579a
		ccenv_os_semantics=$(printf                   \
38579a
				"$ccenv_os_semantics_pattern"  \
38579a
				"$ccenv_cc_binfmt"              \
38579a
			| tr '[:upper:]' '[:lower:]')
38579a
	else
38579a
		ccenv_os_semantics='unknown-posix-anyos-unknown'
38579a
	fi
82c35d
82c35d
	ccenv_attr_epilog "$ccenv_os_semantics"
38579a
}
38579a
1623fc
ccenv_set_os_dso_format()
1623fc
{
1623fc
	ccenv_attr_prolog 'os dso format'
1623fc
1623fc
	case "$ccenv_cc_arfmt" in
1623fc
		common )
1623fc
			ccenv_cc_sofmt="$ccenv_cc_binfmt"
1623fc
			;;
1623fc
1623fc
		bigaf )
1623fc
			ccenv_libgcc_s_a_header=$(od -b -N8             \
1623fc
				$($ccenv_cc -print-file-name=libgcc_s.a) \
1623fc
					2>/dev/null                       \
1623fc
					| head -n1)
1623fc
1623fc
			ccenv_libgcc_s_so_header=$(od -b -N8             \
1623fc
				$($ccenv_cc -print-file-name=libgcc_s.so) \
1623fc
					2>/dev/null                        \
1623fc
					| head -n1)
1623fc
1623fc
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_bigaf_header" ]; then
1623fc
				ccenv_cc_sofmt='bigaf'
1623fc
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_bigaf_header" ]; then
1623fc
				ccenv_cc_sofmt='bigaf'
1623fc
			else
1623fc
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
1623fc
			fi
1623fc
			;;
1623fc
1623fc
		aiaff )
1623fc
			ccenv_libgcc_s_a_header=$(od -b -N8               \
1623fc
				$($ccenv_cc -print-file-name=libgcc_s.a) \
1623fc
					| head -n1)
1623fc
1623fc
			ccenv_libgcc_s_so_header=$(od -b -N8               \
1623fc
				$($ccenv_cc -print-file-name=libgcc_s.so) \
1623fc
					| head -n1)
1623fc
1623fc
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_aiaff_header" ]; then
1623fc
				ccenv_cc_sofmt='aiaff'
1623fc
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_aiaff_header" ]; then
1623fc
				ccenv_cc_sofmt='aiaff'
1623fc
			else
1623fc
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
1623fc
			fi
1623fc
			;;
1623fc
	esac
1623fc
406216
	if [ "$ccenv_cfgtype" = 'host' ]; then
406216
		case "$ccenv_cc_sofmt" in
406216
			bigaf | aiaff )
406216
				mb_shared_lib_cmd='$(AR) -rcs'
406216
				mb_shared_lib_ldflags=
406216
				;;
406216
406216
			* )
406216
				mb_shared_lib_cmd='$(CC) -shared -o'
406216
				mb_shared_lib_ldflags='$(LDFLAGS_SHARED)'
406216
				;;
406216
		esac
406216
	fi
406216
1623fc
	ccenv_attr_epilog "$ccenv_cc_sofmt"
1623fc
}
1623fc
38579a
ccenv_set_os_dso_exrules()
38579a
{
82c35d
	ccenv_attr_prolog 'os dso exrules'
82c35d
38579a
	case "$ccenv_os" in
38579a
		midipix )
38579a
			ccenv_os_dso_exrules='pe-mdso'
38579a
			;;
38579a
		* )
38579a
			if [ "$ccenv_cc_binfmt" = 'PE' ]; then
38579a
				ccenv_os_dso_exrules='pe-dlltool'
38579a
			else
38579a
				ccenv_os_dso_exrules='default'
38579a
			fi
38579a
	esac
82c35d
82c35d
	ccenv_attr_epilog "$ccenv_os_dso_exrules"
38579a
}
38579a
38579a
ccenv_set_os_dso_linkage()
38579a
{
38579a
	# todo: PIC, PIE, and friends
82c35d
	ccenv_attr_prolog 'os linkage'
38579a
	ccenv_os_dso_linkage='default'
82c35d
	ccenv_attr_epilog "$ccenv_os_dso_linkage"
38579a
}
38579a
38579a
ccenv_set_os_dso_patterns_darwin()
38579a
{
38579a
	ccenv_os_app_prefix=
38579a
	ccenv_os_app_suffix=
38579a
38579a
	ccenv_os_lib_prefix=lib
38579a
	ccenv_os_lib_suffix=.dylib
38579a
38579a
	ccenv_os_implib_ext=.invalid
38579a
	ccenv_os_libdef_ext=.invalid
38579a
38579a
	ccenv_os_archive_ext=.a
38579a
	ccenv_os_soname=symlink
38579a
38579a
	ccenv_os_lib_prefixed_suffix=
38579a
	ccenv_os_lib_suffixed_suffix='$(OS_LIB_SUFFIX)'
38579a
}
38579a
38579a
ccenv_set_os_dso_patterns_mdso()
38579a
{
38579a
	ccenv_os_app_prefix=
38579a
	ccenv_os_app_suffix=
38579a
38579a
	ccenv_os_lib_prefix=lib
38579a
	ccenv_os_lib_suffix=.so
38579a
38579a
	ccenv_os_implib_ext=.lib.a
38579a
	ccenv_os_libdef_ext=.so.def
38579a
38579a
	ccenv_os_archive_ext=.a
38579a
	ccenv_os_soname=symlink
38579a
38579a
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
38579a
	ccenv_os_lib_suffixed_suffix=
38579a
}
38579a
38579a
ccenv_set_os_dso_patterns_dlltool()
38579a
{
38579a
	ccenv_os_app_prefix=
38579a
	ccenv_os_app_suffix=.exe
38579a
38579a
	ccenv_os_lib_prefix=lib
38579a
	ccenv_os_lib_suffix=.dll
38579a
38579a
	ccenv_os_implib_ext=.dll.a
38579a
	ccenv_os_libdef_ext=.def
38579a
38579a
	ccenv_os_archive_ext=.a
38579a
	ccenv_os_soname=copy
38579a
38579a
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
38579a
	ccenv_os_lib_suffixed_suffix=
38579a
}
38579a
38579a
ccenv_set_os_dso_patterns_default()
38579a
{
38579a
	ccenv_os_app_prefix=
38579a
	ccenv_os_app_suffix=
38579a
38579a
	ccenv_os_lib_prefix=lib
38579a
	ccenv_os_lib_suffix=.so
38579a
38579a
	ccenv_os_implib_ext=.invalid
38579a
	ccenv_os_libdef_ext=.invalid
38579a
38579a
	ccenv_os_archive_ext=.a
38579a
	ccenv_os_soname=symlink
38579a
38579a
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
38579a
	ccenv_os_lib_suffixed_suffix=
38579a
}
38579a
38579a
ccenv_set_os_dso_patterns()
38579a
{
38579a
	# sover: .so.x.y.z
38579a
	# verso: .x.y.z.so
38579a
38579a
	case "$ccenv_os" in
38579a
		darwin )
38579a
			ccenv_set_os_dso_patterns_darwin
38579a
			;;
38579a
		midipix )
38579a
			ccenv_set_os_dso_patterns_mdso
38579a
			;;
38579a
		cygwin | msys | mingw )
38579a
			ccenv_set_os_dso_patterns_dlltool
38579a
			;;
38579a
		* )
38579a
			ccenv_set_os_dso_patterns_default
38579a
			;;
38579a
	esac
38579a
}
38579a
38579a
ccenv_set_os_pe_switches()
38579a
{
38579a
	if [ "$ccenv_cc_binfmt" = 'PE' ] && [ -z "$ccenv_pe_subsystem" ]; then
38579a
		case "$ccenv_os" in
38579a
			midipix | mingw )
38579a
				ccenv_pe_subsystem='windows'
38579a
				;;
38579a
			* )
38579a
				ccenv_pe_subsystem='console'
38579a
				;;
38579a
		esac
38579a
	fi
b25d6e
b25d6e
	if [ "$ccenv_cc_binfmt" = 'PE' ]; then
b25d6e
		if ! cfgtest_macro_definition '__PE__'; then
b25d6e
			ccenv_cflags_os="${ccenv_cflags_os} -D__PE__"
b25d6e
		fi
b25d6e
b25d6e
		if ! cfgtest_macro_definition '__dllexport'; then
b25d6e
			ccenv_cflags_os="${ccenv_cflags_os} -D__dllexport=__attribute__\(\(__dllexport__\)\)"
b25d6e
		fi
b25d6e
b25d6e
		if ! cfgtest_macro_definition '__dllimport'; then
b25d6e
			ccenv_cflags_os="${ccenv_cflags_os} -D__dllimport=__attribute__\(\(__dllimport__\)\)"
b25d6e
		fi
b25d6e
	fi
38579a
}
38579a
38579a
ccenv_output_defs()
38579a
{
38579a
	ccenv_in="$mb_project_dir/sofort/ccenv/ccenv.in"
38579a
	ccenv_mk="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
38579a
	ccenv_tmp=
38579a
38579a
	if [ "$ccenv_cc_binfmt" = 'PE' ]; then
38579a
		ccenv_pe="$mb_project_dir/sofort/ccenv/pedefs.in"
38579a
		ccenv_in="$ccenv_in $ccenv_pe"
38579a
	fi
38579a
38579a
	if [ $ccenv_cfgtype = 'native' ]; then
38579a
38579a
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
38579a
ef749d
		sed                                      \
edebf7
				-e 's/^[[:space:]]*$/@/g' \
ef749d
				-e 's/^/NATIVE_/'          \
ef749d
				-e 's/NATIVE_@//g'          \
ef749d
				-e 's/NATIVE_#/#/g'          \
ef749d
				-e 's/       =/=/g'           \
ef749d
				-e 's/       +=/+=/g'          \
28d6e3
			$(printf '%s ' $ccenv_in)               \
28d6e3
				> "$ccenv_tmp"
38579a
38579a
		ccenv_in="$ccenv_tmp"
38579a
	else
38579a
		unset ccenv_tmp
38579a
	fi
38579a
738780
	ccenv_var_defs=
8c7382
	ccenv_sed_substs="-e s/@ccenv_cfgtype@/${ccenv_cfgtype}/g"
738780
38579a
	ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
738780
		| grep -v '^#');
38579a
8c7382
	ccenv_exvars="ccenv_makevar_prefix"
38579a
738780
	for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do
738780
		ccenv_sed_subst=$(printf '%s %s%s%s' \
738780
				'-e' "'s^@$__var@"    \
738780
				"^___${__var}___"      \
738780
				"^g'")
738780
738780
		ccenv_sed_substs="$ccenv_sed_substs $ccenv_sed_subst"
738780
738780
		ccenv_var_def=$(printf '%s%s="${%s}"' "-D" "___${__var}___" "${__var}")
738780
		eval ccenv_var_defs='"$ccenv_var_defs "$ccenv_var_def'
738780
	done
38579a
738780
	eval sed $ccenv_sed_substs $(printf '%s ' $ccenv_in) \
738780
			| eval m4 $ccenv_var_defs -           \
738780
			| sed -e 's/[[:blank:]]*$//g'          \
38579a
		> "$ccenv_mk"
38579a
38579a
	if [ "$ccenv_cfgtype" = 'host' ]; then
38579a
		for __var in $(printf '%s' "$ccenv_vars"); do
38579a
			ccenv_src_var=$__var
38579a
			ccenv_dst_var=mb_${__var#*ccenv_}
38579a
			ccenv_var_expr='${'$ccenv_src_var':-}'
38579a
			eval $ccenv_dst_var=$ccenv_var_expr
38579a
38579a
		done
38579a
38579a
		mb_host=$ccenv_host
38579a
		mb_cchost=$ccenv_cchost
38579a
	else
38579a
		for __var in $(printf '%s' "$ccenv_vars"); do
38579a
			ccenv_src_var=$__var
38579a
			ccenv_dst_var=mb_native_${__var#*ccenv_}
38579a
			ccenv_var_expr='${'$ccenv_src_var':-}'
38579a
			eval "$ccenv_dst_var=$ccenv_var_expr"
38579a
		done
38579a
38579a
		mb_native_host=$ccenv_host
38579a
		mb_native_cchost=$ccenv_cchost
38579a
	fi
38579a
38579a
	if [ -n "${ccenv_tmp:-}" ]; then
38579a
		rm -f "$ccenv_tmp"
38579a
		unset ccenv_tmp
38579a
	fi
9f259e
027376
027376
	if [ "${ccenv_cfgtype}" = 'host' ]; then
027376
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-host)
027376
		ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-host)
027376
	else
027376
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-native)
027376
		ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-native)
027376
	fi
027376
027376
	ccenv_cflags="${ccenv_cflags#*: }"
027376
	ccenv_ldflags="${ccenv_ldflags#*: }"
027376
c5a7c7
	ccenv_sysroot=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
c5a7c7
		-print-sysroot 2>/dev/null || true)
c5a7c7
027376
	eval 'ccenv_'${ccenv_cfgtype}'_cflags'=\'$ccenv_cflags\'
027376
	eval 'ccenv_'${ccenv_cfgtype}'_ldflags'=\'$ccenv_ldflags\'
c5a7c7
	eval 'ccenv_'${ccenv_cfgtype}'_sysroot'=\'$ccenv_sysroot\'
027376
9f259e
	eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\'
debca4
	eval 'ccenv_'${ccenv_cfgtype}'_cc_environment'=\'$ccenv_cc_environment\'
ff5932
	eval 'ccenv_'${ccenv_cfgtype}'_dumpmachine_switch'=\'$ccenv_dumpmachine_switch\'
bb2a35
	eval 'ccenv_'${ccenv_cfgtype}'_pkgconf'=\'$ccenv_pkgconf\'
027376
38579a
}
38579a
607c30
ccenv_set_cc_sysroot_vars()
607c30
{
607c30
	if [ "$ccenv_cfgtype" = 'native' ] || [ -z "$mb_sysroot" ]; then
607c30
		return 0
607c30
	fi
607c30
607c30
	cfgtest_host_section
607c30
	ccenv_switch_var="--sysroot=${mb_sysroot}"
607c30
607c30
	if cfgtest_compiler_switch_arg "${ccenv_switch_var}"; then
607c30
		printf '\n# %s sysroot: cflags and ldflags\n' "$ccenv_cfgtype" \
607c30
			>> "$ccenv_mk"
607c30
607c30
		for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do
607c30
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
607c30
				>> "$ccenv_mk"
607c30
		done
607c30
	else
607c30
		printf '\n# %s sysroot: cflags and ldflags %s\n' "$ccenv_cfgtype" \
607c30
			'(not supported: see config.log)'                          \
607c30
			>> "$ccenv_mk"
607c30
607c30
		for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do
607c30
			printf '%-40s=\n' "${ccenv_make_var}" \
607c30
				>> "$ccenv_mk"
607c30
		done
607c30
	fi
607c30
}
607c30
a15330
ccenv_set_cc_switch_vars()
a15330
{
d4b3a3
	printf '\n# %s cflags: supported compiler switches\n' "$ccenv_cfgtype" \
d4b3a3
		>> "$ccenv_mk"
d4b3a3
a15330
	if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
24e265
		ccenv_switch_vars=$(cat                            \
a15330
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
a15330
			$mb_project_dir/project/config/ccswitch.strs \
24e265
		| grep -v -e '^#' -e '^-Wl,'                          \
24e265
		| sort -u)
a15330
	else
c57f30
		ccenv_switch_vars=$(grep -v -e '^#' -e '^-Wl,'     \
a15330
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
a15330
			| sort -u)
a15330
	fi
a15330
a15330
	if [ $ccenv_cfgtype = 'host' ]; then
a15330
		ccenv_makevar_prefix='_CFLAGS_'
a15330
		cfgtest_host_section
a15330
	else
a15330
		ccenv_makevar_prefix='_NATIVE_CFLAGS_'
a15330
		cfgtest_native_section
a15330
	fi
a15330
a15330
	for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
a15330
		ccenv_make_var=${ccenv_switch_var%=}
a15330
		ccenv_make_var=${ccenv_make_var%,}
a15330
a15330
		ccenv_make_var=${ccenv_make_var##---}
a15330
		ccenv_make_var=${ccenv_make_var##--}
a15330
		ccenv_make_var=${ccenv_make_var##-}
a15330
a15330
		ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
a15330
			| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
a15330
a15330
		ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
a15330
a15330
		if cfgtest_compiler_switch "$ccenv_switch_var"; then
a15330
			ccenv_switch_var=${ccenv_switch_var%=}
a15330
			ccenv_switch_var=${ccenv_switch_var%,}
a15330
762c4f
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
a15330
				>> "$ccenv_mk"
a15330
		else
762c4f
			printf '%-40s=\n' "${ccenv_make_var}" \
a15330
				>> "$ccenv_mk"
a15330
		fi
a15330
	done
a15330
}
a15330
c57f30
ccenv_set_cc_linker_switch_vars()
c57f30
{
c57f30
	printf '\n# %s ldflags: supported compiler switches\n' "$ccenv_cfgtype" \
c57f30
		>> "$ccenv_mk"
c57f30
c57f30
	if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
24e265
		ccenv_switch_vars=$(cat                            \
c57f30
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
c57f30
			$mb_project_dir/project/config/ccswitch.strs \
24e265
			| grep -e '^-Wl,'                             \
c57f30
			| sort -u)
c57f30
	else
c57f30
		ccenv_switch_vars=$(grep -e '^-Wl,'                \
c57f30
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
c57f30
			| sort -u)
c57f30
	fi
c57f30
c57f30
	if [ $ccenv_cfgtype = 'host' ]; then
c57f30
		ccenv_makevar_prefix='_LDFLAGS_'
c57f30
		cfgtest_host_section
c57f30
	else
c57f30
		ccenv_makevar_prefix='_NATIVE_LDFLAGS_'
c57f30
		cfgtest_native_section
c57f30
	fi
c57f30
c57f30
	for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
c57f30
		ccenv_make_var=${ccenv_switch_var%=}
c57f30
		ccenv_make_var=${ccenv_make_var%,}
c57f30
c57f30
		ccenv_make_var=${ccenv_make_var##---}
c57f30
		ccenv_make_var=${ccenv_make_var##--}
c57f30
		ccenv_make_var=${ccenv_make_var##-}
c57f30
c57f30
		ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
c57f30
			| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
c57f30
c57f30
		ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
c57f30
c57f30
		if cfgtest_compiler_switch "$ccenv_switch_var"; then
c57f30
			ccenv_switch_var=${ccenv_switch_var%=}
c57f30
			ccenv_switch_var=${ccenv_switch_var%,}
c57f30
c57f30
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
c57f30
				>> "$ccenv_mk"
c57f30
		else
c57f30
			printf '%-40s=\n' "${ccenv_make_var}" \
c57f30
				>> "$ccenv_mk"
c57f30
		fi
c57f30
	done
c57f30
}
c57f30
3a0b3b
ccenv_set_cc_attr_visibility_vars()
3a0b3b
{
3a0b3b
	if cfgtest_attr_visibility 'default'; then
3a0b3b
		ccenv_attr_visibility_default="$mb_cfgtest_attr"
3a0b3b
	fi
3a0b3b
3a0b3b
	if cfgtest_attr_visibility 'hidden'; then
3a0b3b
		ccenv_attr_visibility_hidden="$mb_cfgtest_attr"
3a0b3b
	fi
3a0b3b
3a0b3b
	if cfgtest_attr_visibility 'internal'; then
3a0b3b
		ccenv_attr_visibility_internal="$mb_cfgtest_attr"
3a0b3b
	fi
3a0b3b
3a0b3b
	if cfgtest_attr_visibility 'protected'; then
3a0b3b
		ccenv_attr_visibility_protected="$mb_cfgtest_attr"
3a0b3b
	fi
3a0b3b
}
3a0b3b
38579a
ccenv_dso_verify()
38579a
{
38579a
	ccenv_str='int foo(int x){return ++x;}'
38579a
	ccenv_cmd="$ccenv_cc -xc - -shared -o a.out"
38579a
38579a
	rm -f a.out
38579a
72557f
	printf '%s' "$ccenv_str" | $(printf %s "$ccenv_cmd") \
ba10e0
		> /dev/null 2>&3              \
38579a
	|| mb_disable_shared=yes
38579a
38579a
	rm -f a.out
38579a
}
38579a
38579a
ccenv_clean_up()
38579a
{
38579a
	rm -f $ccenv_image
38579a
}
38579a
38579a
ccenv_common_init()
38579a
{
38579a
	. "$mb_project_dir/sofort/ccenv/ccenv.vars"
38579a
38579a
	ccenv_cfgtype=$1
38579a
	ccenv_cfgfile="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
38579a
	ccenv_cchost=
38579a
38579a
	if [ $ccenv_cfgtype = 'native' ]; then
38579a
		ccenv_makevar_prefix='NATIVE_'
38579a
		ccenv_image='./ccenv/native.a.out'
38579a
	else
38579a
		ccenv_makevar_prefix=
38579a
		ccenv_image='./ccenv/host.a.out'
38579a
	fi
38579a
38579a
	if [ $ccenv_cfgtype = 'native' ]; then
38579a
		ccenv_prefixes=
38579a
	elif [ -n "$mb_cross_compile" ]; then
38579a
		ccenv_prefixes="$mb_cross_compile"
38579a
	elif [ -n "$mb_host" ]; then
38579a
		ccenv_prefixes="$mb_host-"
38579a
	else
38579a
		ccenv_prefixes=
38579a
	fi
38579a
38579a
	if [ $ccenv_cfgtype = 'host' ]; then
38579a
		ccenv_tflags=
c86ef4
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
9a06ee
			OS_DSO_EXRULES=default                          \
9a06ee
			OS_SONAME=symlink                                \
443c84
			OS_ARCHIVE_EXT='.a'                               \
9a06ee
			.cflags-host)
12513b
c86ef4
		ccenv_cflags="${ccenv_cflags#*: }"
c86ef4
38579a
		ccenv_cc="$mb_user_cc"
38579a
		ccenv_cpp="$mb_user_cpp"
38579a
		ccenv_cxx="$mb_user_cxx"
38579a
38579a
		ccenv_pe_subsystem="$mb_pe_subsystem"
38579a
		ccenv_pe_image_base="$mb_pe_image_base"
38579a
	else
38579a
		ccenv_tflags=
c86ef4
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
9a06ee
			OS_DSO_EXRULES=default                          \
9a06ee
			OS_SONAME=symlink                                \
443c84
			OS_ARCHIVE_EXT='.a'                               \
9a06ee
			.cflags-native)
9a06ee
c86ef4
		ccenv_cflags="${ccenv_cflags#*: }"
c86ef4
38579a
		ccenv_cc="$mb_native_cc"
38579a
		ccenv_cpp="$mb_native_cpp"
38579a
		ccenv_cxx="$mb_native_cxx"
38579a
38579a
		ccenv_pe_subsystem="$mb_native_pe_subsystem"
38579a
		ccenv_pe_image_base="$mb_native_pe_image_base"
38579a
	fi
38579a
}
38579a
38579a
ccenv_set_characteristics()
38579a
{
38579a
	ccenv_set_cc_host
38579a
	ccenv_set_cc_bits
38579a
	ccenv_set_cc_binfmt
82c35d
	ccenv_set_cc_underscore
38579a
}
38579a
38579a
ccenv_set_toolchain_variables()
38579a
{
38579a
	ccenv_common_init $1
38579a
	ccenv_set_cc
38579a
	ccenv_set_cpp
38579a
	ccenv_set_cxx
38579a
	ccenv_set_primary_tools
38579a
	ccenv_set_tool_variants
38579a
	ccenv_set_characteristics
38579a
38579a
	ccenv_set_os
38579a
	ccenv_set_os_flags
38579a
	ccenv_set_os_semantics
1623fc
	ccenv_set_os_dso_format
38579a
	ccenv_set_os_dso_exrules
38579a
	ccenv_set_os_dso_linkage
38579a
	ccenv_set_os_dso_patterns
38579a
	ccenv_set_os_pe_switches
3a0b3b
	ccenv_set_cc_attr_visibility_vars
38579a
38579a
	ccenv_output_defs
38579a
	ccenv_clean_up
a15330
607c30
	ccenv_set_cc_sysroot_vars
a15330
	ccenv_set_cc_switch_vars
c57f30
	ccenv_set_cc_linker_switch_vars
38579a
}
38579a
38579a
ccenv_set_host_variables()
38579a
{
82c35d
	output_script_status ${mb_script} \
757c96
		'detect and query host (targeted) system'
82c35d
38579a
	ccenv_set_toolchain_variables 'host'
38579a
	ccenv_dso_verify
38579a
}
38579a
38579a
ccenv_set_native_variables()
38579a
{
82c35d
	output_script_status ${mb_script} \
757c96
		'detect and query native (local build) system'
82c35d
38579a
	if [ _$mb_ccenv_skip_native != _yes ]; then
38579a
		ccenv_set_toolchain_variables 'native'
38579a
	fi
38579a
}