Blame sofort/ccenv/ccenv.sh

f979e6
f7f887
# ccenv.sh: sofort's tool-finding bits,
f7f887
# invoked from within the project-agnostic configure script.
f7f887
c88d44
# this file is covered by COPYING.SOFORT.
c88d44
f7f887
# invocation and names of binary tools:
f7f887
# agnostic names (ar, nm, objdump, ...);
f7f887
# target-prefixed agnostic names (x86_64-nt64-midipix-ar, ...);
f7f887
# branded names (llvm-ar, llvm-nm, llvm-objdump, ...);
f7f887
# target-prefixed branded names (x86_64-linux-gnu-gcc-ar, ...);
f7f887
# target-specifying branded tools (llvm-ar --target=x86_64-linux, ...).
f7f887
f7f887
# cross-compilation: default search order:
f7f887
# target-prefixed agnostic tools;
f7f887
# target-prefixed branded tools, starting with the prefix
f7f887
# most commonly associated with the selected compiler (that is,
f7f887
# ``gcc'' when using gcc, and ``llvm'' when using clang);
f7f887
# target-speficying branded tools, starting once again with the
f7f887
# prefix most commonly associated with the selected compiler.
f7f887
f7f887
# internal variables of interest:
f7f887
# ccenv_cfgtype: the type of host being tested (host/native)
f7f887
# ccenv_cfgfile: the configuration file for the host being tested
f7f887
# ccenv_cflags:  the comprehensive cflags for the host being tested
f7f887
# ccenv_cchost:  the host being tested, as reported by -dumpmachine
f7f887
f979e6
# variables available to cfgdefs.sh and cfgfini.sh:
f979e6
# ccenv_host_cflags:    expanded cflags, valid for the host compiler
f979e6
# ccenv_host_ldflags:   expanded ldflags, valid for the host compiler
9cbe7c
# ccenv_host_sysroot:   host sysroot, as reported by the host compiler
f979e6
# ccenv_native_cflags:  expanded cflags, valid for the native compiler
f979e6
# ccenv_native_ldflags: expanded ldflags, valid for the native compiler
9cbe7c
# ccenv_native_sysroot: native sysroot, as reported by the native compiler
f7f887
f7f887
ccenv_usage()
f7f887
{
f7f887
	cat "$mb_project_dir"/sofort/ccenv/ccenv.usage
f7f887
	exit 0
f7f887
}
f7f887
f7f887
f7f887
ccenv_newline()
f7f887
{
f7f887
	printf '\n' >> "$ccenv_cfgfile"
f7f887
}
f7f887
f7f887
f7f887
ccenv_comment()
f7f887
{
f7f887
	ccenv_internal_str='#'
f7f887
f7f887
	for ccenv_internal_arg ; do
f7f887
		ccenv_internal_str="$ccenv_internal_str $ccenv_internal_arg"
f7f887
	done
f7f887
f7f887
	printf '%s\n' "$ccenv_internal_str" >> "$ccenv_cfgfile"
f7f887
}
f7f887
f7f887
54797a
ccenv_tool_prolog()
54797a
{
f23bfe
	ccenv_line_dots='.....................................'
2f82db
	ccenv_tool_desc=" == checking for ${1}"
54797a
	ccenv_tool_dlen="${#ccenv_line_dots}"
54797a
a8f188
	printf '\n%s\n' '________________________' >&3
a8f188
	printf "ccenv: checking for ${1}\n\n" >&3
54797a
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s" \
f23bfe
		"${ccenv_tool_desc}  ${mb_line_dots}"
54797a
}
54797a
54797a
54797a
ccenv_tool_epilog()
54797a
{
54797a
	ccenv_line_dots='................................'
54797a
	ccenv_tool_dlen="$((${#ccenv_line_dots} - ${#1}))"
54797a
c04745
	case ${ccenv_tool_dlen} in
c04745
		0 | -* )
c04745
			ccenv_tool_dlen='3' ;;
c04745
	esac
c04745
f23bfe
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
54797a
		"${ccenv_line_dots}" "${1}"
a8f188
a8f188
	if [ "${1}" = 'false' ]; then
a8f188
		printf '\n\nccenv: not (yet) found.\n' >&3
a8f188
	else
a8f188
		printf "\n\nccenv : found $(command -v ${1}).\n" >&3
a8f188
	fi
a8f188
a8f188
	printf '%s\n' '------------------------' >&3
54797a
}
54797a
54797a
81eb66
ccenv_tool_variant_epilog()
81eb66
{
81eb66
	ccenv_expr=${1}='${'${1}':-false}'
81eb66
	eval "$ccenv_expr"
81eb66
81eb66
	ccenv_expr='${'${1}'}'
81eb66
	eval ccenv_tool_epilog "$ccenv_expr"
81eb66
}
81eb66
81eb66
54797a
ccenv_attr_prolog()
54797a
{
f23bfe
	ccenv_line_dots=' .....................................'
f23bfe
	ccenv_attr_desc=" == detect ${ccenv_cfgtype} ${1}"
54797a
	ccenv_attr_dlen="${#ccenv_line_dots}"
54797a
54797a
	printf "%${ccenv_attr_dlen}.${ccenv_attr_dlen}s" \
54797a
		"${ccenv_attr_desc} ${ccenv_line_dots}"
a8f188
a8f188
	printf '\n%s\n' '________________________' >&3
a8f188
	printf "ccenv: detecting ${1}\n\n" >&3
54797a
}
54797a
54797a
54797a
ccenv_attr_epilog()
54797a
{
a8f188
	ccenv_line_dots='................................'
f23bfe
	ccenv_tool_dlen="$((${#ccenv_line_dots} - 1 - ${#1}))"
a8f188
c04745
	case ${ccenv_tool_dlen} in
c04745
		0 | -* )
c04745
			ccenv_tool_dlen='3' ;;
c04745
	esac
c04745
f23bfe
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
a8f188
		"${ccenv_line_dots}" "${1}"
a8f188
a8f188
	printf '\n\nccenv: detected result: %s\n' "${1}" >&3
a8f188
	printf '%s\n' '------------------------' >&3
