Blame sofort/ccenv/ccenv.sh

c0ca97
# ccenv.sh: sofort's tool-finding bits,
c0ca97
# invoked from within the project-agnostic configure script.
c0ca97
c0ca97
# invocation and names of binary tools:
c0ca97
# agnostic names (ar, nm, objdump, ...);
c0ca97
# target-prefixed agnostic names (x86_64-nt64-midipix-ar, ...);
c0ca97
# branded names (llvm-ar, llvm-nm, llvm-objdump, ...);
c0ca97
# target-prefixed branded names (x86_64-linux-gnu-gcc-ar, ...);
c0ca97
# target-specifying branded tools (llvm-ar --target=x86_64-linux, ...).
c0ca97
c0ca97
# cross-compilation: default search order:
c0ca97
# target-prefixed agnostic tools;
c0ca97
# target-prefixed branded tools, starting with the prefix
c0ca97
# most commonly associated with the selected compiler (that is,
c0ca97
# ``gcc'' when using gcc, and ``llvm'' when using clang);
c0ca97
# target-speficying branded tools, starting once again with the
c0ca97
# prefix most commonly associated with the selected compiler.
c0ca97
c0ca97
# internal variables of interest:
c0ca97
# ccenv_cfgtype: the type of host being tested (host/native)
c0ca97
# ccenv_cfgfile: the configuration file for the host being tested
c0ca97
# ccenv_cflags:  the comprehensive cflags for the host being tested
c0ca97
# ccenv_cchost:  the host being tested, as reported by -dumpmachine
c0ca97
c0ca97
c0ca97
ccenv_usage()
c0ca97
{
c0ca97
	cat "$mb_project_dir"/sofort/ccenv/ccenv.usage
c0ca97
	exit 0
c0ca97
}
c0ca97
c0ca97
c0ca97
ccenv_newline()
c0ca97
{
c0ca97
	printf '\n' >> "$ccenv_cfgfile"
c0ca97
}
c0ca97
c0ca97
c0ca97
ccenv_comment()
c0ca97
{
c0ca97
	ccenv_internal_str='#'
c0ca97
c0ca97
	for ccenv_internal_arg ; do
c0ca97
		ccenv_internal_str="$ccenv_internal_str $ccenv_internal_arg"
c0ca97
	done
c0ca97
c0ca97
	printf '%s\n' "$ccenv_internal_str" >> "$ccenv_cfgfile"
c0ca97
}
c0ca97
c0ca97
c0ca97
ccenv_find_tool()
c0ca97
{
c0ca97
	if [ -z "$ccenv_prefixes" ]; then
ce069b
		for ccenv_candidate in $(printf %s "$ccenv_candidates"); do
2c9647
			if [ -z ${@:-} ]; then
ce069b
				if command -v "$ccenv_candidate" > /dev/null; then
ce069b
					ccenv_tool="$ccenv_candidate"
2c9647
					return 0
96f2de
				fi
2c9647
			else
ce069b
				if command -v "$ccenv_candidate" > /dev/null; then
ce069b
					if "$ccenv_candidate" $@ > /dev/null 2>&1; then
ce069b
						ccenv_tool="$ccenv_candidate"
2c9647
						return 0
96f2de
					fi
96f2de
				fi
2c9647
			fi
c0ca97
		done
c0ca97
c0ca97
		ccenv_tool=false
c0ca97
c0ca97
		return 0
c0ca97
	fi
c0ca97
9dc723
	for ccenv_prefix in $(printf %s "$ccenv_prefixes"); do
9dc723
		for ccenv_candidate in $(printf %s "$ccenv_candidates"); do
c0ca97
			ccenv_tool="$ccenv_prefix$ccenv_candidate"
96f2de
96f2de
			if command -v "$ccenv_tool" > /dev/null; then
96f2de
				return 0
96f2de
			fi
c0ca97
		done
c0ca97
	done
c0ca97
ce069b
	for ccenv_candidate in $(printf %s "$ccenv_candidates"); do
ce069b
		if command -v "$ccenv_candidate" > /dev/null; then
ce069b
			ccenv_tool="$ccenv_candidate"
96f2de
			return 0
96f2de
		fi
c0ca97
	done
c0ca97
c0ca97
	ccenv_tool=false
c0ca97
c0ca97
	return 0
c0ca97
}
c0ca97
c0ca97
c0ca97
ccenv_set_primary_tools()
c0ca97
{
c0ca97
	ccenv_core_tools="ar nm objdump ranlib size strip strings objcopy"
47c52e
	ccenv_hack_tools="addr2line cov elfedit readelf readobj otool"
c0ca97
	ccenv_peep_tools="perk mdso dlltool windmc windres"
c0ca97
9dc723
	for __tool in $(printf %s "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do
c0ca97
		if [ -n "$mb_agnostic" ]; then
c0ca97
			ccenv_candidates=" $__tool"
c0ca97
c0ca97
		elif [ -n "$mb_zealous" ]; then
c0ca97
			ccenv_candidates="$mb_zealous-$__tool"
c0ca97
c0ca97
		elif [ "$mb_toolchain" = 'gcc' ]; then
c0ca97
			ccenv_candidates="gcc-$__tool"
c0ca97
			ccenv_candidates="$ccenv_candidates $__tool"
c0ca97
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
c0ca97
c0ca97
		elif [ "$mb_toolchain" = 'llvm' ]; then
c0ca97
			ccenv_candidates="llvm-$__tool"
c0ca97
			ccenv_candidates="$ccenv_candidates $__tool"
c0ca97
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
c0ca97
c0ca97
		elif [ -n "$mb_toolchain" ]; then
c0ca97
			ccenv_candidates="$mb_toolchain-$__tool"
c0ca97
			ccenv_candidates="$ccenv_candidates $__tool"
c0ca97
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
c0ca97
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
c0ca97
c0ca97
		else
c0ca97
			ccenv_candidates="$__tool"
c0ca97
			ccenv_candidates="$ccenv_candidates gcc-$__tool"
c0ca97
			ccenv_candidates="$ccenv_candidates llvm-$__tool"
c0ca97
		fi
c0ca97
c0ca97
		if [ "$ccenv_cfgtype" = 'host' ]; then
c0ca97
			ccenv_var_prefix='mb_'
c0ca97
		else
c0ca97
			ccenv_var_prefix='mb_native_'
c0ca97
		fi
c0ca97
c0ca97
		ccenv_var_name=$ccenv_var_prefix$__tool
c0ca97
		ccenv_var_expr='${'$ccenv_var_name':-}'
c0ca97
		eval ccenv_var_val=$ccenv_var_expr
c0ca97
c0ca97
		if [ -n "$ccenv_var_val" ]; then
c0ca97
			eval ccenv_$__tool="$ccenv_var_val"
c0ca97
		else
c0ca97
			ccenv_find_tool
c0ca97
			eval ccenv_$__tool="$ccenv_tool"
c0ca97
		fi
c0ca97
	done
c0ca97
c0ca97
	# windrc
c0ca97
	ccenv_windrc="$ccenv_windres"
c0ca97
}
c0ca97
c0ca97
ccenv_set_tool_variants()
c0ca97
{
c0ca97
	# as (asm)
c0ca97
	ccenv_candidates=as
c0ca97
	ccenv_find_tool
c0ca97
c0ca97
	if [ "$ccenv_tool" = false ]; then
c0ca97
		ccenv_as_asm=
c0ca97
	else
c0ca97
		$ccenv_tool --help | grep -i '.bc assembler' \
c0ca97
		|| ccenv_as_asm="$ccenv_tool"
c0ca97
	fi
c0ca97
c0ca97
	# as (ll)
c0ca97
	ccenv_candidates=llvm-as
c0ca97
	ccenv_find_tool
c0ca97
c0ca97
	if [ "$ccenv_tool" != false ]; then
c0ca97
		ccenv_as_ll="$ccenv_tool"
c0ca97
	fi
c0ca97
c0ca97
	# as (mc)
c0ca97
	ccenv_candidates=llvm-mc
c0ca97
	ccenv_find_tool
c0ca97
c0ca97
	if [ "$ccenv_tool" != false ]; then
c0ca97
		ccenv_as_mc="$ccenv_tool"
c0ca97
	fi
c0ca97
c0ca97
	# ld (bfd)
c0ca97
	ccenv_candidates=ld.bfd
c0ca97
	ccenv_find_tool
c0ca97
c0ca97
	if [ "$ccenv_tool" != false ]; then
c0ca97
		ccenv_ld_bfd="$ccenv_tool"
c0ca97
	fi
c0ca97
c0ca97
	# ld (gold)
c0ca97
	ccenv_candidates=ld.gold
c0ca97
	ccenv_find_tool
c0ca97
c0ca97
	if [ "$ccenv_tool" != false ]; then
c0ca97
		ccenv_ld_gold="$ccenv_tool"
c0ca97
	fi
c0ca97
c0ca97
	# ld (lld)
c0ca97
	ccenv_candidates=lld
c0ca97
	ccenv_find_tool
c0ca97
c0ca97
	if [ "$ccenv_tool" != false ]; then
c0ca97
		ccenv_ld_lld="$ccenv_tool"
c0ca97
	fi
c0ca97
c0ca97
	# objdump (bfd)
c0ca97
	ccenv_candidates=objdump
c0ca97
	ccenv_find_tool
c0ca97
24ebb0
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
24ebb0
		ccenv_objdump_bfd="$ccenv_tool"
24ebb0
	fi
c0ca97
c0ca97
	# objdump (llvm)
c0ca97
	ccenv_candidates=llvm-objdump
c0ca97
	ccenv_find_tool
c0ca97
24ebb0
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
24ebb0
		ccenv_objdump_llvm="$ccenv_tool"
24ebb0
	fi
c0ca97
c0ca97
	# readelf (bfd)
c0ca97
	ccenv_candidates=readelf
c0ca97
	ccenv_find_tool
c0ca97
24ebb0
	if $ccenv_tool --version | grep -i Binutils > /dev/null; then
24ebb0
		ccenv_readelf_bfd="$ccenv_tool"
24ebb0
	fi
c0ca97
c0ca97
	# readelf (llvm)
c0ca97
	ccenv_candidates=llvm-readelf
c0ca97
	ccenv_find_tool
c0ca97
24ebb0
	if $ccenv_tool --version | grep -i LLVM > /dev/null; then
24ebb0
		ccenv_readelf_llvm="$ccenv_tool"
24ebb0
	fi
c0ca97
c0ca97
	# as
c0ca97
	if [ -n "$ccenv_cc" ]; then
48da05
		ccenv_as='$('"$ccenv_makevar_prefix"'CC) -c -x assembler'
c0ca97
	elif [ -n "$mb_agnostic" ]; then
c0ca97
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
c0ca97
	elif [ "$mb_zealous" = 'gcc' ]; then
c0ca97
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
c0ca97
	elif [ -n "$mb_zealous" = 'llvm' ]; then
c0ca97
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
c0ca97
	elif [ "$mb_toolchain" = 'gcc' ]; then
c0ca97
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
c0ca97
	elif [ "$mb_toolchain" = 'llvm' ]; then
c0ca97
		ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
c0ca97
	fi
c0ca97
c0ca97
	# ld
c0ca97
	if [ -n "$ccenv_cc" ]; then
c0ca97
		ccenv_ld='$('"$ccenv_makevar_prefix"'CC) -nostdlib -nostartfiles'
c0ca97
	fi
c0ca97
}
c0ca97
c0ca97
ccenv_set_c_compiler_candidates()
c0ca97
{
c0ca97
	if   [ -n "$mb_compiler" ]; then
c0ca97
		ccenv_candidates="$mb_compiler"
c0ca97
c0ca97
	elif [ -n "$mb_agnostic" ]; then
c0ca97
		ccenv_candidates="c99 c11 cc"
c0ca97
c0ca97
	elif [ "$mb_zealous" = 'gcc' ]; then
c0ca97
		ccenv_candidates="gcc"
c0ca97
c0ca97
	elif [ "$mb_zealous" = 'llvm' ]; then
c0ca97
		ccenv_candidates="clang"
c0ca97
c0ca97
	elif [ "$mb_toolchain" = 'gcc' ]; then
c0ca97
		ccenv_candidates="gcc c99 c11 cc clang"
c0ca97
c0ca97
	elif [ "$mb_toolchain" = 'llvm' ]; then
c0ca97
		ccenv_candidates="clang c99 c11 cc gcc"
c0ca97
c0ca97
	elif [ -n "$mb_toolchain" ]; then
c0ca97
		ccenv_candidates="$mb_toolchain c99 c11 cc gcc clang"
c0ca97
c0ca97
	else
c0ca97
		ccenv_candidates="c99 c11 cc gcc clang"
c0ca97
	fi
c0ca97
}
c0ca97
c0ca97
c0ca97
ccenv_set_cc()
c0ca97
{
c0ca97
	if [ -z "$ccenv_cc" ]; then
c0ca97
		ccenv_set_c_compiler_candidates
2c9647
		ccenv_find_tool -dumpmachine
c0ca97
		ccenv_cc="$ccenv_tool"
c0ca97
	fi
c0ca97
c0ca97
	if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
c0ca97
		ccenv_cc="$mb_compiler"
c0ca97
	fi
c0ca97
c0ca97
	ccenv_cc_cmd="$ccenv_cc"
c0ca97
c0ca97
	if [ "$ccenv_cfgtype" = 'native' ]; then
f7005f
		ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>/dev/null)
c00fea
		ccenv_cchost=$ccenv_host
c0ca97
		return 0
c0ca97
	fi
c0ca97
c0ca97
	if [ -n "$mb_cchost" ]; then
c0ca97
		ccenv_host="$mb_cchost"
c0ca97
	elif [ -n "$mb_host" ]; then
c0ca97
		ccenv_host="$mb_host"
c0ca97
	else
c0ca97
		ccenv_host=
c0ca97
	fi
c0ca97
c0ca97
	if [ -z "$ccenv_host" ]; then
f7005f
		ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>/dev/null)
