Blame sofort/ccenv/ccenv.sh

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