Blame sofort/ccenv/ccenv.sh

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
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
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
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
b0d9d6
			if [ -z ${@:-} ]; 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"
b0d9d6
	ccenv_peep_tools="perk mdso dlltool windmc windres"
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
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
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"
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"
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
b0d9d6
		$ccenv_tool --help | 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
b0d9d6
		ccenv_candidates="c99 c11 cc gcc clang"
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
b0d9d6
		ccenv_find_tool -dumpmachine
b0d9d6
		ccenv_cc="$ccenv_tool"
b0d9d6
	fi
b0d9d6
b0d9d6
	if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
b0d9d6
		ccenv_cc="$mb_compiler"
b0d9d6
	fi
b0d9d6
b0d9d6
	ccenv_cc_cmd="$ccenv_cc"
b0d9d6
	ccenv_errors=
b0d9d6
b0d9d6
	if [ "$ccenv_cfgtype" = 'native' ]; then
b0d9d6
		ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3)
b0d9d6
		ccenv_cchost=$ccenv_host
b0d9d6
		ccenv_tool_epilog "$ccenv_cc"
b0d9d6
		return 0
b0d9d6
	fi
b0d9d6
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
b0d9d6
	if [ -z "$ccenv_host" ]; then
b0d9d6
		ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3)
b0d9d6
		ccenv_cchost=$ccenv_host
b0d9d6
	else
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
b0d9d6
				ccenv_tflags="--target=$ccenv_host"
b0d9d6
				ccenv_cc="$ccenv_cc $ccenv_tflags"
b0d9d6
			else
b0d9d6
				printf '%s' "$ccenv_errors" >&3
b0d9d6
			fi
b0d9d6
		fi
b0d9d6
b0d9d6
		rm -f "$ccenv_tmp"
b0d9d6
		unset ccenv_tmp
b0d9d6
b0d9d6
		ccenv_cchost=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3)
b0d9d6
	fi
b0d9d6
b0d9d6
	if [ "$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
	ccenv_tool_epilog "$ccenv_cc"
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 )
b0d9d6
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
b0d9d6
			ccenv_candidates="${ccenv_cpp_prefix}g++" ;;
b0d9d6
b0d9d6
		*-clang )
b0d9d6
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
b0d9d6
			ccenv_candidates="${ccenv_cpp_prefix}clang++" ;;
b0d9d6
b0d9d6
		*cc )
b0d9d6
			ccenv_cxx_prefix=${ccenv_cc_cmd%cc*}
b0d9d6
			ccenv_candidates="${ccenv_cpp_prefix}++" ;;
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
b0d9d6
		if [ -z $ccenv_internal_size ]; then
b0d9d6
			ccenv_internal_str=$(printf "$ccenv_internal_test"  \
b0d9d6
				"$ccenv_internal_type"                      \
b0d9d6
				"$ccenv_internal_guess")
b0d9d6
b0d9d6
			printf '%s' "$ccenv_internal_str"                   \
b0d9d6
					| $ccenv_cc -S -xc - -o -           \
b0d9d6
					  $(printf '%s' "$ccenv_cflags")    \
b0d9d6
				> /dev/null 2>&3                            \
b0d9d6
			&& ccenv_internal_size=$ccenv_internal_guess
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
b0d9d6
	if printf "$ccenv_fn_code" $ccenv_fn_name  \
b0d9d6
			| $ccenv_cc -xc - -S -o -  \
b0d9d6
			| grep "^_$ccenv_fn_name:" \
b0d9d6
				> /dev/null; then
b0d9d6
		ccenv_cc_underscore='_'
b0d9d6
		ccenv_attr_epilog 'yes'
b0d9d6
	fi
b0d9d6
b0d9d6
	ccenv_attr_epilog 'no'
b0d9d6
b0d9d6
	return 0
b0d9d6
}
b0d9d6
b0d9d6
ccenv_create_framework_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
	printf 'int main(void){return 0;}'  \
b0d9d6
		| $ccenv_cc -xc -           \
b0d9d6
			-o $ccenv_image     \
b0d9d6
	|| return 1
b0d9d6
b0d9d6
	return 0
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
b0d9d6
	printf 'int %s(void){return 0;}' "$ccenv_start_fn"  \
b0d9d6
		| $ccenv_cc -xc -                           \
b0d9d6
			-ffreestanding                      \
b0d9d6
			-nostdlib -nostartfiles             \
b0d9d6
			-o $ccenv_image                     \
b0d9d6
	|| return 1
b0d9d6
b0d9d6
	ccenv_freestd=yes
b0d9d6
b0d9d6
	return 0
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                  \
b0d9d6
				| grep -i 'Format:' | sed '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
{
b0d9d6
	if [ -n "$ccenv_freestd" ]; 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
		*-*-*-* )
b0d9d6
			ccenv_tip=${ccenv_cchost%-*}
b0d9d6
			ccenv_os=${ccenv_tip#*-*-}
b0d9d6
			;;
b0d9d6
		*-*-musl | *-*-gnu )
b0d9d6
			ccenv_tip=${ccenv_cchost%-*}
b0d9d6
			ccenv_os=${ccenv_tip#*-}
b0d9d6
			;;
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
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
b0d9d6
}
b0d9d6
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
b0d9d6
		sed                             \
b0d9d6
				-e 's/^\s*$/@/g' \
b0d9d6
				-e 's/^/NATIVE_/' \
b0d9d6
				-e 's/NATIVE_@//g' \
b0d9d6
				-e 's/NATIVE_#/#/g' \
b0d9d6
				-e 's/       =/=/g'  \
b0d9d6
				-e 's/       +=/+=/g' \
b0d9d6
			$ccenv_in > "$ccenv_tmp"
b0d9d6
b0d9d6
		ccenv_in="$ccenv_tmp"
b0d9d6
	else
b0d9d6
		unset ccenv_tmp
b0d9d6
	fi
b0d9d6
b0d9d6
	ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
b0d9d6
			| grep -v '^#')
b0d9d6
b0d9d6
	ccenv_exvars="ccenv_cfgtype ccenv_makevar_prefix"
b0d9d6
b0d9d6
	ccenv_sed_substs=" \
b0d9d6
		$(for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do \
b0d9d6
			printf '%s"$%s"%s' "-e 's/@$__var@/'" \
b0d9d6
				"$__var" "'/g' ";              \
b0d9d6
		done)"
b0d9d6
b0d9d6
	eval sed $ccenv_sed_substs $ccenv_in   \
b0d9d6
			| 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
b0d9d6
}
b0d9d6
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_freestd=
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=
b0d9d6
		ccenv_cflags=$(make -s -f "$mb_pwd/Makefile.tmp" .cflags-host)
b0d9d6
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=
b0d9d6
		ccenv_cflags=$(make -s -f "$mb_pwd/Makefile.tmp" .cflags-native)
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
b0d9d6
	ccenv_set_os_dso_exrules
b0d9d6
	ccenv_set_os_dso_linkage
b0d9d6
	ccenv_set_os_dso_patterns
b0d9d6
	ccenv_set_os_pe_switches
b0d9d6
b0d9d6
	ccenv_output_defs
b0d9d6
	ccenv_clean_up
b0d9d6
b0d9d6
	eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\'
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
}