c0ca97
		ccenv_cchost=$ccenv_host
c0ca97
	else
5664b7
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
c0ca97
		ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -"
c0ca97
c0ca97
		if [ -z "$mb_user_cc" ]; then
c0ca97
			$ccenv_cmd < /dev/null > /dev/null \
c0ca97
				2>"$ccenv_tmp" || true
c0ca97
c0ca97
			ccenv_errors=$(cat "$ccenv_tmp")
c0ca97
c0ca97
			if [ -z "$ccenv_errors" ]; then
c0ca97
				ccenv_tflags="--target=$ccenv_host"
c0ca97
				ccenv_cc="$ccenv_cc $ccenv_tflags"
c0ca97
			fi
c0ca97
		fi
c0ca97
5664b7
		rm -f "$ccenv_tmp"
5664b7
		unset ccenv_tmp
5664b7
f7005f
		ccenv_cchost=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>/dev/null)
c0ca97
	fi
c0ca97
c0ca97
	if [ "$ccenv_cchost" != "$ccenv_host" ]; then
c0ca97
		printf 'ccenv:\n' >&2
c0ca97
		printf 'ccenv: ccenv_host:   %s \n' $ccenv_host >&2
c0ca97
		printf 'ccenv: ccenv_cchost: %s \n' $ccenv_cchost >&2
