Blame sofort/ccenv/ccenv.sh

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