54797a
}
54797a
54797a
f7f887
ccenv_find_tool()
f7f887
{
f7f887
	if [ -z "$ccenv_prefixes" ]; then
7cf81c
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
100c12
			ccenv_cmd_args="${@:-}"
100c12
100c12
			if [ -z "$ccenv_cmd_args" ]; then
6c3c34
				if command -v "$ccenv_candidate" > /dev/null; then
6c3c34
					ccenv_tool="$ccenv_candidate"
1311bb
					return 0
a408d8
				fi
1311bb
			else
6c3c34
				if command -v "$ccenv_candidate" > /dev/null; then
a8f188
					if "$ccenv_candidate" $@ > /dev/null 2>&3; then
6c3c34
						ccenv_tool="$ccenv_candidate"
1311bb
						return 0
a408d8
					fi
a408d8
				fi
1311bb
			fi
f7f887
		done
f7f887
f7f887
		ccenv_tool=false
f7f887
f7f887
		return 0
f7f887
	fi
f7f887
7cf81c
	for ccenv_prefix in $(printf '%s' "$ccenv_prefixes"); do
7cf81c
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
f7f887
			ccenv_tool="$ccenv_prefix$ccenv_candidate"
a408d8
a408d8
			if command -v "$ccenv_tool" > /dev/null; then
a408d8
				return 0
a408d8
			fi
f7f887
		done
f7f887
	done
f7f887
7cf81c
	for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
6c3c34
		if command -v "$ccenv_candidate" > /dev/null; then
6c3c34
			ccenv_tool="$ccenv_candidate"
a408d8
			return 0
a408d8
		fi
f7f887
	done
f7f887
f7f887
	ccenv_tool=false
f7f887
f7f887
	return 0
f7f887
}
f7f887
f7f887
f7f887
ccenv_set_primary_tools()
f7f887
{
f7f887
	ccenv_core_tools="ar nm objdump ranlib size strip strings objcopy"
49f783
	ccenv_hack_tools="addr2line cov elfedit readelf readobj otool"
4ac9d2
	ccenv_peep_tools="perk mdso dlltool windmc windres pkgconf"
f7f887
7cf81c
	for __tool in $(printf '%s' "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do
54797a
		ccenv_tool_prolog "$__tool"
54797a
f7f887
		if [ -n "$mb_agnostic" ]; then
f7f887
			ccenv_candidates=" $__tool"
f7f887
f7f887
		elif [ -n "$mb_zealous" ]; then
f7f887
			ccenv_candidates="$mb_zealous-$__tool"
f7f887
f7f887
		elif [ "$mb_toolchain" = 'gcc' ]; then
f7f887
			ccenv_candidates="gcc-$__tool"
f7f887
			ccenv_candidates="$ccenv_candidates $__tool"
f7f887
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
f7f887
f7f887
		elif [ "$mb_toolchain" = 'llvm' ]; then
f7f887
			ccenv_candidates="llvm-$__tool"
f7f887
			ccenv_candidates="$ccenv_candidates $__tool"
f7f887
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
f7f887
f7f887
		elif [ -n "$mb_toolchain" ]; then
f7f887
			ccenv_candidates="$mb_toolchain-$__tool"
f7f887
			ccenv_candidates="$ccenv_candidates $__tool"
f7f887
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
f7f887
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
f7f887
296373
		elif [ "$__tool" = 'pkgconf' ]; then
296373
			ccenv_candidates="$__tool pkg-config"
296373
f7f887
		else
f7f887
			ccenv_candidates="$__tool"
f7f887
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
f7f887
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
f7f887
		fi
f7f887
f7f887
		if [ "$ccenv_cfgtype" = 'host' ]; then
f7f887
			ccenv_var_prefix='mb_'
f7f887
		else
f7f887
			ccenv_var_prefix='mb_native_'
f7f887
		fi
f7f887
dd82bf
		ccenv_tool=
f7f887
		ccenv_var_name=$ccenv_var_prefix$__tool
f7f887
		ccenv_var_expr='${'$ccenv_var_name':-}'
f7f887
		eval ccenv_var_val=$ccenv_var_expr
f7f887
f7f887
		if [ -n "$ccenv_var_val" ]; then
f7f887
			eval ccenv_$__tool="$ccenv_var_val"
dd82bf
			ccenv_tool="$ccenv_var_val"
f7f887
		else
f7f887
			ccenv_find_tool
f7f887
			eval ccenv_$__tool="$ccenv_tool"
f7f887
		fi
54797a
54797a
		ccenv_tool_epilog "$ccenv_tool"
f7f887
	done
f7f887
f7f887
	# windrc
f7f887
	ccenv_windrc="$ccenv_windres"
b176ca
b176ca
	# archive format preamble
63dba7
	if [ -n "$ccenv_dumpmachine_switch" ]; then
fe2e33
		ccenv_libgcc_path=$($ccenv_cc -print-file-name=libgcc.a \
fe2e33
			2>/dev/null)
fe2e33
fe2e33
		if [ -n "$ccenv_libgcc_path" ]; then
fe2e33
			ccenv_libgcc_a_header=$(od -b -N8             \
fe2e33
				$($ccenv_cc -print-file-name=libgcc.a) \
fe2e33
				| head -n1)
fe2e33
		else
fe2e33
			ccenv_libgcc_a_header=
fe2e33
		fi
63dba7
	else
63dba7
		ccenv_libgcc_a_header=
63dba7
	fi
63dba7
63dba7
	# ar (default)
b176ca
	ccenv_cc_arfmt='common'
b176ca
b176ca
	# ar (big)
b176ca
	ccenv_bigaf_header=$(printf '%s\n' '<bigaf>' | od -b | head -n1)
b176ca
b176ca
	if [ "$ccenv_libgcc_a_header" = "$ccenv_bigaf_header" ]; then
b176ca
		ccenv_cc_arfmt='bigaf'
b176ca
b176ca
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
b176ca
			ccenv_var_name=ccenv_$__tool
b176ca
			ccenv_var_expr='${'$ccenv_var_name':-}'
b176ca
			eval ccenv_var_val="$ccenv_var_expr"
b176ca
b176ca
			if [ "$ccenv_var_val" != false ]; then
b176ca
				ccenv_var_val="$ccenv_var_val -X64"
b176ca
				ccenv_var_expr='${ccenv_var_val:-}'
b176ca
				eval ccenv_$__tool="$ccenv_var_expr"
b176ca
			fi
b176ca
		done
b176ca
	fi
b176ca
b176ca
	# ar (small)
b176ca
	ccenv_aiaff_header=$(printf '%s\n' '<aiaff>' | od -b | head -n1)
b176ca
b176ca
	if [ "$ccenv_libgcc_a_header" = "$ccenv_aiaff_header" ]; then
b176ca
		ccenv_cc_arfmt='aiaff'
b176ca
b176ca
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
b176ca
			ccenv_var_name=ccenv_$__tool
b176ca
			ccenv_var_expr='${'$ccenv_var_name':-}'
b176ca
			eval ccenv_var_val="$ccenv_var_expr"
b176ca
b176ca
			if [ "$ccenv_var_val" != false ]; then
b176ca
				ccenv_var_val="$ccenv_var_val -X32"
b176ca
				ccenv_var_expr='${ccenv_var_val:-}'
b176ca
				eval ccenv_$__tool="$ccenv_var_expr"
b176ca
			fi
b176ca
		done
b176ca
	fi
f7f887
}
f7f887
f7f887
ccenv_set_tool_variants()
f7f887
{
f7f887
	# as (asm)
54797a
	ccenv_tool_prolog 'as (asm)'
f7f887
	ccenv_candidates=as
f7f887
	ccenv_find_tool
f7f887
f7f887
	if [ "$ccenv_tool" = false ]; then
f7f887
		ccenv_as_asm=
f7f887
	else
fd46ae
		$ccenv_tool --help 2>&1 | grep -i '.bc assembler' \
f7f887
		|| ccenv_as_asm="$ccenv_tool"
f7f887
	fi
f7f887
81eb66
	ccenv_tool_variant_epilog 'ccenv_as_asm'
54797a
f7f887
	# as (ll)
54797a
	ccenv_tool_prolog 'as (ll)'
f7f887
	ccenv_candidates=llvm-as
f7f887
	ccenv_find_tool
f7f887
f7f887
	if [ "$ccenv_tool" != false ]; then
f7f887
		ccenv_as_ll="$ccenv_tool"
f7f887
	fi
f7f887
81eb66
	ccenv_tool_variant_epilog 'ccenv_as_ll'
54797a
f7f887
	# as (mc)
54797a
	ccenv_tool_prolog 'as (mc)'
f7f887
	ccenv_candidates=llvm-mc
f7f887
	ccenv_find_tool
f7f887
f7f887
	if [ "$ccenv_tool" != false ]; then
f7f887
		ccenv_as_mc="$ccenv_tool"
f7f887
	fi
f7f887
81eb66
	ccenv_tool_variant_epilog 'ccenv_as_mc'
54797a
f7f887
	# ld (bfd)
54797a
	ccenv_tool_prolog 'ld (bfd)'
f7f887
	ccenv_candidates=ld.bfd
f7f887
	ccenv_find_tool
f7f887
f7f887
	if [ "$ccenv_tool" != false ]; then
f7f887
		ccenv_ld_bfd="$ccenv_tool"
f7f887
	fi
f7f887
81eb66
	ccenv_tool_variant_epilog 'ccenv_ld_bfd'
54797a
f7f887
	# ld (gold)
54797a
	ccenv_tool_prolog 'ld (gold)'
f7f887
	ccenv_candidates=ld.gold
f7f887
	ccenv_find_tool
f7f887
f7f887
	if [ "$ccenv_tool" != false ]; then
f7f887
		ccenv_ld_gold="$ccenv_tool"
f7f887
	fi
f7f887
81eb66
	ccenv_tool_variant_epilog 'ccenv_ld_gold'
54797a
f7f887
	# ld (lld)
54797a
	ccenv_tool_prolog 'ld (lld)'
f7f887
	ccenv_candidates=lld
f7f887
	ccenv_find_tool
f7f887
f7f887
	if [ "$ccenv_tool" != false ]; then
f7f887
		ccenv_ld_lld="$ccenv_tool"
f7f887
	fi
f7f887
81eb66
	ccenv_tool_variant_epilog 'ccenv_ld_lld'
54797a
f7f887
	# objdump (bfd)
54797a
	ccenv_tool_prolog 'objdump (bfd)'
f7f887
	ccenv_candidates=objdump
f7f887
	ccenv_find_tool
f7f887
8d221e
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
8d221e
		ccenv_objdump_bfd="$ccenv_tool"
8d221e
	fi
f7f887
81eb66
	ccenv_tool_variant_epilog 'ccenv_objdump_bfd'
54797a
f7f887
	# objdump (llvm)
54797a
	ccenv_tool_prolog 'objdump (llvm)'
f7f887
	ccenv_candidates=llvm-objdump
f7f887
	ccenv_find_tool
f7f887
8d221e
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
8d221e
		ccenv_objdump_llvm="$ccenv_tool"
8d221e
	fi
f7f887
81eb66
	ccenv_tool_variant_epilog 'ccenv_objdump_llvm'
54797a
f7f887
	# readelf (bfd)
54797a
	ccenv_tool_prolog 'readelf (bfd)'
f7f887
	ccenv_candidates=readelf
f7f887
	ccenv_find_tool
f7f887
8d221e
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
8d221e
		ccenv_readelf_bfd="$ccenv_tool"
8d221e
	fi
f7f887
81eb66
	ccenv_tool_variant_epilog 'ccenv_readelf_bfd'
54797a
f7f887
	# readelf (llvm)
54797a
	ccenv_tool_prolog 'readelf (llvm)'
f7f887
	ccenv_candidates=llvm-readelf
f7f887
	ccenv_find_tool
f7f887
8d221e
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
8d221e
		ccenv_readelf_llvm="$ccenv_tool"
8d221e
	fi
f7f887
81eb66
	ccenv_tool_variant_epilog 'ccenv_readelf_llvm'
54797a
f7f887
	# as
f7f887
	if [ -n "$ccenv_cc" ]; then
4f60bf
		ccenv_as='$('"$ccenv_makevar_prefix"'CC) -c -x assembler'
f7f887
	elif [ -n "$mb_agnostic" ]; then
f7f887
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
f7f887
	elif [ "$mb_zealous" = 'gcc' ]; then
f7f887
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
f7f887
	elif [ -n "$mb_zealous" = 'llvm' ]; then
f7f887
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
f7f887
	elif [ "$mb_toolchain" = 'gcc' ]; then
f7f887
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
f7f887
	elif [ "$mb_toolchain" = 'llvm' ]; then
f7f887
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
f7f887
	fi
f7f887
f7f887
	# ld
f7f887
	if [ -n "$ccenv_cc" ]; then
f7f887
		ccenv_ld='$('"$ccenv_makevar_prefix"'CC) -nostdlib -nostartfiles'
f7f887
	fi
f7f887
}
f7f887
f7f887
ccenv_set_c_compiler_candidates()
f7f887
{
f7f887
	if   [ -n "$mb_compiler" ]; then
f7f887
		ccenv_candidates="$mb_compiler"
f7f887
f7f887
	elif [ -n "$mb_agnostic" ]; then
f7f887
		ccenv_candidates="c99 c11 cc"
f7f887
f7f887
	elif [ "$mb_zealous" = 'gcc' ]; then
f7f887
		ccenv_candidates="gcc"
f7f887
f7f887
	elif [ "$mb_zealous" = 'llvm' ]; then
f7f887
		ccenv_candidates="clang"
f7f887
f7f887
	elif [ "$mb_toolchain" = 'gcc' ]; then
f7f887
		ccenv_candidates="gcc c99 c11 cc clang"
f7f887
f7f887
	elif [ "$mb_toolchain" = 'llvm' ]; then
f7f887
		ccenv_candidates="clang c99 c11 cc gcc"
f7f887
f7f887
	elif [ -n "$mb_toolchain" ]; then
f7f887
		ccenv_candidates="$mb_toolchain c99 c11 cc gcc clang"
f7f887
f7f887
	else
20855b
		ccenv_candidates="cc gcc clang c99 c11"
f7f887
	fi
f7f887
}
f7f887
f7f887
f7f887
ccenv_set_cc()
f7f887
{
54797a
	ccenv_tool_prolog 'C compiler'
54797a
f7f887
	if [ -z "$ccenv_cc" ]; then
f7f887
		ccenv_set_c_compiler_candidates
63dba7
		ccenv_find_tool
f7f887
		ccenv_cc="$ccenv_tool"
f7f887
	fi
f7f887
63dba7
f7f887
	if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
f7f887
		ccenv_cc="$mb_compiler"
f7f887
	fi
f7f887
63dba7
	ccenv_tool_epilog "$ccenv_cc"
63dba7
63dba7
63dba7
	if [ $ccenv_cfgtype = 'host' ]; then
63dba7
		ccenv_host_cc="$ccenv_cc"
63dba7
		cfgtest_host_section
63dba7
		ccenv_host_cc=
63dba7
	else
63dba7
		ccenv_native_cc="$ccenv_cc"
63dba7
		cfgtest_native_section
63dba7
		ccenv_native_cc=
63dba7
	fi
63dba7
2887fc
	cfgtest_silent='yes'
2887fc
63dba7
	if cfgtest_compiler_switch -dumpmachine ; then
63dba7
		ccenv_dumpmachine_switch='-dumpmachine'
63dba7
	else
63dba7
		ccenv_dumpmachine_switch=
63dba7
	fi
63dba7
268231
	if cfgtest_code_snippet_asm 'typedef int dummy;' ; then
268231
		eval ccenv_${ccenv_cfgtype}_stdin_input='yes'
268231
	else
268231
		eval ccenv_${ccenv_cfgtype}_stdin_input='no'
268231
	fi
268231
2887fc
	unset cfgtest_silent
2887fc
f7f887
	ccenv_cc_cmd="$ccenv_cc"
d7b673
	ccenv_errors=
f7f887
f7f887
	if [ "$ccenv_cfgtype" = 'native' ]; then
c16723
		ccenv_host=
c16723
326ed0
		if [ -n "$mb_native_host" ]; then
326ed0
			ccenv_host="$mb_native_host"
326ed0
326ed0
		elif [ -n "$ccenv_dumpmachine_switch" ]; then
63dba7
			ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
63dba7
				$ccenv_dumpmachine_switch 2>&3)
c16723
c16723
		elif command -v slibtool > /dev/null 2>&1; then
deb8a8
			ccenv=$(slibtool --dumpmachine 2>/dev/null || true)
c16723
		fi
c16723
c16723
		if [ -z "$ccenv_host" ]; then
326ed0
			ccenv_machine=$(uname -m 2>/dev/null)
326ed0
			ccenv_system=$(uname -s 2>/dev/null)
326ed0
326ed0
			ccenv_machine="${ccenv_machine:-unknown}"
326ed0
			ccenv_system="${ccenv_system:-anyos}"
326ed0
326ed0
			ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \
e03b33
				| tr '[[:upper:]]' '[[:lower:]]')