c0ca97
c0ca97
		if [ -z "$ccenv_tflags" ]; then
c0ca97
			printf 'ccenv:\n' >&2
c0ca97
			printf 'ccenv: ccenv_host and ccenv_cchost do not match, most likely because:\n' >&2
c0ca97
			printf 'ccenv: (1) you explicitly set CC (or passed --compiler=...)\n' >&2
c0ca97
			printf 'ccenv: (2) the selected compiler does not accept --target=...\n' >&2
c0ca97
			printf 'ccenv: (3) the host reported by -dumpmachine differs from the one you requested.\n' >&2
c0ca97
		fi
c0ca97
c0ca97
		if [ -n "$ccenv_errors" ]; then
c0ca97
			printf 'ccenv:\n' >&2
c0ca97
			printf 'ccenv: something went wrong, see the command and compiler message below.\n\n' >&2
c0ca97
			printf 'cmd: %s < /dev/null > /dev/null\n' "$ccenv_cmd" >&2
c0ca97
			printf '%s\n\n' "$ccenv_errors" >&2
c0ca97
		else
c0ca97
			printf 'ccenv:\n' >&2
c0ca97
			printf 'ccenv: something went wrong, bailing out.\n\n' >&2
c0ca97
		fi
c0ca97
c0ca97
		return 2
c0ca97
	fi
c0ca97
}
c0ca97
c0ca97
ccenv_set_cpp()
c0ca97
{
c0ca97
	case "$ccenv_cc_cmd" in
c0ca97
		cc | c99 | c11 | gcc)
c0ca97
			ccenv_cpp_prefix=
c0ca97
			ccenv_candidates="cpp" ;;
c0ca97
c0ca97
		clang )
c0ca97
			ccenv_cpp_prefix=
c0ca97
			ccenv_candidates="clang-cpp" ;;
c0ca97
c0ca97
		*-cc )
c0ca97
			ccenv_cpp_prefix=${ccenv_cc_cmd%-cc*}-
c0ca97
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
c0ca97
c0ca97
		*-c99 )
c0ca97
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c99*}-
c0ca97
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
c0ca97
c0ca97
		*-c11 )
c0ca97
			ccenv_cpp_prefix=${ccenv_cc_cmd%-c11*}-
c0ca97
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
c0ca97
c0ca97
		*-gcc )
c0ca97
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
c0ca97
			ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
c0ca97
c0ca97
		*-clang )
c0ca97
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
c0ca97
			ccenv_candidates="${ccenv_cpp_prefix}clang-cpp" ;;
c0ca97
c0ca97
		* )
c0ca97
			ccenv_cpp="$ccenv_cc -E"
c0ca97
			return 0
c0ca97
	esac
c0ca97
c0ca97
	ccenv_find_tool
c0ca97
c0ca97
	if [ "$ccenv_tool" = false ]; then
c0ca97
		ccenv_cpp="$ccenv_cc -E"
c0ca97
	elif [ -n "$ccenv_tflags" ]; then
c0ca97
		ccenv_cpp="$ccenv_tool $ccenv_tflags"
c0ca97
	else
c0ca97
		ccenv_cpp="$ccenv_tool"
c0ca97
	fi
c0ca97
}
c0ca97
c0ca97
ccenv_set_cxx()
c0ca97
{
c0ca97
	case "$ccenv_cc_cmd" in
c0ca97
		cc | c99 | c11 )
c0ca97
			ccenv_cxx_prefix=
