Reicher82 / toolchain / sbmake

Forked from toolchain/sbmake 3 years ago
Clone

Blame sofort/ccenv/ccenv.sh

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