63dba7
		fi
63dba7
246bde
		ccenv_cchost=$ccenv_host
f7f887
		return 0
f7f887
	fi
f7f887
63dba7
f7f887
	if [ -n "$mb_cchost" ]; then
f7f887
		ccenv_host="$mb_cchost"
f7f887
	elif [ -n "$mb_host" ]; then
f7f887
		ccenv_host="$mb_host"
f7f887
	else
f7f887
		ccenv_host=
f7f887
	fi
f7f887
63dba7
	if [ -z "$ccenv_host" ] && [ -n "$ccenv_dumpmachine_switch" ]; then
63dba7
		ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
63dba7
			$ccenv_dumpmachine_switch 2>&3)
f7f887
		ccenv_cchost=$ccenv_host
63dba7
63dba7
	elif [ -z "$ccenv_host" ]; then
c16723
		# no -dumpmachine support and no --host argument implies native build
c16723
		if command -v slibtool > /dev/null 2>&1; then
deb8a8
			ccenv=$(slibtool --dumpmachine 2>/dev/null || true)
c16723
		fi
326ed0
c16723
		if [ -z "$ccenv_host" ]; then
c16723
			ccenv_machine=$(uname -m 2>/dev/null)
c16723
			ccenv_system=$(uname -s 2>/dev/null)
c16723
c16723
			ccenv_machine="${ccenv_machine:-unknown}"
c16723
			ccenv_system="${ccenv_system:-anyos}"
326ed0
c16723
			ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \
c16723
				| tr '[[:upper:]]' '[[:lower:]]')
c16723
		fi
326ed0
63dba7
		ccenv_cchost=$ccenv_host
63dba7
63dba7
	elif [ -n "$ccenv_dumpmachine_switch" ]; then
513f55
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
f7f887
		ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -"
f7f887
f7f887
		if [ -z "$mb_user_cc" ]; then
be3a8d
			$(printf %s "$ccenv_cmd") < /dev/null > /dev/null \
f7f887
				2>"$ccenv_tmp" || true
f7f887
f7f887
			ccenv_errors=$(cat "$ccenv_tmp")
f7f887
f7f887
			if [ -z "$ccenv_errors" ]; then
63dba7
				ccenv_tool_prolog 'C compiler for host'
f7f887
				ccenv_tflags="--target=$ccenv_host"
f7f887
				ccenv_cc="$ccenv_cc $ccenv_tflags"
63dba7
				ccenv_tool_epilog "$ccenv_cc"
a8f188
			else
a8f188
				printf '%s' "$ccenv_errors" >&3
f7f887
			fi
f7f887
		fi
f7f887
513f55
		rm -f "$ccenv_tmp"
513f55
		unset ccenv_tmp
513f55
63dba7
		ccenv_cchost=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
63dba7
			$ccenv_dumpmachine_switch 2>&3)
f7f887
	fi
f7f887
f0ad74
	if [ -z "$ccenv_dumpmachine_switch" ] && [ -n "$ccenv_host" ]; then
f0ad74
		ccenv_cchost="$ccenv_host"
f0ad74
f0ad74
	elif [ "$ccenv_cchost" != "$ccenv_host" ]; then
a8f188
		printf 'error!\n' >&2
f7f887
		printf 'ccenv:\n' >&2
f7f887
		printf 'ccenv: ccenv_host:   %s \n' $ccenv_host >&2
f7f887
		printf 'ccenv: ccenv_cchost: %s \n' $ccenv_cchost >&2
f7f887
f7f887
		if [ -z "$ccenv_tflags" ]; then
f7f887
			printf 'ccenv:\n' >&2
f7f887
			printf 'ccenv: ccenv_host and ccenv_cchost do not match, most likely because:\n' >&2
f7f887
			printf 'ccenv: (1) you explicitly set CC (or passed --compiler=...)\n' >&2
f7f887
			printf 'ccenv: (2) the selected compiler does not accept --target=...\n' >&2
f7f887
			printf 'ccenv: (3) the host reported by -dumpmachine differs from the one you requested.\n' >&2
f7f887
		fi
f7f887
f7f887
		if [ -n "$ccenv_errors" ]; then
f7f887
			printf 'ccenv:\n' >&2
f7f887
			printf 'ccenv: something went wrong, see the command and compiler message below.\n\n' >&2
f7f887
			printf 'cmd: %s < /dev/null > /dev/null\n' "$ccenv_cmd" >&2
f7f887
			printf '%s\n\n' "$ccenv_errors" >&2
f7f887
		else
f7f887
			printf 'ccenv:\n' >&2
f7f887
			printf 'ccenv: something went wrong, bailing out.\n\n' >&2
f7f887
		fi
f7f887
f7f887
		return 2
f7f887
	fi
f7f887
}
f7f887
f7f887
ccenv_set_cpp()
f7f887
{
54797a
	ccenv_tool_prolog 'C pre-processor'
54797a
f7f887
	case "$ccenv_cc_cmd" in
f7f887
		cc | c99 | c11 | gcc)
f7f887
			ccenv_cpp_prefix=
f7f887
			ccenv_candidates="cpp" ;;
f7f887
f7f887
		clang )
f7f887
			ccenv_cpp_prefix=
f7f887
			ccenv_candidates="clang-cpp" ;;
f7f887
f7f887
		*-cc )
f7f887
			ccenv_cpp_prefix=${ccenv_cc_cmd%-cc*}-
f7f887
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
f7f887
f7f887
		*-c99 )
f7f887
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c99*}-
f7f887
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
f7f887
f7f887
		*-c11 )
f7f887
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c11*}-
f7f887
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
f7f887
f7f887
		*-gcc )
f7f887
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
f7f887
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
f7f887
f7f887
		*-clang )
f7f887
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
f7f887
			ccenv_candidates="${ccenv_cpp_prefix}clang-cpp" ;;
f7f887
f7f887
		* )
f7f887
			ccenv_cpp="$ccenv_cc -E"
54797a
			ccenv_tool_epilog "$ccenv_cpp"
f7f887
			return 0
f7f887
	esac
f7f887
f7f887
	ccenv_find_tool
f7f887
f7f887
	if [ "$ccenv_tool" = false ]; then
f7f887
		ccenv_cpp="$ccenv_cc -E"
f7f887
	elif [ -n "$ccenv_tflags" ]; then
f7f887
		ccenv_cpp="$ccenv_tool $ccenv_tflags"