c0ca97
			ccenv_candidates="cxx c++" ;;
c0ca97
c0ca97
		gcc )
c0ca97
			ccenv_cxx_prefix=
c0ca97
			ccenv_candidates="g++" ;;
c0ca97
c0ca97
		clang )
c0ca97
			ccenv_cxx_prefix=
c0ca97
			ccenv_candidates="clang++" ;;
c0ca97
c0ca97
		*-gcc )
c0ca97
			ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
c0ca97
			ccenv_candidates="${ccenv_cpp_prefix}g++" ;;
c0ca97
c0ca97
		*-clang )
c0ca97
			ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
c0ca97
			ccenv_candidates="${ccenv_cpp_prefix}clang++" ;;
c0ca97
c0ca97
		*cc )
c0ca97
			ccenv_cxx_prefix=${ccenv_cc_cmd%cc*}
c0ca97
			ccenv_candidates="${ccenv_cpp_prefix}++" ;;
c0ca97
c0ca97
		* )
c0ca97
			ccenv_cxx="$ccenv_cc -xc++"
c0ca97
			return 0
c0ca97
	esac
c0ca97
c0ca97
	ccenv_find_tool
c0ca97
c0ca97
	if [ "$ccenv_tool" = false ]; then
c0ca97
		ccenv_cxx="$ccenv_cc -xc++"
c0ca97
	elif [ -n "$ccenv_tflags" ]; then
c0ca97
		ccenv_cxx="$ccenv_tool $ccenv_tflags"
c0ca97
	else
c0ca97
		ccenv_cxx="$ccenv_tool"
c0ca97
	fi
