Blame sofort/ccenv/ccenv.sh

711507
# ccenv.sh: sofort's tool-finding bits,
711507
# invoked from within the project-agnostic configure script.
711507
b3423c
# this file is covered by COPYING.SOFORT.
b3423c
711507
# invocation and names of binary tools:
711507
# agnostic names (ar, nm, objdump, ...);
711507
# target-prefixed agnostic names (x86_64-nt64-midipix-ar, ...);
711507
# branded names (llvm-ar, llvm-nm, llvm-objdump, ...);
711507
# target-prefixed branded names (x86_64-linux-gnu-gcc-ar, ...);
711507
# target-specifying branded tools (llvm-ar --target=x86_64-linux, ...).
711507
711507
# cross-compilation: default search order:
711507
# target-prefixed agnostic tools;
711507
# target-prefixed branded tools, starting with the prefix
711507
# most commonly associated with the selected compiler (that is,
711507
# ``gcc'' when using gcc, and ``llvm'' when using clang);
711507
# target-speficying branded tools, starting once again with the
711507
# prefix most commonly associated with the selected compiler.
711507
711507
# internal variables of interest:
711507
# ccenv_cfgtype: the type of host being tested (host/native)
711507
# ccenv_cfgfile: the configuration file for the host being tested
711507
# ccenv_cflags:  the comprehensive cflags for the host being tested
711507
# ccenv_cchost:  the host being tested, as reported by -dumpmachine
711507
711507
711507
ccenv_usage()
711507
{
711507
	cat "$mb_project_dir"/sofort/ccenv/ccenv.usage
711507
	exit 0
711507
}
711507
711507
711507
ccenv_newline()
711507
{
711507
	printf '\n' >> "$ccenv_cfgfile"
711507
}
711507
711507
711507
ccenv_comment()
711507
{
711507
	ccenv_internal_str='#'
711507
711507
	for ccenv_internal_arg ; do
711507
		ccenv_internal_str="$ccenv_internal_str $ccenv_internal_arg"
711507
	done
711507
711507
	printf '%s\n' "$ccenv_internal_str" >> "$ccenv_cfgfile"
711507
}
711507
711507
188a79
ccenv_tool_prolog()
188a79
{
a94557
	ccenv_line_dots='.....................................'
b7c699
	ccenv_tool_desc=" == checking for ${1}"
188a79
	ccenv_tool_dlen="${#ccenv_line_dots}"
188a79
bbde52
	printf '\n%s\n' '________________________' >&3
bbde52
	printf "ccenv: checking for ${1}\n\n" >&3
188a79
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s" \
a94557
		"${ccenv_tool_desc}  ${mb_line_dots}"
188a79
}
188a79
188a79
188a79
ccenv_tool_epilog()
188a79
{
188a79
	ccenv_line_dots='................................'
188a79
	ccenv_tool_dlen="$((${#ccenv_line_dots} - ${#1}))"
188a79
b0b2af
	case ${ccenv_tool_dlen} in
b0b2af
		0 | -* )
b0b2af
			ccenv_tool_dlen='3' ;;
b0b2af
	esac
b0b2af
a94557
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
188a79
		"${ccenv_line_dots}" "${1}"
bbde52
bbde52
	if [ "${1}" = 'false' ]; then
bbde52
		printf '\n\nccenv: not (yet) found.\n' >&3
bbde52
	else
bbde52
		printf "\n\nccenv : found $(command -v ${1}).\n" >&3
bbde52
	fi
bbde52
bbde52
	printf '%s\n' '------------------------' >&3
188a79
}
188a79
188a79
4a5a8c
ccenv_tool_variant_epilog()
4a5a8c
{
4a5a8c
	ccenv_expr=${1}='${'${1}':-false}'
4a5a8c
	eval "$ccenv_expr"
4a5a8c
4a5a8c
	ccenv_expr='${'${1}'}'
4a5a8c
	eval ccenv_tool_epilog "$ccenv_expr"
4a5a8c
}
4a5a8c
4a5a8c
188a79
ccenv_attr_prolog()
188a79
{
a94557
	ccenv_line_dots=' .....................................'
a94557
	ccenv_attr_desc=" == detect ${ccenv_cfgtype} ${1}"
188a79
	ccenv_attr_dlen="${#ccenv_line_dots}"
188a79
188a79
	printf "%${ccenv_attr_dlen}.${ccenv_attr_dlen}s" \
188a79
		"${ccenv_attr_desc} ${ccenv_line_dots}"
bbde52
bbde52
	printf '\n%s\n' '________________________' >&3
bbde52
	printf "ccenv: detecting ${1}\n\n" >&3
188a79
}
188a79
188a79
188a79
ccenv_attr_epilog()
188a79
{
bbde52
	ccenv_line_dots='................................'
a94557
	ccenv_tool_dlen="$((${#ccenv_line_dots} - 1 - ${#1}))"
bbde52
b0b2af
	case ${ccenv_tool_dlen} in
b0b2af
		0 | -* )
b0b2af
			ccenv_tool_dlen='3' ;;
b0b2af
	esac
b0b2af
a94557
	printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s  %s.\n" \
bbde52
		"${ccenv_line_dots}" "${1}"
bbde52
bbde52
	printf '\n\nccenv: detected result: %s\n' "${1}" >&3
bbde52
	printf '%s\n' '------------------------' >&3
