Reicher82 / python / sbpython3

Forked from python/sbpython3 3 years ago
Clone

Blame sofort/ccenv/ccenv.sh

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