c0ca97
}
c0ca97
c0ca97
ccenv_set_cc_host()
c0ca97
{
c0ca97
	ccenv_cc_host="$ccenv_cchost"
c0ca97
}
c0ca97
c0ca97
ccenv_set_cc_bits()
c0ca97
{
c0ca97
	ccenv_internal_size=
c0ca97
	ccenv_internal_type='void *'
c0ca97
	ccenv_internal_test='char x[(sizeof(%s) == %s/8) ? 1 : -1];'
c0ca97
c0ca97
	for ccenv_internal_guess in 64 32 128; do
c0ca97
		if [ -z $ccenv_internal_size ]; then
c0ca97
			ccenv_internal_str=$(printf "$ccenv_internal_test"  \
c0ca97
				"$ccenv_internal_type"                      \
c0ca97
				"$ccenv_internal_guess")
c0ca97
a0e9a0
			printf '%s' "$ccenv_internal_str"                   \
a0e9a0
					| $ccenv_cc -S -xc - -o -           \
a0e9a0
					  $(printf '%s' "$ccenv_cflags")    \
a0e9a0
				> /dev/null 2>/dev/null                     \
c0ca97
			&& ccenv_internal_size=$ccenv_internal_guess
c0ca97
		fi
c0ca97
	done
c0ca97
c0ca97
	ccenv_cc_bits=$ccenv_internal_size
c0ca97
}
c0ca97
c0ca97
ccenv_set_cc_underscore()
c0ca97
{
c0ca97
	ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe'
c0ca97
	ccenv_fn_code='int %s(void){return 0;}'
c0ca97
24ebb0
	if printf "$ccenv_fn_code" $ccenv_fn_name  \
24ebb0
			| $ccenv_cc -xc - -S -o -  \
24ebb0
			| grep "^_$ccenv_fn_name:" \
24ebb0
				> /dev/null; then
24ebb0
		ccenv_cc_underscore='_'
24ebb0
	fi
c0ca97
c0ca97
	return 0
c0ca97
}
c0ca97
c0ca97
ccenv_create_framework_executable()
c0ca97
{
c0ca97
	if [ -f $ccenv_image ]; then
c0ca97
		mv $ccenv_image $ccenv_image.tmp
c0ca97
		rm -f $ccenv_image.tmp
c0ca97
	fi
c0ca97
c0ca97
	printf 'int main(void){return 0;}'  \
c0ca97
		| $ccenv_cc -xc -           \
c0ca97
			-o $ccenv_image     \
c0ca97
	|| return 1
c0ca97
c0ca97
	return 0
c0ca97
}
c0ca97
c0ca97
ccenv_create_freestanding_executable()
c0ca97
{
c0ca97
	if [ -f $ccenv_image ]; then
c0ca97
		mv $ccenv_image $ccenv_image.tmp
c0ca97
		rm -f $ccenv_image.tmp
c0ca97
	fi
c0ca97
c0ca97
	if [ -z "ccenv_cc_underscore" ]; then
c0ca97
		ccenv_start_fn='_start'
c0ca97
	else
c0ca97
		ccenv_start_fn='start'
c0ca97
	fi
c0ca97
c0ca97
	printf 'int %s(void){return 0;}' "$ccenv_start_fn"  \
c0ca97
		| $ccenv_cc -xc -                           \
c0ca97
			-ffreestanding                      \
c0ca97
			-nostdlib -nostartfiles             \
c0ca97
			-o $ccenv_image                     \
c0ca97
	|| return 1
c0ca97
c0ca97
	ccenv_freestd=yes
c0ca97
c0ca97
	return 0
c0ca97
}
c0ca97
c0ca97
ccenv_set_cc_binfmt()
c0ca97
{
c0ca97
	ccenv_use_perk=
47c52e
	ccenv_use_otool=
c0ca97
	ccenv_use_readelf=
c0ca97
	ccenv_use_readobj=
c0ca97
	ccenv_use_bfd_objdump=
c0ca97
	ccenv_use_llvm_objdump=
c0ca97
c0ca97
	ccenv_create_framework_executable               \
c0ca97
		|| ccenv_create_freestanding_executable \
c0ca97
		|| return 0
c0ca97
c0ca97
	# PE / perk
c0ca97
	if [ -n "$ccenv_perk" ]; then
24ebb0
		if $ccenv_perk $ccenv_image 2>/dev/null; then
24ebb0
			ccenv_cc_binfmt='PE'
24ebb0
			ccenv_use_perk=yes
24ebb0
		fi
c0ca97
	fi
c0ca97
c0ca97
	# ELF / readelf
c0ca97
	if [ -n "$ccenv_readelf" ] && [ -z "$ccenv_cc_binfmt" ]; then
24ebb0
		if $ccenv_readelf -h $ccenv_image 2>/dev/null        \
24ebb0
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
24ebb0
				| grep 'Magic:7f454c46'              \
24ebb0
					> /dev/null; then
24ebb0
			ccenv_cc_binfmt='ELF'
24ebb0
			ccenv_use_readelf=yes
24ebb0
		fi
c0ca97
	fi
c0ca97
c0ca97
	# a marble of astonishing design:
c0ca97
	# llvm-readelf also parses PE and Mach-O
c0ca97
c0ca97
	if [ -n "$ccenv_readelf_llvm" ]; then
c0ca97
		ccenv_readany="$ccenv_readelf_llvm"
c0ca97
	else
c0ca97
		ccenv_readany="$ccenv_readelf"
c0ca97
	fi
c0ca97
c0ca97
	# PE / readelf
c0ca97
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
24ebb0
		if $ccenv_readany -h $ccenv_image 2>/dev/null        \
24ebb0
				| grep 'Magic:' | sed -e 's/[ ]*//g' \
24ebb0
				| grep 'Magic:MZ'                    \
24ebb0
					> /dev/null; then
24ebb0
			ccenv_cc_binfmt='PE'
24ebb0
			ccenv_use_readelf=yes
24ebb0
		fi
c0ca97
	fi
c0ca97
47c52e
	# MACHO-64 / otool
47c52e
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
24ebb0
		if $ccenv_otool -hv $ccenv_image 2>/dev/null \
24ebb0
				| grep -i 'MH_MAGIC_64'      \
24ebb0
					> /dev/null; then
24ebb0
			ccenv_cc_binfmt='MACHO'
24ebb0
			ccenv_use_otool=yes
24ebb0
		fi
47c52e
	fi
47c52e
47c52e
	# MACHO-32 / otool
47c52e
	if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
24ebb0
		if $ccenv_otool -hv $ccenv_image 2>/dev/null \
24ebb0
				| grep -i 'MH_MAGIC'         \
24ebb0
					> /dev/null; then
24ebb0
			ccenv_cc_binfmt='MACHO'
24ebb0
			ccenv_use_otool=yes
24ebb0
		fi
47c52e
	fi
47c52e
c0ca97
	# MACHO-64 / readelf
c0ca97
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
24ebb0
		if $ccenv_readany -h $ccenv_image 2>/dev/null             \
24ebb0
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
24ebb0
				| grep -i '(0xfeedfacf)'                  \
24ebb0
					> /dev/null; then
24ebb0
			ccenv_cc_binfmt='MACHO'
24ebb0
			ccenv_use_readelf=yes
24ebb0
		fi
c0ca97
	fi
c0ca97
c0ca97
	# MACHO-32 / readelf
c0ca97
	if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
24ebb0
		if $ccenv_readany -h $ccenv_image 2>/dev/null             \
24ebb0
				| grep -i 'Magic:' | sed -e 's/[ ]*//g'   \
24ebb0
				| grep -i '(0xcafebabe)'                  \
24ebb0
					> /dev/null; then
24ebb0
			ccenv_cc_binfmt='MACHO'
24ebb0
			ccenv_use_readelf=yes
24ebb0
		fi
c0ca97
	fi
c0ca97
c0ca97
	# MACHO / readobj
c0ca97
	if [ -n "$ccenv_readobj" ] && [ -z "$ccenv_cc_binfmt" ]; then
24ebb0
		if $ccenv_readobj $ccenv_image 2>/dev/null           \
24ebb0
				| grep -i 'Format:' | sed 's/ /_/g'  \
24ebb0
				| grep -i '_Mach-O_'                 \
24ebb0
					> /dev/null; then
24ebb0
			ccenv_cc_binfmt='MACHO'
24ebb0
			ccenv_use_readobj=yes
24ebb0
		fi
c0ca97
	fi
c0ca97
c0ca97
	# MACHO / objdump (llvm)
c0ca97
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
24ebb0
		if $ccenv_objdump -section-headers $ccenv_image  \
24ebb0
					2>/dev/null              \
24ebb0
				| grep -i 'file format Mach-O'   \
24ebb0
					> /dev/null; then
24ebb0
			ccenv_cc_binfmt='MACHO'
24ebb0
			ccenv_use_objdump=yes
24ebb0
		fi
c0ca97
	fi
c0ca97
c0ca97
	# MACHO / objdump (bfd)
c0ca97
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
c0ca97
		$ccenv_objdump -h  $ccenv_image 2>/dev/null       \
c0ca97
			| grep -i 'file format Mach-O'            \
c0ca97
				> /dev/null                       \
c0ca97
		&& ccenv_cc_binfmt='MACHO'                        \
c0ca97
		&& ccenv_use_objdump=yes
c0ca97
	fi
c0ca97
c0ca97
	# PE / objdump (bfd)
c0ca97
	if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
24ebb0
		if $ccenv_objdump -h  $ccenv_image 2>/dev/null \
24ebb0
				| grep -i 'file format pei-'   \
24ebb0
					> /dev/null; then
24ebb0
			ccenv_cc_binfmt='PE'
24ebb0
			ccenv_use_bfd_objdump=yes
24ebb0
		fi
c0ca97
	fi
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_pe()
c0ca97
{
c0ca97
	if [ -n "$ccenv_freestd" ]; then
c0ca97
		case "$ccenv_cchost" in
c0ca97
			*-midipix | *-midipix-* )
c0ca97
				ccenv_os='midipix' ;;
c0ca97
			*-mingw | *-mingw32 | *-mingw64 )
c0ca97
				ccenv_os='mingw' ;;
c0ca97
			*-mingw-* | *-mingw32-* | *-mingw64 )
c0ca97
				ccenv_os='mingw' ;;
c0ca97
			*-msys | *-msys2 | *-msys-* | *-msys2-* )
c0ca97
				ccenv_os='msys' ;;
c0ca97
			*-cygwin | *-cygwin-* )
c0ca97
				ccenv_os='cygwin' ;;
c0ca97
		esac
c0ca97
	fi
c0ca97
c0ca97
	if [ -n "$ccenv_os" ]; then
c0ca97
		return 0
c0ca97
	fi
c0ca97
c0ca97
	if [ -n "$ccenv_use_perk" ]; then
c0ca97
		ccenv_framework=$($ccenv_perk -y $ccenv_image)