188a79
}
188a79
188a79
711507
ccenv_find_tool()
711507
{
711507
	if [ -z "$ccenv_prefixes" ]; then
7d9a2d
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
be9f9d
			ccenv_cmd_args="${@:-}"
be9f9d
be9f9d
			if [ -z "$ccenv_cmd_args" ]; then
3a6b25
				if command -v "$ccenv_candidate" > /dev/null; then
3a6b25
					ccenv_tool="$ccenv_candidate"
c42cf9
					return 0
e4b2db
				fi
c42cf9
			else
3a6b25
				if command -v "$ccenv_candidate" > /dev/null; then
bbde52
					if "$ccenv_candidate" $@ > /dev/null 2>&3; then
3a6b25
						ccenv_tool="$ccenv_candidate"
c42cf9
						return 0
e4b2db
					fi
e4b2db
				fi
c42cf9
			fi
711507
		done
711507
711507
		ccenv_tool=false
711507
711507
		return 0
711507
	fi
711507
7d9a2d
	for ccenv_prefix in $(printf '%s' "$ccenv_prefixes"); do
7d9a2d
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
711507
			ccenv_tool="$ccenv_prefix$ccenv_candidate"
e4b2db
e4b2db
			if command -v "$ccenv_tool" > /dev/null; then
e4b2db
				return 0
e4b2db
			fi
711507
		done
711507
	done
711507
7d9a2d
	for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
3a6b25
		if command -v "$ccenv_candidate" > /dev/null; then
3a6b25
			ccenv_tool="$ccenv_candidate"
e4b2db
			return 0
e4b2db
		fi
711507
	done
711507
711507
	ccenv_tool=false
711507
711507
	return 0
711507
}
711507
711507
711507
ccenv_set_primary_tools()
711507
{
711507
	ccenv_core_tools="ar nm objdump ranlib size strip strings objcopy"
e6f0f0
	ccenv_hack_tools="addr2line cov elfedit readelf readobj otool"
711507
	ccenv_peep_tools="perk mdso dlltool windmc windres"
711507
7d9a2d
	for __tool in $(printf '%s' "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do
188a79
		ccenv_tool_prolog "$__tool"
188a79
711507
		if [ -n "$mb_agnostic" ]; then
711507
			ccenv_candidates=" $__tool"
711507
711507
		elif [ -n "$mb_zealous" ]; then
711507
			ccenv_candidates="$mb_zealous-$__tool"
711507
711507
		elif [ "$mb_toolchain" = 'gcc' ]; then
711507
			ccenv_candidates="gcc-$__tool"
711507
			ccenv_candidates="$ccenv_candidates $__tool"
711507
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
711507
711507
		elif [ "$mb_toolchain" = 'llvm' ]; then
711507
			ccenv_candidates="llvm-$__tool"
711507
			ccenv_candidates="$ccenv_candidates $__tool"
711507
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
711507
711507
		elif [ -n "$mb_toolchain" ]; then
711507
			ccenv_candidates="$mb_toolchain-$__tool"
711507
			ccenv_candidates="$ccenv_candidates $__tool"
711507
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
711507
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
711507
711507
		else
711507
			ccenv_candidates="$__tool"
711507
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
711507
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
711507
		fi
711507
711507
		if [ "$ccenv_cfgtype" = 'host' ]; then
711507
			ccenv_var_prefix='mb_'
711507
		else
711507
			ccenv_var_prefix='mb_native_'
711507
		fi
711507
711507
		ccenv_var_name=$ccenv_var_prefix$__tool
711507
		ccenv_var_expr='${'$ccenv_var_name':-}'
711507
		eval ccenv_var_val=$ccenv_var_expr
711507
711507
		if [ -n "$ccenv_var_val" ]; then
711507
			eval ccenv_$__tool="$ccenv_var_val"
711507
		else
711507
			ccenv_find_tool
711507
			eval ccenv_$__tool="$ccenv_tool"
711507
		fi
188a79
188a79
		ccenv_tool_epilog "$ccenv_tool"
711507
	done
711507
711507
	# windrc
711507
	ccenv_windrc="$ccenv_windres"
bb082e
bb082e
	# archive format preamble
bb082e
	ccenv_libgcc_a_header=$(od -b -N8 $($ccenv_cc -print-file-name=libgcc.a) | head -n1)
bb082e
	ccenv_cc_arfmt='common'
bb082e
bb082e
	# ar (big)
bb082e
	ccenv_bigaf_header=$(printf '%s\n' '<bigaf>' | od -b | head -n1)
bb082e
bb082e
	if [ "$ccenv_libgcc_a_header" = "$ccenv_bigaf_header" ]; then
bb082e
		ccenv_cc_arfmt='bigaf'
bb082e
bb082e
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
bb082e
			ccenv_var_name=ccenv_$__tool
bb082e
			ccenv_var_expr='${'$ccenv_var_name':-}'
bb082e
			eval ccenv_var_val="$ccenv_var_expr"
bb082e
bb082e
			if [ "$ccenv_var_val" != false ]; then
bb082e
				ccenv_var_val="$ccenv_var_val -X64"
bb082e
				ccenv_var_expr='${ccenv_var_val:-}'
bb082e
				eval ccenv_$__tool="$ccenv_var_expr"
bb082e
			fi
bb082e
		done
bb082e
	fi
bb082e
bb082e
	# ar (small)
bb082e
	ccenv_aiaff_header=$(printf '%s\n' '<aiaff>' | od -b | head -n1)
bb082e
bb082e
	if [ "$ccenv_libgcc_a_header" = "$ccenv_aiaff_header" ]; then
bb082e
		ccenv_cc_arfmt='aiaff'
bb082e
bb082e
		for __tool in $(printf '%s' "$ccenv_core_tools"); do
bb082e
			ccenv_var_name=ccenv_$__tool
bb082e
			ccenv_var_expr='${'$ccenv_var_name':-}'
bb082e
			eval ccenv_var_val="$ccenv_var_expr"
bb082e
bb082e
			if [ "$ccenv_var_val" != false ]; then
bb082e
				ccenv_var_val="$ccenv_var_val -X32"
bb082e
				ccenv_var_expr='${ccenv_var_val:-}'
bb082e
				eval ccenv_$__tool="$ccenv_var_expr"
bb082e
			fi
bb082e
		done
bb082e
	fi
711507
}
711507
711507
ccenv_set_tool_variants()
711507
{
711507
	# as (asm)
188a79
	ccenv_tool_prolog 'as (asm)'
711507
	ccenv_candidates=as
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" = false ]; then
711507
		ccenv_as_asm=
711507
	else
4440ff
		$ccenv_tool --help 2>&1 | grep -i '.bc assembler' \
711507
		|| ccenv_as_asm="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_as_asm'
188a79
711507
	# as (ll)
188a79
	ccenv_tool_prolog 'as (ll)'
711507
	ccenv_candidates=llvm-as
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" != false ]; then
711507
		ccenv_as_ll="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_as_ll'
188a79
711507
	# as (mc)
188a79
	ccenv_tool_prolog 'as (mc)'
711507
	ccenv_candidates=llvm-mc
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" != false ]; then
711507
		ccenv_as_mc="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_as_mc'
188a79
711507
	# ld (bfd)
188a79
	ccenv_tool_prolog 'ld (bfd)'
711507
	ccenv_candidates=ld.bfd
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" != false ]; then
711507
		ccenv_ld_bfd="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_ld_bfd'
188a79
711507
	# ld (gold)
188a79
	ccenv_tool_prolog 'ld (gold)'
711507
	ccenv_candidates=ld.gold
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" != false ]; then
711507
		ccenv_ld_gold="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_ld_gold'
188a79
711507
	# ld (lld)
188a79
	ccenv_tool_prolog 'ld (lld)'
711507
	ccenv_candidates=lld
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" != false ]; then
711507
		ccenv_ld_lld="$ccenv_tool"
711507
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_ld_lld'
188a79
711507
	# objdump (bfd)
188a79
	ccenv_tool_prolog 'objdump (bfd)'
711507
	ccenv_candidates=objdump
711507
	ccenv_find_tool
711507
ec40cb
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
ec40cb
		ccenv_objdump_bfd="$ccenv_tool"
ec40cb
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_objdump_bfd'
188a79
711507
	# objdump (llvm)
188a79
	ccenv_tool_prolog 'objdump (llvm)'
711507
	ccenv_candidates=llvm-objdump
711507
	ccenv_find_tool
711507
ec40cb
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
ec40cb
		ccenv_objdump_llvm="$ccenv_tool"
ec40cb
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_objdump_llvm'
188a79
711507
	# readelf (bfd)
188a79
	ccenv_tool_prolog 'readelf (bfd)'
711507
	ccenv_candidates=readelf
711507
	ccenv_find_tool
711507
ec40cb
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
ec40cb
		ccenv_readelf_bfd="$ccenv_tool"
ec40cb
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_readelf_bfd'
188a79
711507
	# readelf (llvm)
188a79
	ccenv_tool_prolog 'readelf (llvm)'
711507
	ccenv_candidates=llvm-readelf
711507
	ccenv_find_tool
711507
ec40cb
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
ec40cb
		ccenv_readelf_llvm="$ccenv_tool"
ec40cb
	fi
711507
4a5a8c
	ccenv_tool_variant_epilog 'ccenv_readelf_llvm'
188a79
711507
	# as
711507
	if [ -n "$ccenv_cc" ]; then
49b7fa
		ccenv_as='$('"$ccenv_makevar_prefix"'CC) -c -x assembler'
711507
	elif [ -n "$mb_agnostic" ]; then
711507
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
711507
	elif [ "$mb_zealous" = 'gcc' ]; then
711507
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
711507
	elif [ -n "$mb_zealous" = 'llvm' ]; then
711507
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
711507
	elif [ "$mb_toolchain" = 'gcc' ]; then
711507
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
711507
	elif [ "$mb_toolchain" = 'llvm' ]; then
711507
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
711507
	fi
711507
711507
	# ld
711507
	if [ -n "$ccenv_cc" ]; then
711507
		ccenv_ld='$('"$ccenv_makevar_prefix"'CC) -nostdlib -nostartfiles'
711507
	fi
711507
}
711507
711507
ccenv_set_c_compiler_candidates()
711507
{
711507
	if   [ -n "$mb_compiler" ]; then
711507
		ccenv_candidates="$mb_compiler"
711507
711507
	elif [ -n "$mb_agnostic" ]; then
711507
		ccenv_candidates="c99 c11 cc"
711507
711507
	elif [ "$mb_zealous" = 'gcc' ]; then
711507
		ccenv_candidates="gcc"
711507
711507
	elif [ "$mb_zealous" = 'llvm' ]; then
711507
		ccenv_candidates="clang"
711507
711507
	elif [ "$mb_toolchain" = 'gcc' ]; then
711507
		ccenv_candidates="gcc c99 c11 cc clang"
711507
711507
	elif [ "$mb_toolchain" = 'llvm' ]; then
711507
		ccenv_candidates="clang c99 c11 cc gcc"
711507
711507
	elif [ -n "$mb_toolchain" ]; then
711507
		ccenv_candidates="$mb_toolchain c99 c11 cc gcc clang"
711507
711507
	else
711507
		ccenv_candidates="c99 c11 cc gcc clang"
711507
	fi
711507
}
711507
711507
711507
ccenv_set_cc()
711507
{
188a79
	ccenv_tool_prolog 'C compiler'
188a79
711507
	if [ -z "$ccenv_cc" ]; then
711507
		ccenv_set_c_compiler_candidates
c42cf9
		ccenv_find_tool -dumpmachine
711507
		ccenv_cc="$ccenv_tool"
711507
	fi
711507
711507
	if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
711507
		ccenv_cc="$mb_compiler"
711507
	fi
711507
711507
	ccenv_cc_cmd="$ccenv_cc"
aeb703
	ccenv_errors=
711507
711507
	if [ "$ccenv_cfgtype" = 'native' ]; then
bbde52
		ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3)
5b51ca
		ccenv_cchost=$ccenv_host
188a79
		ccenv_tool_epilog "$ccenv_cc"
711507
		return 0
711507
	fi
711507
711507
	if [ -n "$mb_cchost" ]; then
711507
		ccenv_host="$mb_cchost"
711507
	elif [ -n "$mb_host" ]; then
711507
		ccenv_host="$mb_host"
711507
	else
711507
		ccenv_host=
711507
	fi
711507
711507
	if [ -z "$ccenv_host" ]; then
bbde52
		ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3)
