Blame sofort/ccenv/ccenv.sh

97f8b2
# ccenv.sh: sofort's tool-finding bits,
97f8b2
# invoked from within the project-agnostic configure script.
97f8b2
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
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
97f8b2
ccenv_find_tool()
97f8b2
{
97f8b2
	if [ -z "$ccenv_prefixes" ]; then
9bd82c
		for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
5b8144
			if [ -z ${@:-} ]; 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
b8d2fe
					if "$ccenv_candidate" $@ > /dev/null 2>&1; 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"
97f8b2
	ccenv_peep_tools="perk mdso dlltool windmc windres"
97f8b2
9bd82c
	for __tool in $(printf '%s' "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do
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
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
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"
97f8b2
		else
97f8b2
			ccenv_find_tool
97f8b2
			eval ccenv_$__tool="$ccenv_tool"
97f8b2
		fi
97f8b2
	done
97f8b2
97f8b2
	# windrc
97f8b2
	ccenv_windrc="$ccenv_windres"
97f8b2
}
97f8b2
97f8b2
ccenv_set_tool_variants()
97f8b2
{
97f8b2
	# as (asm)
97f8b2
	ccenv_candidates=as
97f8b2
	ccenv_find_tool
97f8b2
97f8b2
	if [ "$ccenv_tool" = false ]; then
97f8b2
		ccenv_as_asm=
97f8b2
	else
97f8b2
		$ccenv_tool --help | grep -i '.bc assembler' \
97f8b2
		|| ccenv_as_asm="$ccenv_tool"
97f8b2
	fi
97f8b2
97f8b2
	# 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
97f8b2
	# 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
97f8b2
	# 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
97f8b2
	# 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
97f8b2
	# 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
97f8b2
	# 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
97f8b2
	# 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
97f8b2
	# 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
97f8b2
	# 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
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
97f8b2
		ccenv_candidates="c99 c11 cc gcc clang"
97f8b2
	fi
97f8b2
}
97f8b2
97f8b2
97f8b2
ccenv_set_cc()
97f8b2
{
97f8b2
	if [ -z "$ccenv_cc" ]; then
97f8b2
		ccenv_set_c_compiler_candidates
5b8144
		ccenv_find_tool -dumpmachine
97f8b2
		ccenv_cc="$ccenv_tool"
97f8b2
	fi
97f8b2
97f8b2
	if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
97f8b2
		ccenv_cc="$mb_compiler"
97f8b2
	fi
97f8b2
97f8b2
	ccenv_cc_cmd="$ccenv_cc"
97f8b2
97f8b2
	if [ "$ccenv_cfgtype" = 'native' ]; then
1b92d3
		ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>/dev/null)
46f334
		ccenv_cchost=$ccenv_host
97f8b2
		return 0
97f8b2
	fi
97f8b2
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
97f8b2
	if [ -z "$ccenv_host" ]; then
1b92d3
		ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>/dev/null)
97f8b2
		ccenv_cchost=$ccenv_host
97f8b2
	else
4b04d8
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
97f8b2
		ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -"
97f8b2
97f8b2
		if [ -z "$mb_user_cc" ]; then
97f8b2
			$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
97f8b2
				ccenv_tflags="--target=$ccenv_host"
97f8b2
				ccenv_cc="$ccenv_cc $ccenv_tflags"
97f8b2
			fi
97f8b2
		fi
97f8b2
4b04d8
		rm -f "$ccenv_tmp"
4b04d8
		unset ccenv_tmp
4b04d8
1b92d3
		ccenv_cchost=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>/dev/null)
97f8b2
	fi
97f8b2
97f8b2
	if [ "$ccenv_cchost" != "$ccenv_host" ]; then
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
{
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"
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
97f8b2
}
97f8b2
97f8b2
ccenv_set_cxx()
97f8b2
{
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 )
97f8b2
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
97f8b2
			ccenv_candidates="${ccenv_cpp_prefix}g++" ;;
97f8b2
97f8b2
		*-clang )
97f8b2
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
97f8b2
			ccenv_candidates="${ccenv_cpp_prefix}clang++" ;;
97f8b2
97f8b2
		*cc )
97f8b2
			ccenv_cxx_prefix=${ccenv_cc_cmd%cc*}
97f8b2
			ccenv_candidates="${ccenv_cpp_prefix}++" ;;
97f8b2
97f8b2
		* )
97f8b2
			ccenv_cxx="$ccenv_cc -xc++"
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
97f8b2
}
97f8b2
97f8b2
ccenv_set_cc_host()
97f8b2
{
97f8b2
	ccenv_cc_host="$ccenv_cchost"
97f8b2
}
97f8b2
97f8b2
ccenv_set_cc_bits()
97f8b2
{
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
97f8b2
		if [ -z $ccenv_internal_size ]; then
9bd82c
			ccenv_internal_str=$(printf '%s' "$ccenv_internal_test"  \
9bd82c
				"$ccenv_internal_type"                           \
97f8b2
				"$ccenv_internal_guess")
97f8b2
067777
			printf '%s' "$ccenv_internal_str"                   \
067777
					| $ccenv_cc -S -xc - -o -           \
067777
					  $(printf '%s' "$ccenv_cflags")    \
067777
				> /dev/null 2>/dev/null                     \
97f8b2
			&& ccenv_internal_size=$ccenv_internal_guess
97f8b2
		fi
97f8b2
	done
97f8b2
97f8b2
	ccenv_cc_bits=$ccenv_internal_size
97f8b2
}
97f8b2
97f8b2
ccenv_set_cc_underscore()
97f8b2
{
97f8b2
	ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe'
97f8b2
	ccenv_fn_code='int %s(void){return 0;}'
97f8b2
7611fd
	if printf "$ccenv_fn_code" $ccenv_fn_name  \
7611fd
			| $ccenv_cc -xc - -S -o -  \
7611fd
			| grep "^_$ccenv_fn_name:" \
7611fd
				> /dev/null; then
7611fd
		ccenv_cc_underscore='_'
7611fd
	fi
97f8b2
97f8b2
	return 0
97f8b2
}
97f8b2
97f8b2
ccenv_create_framework_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
	printf 'int main(void){return 0;}'  \