c0ca97
		ccenv_os=${ccenv_framework#*-*-*-*}
c0ca97
	fi
c0ca97
c0ca97
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
c0ca97
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
c0ca97
			| grep 'cygwin1.dll' > /dev/null                \
c0ca97
		&& ccenv_os='cygwin'
c0ca97
	fi
c0ca97
c0ca97
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
c0ca97
		$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
c0ca97
			| grep 'msys-2.0.dll' > /dev/null               \
c0ca97
		&& ccenv_os='msys'
c0ca97
	fi
c0ca97
c0ca97
	if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
c0ca97
		$ccenv_objdump_bfd -x $ccenv_image          \
c0ca97
			| grep -i 'DLL Name' | grep '.CRT'  \
c0ca97
				> /dev/null                 \
c0ca97
		&& $ccenv_objdump_bfd -x $ccenv_image       \
c0ca97
			| grep -i 'DLL Name' | grep '.bss'  \
c0ca97
				> /dev/null                 \
c0ca97
		&& $ccenv_objdump_bfd -x $ccenv_image       \
c0ca97
			| grep -i 'DLL Name' | grep '.tls'  \
c0ca97
				> /dev/null                 \
c0ca97
		&& ccenv_os='mingw'
c0ca97
	fi
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_macho()
c0ca97
{
c0ca97
	case "$ccenv_cchost" in
c0ca97
		*-apple-darwin* )
c0ca97
			ccenv_os='darwin' ;;
c0ca97
	esac
c0ca97
}
c0ca97
c0ca97
ccenv_set_os()
c0ca97
{
c0ca97
	case "$ccenv_cc_binfmt" in
c0ca97
		PE )
c0ca97
			ccenv_set_os_pe ;;
c0ca97
		MACHO )
c0ca97
			ccenv_set_os_macho ;;
c0ca97
	esac
c0ca97
c0ca97
	if [ -n "$ccenv_os" ]; then
c0ca97
		return 0
c0ca97
	fi
c0ca97
c0ca97
	case "$ccenv_cchost" in
c0ca97
		*-*-*-* )
27d529
			ccenv_tip=${ccenv_cchost%-*}
c0ca97
			ccenv_os=${ccenv_tip#*-*-}
c0ca97
			;;
27d529
		*-*-musl | *-*-gnu )
27d529
			ccenv_tip=${ccenv_cchost%-*}
c0ca97
			ccenv_os=${ccenv_tip#*-}
c0ca97
			;;
27d529
		*-*-* )
27d529
			ccenv_os=${ccenv_cchost#*-*-}
27d529
			;;
27d529
		*-* )
27d529
			ccenv_os=${ccenv_cchost#*-}
27d529
			;;
c0ca97
	esac
c0ca97
c0ca97
	if [ -z "$ccenv_os" ]; then
c0ca97
		ccenv_os='anyos'
c0ca97
	fi
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_flags()
c0ca97
{
c0ca97
	case "$ccenv_os" in
c0ca97
		darwin )
c0ca97
			ccenv_cflags_os='-D_DARWIN_C_SOURCE'
c0ca97
			ccenv_cflags_pic='-fPIC'
c0ca97
			;;
c0ca97
		midipix )
c0ca97
			ccenv_cflags_os=
c0ca97
			ccenv_cflags_pic='-fPIC'
c0ca97
			;;
c0ca97
		cygwin )
c0ca97
			ccenv_cflags_os=
c0ca97
			ccenv_cflags_pic=
c0ca97
			;;
c0ca97
		msys | msys* | mingw | mingw* )
c0ca97
			ccenv_cflags_os='-U__STRICT_ANSI__'
c0ca97
			ccenv_cflags_pic=
c0ca97
			;;
c0ca97
		* )
c0ca97
			ccenv_cflags_os=
c0ca97
			ccenv_cflags_pic='-fPIC'
c0ca97
			;;
c0ca97
	esac
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_semantics()
c0ca97
{
c0ca97
	# binary_format - core_api - ex_api - dependency_resolution
c0ca97
c0ca97
	case "$ccenv_os" in
c0ca97
		linux )
c0ca97
			ccenv_os_semantics='elf-posix-linux-ldso'
c0ca97
			;;
c0ca97
		bsd )
c0ca97
			ccenv_os_semantics='elf-posix-bsd-ldso'
c0ca97
			;;
c0ca97
		darwin )
c0ca97
			ccenv_os_semantics='macho-posix-osx-ldso'
c0ca97
			;;
c0ca97
		midipix )
c0ca97
			ccenv_os_semantics='pe-posix-winnt-ldso'
c0ca97
			;;
c0ca97
		cygwin )
c0ca97
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
c0ca97
			;;
c0ca97
		msys )
c0ca97
			ccenv_os_semantics='pe-hybrid-winnt-unsafe'
c0ca97
			;;
c0ca97
		mingw )
c0ca97
			ccenv_os_semantics='pe-win32-winnt-unsafe'
c0ca97
			;;
c0ca97
	esac
c0ca97
c0ca97
	if [ -n "$ccenv_os_semantics" ]; then
c0ca97
		return 0
c0ca97
	fi
c0ca97
c0ca97
	if [ -n "$ccenv_cc_binfmt" ]; then
c0ca97
		ccenv_os_semantics_pattern='%s-posix-anyos-unknown'
c0ca97
		ccenv_os_semantics=$(printf                   \
c0ca97
				"$ccenv_os_semantics_pattern"  \
c0ca97
				"$ccenv_cc_binfmt"              \
c0ca97
			| tr '[:upper:]' '[:lower:]')
c0ca97
	else
c0ca97
		ccenv_os_semantics='unknown-posix-anyos-unknown'
c0ca97
	fi
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_dso_exrules()
c0ca97
{
c0ca97
	case "$ccenv_os" in
c0ca97
		midipix )
c0ca97
			ccenv_os_dso_exrules='pe-mdso'
c0ca97
			;;
c0ca97
		* )
c0ca97
			if [ "$ccenv_cc_binfmt" = 'PE' ]; then
c0ca97
				ccenv_os_dso_exrules='pe-dlltool'
c0ca97
			else
c0ca97
				ccenv_os_dso_exrules='default'
c0ca97
			fi