711507
		ccenv_cchost=$ccenv_host
711507
	else
1cc479
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
711507
		ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -"
711507
711507
		if [ -z "$mb_user_cc" ]; then
03b8d4
			$(printf %s "$ccenv_cmd") < /dev/null > /dev/null \
711507
				2>"$ccenv_tmp" || true
711507
711507
			ccenv_errors=$(cat "$ccenv_tmp")
711507
711507
			if [ -z "$ccenv_errors" ]; then
711507
				ccenv_tflags="--target=$ccenv_host"
711507
				ccenv_cc="$ccenv_cc $ccenv_tflags"
bbde52
			else
bbde52
				printf '%s' "$ccenv_errors" >&3
711507
			fi
711507
		fi
711507
1cc479
		rm -f "$ccenv_tmp"
1cc479
		unset ccenv_tmp
1cc479
bbde52
		ccenv_cchost=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3)
711507
	fi
711507
711507
	if [ "$ccenv_cchost" != "$ccenv_host" ]; then
bbde52
		printf 'error!\n' >&2
711507
		printf 'ccenv:\n' >&2
711507
		printf 'ccenv: ccenv_host:   %s \n' $ccenv_host >&2
711507
		printf 'ccenv: ccenv_cchost: %s \n' $ccenv_cchost >&2
711507
711507
		if [ -z "$ccenv_tflags" ]; then
711507
			printf 'ccenv:\n' >&2
711507
			printf 'ccenv: ccenv_host and ccenv_cchost do not match, most likely because:\n' >&2
711507
			printf 'ccenv: (1) you explicitly set CC (or passed --compiler=...)\n' >&2
711507
			printf 'ccenv: (2) the selected compiler does not accept --target=...\n' >&2
711507
			printf 'ccenv: (3) the host reported by -dumpmachine differs from the one you requested.\n' >&2
711507
		fi
711507
711507
		if [ -n "$ccenv_errors" ]; then
711507
			printf 'ccenv:\n' >&2
711507
			printf 'ccenv: something went wrong, see the command and compiler message below.\n\n' >&2
711507
			printf 'cmd: %s < /dev/null > /dev/null\n' "$ccenv_cmd" >&2
711507
			printf '%s\n\n' "$ccenv_errors" >&2
711507
		else