f7f887
	else
f7f887
		ccenv_cpp="$ccenv_tool"
f7f887
	fi
54797a
54797a
	ccenv_tool_epilog "$ccenv_cpp"
f7f887
}
f7f887
f7f887
ccenv_set_cxx()
f7f887
{
54797a
	ccenv_tool_prolog 'C++ compiler'
54797a
f7f887
	case "$ccenv_cc_cmd" in
f7f887
		cc | c99 | c11 )
f7f887
			ccenv_cxx_prefix=
f7f887
			ccenv_candidates="cxx c++" ;;
f7f887
f7f887
		gcc )
f7f887
			ccenv_cxx_prefix=
f7f887
			ccenv_candidates="g++" ;;
f7f887
f7f887
		clang )
f7f887
			ccenv_cxx_prefix=
f7f887
			ccenv_candidates="clang++" ;;
f7f887
f7f887
		*-gcc )
b0cc9e
			ccenv_cxx_prefix=${ccenv_cc_cmd%-gcc*}-
b0cc9e
			ccenv_candidates="${ccenv_cxx_prefix}g++" ;;
f7f887
f7f887
		*-clang )
b0cc9e
			ccenv_cxx_prefix=${ccenv_cc_cmd%-clang*}-
b0cc9e
			ccenv_candidates="${ccenv_cxx_prefix}clang++" ;;
