Blame sofort/ccenv/ccenv.sh

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