711507
			printf 'ccenv:\n' >&2
711507
			printf 'ccenv: something went wrong, bailing out.\n\n' >&2
711507
		fi
711507
711507
		return 2
711507
	fi
188a79
188a79
	ccenv_tool_epilog "$ccenv_cc"
711507
}
711507
711507
ccenv_set_cpp()
711507
{
188a79
	ccenv_tool_prolog 'C pre-processor'
188a79
711507
	case "$ccenv_cc_cmd" in
711507
		cc | c99 | c11 | gcc)
711507
			ccenv_cpp_prefix=
711507
			ccenv_candidates="cpp" ;;
711507
711507
		clang )
711507
			ccenv_cpp_prefix=
711507
			ccenv_candidates="clang-cpp" ;;
711507
711507
		*-cc )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-cc*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
711507
711507
		*-c99 )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c99*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
711507
711507
		*-c11 )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c11*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
711507
711507
		*-gcc )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
711507
711507
		*-clang )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}clang-cpp" ;;
711507
711507
		* )
711507
			ccenv_cpp="$ccenv_cc -E"
188a79
			ccenv_tool_epilog "$ccenv_cpp"
711507
			return 0
711507
	esac
711507
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" = false ]; then
711507
		ccenv_cpp="$ccenv_cc -E"
711507
	elif [ -n "$ccenv_tflags" ]; then
711507
		ccenv_cpp="$ccenv_tool $ccenv_tflags"
711507
	else
711507
		ccenv_cpp="$ccenv_tool"
711507
	fi
188a79
188a79
	ccenv_tool_epilog "$ccenv_cpp"
711507
}
711507
711507
ccenv_set_cxx()
711507
{
188a79
	ccenv_tool_prolog 'C++ compiler'
188a79
711507
	case "$ccenv_cc_cmd" in
711507
		cc | c99 | c11 )
711507
			ccenv_cxx_prefix=
711507
			ccenv_candidates="cxx c++" ;;
711507
711507
		gcc )
711507
			ccenv_cxx_prefix=
711507
			ccenv_candidates="g++" ;;
711507
711507
		clang )
711507
			ccenv_cxx_prefix=
711507
			ccenv_candidates="clang++" ;;
711507
711507
		*-gcc )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}g++" ;;
711507
711507
		*-clang )
711507
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
711507
			ccenv_candidates="${ccenv_cpp_prefix}clang++" ;;
711507
711507
		*cc )
711507
			ccenv_cxx_prefix=${ccenv_cc_cmd%cc*}
711507
			ccenv_candidates="${ccenv_cpp_prefix}++" ;;
711507
711507
		* )
711507
			ccenv_cxx="$ccenv_cc -xc++"
188a79
			ccenv_tool_epilog "$ccenv_cxx"
711507
			return 0
711507
	esac
711507
711507
	ccenv_find_tool
711507
711507
	if [ "$ccenv_tool" = false ]; then
711507
		ccenv_cxx="$ccenv_cc -xc++"
711507
	elif [ -n "$ccenv_tflags" ]; then
711507
		ccenv_cxx="$ccenv_tool $ccenv_tflags"
711507
	else
711507
		ccenv_cxx="$ccenv_tool"
711507
	fi
188a79
188a79
	ccenv_tool_epilog "$ccenv_cxx"
