Blame sofort/ccenv/ccenv.sh

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