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