b0cc9e
b0cc9e
		/*cc | /*c99 | /*c11 )
b0cc9e
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
b0cc9e
			ccenv_candidates="${ccenv_cxx_prefix}/cxx"
b0cc9e
			ccenv_candidates="${ccenv_candidates} ${ccenv_cxx_prefix}/c++" ;;
b0cc9e
b0cc9e
		/*gcc )
b0cc9e
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
b0cc9e
			ccenv_candidates="${ccenv_cxx_prefix}/g++" ;;
f7f887
b0cc9e
		/*clang )
b0cc9e
			ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
b0cc9e
			ccenv_candidates="${ccenv_cxx_prefix}/clang++" ;;
f7f887
f7f887
		* )
f7f887
			ccenv_cxx="$ccenv_cc -xc++"
54797a
			ccenv_tool_epilog "$ccenv_cxx"
f7f887
			return 0
f7f887
	esac
f7f887
f7f887
	ccenv_find_tool
f7f887
f7f887
	if [ "$ccenv_tool" = false ]; then
f7f887
		ccenv_cxx="$ccenv_cc -xc++"
f7f887
	elif [ -n "$ccenv_tflags" ]; then
f7f887
		ccenv_cxx="$ccenv_tool $ccenv_tflags"
f7f887
	else
f7f887
		ccenv_cxx="$ccenv_tool"
f7f887
	fi
54797a
54797a
	ccenv_tool_epilog "$ccenv_cxx"
f7f887
}
f7f887
f7f887
ccenv_set_cc_host()
f7f887
{
a8acaf
	ccenv_attr_prolog 'system'
f7f887
	ccenv_cc_host="$ccenv_cchost"
54797a
	ccenv_attr_epilog "$ccenv_cc_host"
f7f887
}
f7f887
f7f887
ccenv_set_cc_bits()
f7f887
{
54797a
	ccenv_attr_prolog 'bits'
54797a
f7f887
	ccenv_internal_size=
f7f887
	ccenv_internal_type='void *'
f7f887
	ccenv_internal_test='char x[(sizeof(%s) == %s/8) ? 1 : -1];'
f7f887
f7f887
	for ccenv_internal_guess in 64 32 128; do
24912d
		if [ -z "${ccenv_internal_size:-}" ]; then
2f64c9
			ccenv_internal_str=$(printf "$ccenv_internal_test"  \
2f64c9
				"$ccenv_internal_type"                      \
f7f887
				"$ccenv_internal_guess")
f7f887
95edcc
			ccenv_expr='ccenv_stdin_input=$ccenv_'${ccenv_cfgtype}'_stdin_input'
95edcc
			eval ${ccenv_expr}
95edcc
95edcc
			if [ "$ccenv_stdin_input" = 'yes' ]; then
282784
				printf '%s' "$ccenv_internal_str"                   \
282784
						| eval $ccenv_cc -S -xc - -o -      \
282784
						  $(printf '%s' "$ccenv_cflags")    \
282784
					> /dev/null 2>&3                            \
282784
				&& ccenv_internal_size=$ccenv_internal_guess
282784
			else
282784
				ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
282784
282784
				printf '%s' "$ccenv_internal_str" \
282784
					> "$ccenv_tmpname"
282784
282784
				$ccenv_cc -c "$ccenv_tmpname" -o a.out \
282784
					> /dev/null 2>&3                \
282784
				&& ccenv_internal_size=$ccenv_internal_guess
282784
282784
				rm "$ccenv_tmpname"
282784
			fi
f7f887
		fi
f7f887
	done
f7f887
f7f887
	ccenv_cc_bits=$ccenv_internal_size
54797a
54797a
	ccenv_attr_epilog "$ccenv_cc_bits"
f7f887
}
f7f887
f7f887
ccenv_set_cc_underscore()
f7f887
{
54797a
	ccenv_attr_prolog 'prepended underscores'
54797a
f7f887
	ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe'
f7f887
	ccenv_fn_code='int %s(void){return 0;}'
f7f887
d6df7b
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
d6df7b
d6df7b
	printf "$ccenv_fn_code" $ccenv_fn_name \
d6df7b
		> "$ccenv_tmpname"
d6df7b
d6df7b
	$ccenv_cc -c "$ccenv_tmpname" -o a.out \
d6df7b
		> /dev/null 2>&3
d6df7b
d6df7b
	if "$ccenv_nm" a.out | grep          \
d6df7b
			-e "^_$ccenv_fn_name" \
d6df7b
			-e " _$ccenv_fn_name"  \
d6df7b
			> /dev/null; then
8d221e
		ccenv_cc_underscore='_'
54797a
		ccenv_attr_epilog 'yes'
d6df7b
	else
d6df7b
		ccenv_attr_epilog 'no'
8d221e
	fi
f7f887
d6df7b
	rm "$ccenv_tmpname"
d6df7b
	rm a.out
54797a
f7f887
	return 0
f7f887
}
f7f887
f7f887
ccenv_create_framework_executable()
f7f887
{
f8afdb
	if [ "$ccenv_cfgtype" = 'host' ]; then
f8afdb
		if [ "$mb_freestanding" = 'yes' ]; then
f8afdb
			return 1
f8afdb
		fi
f8afdb
	fi
f8afdb
f7f887
	if [ -f $ccenv_image ]; then
f7f887
		mv $ccenv_image $ccenv_image.tmp
f7f887
		rm -f $ccenv_image.tmp
f7f887
	fi
f7f887
825dbe
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
825dbe
f7f887
	printf 'int main(void){return 0;}'  \
825dbe
		> "$ccenv_tmpname"
f7f887
825dbe
	if $ccenv_cc "$ccenv_tmpname" -o $ccenv_image 2>&3; then
825dbe
		ccenv_ret=0
f8afdb
		ccenv_cc_environment='hosted'
825dbe
	else
825dbe
		ccenv_ret=1
825dbe
	fi
825dbe
825dbe
	rm "$ccenv_tmpname"
825dbe
825dbe
	return $ccenv_ret
f7f887
}
f7f887
f7f887
ccenv_create_freestanding_executable()
f7f887
{
f7f887
	if [ -f $ccenv_image ]; then
f7f887
		mv $ccenv_image $ccenv_image.tmp
f7f887
		rm -f $ccenv_image.tmp
f7f887
	fi
f7f887
f7f887
	if [ -z "ccenv_cc_underscore" ]; then
f7f887
		ccenv_start_fn='_start'
f7f887
	else
f7f887
		ccenv_start_fn='start'
f7f887
	fi
f7f887
825dbe
	ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
f7f887
825dbe
	printf 'int %s(void){return 0;}' "$ccenv_start_fn" \
825dbe
		> "$ccenv_tmpname"
f7f887
825dbe
	if $ccenv_cc "$ccenv_tmpname"         \
825dbe
			-ffreestanding         \
825dbe
			-nostdlib -nostartfiles \
825dbe
			-o $ccenv_image          \
825dbe
			2>&3; then
825dbe
		ccenv_ret=0
f8afdb
		ccenv_cc_environment='freestanding'
825dbe
	else
825dbe
		ccenv_ret=1
825dbe
	fi
825dbe
825dbe
	rm "$ccenv_tmpname"
825dbe
825dbe
	return $ccenv_ret
f7f887
}
f7f887
54797a
ccenv_set_cc_binfmt_error()
54797a
{
54797a
	ccenv_attr_epilog '(unable to create executable)'
54797a
}
54797a
f7f887
ccenv_set_cc_binfmt()
f7f887
{
f7f887
	ccenv_use_perk=
49f783
	ccenv_use_otool=
f7f887
	ccenv_use_readelf=
f7f887
	ccenv_use_readobj=
f7f887
	ccenv_use_bfd_objdump=
f7f887
	ccenv_use_llvm_objdump=
f7f887
54797a
	ccenv_attr_prolog 'binary format'
54797a
f7f887
	ccenv_create_framework_executable               \
f7f887
		|| ccenv_create_freestanding_executable \
54797a
		|| ccenv_set_cc_binfmt_error            \
f7f887
		|| return 0
f7f887
f7f887
	# PE / perk
f7f887
	if [ -n "$ccenv_perk" ]; then
a8f188
		if $ccenv_perk $ccenv_image 2>&3; then
8d221e
			ccenv_cc_binfmt='PE'
8d221e
			ccenv_use_perk=yes
8d221e
		fi
f7f887
	fi
f7f887
f7f887
	# ELF / readelf
f7f887
	if [ -n "$ccenv_readelf" ] && [ -z "$ccenv_cc_binfmt" ]; then
a8f188
		if $ccenv_readelf -h $ccenv_image 2>&3               \
8d221e
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
8d221e
				| grep 'Magic:7f454c46'              \
8d221e
					> /dev/null; then
8d221e
			ccenv_cc_binfmt='ELF'
8d221e
			ccenv_use_readelf=yes
8d221e
		fi
f7f887
	fi
f7f887
f7f887
	# a marble of astonishing design:
f7f887
	# llvm-readelf also parses PE and Mach-O
f7f887
f7f887
	if [ -n "$ccenv_readelf_llvm" ]; then
f7f887
		ccenv_readany="$ccenv_readelf_llvm"
f7f887
	else
f7f887
		ccenv_readany="$ccenv_readelf"
f7f887
	fi
f7f887
f7f887
	# PE / readelf
f7f887
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
a8f188
		if $ccenv_readany -h $ccenv_image 2>&3               \
8d221e
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
8d221e
				| grep 'Magic:MZ'                    \
8d221e
					> /dev/null; then
8d221e
			ccenv_cc_binfmt='PE'
8d221e
			ccenv_use_readelf=yes
8d221e
		fi
f7f887
	fi
f7f887
49f783
	# MACHO-64 / otool
49f783
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
a8f188
		if $ccenv_otool -hv $ccenv_image 2>&3        \
8d221e
				| grep -i 'MH_MAGIC_64'      \
8d221e
					> /dev/null; then
8d221e
			ccenv_cc_binfmt='MACHO'
8d221e
			ccenv_use_otool=yes
8d221e
		fi
49f783
	fi
49f783
49f783
	# MACHO-32 / otool
49f783
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
a8f188
		if $ccenv_otool -hv $ccenv_image 2>&3        \
8d221e
				| grep -i 'MH_MAGIC'         \
8d221e
					> /dev/null; then
8d221e
			ccenv_cc_binfmt='MACHO'
8d221e
			ccenv_use_otool=yes
8d221e
		fi
49f783
	fi
49f783
f7f887
	# MACHO-64 / readelf
f7f887
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
a8f188
		if $ccenv_readany -h $ccenv_image 2>&3                    \
8d221e
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
8d221e
				| grep -i '(0xfeedfacf)'                  \
8d221e
					> /dev/null; then
8d221e
			ccenv_cc_binfmt='MACHO'
8d221e
			ccenv_use_readelf=yes
8d221e
		fi
f7f887
	fi
f7f887
f7f887
	# MACHO-32 / readelf
f7f887
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
a8f188
		if $ccenv_readany -h $ccenv_image 2>&3                    \
8d221e
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
8d221e
				| grep -i '(0xcafebabe)'                  \
8d221e
					> /dev/null; then
8d221e
			ccenv_cc_binfmt='MACHO'
8d221e
			ccenv_use_readelf=yes
8d221e
		fi
f7f887
	fi
f7f887
f7f887
	# MACHO / readobj
f7f887
	if [ -n "$ccenv_readobj" ] && [ -z "$ccenv_cc_binfmt" ]; then
a8f188
		if $ccenv_readobj $ccenv_image 2>&3                  \
6ea214
				| grep -i 'Format:'                  \
6ea214
				| sed  -e 's/ /_/g'                  \
8d221e
				| grep -i '_Mach-O_'                 \
8d221e
					> /dev/null; then
8d221e
			ccenv_cc_binfmt='MACHO'
8d221e
			ccenv_use_readobj=yes
8d221e
		fi
f7f887
	fi
f7f887
f7f887
	# MACHO / objdump (llvm)
f7f887
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
8d221e
		if $ccenv_objdump -section-headers $ccenv_image  \
a8f188
					2>&3                     \
8d221e
				| grep -i 'file format Mach-O'   \
8d221e
					> /dev/null; then
8d221e
			ccenv_cc_binfmt='MACHO'
8d221e
			ccenv_use_objdump=yes
8d221e
		fi
f7f887
	fi
f7f887
f7f887
	# MACHO / objdump (bfd)
f7f887
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
a8f188
		$ccenv_objdump -h  $ccenv_image 2>&3              \
f7f887
			| grep -i 'file format Mach-O'            \
f7f887
				> /dev/null                       \
f7f887
		&& ccenv_cc_binfmt='MACHO'                        \
f7f887
		&& ccenv_use_objdump=yes
f7f887
	fi
f7f887
f7f887
	# PE / objdump (bfd)
f7f887
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
a8f188
		if $ccenv_objdump -h  $ccenv_image 2>&3        \
8d221e
				| grep -i 'file format pei-'   \
8d221e
					> /dev/null; then
8d221e
			ccenv_cc_binfmt='PE'
8d221e
			ccenv_use_bfd_objdump=yes
8d221e
		fi
f7f887
	fi
54797a
54797a
	ccenv_attr_epilog "$ccenv_cc_binfmt"
f7f887
}
f7f887
f7f887
ccenv_set_os_pe()
f7f887
{
f8afdb
	if [ "$ccenv_cc_environment" = 'freestanding' ]; then
f7f887
		case "$ccenv_cchost" in
f7f887
			*-midipix | *-midipix-* )
f7f887
				ccenv_os='midipix' ;;
f7f887
			*-mingw | *-mingw32 | *-mingw64 )
f7f887
				ccenv_os='mingw' ;;
f7f887
			*-mingw-* | *-mingw32-* | *-mingw64 )
f7f887
				ccenv_os='mingw' ;;
f7f887
			*-msys | *-msys2 | *-msys-* | *-msys2-* )
f7f887
				ccenv_os='msys' ;;
f7f887
			*-cygwin | *-cygwin-* )
f7f887
				ccenv_os='cygwin' ;;
f7f887
		esac
f7f887
	fi
f7f887
f7f887
	if [ -n "$ccenv_os" ]; then
f7f887
		return 0
f7f887
	fi
f7f887
f7f887
	if [ -n "$ccenv_use_perk" ]; then
f7f887
		ccenv_framework=$($ccenv_perk -y $ccenv_image)
f7f887
		ccenv_os=${ccenv_framework#*-*-*-*}
f7f887
	fi
f7f887
f7f887
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
f7f887
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
f7f887
			| grep 'cygwin1.dll' > /dev/null                \
f7f887
		&& ccenv_os='cygwin'
f7f887
	fi
f7f887
f7f887
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
f7f887
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
f7f887
			| grep 'msys-2.0.dll' > /dev/null               \
f7f887
		&& ccenv_os='msys'
f7f887
	fi
f7f887
f7f887
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
f7f887
		$ccenv_objdump_bfd -x $ccenv_image          \
f7f887
			| grep -i 'DLL Name' | grep '.CRT'  \
f7f887
				> /dev/null                 \
f7f887
		&& $ccenv_objdump_bfd -x $ccenv_image       \
f7f887
			| grep -i 'DLL Name' | grep '.bss'  \
f7f887
				> /dev/null                 \
f7f887
		&& $ccenv_objdump_bfd -x $ccenv_image       \
f7f887
			| grep -i 'DLL Name' | grep '.tls'  \
f7f887
				> /dev/null                 \
f7f887
		&& ccenv_os='mingw'
f7f887
	fi
f7f887
}
f7f887
f7f887
ccenv_set_os_macho()
f7f887
{
f7f887
	case "$ccenv_cchost" in
f7f887
		*-apple-darwin* )
f7f887
			ccenv_os='darwin' ;;
f7f887
	esac
f7f887
}
f7f887
f7f887
ccenv_set_os()
f7f887
{
54797a
	ccenv_attr_prolog 'os name'
54797a
f7f887
	case "$ccenv_cc_binfmt" in
f7f887
		PE )
f7f887
			ccenv_set_os_pe ;;
f7f887
		MACHO )
f7f887
			ccenv_set_os_macho ;;
f7f887
	esac
f7f887
f7f887
	if [ -n "$ccenv_os" ]; then
54797a
		ccenv_attr_epilog "$ccenv_os"
f7f887
		return 0
f7f887
	fi
f7f887
f7f887
	case "$ccenv_cchost" in
185910
		*-*-musl | *-*-gnu )
185910
			ccenv_tip=${ccenv_cchost%-*}
f7f887
			ccenv_os=${ccenv_tip#*-}
f7f887
			;;
5776a8
		*-*-solaris* )
5776a8
			ccenv_os='solaris'
5776a8
			;;
1c2246
		*-*-*bsd* | *-*-dragonfly* )
1c2246
			ccenv_os='bsd'
1c2246
			;;
1c2246
		*-*-*-* )
1c2246
			ccenv_tip=${ccenv_cchost%-*}
1c2246
			ccenv_os=${ccenv_tip#*-*-}
1c2246
			;;
185910
		*-*-* )
185910
			ccenv_os=${ccenv_cchost#*-*-}
185910
			;;
185910
		*-* )
185910
			ccenv_os=${ccenv_cchost#*-}
185910
			;;
f7f887
	esac
f7f887
f7f887
	if [ -z "$ccenv_os" ]; then
f7f887
		ccenv_os='anyos'
f7f887
	fi
54797a
54797a
	ccenv_attr_epilog "$ccenv_os"
f7f887
}
f7f887
f7f887
ccenv_set_os_flags()
f7f887
{
f7f887
	case "$ccenv_os" in
f7f887
		darwin )
f7f887
			ccenv_cflags_os='-D_DARWIN_C_SOURCE'
f7f887
			ccenv_cflags_pic='-fPIC'
f7f887
			;;
f7f887
		midipix )
f7f887
			ccenv_cflags_os=
f7f887
			ccenv_cflags_pic='-fPIC'
f7f887
			;;
f7f887
		cygwin )
f7f887
			ccenv_cflags_os=
f7f887
			ccenv_cflags_pic=
f7f887
			;;
f7f887
		msys | msys* | mingw | mingw* )
f7f887
			ccenv_cflags_os='-U__STRICT_ANSI__'
f7f887
			ccenv_cflags_pic=
f7f887
			;;
f7f887
		* )
f7f887
			ccenv_cflags_os=
f7f887
			ccenv_cflags_pic='-fPIC'
f7f887
			;;
f7f887
	esac
f7f887
}
f7f887
f7f887
ccenv_set_os_semantics()
f7f887
{
f7f887
	# binary_format - core_api - ex_api - dependency_resolution
f7f887
54797a
	ccenv_attr_prolog 'os semantics'
54797a
f7f887
	case "$ccenv_os" in
f7f887
		linux )
f7f887
			ccenv_os_semantics='elf-posix-linux-ldso'
f7f887
			;;
f7f887
		bsd )
f7f887
			ccenv_os_semantics='elf-posix-bsd-ldso'
f7f887
			;;
f7f887
		darwin )
f7f887
			ccenv_os_semantics='macho-posix-osx-ldso'
f7f887
			;;
f7f887
		midipix )
f7f887
			ccenv_os_semantics='pe-posix-winnt-ldso'
f7f887
			;;
f7f887
		cygwin )
f7f887
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
f7f887
			;;
f7f887
		msys )
f7f887
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
f7f887
			;;
f7f887
		mingw )
f7f887
			ccenv_os_semantics='pe-win32-winnt-unsafe'
f7f887
			;;
f7f887
	esac
f7f887
f7f887
	if [ -n "$ccenv_os_semantics" ]; then
54797a
		ccenv_attr_epilog "$ccenv_os_semantics"
f7f887
		return 0
f7f887
	fi
f7f887
f7f887
	if [ -n "$ccenv_cc_binfmt" ]; then
f7f887
		ccenv_os_semantics_pattern='%s-posix-anyos-unknown'
f7f887
		ccenv_os_semantics=$(printf                   \
f7f887
				"$ccenv_os_semantics_pattern"  \
f7f887
				"$ccenv_cc_binfmt"              \
f7f887
			| tr '[:upper:]' '[:lower:]')
f7f887
	else
f7f887
		ccenv_os_semantics='unknown-posix-anyos-unknown'
f7f887
	fi
54797a
54797a
	ccenv_attr_epilog "$ccenv_os_semantics"
f7f887
}
f7f887
c425d2
ccenv_set_os_dso_format()
c425d2
{
c425d2
	ccenv_attr_prolog 'os dso format'
c425d2
c425d2
	case "$ccenv_cc_arfmt" in
c425d2
		common )
c425d2
			ccenv_cc_sofmt="$ccenv_cc_binfmt"
c425d2
			;;
c425d2
c425d2
		bigaf )
c425d2
			ccenv_libgcc_s_a_header=$(od -b -N8             \
c425d2
				$($ccenv_cc -print-file-name=libgcc_s.a) \
c425d2
					2>/dev/null                       \
c425d2
					| head -n1)
c425d2
c425d2
			ccenv_libgcc_s_so_header=$(od -b -N8             \
c425d2
				$($ccenv_cc -print-file-name=libgcc_s.so) \
c425d2
					2>/dev/null                        \
c425d2
					| head -n1)
c425d2
c425d2
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_bigaf_header" ]; then
c425d2
				ccenv_cc_sofmt='bigaf'
c425d2
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_bigaf_header" ]; then
c425d2
				ccenv_cc_sofmt='bigaf'
c425d2
			else
c425d2
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
c425d2
			fi
c425d2
			;;
c425d2
c425d2
		aiaff )
c425d2
			ccenv_libgcc_s_a_header=$(od -b -N8               \
c425d2
				$($ccenv_cc -print-file-name=libgcc_s.a) \
c425d2
					| head -n1)
c425d2
c425d2
			ccenv_libgcc_s_so_header=$(od -b -N8               \
c425d2
				$($ccenv_cc -print-file-name=libgcc_s.so) \
c425d2
					| head -n1)
c425d2
c425d2
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_aiaff_header" ]; then
c425d2
				ccenv_cc_sofmt='aiaff'
c425d2
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_aiaff_header" ]; then
c425d2
				ccenv_cc_sofmt='aiaff'
c425d2
			else
c425d2
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
c425d2
			fi
c425d2
			;;
c425d2
	esac
c425d2
139454
	if [ "$ccenv_cfgtype" = 'host' ]; then
139454
		case "$ccenv_cc_sofmt" in
139454
			bigaf | aiaff )
139454
				mb_shared_lib_cmd='$(AR) -rcs'
139454
				mb_shared_lib_ldflags=
139454
				;;
139454
139454
			* )
139454
				mb_shared_lib_cmd='$(CC) -shared -o'
139454
				mb_shared_lib_ldflags='$(LDFLAGS_SHARED)'
139454
				;;
139454
		esac
139454
	fi
139454
c425d2
	ccenv_attr_epilog "$ccenv_cc_sofmt"
c425d2
}
c425d2
f7f887
ccenv_set_os_dso_exrules()
f7f887
{
54797a
	ccenv_attr_prolog 'os dso exrules'
54797a
f7f887
	case "$ccenv_os" in
f7f887
		midipix )
f7f887
			ccenv_os_dso_exrules='pe-mdso'
f7f887
			;;
f7f887
		* )
f7f887
			if [ "$ccenv_cc_binfmt" = 'PE' ]; then
f7f887
				ccenv_os_dso_exrules='pe-dlltool'
f7f887
			else
f7f887
				ccenv_os_dso_exrules='default'
f7f887
			fi
f7f887
	esac
54797a
54797a
	ccenv_attr_epilog "$ccenv_os_dso_exrules"
f7f887
}
f7f887
f7f887
ccenv_set_os_dso_linkage()
f7f887
{
f7f887
	# todo: PIC, PIE, and friends
54797a
	ccenv_attr_prolog 'os linkage'
f7f887
	ccenv_os_dso_linkage='default'
54797a
	ccenv_attr_epilog "$ccenv_os_dso_linkage"
f7f887
}
f7f887
f7f887
ccenv_set_os_dso_patterns_darwin()
f7f887
{
f7f887
	ccenv_os_app_prefix=
f7f887
	ccenv_os_app_suffix=
f7f887
f7f887
	ccenv_os_lib_prefix=lib
f7f887
	ccenv_os_lib_suffix=.dylib
f7f887
f7f887
	ccenv_os_implib_ext=.invalid
f7f887
	ccenv_os_libdef_ext=.invalid
f7f887
f7f887
	ccenv_os_archive_ext=.a
f7f887
	ccenv_os_soname=symlink
f7f887
f7f887
	ccenv_os_lib_prefixed_suffix=
f7f887
	ccenv_os_lib_suffixed_suffix='$(OS_LIB_SUFFIX)'
f7f887
}
f7f887
f7f887
ccenv_set_os_dso_patterns_mdso()
f7f887
{
f7f887
	ccenv_os_app_prefix=
f7f887
	ccenv_os_app_suffix=
f7f887
f7f887
	ccenv_os_lib_prefix=lib
f7f887
	ccenv_os_lib_suffix=.so
f7f887
f7f887
	ccenv_os_implib_ext=.lib.a
f7f887
	ccenv_os_libdef_ext=.so.def
f7f887
f7f887
	ccenv_os_archive_ext=.a
f7f887
	ccenv_os_soname=symlink
f7f887
f7f887
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
f7f887
	ccenv_os_lib_suffixed_suffix=
f7f887
}
f7f887
f7f887
ccenv_set_os_dso_patterns_dlltool()
f7f887
{
f7f887
	ccenv_os_app_prefix=
f7f887
	ccenv_os_app_suffix=.exe
f7f887
f7f887
	ccenv_os_lib_prefix=lib
f7f887
	ccenv_os_lib_suffix=.dll
f7f887
f7f887
	ccenv_os_implib_ext=.dll.a
f7f887
	ccenv_os_libdef_ext=.def
f7f887
f7f887
	ccenv_os_archive_ext=.a
f7f887
	ccenv_os_soname=copy
f7f887
f7f887
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
f7f887
	ccenv_os_lib_suffixed_suffix=
f7f887
}
f7f887
f7f887
ccenv_set_os_dso_patterns_default()
f7f887
{
f7f887
	ccenv_os_app_prefix=
f7f887
	ccenv_os_app_suffix=
f7f887
f7f887
	ccenv_os_lib_prefix=lib
f7f887
	ccenv_os_lib_suffix=.so
f7f887
f7f887
	ccenv_os_implib_ext=.invalid
f7f887
	ccenv_os_libdef_ext=.invalid
f7f887
f7f887
	ccenv_os_archive_ext=.a
f7f887
	ccenv_os_soname=symlink
f7f887
f7f887
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
f7f887
	ccenv_os_lib_suffixed_suffix=
f7f887
}
f7f887
f7f887
ccenv_set_os_dso_patterns()
f7f887
{
f7f887
	# sover: .so.x.y.z
f7f887
	# verso: .x.y.z.so
f7f887
f7f887
	case "$ccenv_os" in
f7f887
		darwin )
f7f887
			ccenv_set_os_dso_patterns_darwin
f7f887
			;;
f7f887
		midipix )
f7f887
			ccenv_set_os_dso_patterns_mdso
f7f887
			;;
f7f887
		cygwin | msys | mingw )
f7f887
			ccenv_set_os_dso_patterns_dlltool
f7f887
			;;
f7f887
		* )
f7f887
			ccenv_set_os_dso_patterns_default
f7f887
			;;
f7f887
	esac
f7f887
}
f7f887
fc67fb
ccenv_set_os_pe_switches()
fc67fb
{
b522af
	if [ "$ccenv_cc_binfmt" = 'PE' ] && [ -z "$ccenv_pe_subsystem" ]; then
fc67fb
		case "$ccenv_os" in
fc67fb
			midipix | mingw )
fc67fb
				ccenv_pe_subsystem='windows'
fc67fb
				;;
fc67fb
			* )
fc67fb
				ccenv_pe_subsystem='console'
fc67fb
				;;
fc67fb
		esac
fc67fb
	fi
4c3598
4c3598
	if [ "$ccenv_cc_binfmt" = 'PE' ]; then
4c3598
		if ! cfgtest_macro_definition '__PE__'; then
4c3598
			ccenv_cflags_os="${ccenv_cflags_os} -D__PE__"
4c3598
		fi
4c3598
4c3598
		if ! cfgtest_macro_definition '__dllexport'; then
4c3598
			ccenv_cflags_os="${ccenv_cflags_os} -D__dllexport=__attribute__\(\(__dllexport__\)\)"
4c3598
		fi
4c3598
4c3598
		if ! cfgtest_macro_definition '__dllimport'; then
4c3598
			ccenv_cflags_os="${ccenv_cflags_os} -D__dllimport=__attribute__\(\(__dllimport__\)\)"
4c3598
		fi
4c3598
	fi
fc67fb
}
fc67fb
5776a8
ccenv_set_os_gate_switches()
5776a8
{
5776a8
	if [ "$ccenv_os" = 'solaris' ]; then
5776a8
		if ! cfgtest_macro_definition 'AT_FDCWD'; then
5776a8
			ccenv_cflags_os="${ccenv_cflags_os} -D__EXTENSIONS__"
5776a8
		fi
5776a8
	fi
5776a8
}
5776a8
1c2246
ccenv_set_os_bsd_switches()
1c2246
{
1c2246
	if [ "$ccenv_os" = 'bsd' ]; then
1c2246
		mb_cfgtest_headers='sys/mman.h'
1c2246
1c2246
		if ! cfgtest_macro_definition 'MAP_ANON'; then
1c2246
			ccenv_cflags_os="${ccenv_cflags_os} -D__BSD_VISIBLE"
1c2246
		fi
1c2246
1c2246
		mb_cfgtest_headers=
1c2246
	fi
1c2246
}
1c2246
f7f887
ccenv_output_defs()
f7f887
{
f7f887
	ccenv_in="$mb_project_dir/sofort/ccenv/ccenv.in"
f7f887
	ccenv_mk="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
efffb2
	ccenv_tmp=
f7f887
fc67fb
	if [ "$ccenv_cc_binfmt" = 'PE' ]; then
fc67fb
		ccenv_pe="$mb_project_dir/sofort/ccenv/pedefs.in"
fc67fb
		ccenv_in="$ccenv_in $ccenv_pe"
fc67fb
	fi
fc67fb
f7f887
	if [ $ccenv_cfgtype = 'native' ]; then
f7f887
513f55
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
f7f887
f2ca61
		sed                                      \
15a19f
				-e 's/^[[:space:]]*$/@/g' \
f2ca61
				-e 's/^/NATIVE_/'          \
f2ca61
				-e 's/NATIVE_@//g'          \
f2ca61
				-e 's/NATIVE_#/#/g'          \
f2ca61
				-e 's/       =/=/g'           \
f2ca61
				-e 's/       +=/+=/g'          \
a6f65a
			$(printf '%s ' $ccenv_in)               \
a6f65a
				> "$ccenv_tmp"
f7f887
f7f887
		ccenv_in="$ccenv_tmp"
513f55
	else
efffb2
		unset ccenv_tmp
f7f887
	fi
f7f887
b5b326
	ccenv_var_defs=
db8d9a
	ccenv_sed_substs="-e s/@ccenv_cfgtype@/${ccenv_cfgtype}/g"
b5b326
f7f887
	ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
b5b326
		| grep -v '^#');
f7f887
db8d9a
	ccenv_exvars="ccenv_makevar_prefix"
f7f887
b5b326
	for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do
b5b326
		ccenv_sed_subst=$(printf '%s %s%s%s' \
b5b326
				'-e' "'s^@$__var@"    \
b5b326
				"^___${__var}___"      \
b5b326
				"^g'")
b5b326
b5b326
		ccenv_sed_substs="$ccenv_sed_substs $ccenv_sed_subst"
b5b326
b5b326
		ccenv_var_def=$(printf '%s%s="${%s}"' "-D" "___${__var}___" "${__var}")
b5b326
		eval ccenv_var_defs='"$ccenv_var_defs "$ccenv_var_def'
b5b326
	done
f7f887
b5b326
	eval sed $ccenv_sed_substs $(printf '%s ' $ccenv_in) \
b5b326
			| eval m4 $ccenv_var_defs -           \
b5b326
			| sed -e 's/[[:blank:]]*$//g'          \
f7f887
		> "$ccenv_mk"
f7f887
fc6df7
	if [ "$ccenv_cfgtype" = 'host' ]; then
7cf81c
		for __var in $(printf '%s' "$ccenv_vars"); do
fc6df7
			ccenv_src_var=$__var
fc6df7
			ccenv_dst_var=mb_${__var#*ccenv_}
fc6df7
			ccenv_var_expr='${'$ccenv_src_var':-}'
fc6df7
			eval $ccenv_dst_var=$ccenv_var_expr
fc6df7
fc6df7
		done
fc6df7
fc6df7
		mb_host=$ccenv_host
fc6df7
		mb_cchost=$ccenv_cchost
fc6df7
	else
7cf81c
		for __var in $(printf '%s' "$ccenv_vars"); do
fc6df7
			ccenv_src_var=$__var
fc6df7
			ccenv_dst_var=mb_native_${__var#*ccenv_}
fc6df7
			ccenv_var_expr='${'$ccenv_src_var':-}'
fc6df7
			eval "$ccenv_dst_var=$ccenv_var_expr"
fc6df7
		done
fc6df7
fc6df7
		mb_native_host=$ccenv_host
fc6df7
		mb_native_cchost=$ccenv_cchost
fc6df7
	fi
513f55
513f55
	if [ -n "${ccenv_tmp:-}" ]; then
513f55
		rm -f "$ccenv_tmp"
513f55
		unset ccenv_tmp
513f55
	fi
282fe9
f979e6
f979e6
	if [ "${ccenv_cfgtype}" = 'host' ]; then
f979e6
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-host)
f979e6
		ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-host)
f979e6
	else
f979e6
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-native)
f979e6
		ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-native)
f979e6
	fi
f979e6
f979e6
	ccenv_cflags="${ccenv_cflags#*: }"
f979e6
	ccenv_ldflags="${ccenv_ldflags#*: }"
f979e6
9cbe7c
	ccenv_sysroot=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
9cbe7c
		-print-sysroot 2>/dev/null || true)
9cbe7c
f979e6
	eval 'ccenv_'${ccenv_cfgtype}'_cflags'=\'$ccenv_cflags\'
f979e6
	eval 'ccenv_'${ccenv_cfgtype}'_ldflags'=\'$ccenv_ldflags\'
9cbe7c
	eval 'ccenv_'${ccenv_cfgtype}'_sysroot'=\'$ccenv_sysroot\'
f979e6
282fe9
	eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\'
ae1d75
	eval 'ccenv_'${ccenv_cfgtype}'_cc_environment'=\'$ccenv_cc_environment\'
dd9dbe
	eval 'ccenv_'${ccenv_cfgtype}'_dumpmachine_switch'=\'$ccenv_dumpmachine_switch\'
5195d6
	eval 'ccenv_'${ccenv_cfgtype}'_pkgconf'=\'$ccenv_pkgconf\'
f979e6
f7f887
}
f7f887
9bbef5
ccenv_set_cc_sysroot_vars()
9bbef5
{
9bbef5
	if [ "$ccenv_cfgtype" = 'native' ] || [ -z "$mb_sysroot" ]; then
9bbef5
		return 0
9bbef5
	fi
9bbef5
9bbef5
	cfgtest_host_section
9bbef5
	ccenv_switch_var="--sysroot=${mb_sysroot}"
9bbef5
9bbef5
	if cfgtest_compiler_switch_arg "${ccenv_switch_var}"; then
9bbef5
		printf '\n# %s sysroot: cflags and ldflags\n' "$ccenv_cfgtype" \
9bbef5
			>> "$ccenv_mk"
9bbef5
9bbef5
		for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do
9bbef5
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
9bbef5
				>> "$ccenv_mk"
9bbef5
		done
9bbef5
	else
9bbef5
		printf '\n# %s sysroot: cflags and ldflags %s\n' "$ccenv_cfgtype" \
9bbef5
			'(not supported: see config.log)'                          \
9bbef5
			>> "$ccenv_mk"
9bbef5
9bbef5
		for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do
9bbef5
			printf '%-40s=\n' "${ccenv_make_var}" \
9bbef5
				>> "$ccenv_mk"
9bbef5
		done
9bbef5
	fi
9bbef5
}
9bbef5
5dc03c
ccenv_set_cc_switch_vars()
5dc03c
{
da093c
	printf '\n# %s cflags: supported compiler switches\n' "$ccenv_cfgtype" \
da093c
		>> "$ccenv_mk"
da093c
5dc03c
	if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
a92c18
		ccenv_switch_vars=$(cat                            \
5dc03c
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
5dc03c
			$mb_project_dir/project/config/ccswitch.strs \
a92c18
		| grep -v -e '^#' -e '^-Wl,'                          \
a92c18
		| sort -u)
5dc03c
	else
fa4aa3
		ccenv_switch_vars=$(grep -v -e '^#' -e '^-Wl,'     \
5dc03c
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
5dc03c
			| sort -u)
5dc03c
	fi
5dc03c
5dc03c
	if [ $ccenv_cfgtype = 'host' ]; then
5dc03c
		ccenv_makevar_prefix='_CFLAGS_'
5dc03c
		cfgtest_host_section
5dc03c
	else
5dc03c
		ccenv_makevar_prefix='_NATIVE_CFLAGS_'
5dc03c
		cfgtest_native_section
5dc03c
	fi
5dc03c
5dc03c
	for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
5dc03c
		ccenv_make_var=${ccenv_switch_var%=}
5dc03c
		ccenv_make_var=${ccenv_make_var%,}
5dc03c
5dc03c
		ccenv_make_var=${ccenv_make_var##---}
5dc03c
		ccenv_make_var=${ccenv_make_var##--}
5dc03c
		ccenv_make_var=${ccenv_make_var##-}
5dc03c
5dc03c
		ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
5dc03c
			| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
5dc03c
5dc03c
		ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
5dc03c
5dc03c
		if cfgtest_compiler_switch "$ccenv_switch_var"; then
5dc03c
			ccenv_switch_var=${ccenv_switch_var%=}
5dc03c
			ccenv_switch_var=${ccenv_switch_var%,}
5dc03c
b62f97
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
5dc03c
				>> "$ccenv_mk"
5dc03c
		else
b62f97
			printf '%-40s=\n' "${ccenv_make_var}" \
5dc03c
				>> "$ccenv_mk"
5dc03c
		fi
5dc03c
	done
5dc03c
}
5dc03c
fa4aa3
ccenv_set_cc_linker_switch_vars()
fa4aa3
{
fa4aa3
	printf '\n# %s ldflags: supported compiler switches\n' "$ccenv_cfgtype" \
fa4aa3
		>> "$ccenv_mk"
fa4aa3
fa4aa3
	if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
a92c18
		ccenv_switch_vars=$(cat                            \
fa4aa3
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
fa4aa3
			$mb_project_dir/project/config/ccswitch.strs \
a92c18
			| grep -e '^-Wl,'                             \
fa4aa3
			| sort -u)
fa4aa3
	else
fa4aa3
		ccenv_switch_vars=$(grep -e '^-Wl,'                \
fa4aa3
			$mb_project_dir/sofort/ccenv/ccswitch.strs  \
fa4aa3
			| sort -u)
fa4aa3
	fi
fa4aa3
fa4aa3
	if [ $ccenv_cfgtype = 'host' ]; then
fa4aa3
		ccenv_makevar_prefix='_LDFLAGS_'
fa4aa3
		cfgtest_host_section
fa4aa3
	else
fa4aa3
		ccenv_makevar_prefix='_NATIVE_LDFLAGS_'
fa4aa3
		cfgtest_native_section
fa4aa3
	fi
fa4aa3
fa4aa3
	for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
fa4aa3
		ccenv_make_var=${ccenv_switch_var%=}
fa4aa3
		ccenv_make_var=${ccenv_make_var%,}
fa4aa3
fa4aa3
		ccenv_make_var=${ccenv_make_var##---}
fa4aa3
		ccenv_make_var=${ccenv_make_var##--}
fa4aa3
		ccenv_make_var=${ccenv_make_var##-}
fa4aa3
fa4aa3
		ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
fa4aa3
			| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
fa4aa3
fa4aa3
		ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
fa4aa3
fa4aa3
		if cfgtest_compiler_switch "$ccenv_switch_var"; then
fa4aa3
			ccenv_switch_var=${ccenv_switch_var%=}
fa4aa3
			ccenv_switch_var=${ccenv_switch_var%,}
fa4aa3
fa4aa3
			printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
fa4aa3
				>> "$ccenv_mk"
fa4aa3
		else
fa4aa3
			printf '%-40s=\n' "${ccenv_make_var}" \
fa4aa3
				>> "$ccenv_mk"
fa4aa3
		fi
fa4aa3
	done
fa4aa3
}
fa4aa3
d603a4
ccenv_set_cc_attr_visibility_vars()
d603a4
{
d603a4
	if cfgtest_attr_visibility 'default'; then
d603a4
		ccenv_attr_visibility_default="$mb_cfgtest_attr"
d603a4
	fi
d603a4
d603a4
	if cfgtest_attr_visibility 'hidden'; then
d603a4
		ccenv_attr_visibility_hidden="$mb_cfgtest_attr"
d603a4
	fi
d603a4
d603a4
	if cfgtest_attr_visibility 'internal'; then
d603a4
		ccenv_attr_visibility_internal="$mb_cfgtest_attr"
d603a4
	fi
d603a4
d603a4
	if cfgtest_attr_visibility 'protected'; then
d603a4
		ccenv_attr_visibility_protected="$mb_cfgtest_attr"
d603a4
	fi
d603a4
}
d603a4
8f0776
ccenv_dso_verify()
8f0776
{
8f0776
	ccenv_str='int foo(int x){return ++x;}'
8f0776
	ccenv_cmd="$ccenv_cc -xc - -shared -o a.out"
8f0776
8f0776
	rm -f a.out
8f0776
be3a8d
	printf '%s' "$ccenv_str" | $(printf %s "$ccenv_cmd") \
a8f188
		> /dev/null 2>&3              \
8f0776
	|| mb_disable_shared=yes
8f0776
8f0776
	rm -f a.out
8f0776
}
8f0776
f7f887
ccenv_clean_up()
f7f887
{
f7f887
	rm -f $ccenv_image
f7f887
}
f7f887
f7f887
ccenv_common_init()
f7f887
{
f7f887
	. "$mb_project_dir/sofort/ccenv/ccenv.vars"
f7f887
f7f887
	ccenv_cfgtype=$1
f7f887
	ccenv_cfgfile="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
246bde
	ccenv_cchost=
f7f887
f7f887
	if [ $ccenv_cfgtype = 'native' ]; then
f7f887
		ccenv_makevar_prefix='NATIVE_'
f7f887
		ccenv_image='./ccenv/native.a.out'
f7f887
	else
f7f887
		ccenv_makevar_prefix=
f7f887
		ccenv_image='./ccenv/host.a.out'
f7f887
	fi
f7f887
f7f887
	if [ $ccenv_cfgtype = 'native' ]; then
f7f887
		ccenv_prefixes=
f7f887
	elif [ -n "$mb_cross_compile" ]; then
f7f887
		ccenv_prefixes="$mb_cross_compile"
f7f887
	elif [ -n "$mb_host" ]; then
f7f887
		ccenv_prefixes="$mb_host-"
f7f887
	else
f7f887
		ccenv_prefixes=
f7f887
	fi
f7f887
f7f887
	if [ $ccenv_cfgtype = 'host' ]; then
f7f887
		ccenv_tflags=
45190f
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
db7312
			OS_DSO_EXRULES=default                          \
db7312
			OS_SONAME=symlink                                \
b55149
			OS_ARCHIVE_EXT='.a'                               \
db7312
			.cflags-host)
22927a
45190f
		ccenv_cflags="${ccenv_cflags#*: }"
45190f
f7f887
		ccenv_cc="$mb_user_cc"
f7f887
		ccenv_cpp="$mb_user_cpp"
f7f887
		ccenv_cxx="$mb_user_cxx"
fc67fb
fc67fb
		ccenv_pe_subsystem="$mb_pe_subsystem"
fc67fb
		ccenv_pe_image_base="$mb_pe_image_base"
f7f887
	else
f7f887
		ccenv_tflags=
45190f
		ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
db7312
			OS_DSO_EXRULES=default                          \
db7312
			OS_SONAME=symlink                                \
b55149
			OS_ARCHIVE_EXT='.a'                               \
db7312
			.cflags-native)
db7312
45190f
		ccenv_cflags="${ccenv_cflags#*: }"
45190f
f7f887
		ccenv_cc="$mb_native_cc"
f7f887
		ccenv_cpp="$mb_native_cpp"
f7f887
		ccenv_cxx="$mb_native_cxx"
fc67fb
fc67fb
		ccenv_pe_subsystem="$mb_native_pe_subsystem"
fc67fb
		ccenv_pe_image_base="$mb_native_pe_image_base"
f7f887
	fi
f7f887
}
f7f887
f7f887
ccenv_set_characteristics()
f7f887
{
f7f887
	ccenv_set_cc_host
f7f887
	ccenv_set_cc_bits
f7f887
	ccenv_set_cc_binfmt
54797a
	ccenv_set_cc_underscore
f7f887
}
f7f887
f7f887
ccenv_set_toolchain_variables()
f7f887
{
f7f887
	ccenv_common_init $1
f7f887
	ccenv_set_cc
f7f887
	ccenv_set_cpp
f7f887
	ccenv_set_cxx
f7f887
	ccenv_set_primary_tools
f7f887
	ccenv_set_tool_variants
f7f887
	ccenv_set_characteristics
f7f887
f7f887
	ccenv_set_os
f7f887
	ccenv_set_os_flags
f7f887
	ccenv_set_os_semantics
c425d2
	ccenv_set_os_dso_format
f7f887
	ccenv_set_os_dso_exrules
f7f887
	ccenv_set_os_dso_linkage
f7f887
	ccenv_set_os_dso_patterns
fc67fb
	ccenv_set_os_pe_switches
5776a8
	ccenv_set_os_gate_switches
1c2246
	ccenv_set_os_bsd_switches
d603a4
	ccenv_set_cc_attr_visibility_vars
f7f887
f7f887
	ccenv_output_defs
f7f887
	ccenv_clean_up
5dc03c
9bbef5
	ccenv_set_cc_sysroot_vars
5dc03c
	ccenv_set_cc_switch_vars
fa4aa3
	ccenv_set_cc_linker_switch_vars
f7f887
}
f7f887
f7f887
ccenv_set_host_variables()
f7f887
{
54797a
	output_script_status ${mb_script} \
e002f2
		'detect and query host (targeted) system'
54797a
f7f887
	ccenv_set_toolchain_variables 'host'
8f0776
	ccenv_dso_verify
f7f887
}
f7f887
f7f887
ccenv_set_native_variables()
f7f887
{
54797a
	output_script_status ${mb_script} \
e002f2
		'detect and query native (local build) system'
54797a
239f6e
	if [ _$mb_ccenv_skip_native != _yes ]; then
239f6e
		ccenv_set_toolchain_variables 'native'
239f6e
	fi
f7f887
}