711507
}
711507
711507
ccenv_set_cc_host()
711507
{
2628b5
	ccenv_attr_prolog 'system'
711507
	ccenv_cc_host="$ccenv_cchost"
188a79
	ccenv_attr_epilog "$ccenv_cc_host"
711507
}
711507
711507
ccenv_set_cc_bits()
711507
{
188a79
	ccenv_attr_prolog 'bits'
188a79
711507
	ccenv_internal_size=
711507
	ccenv_internal_type='void *'
711507
	ccenv_internal_test='char x[(sizeof(%s) == %s/8) ? 1 : -1];'
711507
711507
	for ccenv_internal_guess in 64 32 128; do
20aac4
		if [ -z "${ccenv_internal_size:-}" ]; then
470dc7
			ccenv_internal_str=$(printf "$ccenv_internal_test"  \
470dc7
				"$ccenv_internal_type"                      \
711507
				"$ccenv_internal_guess")
711507
11dc72
			printf '%s' "$ccenv_internal_str"                   \
11dc72
					| $ccenv_cc -S -xc - -o -           \
11dc72
					  $(printf '%s' "$ccenv_cflags")    \
bbde52
				> /dev/null 2>&3                            \
711507
			&& ccenv_internal_size=$ccenv_internal_guess
711507
		fi
711507
	done
711507
711507
	ccenv_cc_bits=$ccenv_internal_size
188a79
188a79
	ccenv_attr_epilog "$ccenv_cc_bits"
711507
}
711507
711507
ccenv_set_cc_underscore()
711507
{
188a79
	ccenv_attr_prolog 'prepended underscores'
188a79
711507
	ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe'
711507
	ccenv_fn_code='int %s(void){return 0;}'
711507
ec40cb
	if printf "$ccenv_fn_code" $ccenv_fn_name  \
ec40cb
			| $ccenv_cc -xc - -S -o -  \
ec40cb
			| grep "^_$ccenv_fn_name:" \
ec40cb
				> /dev/null; then
ec40cb
		ccenv_cc_underscore='_'
188a79
		ccenv_attr_epilog 'yes'
ec40cb
	fi
711507
188a79
	ccenv_attr_epilog 'no'
188a79
711507
	return 0
711507
}
711507
711507
ccenv_create_framework_executable()
711507
{
711507
	if [ -f $ccenv_image ]; then
711507
		mv $ccenv_image $ccenv_image.tmp
711507
		rm -f $ccenv_image.tmp
711507
	fi
711507
711507
	printf 'int main(void){return 0;}'  \
711507
		| $ccenv_cc -xc -           \
711507
			-o $ccenv_image     \
94daee
			2>/dev/null         \
711507
	|| return 1
711507
711507
	return 0
711507
}
711507
711507
ccenv_create_freestanding_executable()
711507
{
711507
	if [ -f $ccenv_image ]; then
711507
		mv $ccenv_image $ccenv_image.tmp
711507
		rm -f $ccenv_image.tmp
711507
	fi
711507
711507
	if [ -z "ccenv_cc_underscore" ]; then
711507
		ccenv_start_fn='_start'
711507
	else
711507
		ccenv_start_fn='start'
711507
	fi
711507
711507
	printf 'int %s(void){return 0;}' "$ccenv_start_fn"  \
711507
		| $ccenv_cc -xc -                           \
711507
			-ffreestanding                      \
711507
			-nostdlib -nostartfiles             \
711507
			-o $ccenv_image                     \
711507
	|| return 1
711507
711507
	ccenv_freestd=yes
711507
711507
	return 0
711507
}
711507
188a79
ccenv_set_cc_binfmt_error()
188a79
{
188a79
	ccenv_attr_epilog '(unable to create executable)'
188a79
}
188a79
711507
ccenv_set_cc_binfmt()
711507
{
711507
	ccenv_use_perk=
e6f0f0
	ccenv_use_otool=
711507
	ccenv_use_readelf=
711507
	ccenv_use_readobj=
711507
	ccenv_use_bfd_objdump=
711507
	ccenv_use_llvm_objdump=
711507
188a79
	ccenv_attr_prolog 'binary format'
188a79
711507
	ccenv_create_framework_executable               \
711507
		|| ccenv_create_freestanding_executable \
188a79
		|| ccenv_set_cc_binfmt_error            \
711507
		|| return 0
711507
711507
	# PE / perk
711507
	if [ -n "$ccenv_perk" ]; then
bbde52
		if $ccenv_perk $ccenv_image 2>&3; then
ec40cb
			ccenv_cc_binfmt='PE'
ec40cb
			ccenv_use_perk=yes
ec40cb
		fi
711507
	fi
711507
711507
	# ELF / readelf
711507
	if [ -n "$ccenv_readelf" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_readelf -h $ccenv_image 2>&3               \
ec40cb
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
ec40cb
				| grep 'Magic:7f454c46'              \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='ELF'
ec40cb
			ccenv_use_readelf=yes
ec40cb
		fi
711507
	fi
711507
711507
	# a marble of astonishing design:
711507
	# llvm-readelf also parses PE and Mach-O
711507
711507
	if [ -n "$ccenv_readelf_llvm" ]; then
711507
		ccenv_readany="$ccenv_readelf_llvm"
711507
	else
711507
		ccenv_readany="$ccenv_readelf"
711507
	fi
711507
711507
	# PE / readelf
711507
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_readany -h $ccenv_image 2>&3               \
ec40cb
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
ec40cb
				| grep 'Magic:MZ'                    \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='PE'
ec40cb
			ccenv_use_readelf=yes
ec40cb
		fi
711507
	fi
711507
e6f0f0
	# MACHO-64 / otool
e6f0f0
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_otool -hv $ccenv_image 2>&3        \
ec40cb
				| grep -i 'MH_MAGIC_64'      \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_otool=yes
ec40cb
		fi
e6f0f0
	fi
e6f0f0
e6f0f0
	# MACHO-32 / otool
e6f0f0
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_otool -hv $ccenv_image 2>&3        \
ec40cb
				| grep -i 'MH_MAGIC'         \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_otool=yes
ec40cb
		fi
e6f0f0
	fi
e6f0f0
711507
	# MACHO-64 / readelf
711507
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_readany -h $ccenv_image 2>&3                    \
ec40cb
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
ec40cb
				| grep -i '(0xfeedfacf)'                  \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_readelf=yes
ec40cb
		fi
711507
	fi
711507
711507
	# MACHO-32 / readelf
711507
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_readany -h $ccenv_image 2>&3                    \
ec40cb
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
ec40cb
				| grep -i '(0xcafebabe)'                  \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_readelf=yes
ec40cb
		fi
711507
	fi
711507
711507
	# MACHO / readobj
711507
	if [ -n "$ccenv_readobj" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_readobj $ccenv_image 2>&3                  \
fa64c0
				| grep -i 'Format:'                  \
fa64c0
				| sed  -e 's/ /_/g'                  \
ec40cb
				| grep -i '_Mach-O_'                 \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_readobj=yes
ec40cb
		fi
711507
	fi
711507
711507
	# MACHO / objdump (llvm)
711507
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
ec40cb
		if $ccenv_objdump -section-headers $ccenv_image  \
bbde52
					2>&3                     \
ec40cb
				| grep -i 'file format Mach-O'   \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='MACHO'
ec40cb
			ccenv_use_objdump=yes
ec40cb
		fi
711507
	fi
711507
711507
	# MACHO / objdump (bfd)
711507
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		$ccenv_objdump -h  $ccenv_image 2>&3              \
711507
			| grep -i 'file format Mach-O'            \
711507
				> /dev/null                       \
711507
		&& ccenv_cc_binfmt='MACHO'                        \
711507
		&& ccenv_use_objdump=yes
711507
	fi
711507
711507
	# PE / objdump (bfd)
711507
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
bbde52
		if $ccenv_objdump -h  $ccenv_image 2>&3        \
ec40cb
				| grep -i 'file format pei-'   \
ec40cb
					> /dev/null; then
ec40cb
			ccenv_cc_binfmt='PE'
ec40cb
			ccenv_use_bfd_objdump=yes
ec40cb
		fi
711507
	fi
188a79
188a79
	ccenv_attr_epilog "$ccenv_cc_binfmt"
711507
}
711507
711507
ccenv_set_os_pe()
711507
{
711507
	if [ -n "$ccenv_freestd" ]; then
711507
		case "$ccenv_cchost" in
711507
			*-midipix | *-midipix-* )
711507
				ccenv_os='midipix' ;;
711507
			*-mingw | *-mingw32 | *-mingw64 )
711507
				ccenv_os='mingw' ;;
711507
			*-mingw-* | *-mingw32-* | *-mingw64 )
711507
				ccenv_os='mingw' ;;
711507
			*-msys | *-msys2 | *-msys-* | *-msys2-* )
711507
				ccenv_os='msys' ;;
711507
			*-cygwin | *-cygwin-* )
711507
				ccenv_os='cygwin' ;;
711507
		esac
711507
	fi
711507
711507
	if [ -n "$ccenv_os" ]; then
711507
		return 0
711507
	fi
711507
711507
	if [ -n "$ccenv_use_perk" ]; then
711507
		ccenv_framework=$($ccenv_perk -y $ccenv_image)
711507
		ccenv_os=${ccenv_framework#*-*-*-*}
711507
	fi
711507
711507
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
711507
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
711507
			| grep 'cygwin1.dll' > /dev/null                \
711507
		&& ccenv_os='cygwin'
711507
	fi
711507
711507
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
711507
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
711507
			| grep 'msys-2.0.dll' > /dev/null               \
711507
		&& ccenv_os='msys'
711507
	fi
711507
711507
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
711507
		$ccenv_objdump_bfd -x $ccenv_image          \
711507
			| grep -i 'DLL Name' | grep '.CRT'  \
711507
				> /dev/null                 \
711507
		&& $ccenv_objdump_bfd -x $ccenv_image       \
711507
			| grep -i 'DLL Name' | grep '.bss'  \
711507
				> /dev/null                 \
711507
		&& $ccenv_objdump_bfd -x $ccenv_image       \
711507
			| grep -i 'DLL Name' | grep '.tls'  \
711507
				> /dev/null                 \
711507
		&& ccenv_os='mingw'
711507
	fi
711507
}
711507
711507
ccenv_set_os_macho()
711507
{
711507
	case "$ccenv_cchost" in
711507
		*-apple-darwin* )