97f8b2
		| $ccenv_cc -xc -           \
97f8b2
			-o $ccenv_image     \
97f8b2
	|| return 1
97f8b2
97f8b2
	return 0
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
97f8b2
	printf 'int %s(void){return 0;}' "$ccenv_start_fn"  \
97f8b2
		| $ccenv_cc -xc -                           \
97f8b2
			-ffreestanding                      \
97f8b2
			-nostdlib -nostartfiles             \
97f8b2
			-o $ccenv_image                     \
97f8b2
	|| return 1
97f8b2
97f8b2
	ccenv_freestd=yes
97f8b2
97f8b2
	return 0
97f8b2
}
97f8b2
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
97f8b2
	ccenv_create_framework_executable               \
97f8b2
		|| ccenv_create_freestanding_executable \
97f8b2
		|| return 0
97f8b2
97f8b2
	# PE / perk
97f8b2
	if [ -n "$ccenv_perk" ]; then
7611fd
		if $ccenv_perk $ccenv_image 2>/dev/null; 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
7611fd
		if $ccenv_readelf -h $ccenv_image 2>/dev/null        \
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
7611fd
		if $ccenv_readany -h $ccenv_image 2>/dev/null        \
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
7611fd
		if $ccenv_otool -hv $ccenv_image 2>/dev/null \
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
7611fd
		if $ccenv_otool -hv $ccenv_image 2>/dev/null \
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
7611fd
		if $ccenv_readany -h $ccenv_image 2>/dev/null             \
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
7611fd
		if $ccenv_readany -h $ccenv_image 2>/dev/null             \
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
7611fd
		if $ccenv_readobj $ccenv_image 2>/dev/null           \
7611fd
				| grep -i 'Format:' | sed '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  \
7611fd
					2>/dev/null              \
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
97f8b2
		$ccenv_objdump -h  $ccenv_image 2>/dev/null       \
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
7611fd
		if $ccenv_objdump -h  $ccenv_image 2>/dev/null \
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
97f8b2
}
97f8b2
97f8b2
ccenv_set_os_pe()
97f8b2
{
97f8b2
	if [ -n "$ccenv_freestd" ]; 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
{
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
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
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
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
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
97f8b2
}
97f8b2
97f8b2
ccenv_set_os_dso_exrules()
97f8b2
{
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
97f8b2
}
97f8b2
97f8b2
ccenv_set_os_dso_linkage()
97f8b2
{
97f8b2
	# todo: PIC, PIE, and friends
97f8b2
	ccenv_os_dso_linkage='default'
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
97f8b2
		sed                             \
97f8b2
				-e 's/^\s*$/@/g' \
97f8b2
				-e 's/^/NATIVE_/' \
97f8b2
				-e 's/NATIVE_@//g' \
97f8b2
				-e 's/NATIVE_#/#/g' \
97f8b2
				-e 's/       =/=/g'  \
97f8b2
				-e 's/       +=/+=/g' \
a5dade
			$ccenv_in > "$ccenv_tmp"
97f8b2
97f8b2
		ccenv_in="$ccenv_tmp"
4b04d8
	else
04c49c
		unset ccenv_tmp
97f8b2
	fi
97f8b2
97f8b2
	ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
97f8b2
			| grep -v '^#')
97f8b2
97f8b2
	ccenv_exvars="ccenv_cfgtype ccenv_makevar_prefix"
97f8b2
97f8b2
	ccenv_sed_substs=" \
9bd82c
		$(for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do \
97f8b2
			printf '%s"$%s"%s' "-e 's/@$__var@/'" \
97f8b2
				"$__var" "'/g' ";              \
97f8b2
		done)"
97f8b2
a5dade
	eval sed $ccenv_sed_substs $ccenv_in   \
c4275b
			| 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
97f8b2
}
97f8b2
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
9d9c18
	printf '%s' "$ccenv_str" | $ccenv_cmd \
9d9c18
		> /dev/null 2>/dev/null       \
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"
97f8b2
	ccenv_freestd=
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=
97f8b2
		ccenv_cflags=$(make -s -f "$mb_pwd/Makefile.tmp" .display-cflags)
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=
97f8b2
		ccenv_cflags="$mb_native_cflags"
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_underscore
97f8b2
	ccenv_set_cc_binfmt
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
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
97f8b2
}
97f8b2
97f8b2
ccenv_set_host_variables()
97f8b2
{
97f8b2
	ccenv_set_toolchain_variables 'host'
9d9c18
	ccenv_dso_verify
97f8b2
}
97f8b2
97f8b2
ccenv_set_native_variables()
97f8b2
{
c2520c
	if [ _$mb_ccenv_skip_native != _yes ]; then
c2520c
		ccenv_set_toolchain_variables 'native'
c2520c
	fi
97f8b2
}