Blame sofort/ccenv/ccenv.sh

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