711507
			ccenv_os='darwin' ;;
711507
	esac
711507
}
711507
711507
ccenv_set_os()
711507
{
188a79
	ccenv_attr_prolog 'os name'
188a79
711507
	case "$ccenv_cc_binfmt" in
711507
		PE )
711507
			ccenv_set_os_pe ;;
711507
		MACHO )
711507
			ccenv_set_os_macho ;;
711507
	esac
711507
711507
	if [ -n "$ccenv_os" ]; then
188a79
		ccenv_attr_epilog "$ccenv_os"
711507
		return 0
711507
	fi
711507
711507
	case "$ccenv_cchost" in
711507
		*-*-*-* )
80c2c2
			ccenv_tip=${ccenv_cchost%-*}
711507
			ccenv_os=${ccenv_tip#*-*-}
711507
			;;
80c2c2
		*-*-musl | *-*-gnu )
80c2c2
			ccenv_tip=${ccenv_cchost%-*}
711507
			ccenv_os=${ccenv_tip#*-}
711507
			;;
80c2c2
		*-*-* )
80c2c2
			ccenv_os=${ccenv_cchost#*-*-}
80c2c2
			;;
80c2c2
		*-* )
80c2c2
			ccenv_os=${ccenv_cchost#*-}
80c2c2
			;;
711507
	esac
711507
711507
	if [ -z "$ccenv_os" ]; then
711507
		ccenv_os='anyos'
711507
	fi
188a79
188a79
	ccenv_attr_epilog "$ccenv_os"
711507
}
711507
711507
ccenv_set_os_flags()
711507
{
711507
	case "$ccenv_os" in
711507
		darwin )
711507
			ccenv_cflags_os='-D_DARWIN_C_SOURCE'
711507
			ccenv_cflags_pic='-fPIC'
711507
			;;
711507
		midipix )
711507
			ccenv_cflags_os=
711507
			ccenv_cflags_pic='-fPIC'
711507
			;;
711507
		cygwin )
711507
			ccenv_cflags_os=
711507
			ccenv_cflags_pic=
711507
			;;
711507
		msys | msys* | mingw | mingw* )
711507
			ccenv_cflags_os='-U__STRICT_ANSI__'
711507
			ccenv_cflags_pic=
711507
			;;
711507
		* )
711507
			ccenv_cflags_os=
711507
			ccenv_cflags_pic='-fPIC'
711507
			;;
711507
	esac
711507
}
711507
711507
ccenv_set_os_semantics()
711507
{
711507
	# binary_format - core_api - ex_api - dependency_resolution
711507
188a79
	ccenv_attr_prolog 'os semantics'
188a79
711507
	case "$ccenv_os" in
711507
		linux )
711507
			ccenv_os_semantics='elf-posix-linux-ldso'
711507
			;;
711507
		bsd )
711507
			ccenv_os_semantics='elf-posix-bsd-ldso'
711507
			;;
711507
		darwin )
711507
			ccenv_os_semantics='macho-posix-osx-ldso'
711507
			;;
711507
		midipix )
711507
			ccenv_os_semantics='pe-posix-winnt-ldso'
711507
			;;
711507
		cygwin )
711507
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
711507
			;;
711507
		msys )
711507
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
711507
			;;
711507
		mingw )
711507
			ccenv_os_semantics='pe-win32-winnt-unsafe'
711507
			;;
711507
	esac
711507
711507
	if [ -n "$ccenv_os_semantics" ]; then
188a79
		ccenv_attr_epilog "$ccenv_os_semantics"
711507
		return 0
711507
	fi
711507
711507
	if [ -n "$ccenv_cc_binfmt" ]; then
711507
		ccenv_os_semantics_pattern='%s-posix-anyos-unknown'
711507
		ccenv_os_semantics=$(printf                   \
711507
				"$ccenv_os_semantics_pattern"  \
711507
				"$ccenv_cc_binfmt"              \
711507
			| tr '[:upper:]' '[:lower:]')
711507
	else
711507
		ccenv_os_semantics='unknown-posix-anyos-unknown'
711507
	fi
188a79
188a79
	ccenv_attr_epilog "$ccenv_os_semantics"
711507
}
711507
89ad20
ccenv_set_os_dso_format()
89ad20
{
89ad20
	ccenv_attr_prolog 'os dso format'
89ad20
89ad20
	case "$ccenv_cc_arfmt" in
89ad20
		common )
89ad20
			ccenv_cc_sofmt="$ccenv_cc_binfmt"
89ad20
			;;
89ad20
89ad20
		bigaf )
89ad20
			ccenv_libgcc_s_a_header=$(od -b -N8             \
89ad20
				$($ccenv_cc -print-file-name=libgcc_s.a) \
89ad20
					2>/dev/null                       \
89ad20
					| head -n1)
89ad20
89ad20
			ccenv_libgcc_s_so_header=$(od -b -N8             \
89ad20
				$($ccenv_cc -print-file-name=libgcc_s.so) \
89ad20
					2>/dev/null                        \
89ad20
					| head -n1)
89ad20
89ad20
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_bigaf_header" ]; then
89ad20
				ccenv_cc_sofmt='bigaf'
89ad20
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_bigaf_header" ]; then
89ad20
				ccenv_cc_sofmt='bigaf'
89ad20
			else
89ad20
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
89ad20
			fi
89ad20
			;;
89ad20
89ad20
		aiaff )
89ad20
			ccenv_libgcc_s_a_header=$(od -b -N8               \
89ad20
				$($ccenv_cc -print-file-name=libgcc_s.a) \
89ad20
					| head -n1)
89ad20
89ad20
			ccenv_libgcc_s_so_header=$(od -b -N8               \
89ad20
				$($ccenv_cc -print-file-name=libgcc_s.so) \
89ad20
					| head -n1)
89ad20
89ad20
			if [ "$ccenv_libgcc_s_a_header" = "$ccenv_aiaff_header" ]; then
89ad20
				ccenv_cc_sofmt='aiaff'
89ad20
			elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_aiaff_header" ]; then
89ad20
				ccenv_cc_sofmt='aiaff'
89ad20
			else
89ad20
				ccenv_cc_sofmt="$ccenv_cc_binfmt"
89ad20
			fi
89ad20
			;;
89ad20
	esac
89ad20
da740f
	if [ "$ccenv_cfgtype" = 'host' ]; then
da740f
		case "$ccenv_cc_sofmt" in
da740f
			bigaf | aiaff )
da740f
				mb_shared_lib_cmd='$(AR) -rcs'