c0ca97
	esac
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_dso_linkage()
c0ca97
{
c0ca97
	# todo: PIC, PIE, and friends
c0ca97
	ccenv_os_dso_linkage='default'
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_dso_patterns_darwin()
c0ca97
{
c0ca97
	ccenv_os_app_prefix=
c0ca97
	ccenv_os_app_suffix=
c0ca97
c0ca97
	ccenv_os_lib_prefix=lib
c0ca97
	ccenv_os_lib_suffix=.dylib
c0ca97
c0ca97
	ccenv_os_implib_ext=.invalid
c0ca97
	ccenv_os_libdef_ext=.invalid
c0ca97
c0ca97
	ccenv_os_archive_ext=.a
c0ca97
	ccenv_os_soname=symlink
c0ca97
c0ca97
	ccenv_os_lib_prefixed_suffix=
c0ca97
	ccenv_os_lib_suffixed_suffix='$(OS_LIB_SUFFIX)'
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_dso_patterns_mdso()
c0ca97
{
c0ca97
	ccenv_os_app_prefix=
c0ca97
	ccenv_os_app_suffix=
c0ca97
c0ca97
	ccenv_os_lib_prefix=lib
c0ca97
	ccenv_os_lib_suffix=.so
c0ca97
c0ca97
	ccenv_os_implib_ext=.lib.a
c0ca97
	ccenv_os_libdef_ext=.so.def
c0ca97
c0ca97
	ccenv_os_archive_ext=.a
c0ca97
	ccenv_os_soname=symlink
c0ca97
c0ca97
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
c0ca97
	ccenv_os_lib_suffixed_suffix=
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_dso_patterns_dlltool()
c0ca97
{
c0ca97
	ccenv_os_app_prefix=
c0ca97
	ccenv_os_app_suffix=.exe
c0ca97
c0ca97
	ccenv_os_lib_prefix=lib
c0ca97
	ccenv_os_lib_suffix=.dll
c0ca97
c0ca97
	ccenv_os_implib_ext=.dll.a
c0ca97
	ccenv_os_libdef_ext=.def
c0ca97
c0ca97
	ccenv_os_archive_ext=.a
c0ca97
	ccenv_os_soname=copy
c0ca97
c0ca97
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
c0ca97
	ccenv_os_lib_suffixed_suffix=
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_dso_patterns_default()
c0ca97
{
c0ca97
	ccenv_os_app_prefix=
c0ca97
	ccenv_os_app_suffix=
c0ca97
c0ca97
	ccenv_os_lib_prefix=lib
c0ca97
	ccenv_os_lib_suffix=.so
c0ca97
c0ca97
	ccenv_os_implib_ext=.invalid
c0ca97
	ccenv_os_libdef_ext=.invalid
c0ca97
c0ca97
	ccenv_os_archive_ext=.a
c0ca97
	ccenv_os_soname=symlink
c0ca97
c0ca97
	ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
c0ca97
	ccenv_os_lib_suffixed_suffix=
c0ca97
}
c0ca97
c0ca97
ccenv_set_os_dso_patterns()
c0ca97
{
c0ca97
	# sover: .so.x.y.z
c0ca97
	# verso: .x.y.z.so
c0ca97
c0ca97
	case "$ccenv_os" in
c0ca97
		darwin )
c0ca97
			ccenv_set_os_dso_patterns_darwin
c0ca97
			;;
c0ca97
		midipix )
c0ca97
			ccenv_set_os_dso_patterns_mdso
c0ca97
			;;
c0ca97
		cygwin | msys | mingw )
c0ca97
			ccenv_set_os_dso_patterns_dlltool
c0ca97
			;;
c0ca97
		* )
c0ca97
			ccenv_set_os_dso_patterns_default
c0ca97
			;;
c0ca97
	esac
c0ca97
}
c0ca97
a49d61
ccenv_set_os_pe_switches()
a49d61
{
dffc05
	if [ "$ccenv_cc_binfmt" = 'PE' ] && [ -z "$ccenv_pe_subsystem" ]; then
a49d61
		case "$ccenv_os" in
a49d61
			midipix | mingw )
a49d61
				ccenv_pe_subsystem='windows'
a49d61
				;;
a49d61
			* )
a49d61
				ccenv_pe_subsystem='console'
a49d61
				;;
a49d61
		esac
a49d61
	fi
a49d61
}
a49d61
c0ca97
ccenv_output_defs()
c0ca97
{
c0ca97
	ccenv_in="$mb_project_dir/sofort/ccenv/ccenv.in"
c0ca97
	ccenv_mk="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
2bfadc
	ccenv_tmp=
c0ca97
a49d61
	if [ "$ccenv_cc_binfmt" = 'PE' ]; then
a49d61
		ccenv_pe="$mb_project_dir/sofort/ccenv/pedefs.in"
a49d61
		ccenv_in="$ccenv_in $ccenv_pe"
a49d61
	fi
a49d61
c0ca97
	if [ $ccenv_cfgtype = 'native' ]; then
c0ca97
5664b7
		ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
c0ca97
c0ca97
		sed                             \
c0ca97
				-e 's/^\s*$/@/g' \
c0ca97
				-e 's/^/NATIVE_/' \
c0ca97
				-e 's/NATIVE_@//g' \
c0ca97
				-e 's/NATIVE_#/#/g' \
c0ca97
				-e 's/       =/=/g'  \
c0ca97
				-e 's/       +=/+=/g' \
a49d61
			$ccenv_in > "$ccenv_tmp"
c0ca97
c0ca97
		ccenv_in="$ccenv_tmp"
5664b7
	else
2bfadc
		unset ccenv_tmp
c0ca97
	fi
c0ca97
c0ca97
	ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
c0ca97
			| grep -v '^#')
c0ca97
c0ca97
	ccenv_exvars="ccenv_cfgtype ccenv_makevar_prefix"
c0ca97
c0ca97
	ccenv_sed_substs=" \
9dc723
		$(for __var in $(printf %s "$ccenv_vars $ccenv_exvars"); do \
c0ca97
			printf '%s"$%s"%s' "-e 's/@$__var@/'" \
c0ca97
				"$__var" "'/g' ";              \
c0ca97
		done)"
c0ca97
a49d61
	eval sed $ccenv_sed_substs $ccenv_in   \
fdaea7
			| sed -e 's/[[:blank:]]*$//g' \
