Blame sofort/ccenv/ccenv.sh

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