da740f
				mb_shared_lib_ldflags=
da740f
				;;
da740f
da740f
			* )
da740f
				mb_shared_lib_cmd='$(CC) -shared -o'
da740f
				mb_shared_lib_ldflags='$(LDFLAGS_SHARED)'
da740f
				;;
da740f
		esac
da740f
	fi
da740f
89ad20
	ccenv_attr_epilog "$ccenv_cc_sofmt"
89ad20
}
89ad20
711507
ccenv_set_os_dso_exrules()
711507
{
188a79
	ccenv_attr_prolog 'os dso exrules'
188a79
711507
	case "$ccenv_os" in
711507
		midipix )
711507
			ccenv_os_dso_exrules='pe-mdso'
711507
			;;
711507
		* )
711507
			if [ "$ccenv_cc_binfmt" = 'PE' ]; then
711507
				ccenv_os_dso_exrules='pe-dlltool'
711507
			else
711507
				ccenv_os_dso_exrules='default'
711507
			fi
711507
	esac
188a79
188a79
	ccenv_attr_epilog "$ccenv_os_dso_exrules"
711507
}
711507
711507
ccenv_set_os_dso_linkage()
711507
{
711507
	# todo: PIC, PIE, and friends
188a79
	ccenv_attr_prolog 'os linkage'
711507
	ccenv_os_dso_linkage='default'
188a79
	ccenv_attr_epilog "$ccenv_os_dso_linkage"
711507
}
711507
711507
ccenv_set_os_dso_patterns_darwin()
711507
{
711507
	ccenv_os_app_prefix=
711507
	ccenv_os_app_suffix=
711507
711507
	ccenv_os_lib_prefix=lib
711507
	ccenv_os_lib_suffix=.dylib
711507
711507
	ccenv_os_implib_ext=.invalid
711507
	ccenv_os_libdef_ext=.invalid
711507
711507
	ccenv_os_archive_ext=.a
711507
	ccenv_os_soname=symlink
711507
711507
	ccenv_os_lib_prefixed_suffix=
711507
	ccenv_os_lib_suffixed_suffix='$(OS_LIB_SUFFIX)'
711507
}
711507
711507
ccenv_set_os_dso_patterns_mdso()
711507
{
711507
	ccenv_os_app_prefix=
711507
	ccenv_os_app_suffix=
711507
711507
	ccenv_os_lib_prefix=lib
711507
	ccenv_os_lib_suffix=.so
711507
711507
	ccenv_os_implib_ext=.lib.a
711507
	ccenv_os_libdef_ext=.so.def
711507
711507
	ccenv_os_archive_ext=.a
711507
	ccenv_os_soname=symlink
711507
711507
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
711507
	ccenv_os_lib_suffixed_suffix=
711507
}
711507
711507
ccenv_set_os_dso_patterns_dlltool()
711507
{
711507
	ccenv_os_app_prefix=
711507
	ccenv_os_app_suffix=.exe
711507
711507
	ccenv_os_lib_prefix=lib
711507
	ccenv_os_lib_suffix=.dll
711507
711507
	ccenv_os_implib_ext=.dll.a
711507
	ccenv_os_libdef_ext=.def
711507
711507
	ccenv_os_archive_ext=.a
711507
	ccenv_os_soname=copy
711507
711507
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
711507
	ccenv_os_lib_suffixed_suffix=
711507
}
711507
711507
ccenv_set_os_dso_patterns_default()
711507
{
711507
	ccenv_os_app_prefix=
711507
	ccenv_os_app_suffix=
711507
711507
	ccenv_os_lib_prefix=lib
711507
	ccenv_os_lib_suffix=.so
711507
711507
	ccenv_os_implib_ext=.invalid
711507
	ccenv_os_libdef_ext=.invalid
711507
711507
	ccenv_os_archive_ext=.a
711507
	ccenv_os_soname=symlink
711507
711507
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
711507
	ccenv_os_lib_suffixed_suffix=
711507
}
711507
711507
ccenv_set_os_dso_patterns()
711507
{
711507
	# sover: .so.x.y.z
711507
	# verso: .x.y.z.so
711507
711507
	case "$ccenv_os" in
711507
		darwin )
711507
			ccenv_set_os_dso_patterns_darwin
711507
			;;
711507
		midipix )
711507
			ccenv_set_os_dso_patterns_mdso
711507
			;;
711507
		cygwin | msys | mingw )
711507
			ccenv_set_os_dso_patterns_dlltool
711507
			;;
711507
		* )
711507
			ccenv_set_os_dso_patterns_default
711507
			;;
711507
	esac
711507
}
711507
ad1be2
ccenv_set_os_pe_switches()
ad1be2
{
3ffbfe
	if [ "$ccenv_cc_binfmt" = 'PE' ] && [ -z "$ccenv_pe_subsystem" ]; then
ad1be2
		case "$ccenv_os" in
ad1be2
			midipix | mingw )
ad1be2
				ccenv_pe_subsystem='windows'
ad1be2
				;;
ad1be2
			* )
ad1be2
				ccenv_pe_subsystem='console'
ad1be2
				;;
ad1be2
		esac
ad1be2
	fi
ad1be2
}
ad1be2
711507
ccenv_output_defs()
711507
{
711507
	ccenv_in="$mb_project_dir/sofort/ccenv/ccenv.in"
711507
	ccenv_mk="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
a9069f
	ccenv_tmp=
711507
ad1be2
	if [ "$ccenv_cc_binfmt" = 'PE' ]; then
ad1be2
		ccenv_pe="$mb_project_dir/sofort/ccenv/pedefs.in"
ad1be2
		ccenv_in="$ccenv_in $ccenv_pe"
ad1be2
	fi
ad1be2
711507
	if [ $ccenv_cfgtype = 'native' ]; then
711507
1cc479
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
711507
4ab906
		sed                                      \
801bf0
				-e 's/^[[:space:]]*$/@/g' \
4ab906
				-e 's/^/NATIVE_/'          \
4ab906
				-e 's/NATIVE_@//g'          \
4ab906
				-e 's/NATIVE_#/#/g'          \
4ab906
				-e 's/       =/=/g'           \
4ab906
				-e 's/       +=/+=/g'          \
ad1be2
			$ccenv_in > "$ccenv_tmp"
711507
711507
		ccenv_in="$ccenv_tmp"
1cc479
	else
a9069f
		unset ccenv_tmp
711507
	fi
711507
711507
	ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
711507
			| grep -v '^#')
711507
711507
	ccenv_exvars="ccenv_cfgtype ccenv_makevar_prefix"
711507
711507
	ccenv_sed_substs=" \
7d9a2d
		$(for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do \
711507
			printf '%s"$%s"%s' "-e 's/@$__var@/'" \
711507
				"$__var" "'/g' ";              \
711507
		done)"