c0ca97
		> "$ccenv_mk"
c0ca97
d87a85
	if [ "$ccenv_cfgtype" = 'host' ]; then
9dc723
		for __var in $(printf %s "$ccenv_vars"); do
d87a85
			ccenv_src_var=$__var
d87a85
			ccenv_dst_var=mb_${__var#*ccenv_}
d87a85
			ccenv_var_expr='${'$ccenv_src_var':-}'
d87a85
			eval $ccenv_dst_var=$ccenv_var_expr
d87a85
d87a85
		done
d87a85
d87a85
		mb_host=$ccenv_host
d87a85
		mb_cchost=$ccenv_cchost
d87a85
	else
9dc723
		for __var in $(printf %s "$ccenv_vars"); do
d87a85
			ccenv_src_var=$__var
d87a85
			ccenv_dst_var=mb_native_${__var#*ccenv_}
d87a85
			ccenv_var_expr='${'$ccenv_src_var':-}'
d87a85
			eval "$ccenv_dst_var=$ccenv_var_expr"
d87a85
		done
d87a85
d87a85
		mb_native_host=$ccenv_host
d87a85
		mb_native_cchost=$ccenv_cchost
d87a85
	fi
5664b7
5664b7
	if [ -n "${ccenv_tmp:-}" ]; then
5664b7
		rm -f "$ccenv_tmp"
5664b7
		unset ccenv_tmp
5664b7
	fi
c0ca97
}
c0ca97
6b0e7f
ccenv_dso_verify()
6b0e7f
{
6b0e7f
	ccenv_str='int foo(int x){return ++x;}'
6b0e7f
	ccenv_cmd="$ccenv_cc -xc - -shared -o a.out"
6b0e7f
6b0e7f
	rm -f a.out
6b0e7f
6b0e7f
	printf '%s' "$ccenv_str" | $ccenv_cmd \
6b0e7f
		> /dev/null 2>/dev/null       \
6b0e7f
	|| mb_disable_shared=yes
6b0e7f
6b0e7f
	rm -f a.out
6b0e7f
}
6b0e7f
c0ca97
ccenv_clean_up()
c0ca97
{
c0ca97
	rm -f $ccenv_image
c0ca97
}
c0ca97
c0ca97
ccenv_common_init()
c0ca97
{
c0ca97
	. "$mb_project_dir/sofort/ccenv/ccenv.vars"
c0ca97
c0ca97
	ccenv_cfgtype=$1
c0ca97
	ccenv_cfgfile="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
c0ca97
	ccenv_freestd=
c00fea
	ccenv_cchost=
c0ca97
c0ca97
	if [ $ccenv_cfgtype = 'native' ]; then
c0ca97
		ccenv_makevar_prefix='NATIVE_'
c0ca97
		ccenv_image='./ccenv/native.a.out'
c0ca97
	else
c0ca97
		ccenv_makevar_prefix=
c0ca97
		ccenv_image='./ccenv/host.a.out'
c0ca97
	fi
c0ca97
c0ca97
	if [ $ccenv_cfgtype = 'native' ]; then
c0ca97
		ccenv_prefixes=
c0ca97
	elif [ -n "$mb_cross_compile" ]; then
c0ca97
		ccenv_prefixes="$mb_cross_compile"
c0ca97
	elif [ -n "$mb_host" ]; then
c0ca97
		ccenv_prefixes="$mb_host-"
c0ca97
	else
c0ca97
		ccenv_prefixes=
c0ca97
	fi
c0ca97
c0ca97
	if [ $ccenv_cfgtype = 'host' ]; then
c0ca97
		ccenv_tflags=
c0ca97
		ccenv_cflags=$(make -s -f "$mb_pwd/Makefile.tmp" .display-cflags)
c0ca97
		ccenv_cc="$mb_user_cc"
c0ca97
		ccenv_cpp="$mb_user_cpp"
c0ca97
		ccenv_cxx="$mb_user_cxx"
a49d61
a49d61
		ccenv_pe_subsystem="$mb_pe_subsystem"
a49d61
		ccenv_pe_image_base="$mb_pe_image_base"
c0ca97
	else
c0ca97
		ccenv_tflags=
c0ca97
		ccenv_cflags="$mb_native_cflags"
c0ca97
		ccenv_cc="$mb_native_cc"
c0ca97
		ccenv_cpp="$mb_native_cpp"
c0ca97
		ccenv_cxx="$mb_native_cxx"
a49d61
a49d61
		ccenv_pe_subsystem="$mb_native_pe_subsystem"
a49d61
		ccenv_pe_image_base="$mb_native_pe_image_base"
c0ca97
	fi
c0ca97
}
c0ca97
c0ca97
ccenv_set_characteristics()
c0ca97
{
c0ca97
	ccenv_set_cc_host
c0ca97
	ccenv_set_cc_bits
c0ca97
	ccenv_set_cc_underscore
c0ca97
	ccenv_set_cc_binfmt
c0ca97
}
c0ca97
c0ca97
ccenv_set_toolchain_variables()
c0ca97
{
c0ca97
	ccenv_common_init $1
c0ca97
	ccenv_set_cc
c0ca97
	ccenv_set_cpp
c0ca97
	ccenv_set_cxx
c0ca97
	ccenv_set_primary_tools
c0ca97
	ccenv_set_tool_variants
c0ca97
	ccenv_set_characteristics
c0ca97
c0ca97
	ccenv_set_os
c0ca97
	ccenv_set_os_flags
c0ca97
	ccenv_set_os_semantics
c0ca97
	ccenv_set_os_dso_exrules
c0ca97
	ccenv_set_os_dso_linkage
c0ca97
	ccenv_set_os_dso_patterns
a49d61
	ccenv_set_os_pe_switches
c0ca97
c0ca97
	ccenv_output_defs
c0ca97
	ccenv_clean_up
c0ca97
}
c0ca97
c0ca97
ccenv_set_host_variables()
c0ca97
{
c0ca97
	ccenv_set_toolchain_variables 'host'
6b0e7f
	ccenv_dso_verify
c0ca97
}
c0ca97
c0ca97
ccenv_set_native_variables()
c0ca97
{
096639
	if [ _$mb_ccenv_skip_native != _yes ]; then
096639
		ccenv_set_toolchain_variables 'native'
096639
	fi
c0ca97
}