711507
ad1be2
	eval sed $ccenv_sed_substs $ccenv_in   \
e4cf2f
			| sed -e 's/[[:blank:]]*$//g' \
711507
		> "$ccenv_mk"
711507
8fd818
	if [ "$ccenv_cfgtype" = 'host' ]; then
7d9a2d
		for __var in $(printf '%s' "$ccenv_vars"); do
8fd818
			ccenv_src_var=$__var
8fd818
			ccenv_dst_var=mb_${__var#*ccenv_}
8fd818
			ccenv_var_expr='${'$ccenv_src_var':-}'
8fd818
			eval $ccenv_dst_var=$ccenv_var_expr
8fd818
8fd818
		done
8fd818
8fd818
		mb_host=$ccenv_host
8fd818
		mb_cchost=$ccenv_cchost
8fd818
	else
7d9a2d
		for __var in $(printf '%s' "$ccenv_vars"); do
8fd818
			ccenv_src_var=$__var
8fd818
			ccenv_dst_var=mb_native_${__var#*ccenv_}
8fd818
			ccenv_var_expr='${'$ccenv_src_var':-}'
8fd818
			eval "$ccenv_dst_var=$ccenv_var_expr"
8fd818
		done
8fd818
8fd818
		mb_native_host=$ccenv_host
8fd818
		mb_native_cchost=$ccenv_cchost
8fd818
	fi
1cc479
1cc479
	if [ -n "${ccenv_tmp:-}" ]; then
1cc479
		rm -f "$ccenv_tmp"
1cc479
		unset ccenv_tmp
1cc479
	fi
711507
}
711507
5dbfba
ccenv_dso_verify()
5dbfba
{
5dbfba
	ccenv_str='int foo(int x){return ++x;}'
5dbfba
	ccenv_cmd="$ccenv_cc -xc - -shared -o a.out"
5dbfba
5dbfba
	rm -f a.out
5dbfba
03b8d4
	printf '%s' "$ccenv_str" | $(printf %s "$ccenv_cmd") \
bbde52
		> /dev/null 2>&3              \
5dbfba
	|| mb_disable_shared=yes
5dbfba
5dbfba
	rm -f a.out
5dbfba
}
5dbfba
711507
ccenv_clean_up()
711507
{
711507
	rm -f $ccenv_image
711507
}
711507
711507
ccenv_common_init()
711507
{
711507
	. "$mb_project_dir/sofort/ccenv/ccenv.vars"
711507
711507
	ccenv_cfgtype=$1
711507
	ccenv_cfgfile="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
711507
	ccenv_freestd=
5b51ca
	ccenv_cchost=
711507
711507
	if [ $ccenv_cfgtype = 'native' ]; then
711507
		ccenv_makevar_prefix='NATIVE_'
711507
		ccenv_image='./ccenv/native.a.out'
711507
	else
711507
		ccenv_makevar_prefix=
711507
		ccenv_image='./ccenv/host.a.out'
711507
	fi
711507
711507
	if [ $ccenv_cfgtype = 'native' ]; then
711507
		ccenv_prefixes=
711507
	elif [ -n "$mb_cross_compile" ]; then
711507
		ccenv_prefixes="$mb_cross_compile"
711507
	elif [ -n "$mb_host" ]; then
711507
		ccenv_prefixes="$mb_host-"
711507
	else
711507
		ccenv_prefixes=
711507
	fi
711507
711507
	if [ $ccenv_cfgtype = 'host' ]; then
711507
		ccenv_tflags=
2e3df6
		ccenv_cflags=$(${mb_make} -s -f "$mb_pwd/Makefile.tmp" \
2e3df6
			OS_DSO_EXRULES=default                          \
2e3df6
			OS_SONAME=symlink                                \
1a7e55
			OS_ARCHIVE_EXT='.a'                               \
2e3df6
			.cflags-host)
1541ba
711507
		ccenv_cc="$mb_user_cc"
711507
		ccenv_cpp="$mb_user_cpp"
711507
		ccenv_cxx="$mb_user_cxx"
ad1be2
ad1be2
		ccenv_pe_subsystem="$mb_pe_subsystem"
ad1be2
		ccenv_pe_image_base="$mb_pe_image_base"
711507
	else
711507
		ccenv_tflags=
2e3df6
		ccenv_cflags=$(${mb_make} -s -f "$mb_pwd/Makefile.tmp" \
2e3df6
			OS_DSO_EXRULES=default                          \
2e3df6
			OS_SONAME=symlink                                \
1a7e55
			OS_ARCHIVE_EXT='.a'                               \
2e3df6
			.cflags-native)
2e3df6
711507
		ccenv_cc="$mb_native_cc"
711507
		ccenv_cpp="$mb_native_cpp"
711507
		ccenv_cxx="$mb_native_cxx"
ad1be2
ad1be2
		ccenv_pe_subsystem="$mb_native_pe_subsystem"
ad1be2
		ccenv_pe_image_base="$mb_native_pe_image_base"
711507
	fi
711507
}
711507
711507
ccenv_set_characteristics()
711507
{
711507
	ccenv_set_cc_host
711507
	ccenv_set_cc_bits
711507
	ccenv_set_cc_binfmt
188a79
	ccenv_set_cc_underscore
711507
}
711507
711507
ccenv_set_toolchain_variables()
711507
{
711507
	ccenv_common_init $1
711507
	ccenv_set_cc
711507
	ccenv_set_cpp
711507
	ccenv_set_cxx
711507
	ccenv_set_primary_tools
711507
	ccenv_set_tool_variants
711507
	ccenv_set_characteristics
711507
711507
	ccenv_set_os
711507
	ccenv_set_os_flags
711507
	ccenv_set_os_semantics
89ad20
	ccenv_set_os_dso_format
711507
	ccenv_set_os_dso_exrules
711507
	ccenv_set_os_dso_linkage
711507
	ccenv_set_os_dso_patterns
ad1be2
	ccenv_set_os_pe_switches
711507
711507
	ccenv_output_defs
711507
	ccenv_clean_up
1541ba
f76024
	eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\'
711507
}
711507
711507
ccenv_set_host_variables()
711507
{
188a79
	output_script_status ${mb_script} \
7df17c
		'detect and query host (targeted) system'
188a79
711507
	ccenv_set_toolchain_variables 'host'
5dbfba
	ccenv_dso_verify
711507
}
711507
711507
ccenv_set_native_variables()
711507
{
188a79
	output_script_status ${mb_script} \
7df17c
		'detect and query native (local build) system'
188a79
b28199
	if [ _$mb_ccenv_skip_native != _yes ]; then
b28199
		ccenv_set_toolchain_variables 'native'
b28199
	fi
711507
}