|
|
eb4330 |
# ccenv.sh: sofort's tool-finding bits,
|
|
|
eb4330 |
# invoked from within the project-agnostic configure script.
|
|
|
eb4330 |
|
|
|
12fcaa |
# this file is covered by COPYING.SOFORT.
|
|
|
12fcaa |
|
|
|
eb4330 |
# invocation and names of binary tools:
|
|
|
eb4330 |
# agnostic names (ar, nm, objdump, ...);
|
|
|
eb4330 |
# target-prefixed agnostic names (x86_64-nt64-midipix-ar, ...);
|
|
|
eb4330 |
# branded names (llvm-ar, llvm-nm, llvm-objdump, ...);
|
|
|
eb4330 |
# target-prefixed branded names (x86_64-linux-gnu-gcc-ar, ...);
|
|
|
eb4330 |
# target-specifying branded tools (llvm-ar --target=x86_64-linux, ...).
|
|
|
eb4330 |
|
|
|
eb4330 |
# cross-compilation: default search order:
|
|
|
eb4330 |
# target-prefixed agnostic tools;
|
|
|
eb4330 |
# target-prefixed branded tools, starting with the prefix
|
|
|
eb4330 |
# most commonly associated with the selected compiler (that is,
|
|
|
eb4330 |
# ``gcc'' when using gcc, and ``llvm'' when using clang);
|
|
|
eb4330 |
# target-speficying branded tools, starting once again with the
|
|
|
eb4330 |
# prefix most commonly associated with the selected compiler.
|
|
|
eb4330 |
|
|
|
eb4330 |
# internal variables of interest:
|
|
|
eb4330 |
# ccenv_cfgtype: the type of host being tested (host/native)
|
|
|
eb4330 |
# ccenv_cfgfile: the configuration file for the host being tested
|
|
|
eb4330 |
# ccenv_cflags: the comprehensive cflags for the host being tested
|
|
|
eb4330 |
# ccenv_cchost: the host being tested, as reported by -dumpmachine
|
|
|
eb4330 |
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_usage()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
cat "$mb_project_dir"/sofort/ccenv/ccenv.usage
|
|
|
eb4330 |
exit 0
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_newline()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
printf '\n' >> "$ccenv_cfgfile"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_comment()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
ccenv_internal_str='#'
|
|
|
eb4330 |
|
|
|
eb4330 |
for ccenv_internal_arg ; do
|
|
|
eb4330 |
ccenv_internal_str="$ccenv_internal_str $ccenv_internal_arg"
|
|
|
eb4330 |
done
|
|
|
eb4330 |
|
|
|
eb4330 |
printf '%s\n' "$ccenv_internal_str" >> "$ccenv_cfgfile"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
|
|
|
487309 |
ccenv_tool_prolog()
|
|
|
487309 |
{
|
|
|
e6e220 |
ccenv_line_dots='.....................................'
|
|
|
f520d8 |
ccenv_tool_desc=" == checking for ${1}"
|
|
|
487309 |
ccenv_tool_dlen="${#ccenv_line_dots}"
|
|
|
487309 |
|
|
|
0d8567 |
printf '\n%s\n' '________________________' >&3
|
|
|
0d8567 |
printf "ccenv: checking for ${1}\n\n" >&3
|
|
|
487309 |
printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s" \
|
|
|
e6e220 |
"${ccenv_tool_desc} ${mb_line_dots}"
|
|
|
487309 |
}
|
|
|
487309 |
|
|
|
487309 |
|
|
|
487309 |
ccenv_tool_epilog()
|
|
|
487309 |
{
|
|
|
487309 |
ccenv_line_dots='................................'
|
|
|
487309 |
ccenv_tool_dlen="$((${#ccenv_line_dots} - ${#1}))"
|
|
|
487309 |
|
|
|
197652 |
case ${ccenv_tool_dlen} in
|
|
|
197652 |
0 | -* )
|
|
|
197652 |
ccenv_tool_dlen='3' ;;
|
|
|
197652 |
esac
|
|
|
197652 |
|
|
|
e6e220 |
printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s %s.\n" \
|
|
|
487309 |
"${ccenv_line_dots}" "${1}"
|
|
|
0d8567 |
|
|
|
0d8567 |
if [ "${1}" = 'false' ]; then
|
|
|
0d8567 |
printf '\n\nccenv: not (yet) found.\n' >&3
|
|
|
0d8567 |
else
|
|
|
0d8567 |
printf "\n\nccenv : found $(command -v ${1}).\n" >&3
|
|
|
0d8567 |
fi
|
|
|
0d8567 |
|
|
|
0d8567 |
printf '%s\n' '------------------------' >&3
|
|
|
487309 |
}
|
|
|
487309 |
|
|
|
487309 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog()
|
|
|
ed2324 |
{
|
|
|
ed2324 |
ccenv_expr=${1}='${'${1}':-false}'
|
|
|
ed2324 |
eval "$ccenv_expr"
|
|
|
ed2324 |
|
|
|
ed2324 |
ccenv_expr='${'${1}'}'
|
|
|
ed2324 |
eval ccenv_tool_epilog "$ccenv_expr"
|
|
|
ed2324 |
}
|
|
|
ed2324 |
|
|
|
ed2324 |
|
|
|
487309 |
ccenv_attr_prolog()
|
|
|
487309 |
{
|
|
|
e6e220 |
ccenv_line_dots=' .....................................'
|
|
|
e6e220 |
ccenv_attr_desc=" == detect ${ccenv_cfgtype} ${1}"
|
|
|
487309 |
ccenv_attr_dlen="${#ccenv_line_dots}"
|
|
|
487309 |
|
|
|
487309 |
printf "%${ccenv_attr_dlen}.${ccenv_attr_dlen}s" \
|
|
|
487309 |
"${ccenv_attr_desc} ${ccenv_line_dots}"
|
|
|
0d8567 |
|
|
|
0d8567 |
printf '\n%s\n' '________________________' >&3
|
|
|
0d8567 |
printf "ccenv: detecting ${1}\n\n" >&3
|
|
|
487309 |
}
|
|
|
487309 |
|
|
|
487309 |
|
|
|
487309 |
ccenv_attr_epilog()
|
|
|
487309 |
{
|
|
|
0d8567 |
ccenv_line_dots='................................'
|
|
|
e6e220 |
ccenv_tool_dlen="$((${#ccenv_line_dots} - 1 - ${#1}))"
|
|
|
0d8567 |
|
|
|
197652 |
case ${ccenv_tool_dlen} in
|
|
|
197652 |
0 | -* )
|
|
|
197652 |
ccenv_tool_dlen='3' ;;
|
|
|
197652 |
esac
|
|
|
197652 |
|
|
|
e6e220 |
printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s %s.\n" \
|
|
|
0d8567 |
"${ccenv_line_dots}" "${1}"
|
|
|
0d8567 |
|
|
|
0d8567 |
printf '\n\nccenv: detected result: %s\n' "${1}" >&3
|
|
|
0d8567 |
printf '%s\n' '------------------------' >&3
|
|
|
487309 |
}
|
|
|
487309 |
|
|
|
487309 |
|
|
|
eb4330 |
ccenv_find_tool()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
if [ -z "$ccenv_prefixes" ]; then
|
|
|
aecab0 |
for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
|
|
|
4d67e0 |
ccenv_cmd_args="${@:-}"
|
|
|
4d67e0 |
|
|
|
4d67e0 |
if [ -z "$ccenv_cmd_args" ]; then
|
|
|
9980ab |
if command -v "$ccenv_candidate" > /dev/null; then
|
|
|
9980ab |
ccenv_tool="$ccenv_candidate"
|
|
|
fb505a |
return 0
|
|
|
bb3f66 |
fi
|
|
|
fb505a |
else
|
|
|
9980ab |
if command -v "$ccenv_candidate" > /dev/null; then
|
|
|
0d8567 |
if "$ccenv_candidate" $@ > /dev/null 2>&3; then
|
|
|
9980ab |
ccenv_tool="$ccenv_candidate"
|
|
|
fb505a |
return 0
|
|
|
bb3f66 |
fi
|
|
|
bb3f66 |
fi
|
|
|
fb505a |
fi
|
|
|
eb4330 |
done
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_tool=false
|
|
|
eb4330 |
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
aecab0 |
for ccenv_prefix in $(printf '%s' "$ccenv_prefixes"); do
|
|
|
aecab0 |
for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
|
|
|
eb4330 |
ccenv_tool="$ccenv_prefix$ccenv_candidate"
|
|
|
bb3f66 |
|
|
|
bb3f66 |
if command -v "$ccenv_tool" > /dev/null; then
|
|
|
bb3f66 |
return 0
|
|
|
bb3f66 |
fi
|
|
|
eb4330 |
done
|
|
|
eb4330 |
done
|
|
|
eb4330 |
|
|
|
aecab0 |
for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
|
|
|
9980ab |
if command -v "$ccenv_candidate" > /dev/null; then
|
|
|
9980ab |
ccenv_tool="$ccenv_candidate"
|
|
|
bb3f66 |
return 0
|
|
|
bb3f66 |
fi
|
|
|
eb4330 |
done
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_tool=false
|
|
|
eb4330 |
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_primary_tools()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
ccenv_core_tools="ar nm objdump ranlib size strip strings objcopy"
|
|
|
72602c |
ccenv_hack_tools="addr2line cov elfedit readelf readobj otool"
|
|
|
eb4330 |
ccenv_peep_tools="perk mdso dlltool windmc windres"
|
|
|
eb4330 |
|
|
|
aecab0 |
for __tool in $(printf '%s' "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do
|
|
|
487309 |
ccenv_tool_prolog "$__tool"
|
|
|
487309 |
|
|
|
eb4330 |
if [ -n "$mb_agnostic" ]; then
|
|
|
eb4330 |
ccenv_candidates=" $__tool"
|
|
|
eb4330 |
|
|
|
eb4330 |
elif [ -n "$mb_zealous" ]; then
|
|
|
eb4330 |
ccenv_candidates="$mb_zealous-$__tool"
|
|
|
eb4330 |
|
|
|
eb4330 |
elif [ "$mb_toolchain" = 'gcc' ]; then
|
|
|
eb4330 |
ccenv_candidates="gcc-$__tool"
|
|
|
eb4330 |
ccenv_candidates="$ccenv_candidates $__tool"
|
|
|
eb4330 |
ccenv_candidates="$ccenv_candidates llvm-$__tool"
|
|
|
eb4330 |
|
|
|
eb4330 |
elif [ "$mb_toolchain" = 'llvm' ]; then
|
|
|
eb4330 |
ccenv_candidates="llvm-$__tool"
|
|
|
eb4330 |
ccenv_candidates="$ccenv_candidates $__tool"
|
|
|
eb4330 |
ccenv_candidates="$ccenv_candidates gcc-$__tool"
|
|
|
eb4330 |
|
|
|
eb4330 |
elif [ -n "$mb_toolchain" ]; then
|
|
|
eb4330 |
ccenv_candidates="$mb_toolchain-$__tool"
|
|
|
eb4330 |
ccenv_candidates="$ccenv_candidates $__tool"
|
|
|
eb4330 |
ccenv_candidates="$ccenv_candidates gcc-$__tool"
|
|
|
eb4330 |
ccenv_candidates="$ccenv_candidates llvm-$__tool"
|
|
|
eb4330 |
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_candidates="$__tool"
|
|
|
eb4330 |
ccenv_candidates="$ccenv_candidates gcc-$__tool"
|
|
|
eb4330 |
ccenv_candidates="$ccenv_candidates llvm-$__tool"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_cfgtype" = 'host' ]; then
|
|
|
eb4330 |
ccenv_var_prefix='mb_'
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_var_prefix='mb_native_'
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_var_name=$ccenv_var_prefix$__tool
|
|
|
eb4330 |
ccenv_var_expr='${'$ccenv_var_name':-}'
|
|
|
eb4330 |
eval ccenv_var_val=$ccenv_var_expr
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -n "$ccenv_var_val" ]; then
|
|
|
eb4330 |
eval ccenv_$__tool="$ccenv_var_val"
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
eval ccenv_$__tool="$ccenv_tool"
|
|
|
eb4330 |
fi
|
|
|
487309 |
|
|
|
487309 |
ccenv_tool_epilog "$ccenv_tool"
|
|
|
eb4330 |
done
|
|
|
eb4330 |
|
|
|
eb4330 |
# windrc
|
|
|
eb4330 |
ccenv_windrc="$ccenv_windres"
|
|
|
320a40 |
|
|
|
320a40 |
# archive format preamble
|
|
|
320a40 |
ccenv_libgcc_a_header=$(od -b -N8 $($ccenv_cc -print-file-name=libgcc.a) | head -n1)
|
|
|
320a40 |
ccenv_cc_arfmt='common'
|
|
|
320a40 |
|
|
|
320a40 |
# ar (big)
|
|
|
320a40 |
ccenv_bigaf_header=$(printf '%s\n' '<bigaf>' | od -b | head -n1)
|
|
|
320a40 |
|
|
|
320a40 |
if [ "$ccenv_libgcc_a_header" = "$ccenv_bigaf_header" ]; then
|
|
|
320a40 |
ccenv_cc_arfmt='bigaf'
|
|
|
320a40 |
|
|
|
320a40 |
for __tool in $(printf '%s' "$ccenv_core_tools"); do
|
|
|
320a40 |
ccenv_var_name=ccenv_$__tool
|
|
|
320a40 |
ccenv_var_expr='${'$ccenv_var_name':-}'
|
|
|
320a40 |
eval ccenv_var_val="$ccenv_var_expr"
|
|
|
320a40 |
|
|
|
320a40 |
if [ "$ccenv_var_val" != false ]; then
|
|
|
320a40 |
ccenv_var_val="$ccenv_var_val -X64"
|
|
|
320a40 |
ccenv_var_expr='${ccenv_var_val:-}'
|
|
|
320a40 |
eval ccenv_$__tool="$ccenv_var_expr"
|
|
|
320a40 |
fi
|
|
|
320a40 |
done
|
|
|
320a40 |
fi
|
|
|
320a40 |
|
|
|
320a40 |
# ar (small)
|
|
|
320a40 |
ccenv_aiaff_header=$(printf '%s\n' '<aiaff>' | od -b | head -n1)
|
|
|
320a40 |
|
|
|
320a40 |
if [ "$ccenv_libgcc_a_header" = "$ccenv_aiaff_header" ]; then
|
|
|
320a40 |
ccenv_cc_arfmt='aiaff'
|
|
|
320a40 |
|
|
|
320a40 |
for __tool in $(printf '%s' "$ccenv_core_tools"); do
|
|
|
320a40 |
ccenv_var_name=ccenv_$__tool
|
|
|
320a40 |
ccenv_var_expr='${'$ccenv_var_name':-}'
|
|
|
320a40 |
eval ccenv_var_val="$ccenv_var_expr"
|
|
|
320a40 |
|
|
|
320a40 |
if [ "$ccenv_var_val" != false ]; then
|
|
|
320a40 |
ccenv_var_val="$ccenv_var_val -X32"
|
|
|
320a40 |
ccenv_var_expr='${ccenv_var_val:-}'
|
|
|
320a40 |
eval ccenv_$__tool="$ccenv_var_expr"
|
|
|
320a40 |
fi
|
|
|
320a40 |
done
|
|
|
320a40 |
fi
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_tool_variants()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
# as (asm)
|
|
|
487309 |
ccenv_tool_prolog 'as (asm)'
|
|
|
eb4330 |
ccenv_candidates=as
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_tool" = false ]; then
|
|
|
eb4330 |
ccenv_as_asm=
|
|
|
eb4330 |
else
|
|
|
c780a1 |
$ccenv_tool --help 2>&1 | grep -i '.bc assembler' \
|
|
|
eb4330 |
|| ccenv_as_asm="$ccenv_tool"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog 'ccenv_as_asm'
|
|
|
487309 |
|
|
|
eb4330 |
# as (ll)
|
|
|
487309 |
ccenv_tool_prolog 'as (ll)'
|
|
|
eb4330 |
ccenv_candidates=llvm-as
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_tool" != false ]; then
|
|
|
eb4330 |
ccenv_as_ll="$ccenv_tool"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog 'ccenv_as_ll'
|
|
|
487309 |
|
|
|
eb4330 |
# as (mc)
|
|
|
487309 |
ccenv_tool_prolog 'as (mc)'
|
|
|
eb4330 |
ccenv_candidates=llvm-mc
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_tool" != false ]; then
|
|
|
eb4330 |
ccenv_as_mc="$ccenv_tool"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog 'ccenv_as_mc'
|
|
|
487309 |
|
|
|
eb4330 |
# ld (bfd)
|
|
|
487309 |
ccenv_tool_prolog 'ld (bfd)'
|
|
|
eb4330 |
ccenv_candidates=ld.bfd
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_tool" != false ]; then
|
|
|
eb4330 |
ccenv_ld_bfd="$ccenv_tool"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog 'ccenv_ld_bfd'
|
|
|
487309 |
|
|
|
eb4330 |
# ld (gold)
|
|
|
487309 |
ccenv_tool_prolog 'ld (gold)'
|
|
|
eb4330 |
ccenv_candidates=ld.gold
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_tool" != false ]; then
|
|
|
eb4330 |
ccenv_ld_gold="$ccenv_tool"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog 'ccenv_ld_gold'
|
|
|
487309 |
|
|
|
eb4330 |
# ld (lld)
|
|
|
487309 |
ccenv_tool_prolog 'ld (lld)'
|
|
|
eb4330 |
ccenv_candidates=lld
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_tool" != false ]; then
|
|
|
eb4330 |
ccenv_ld_lld="$ccenv_tool"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog 'ccenv_ld_lld'
|
|
|
487309 |
|
|
|
eb4330 |
# objdump (bfd)
|
|
|
487309 |
ccenv_tool_prolog 'objdump (bfd)'
|
|
|
eb4330 |
ccenv_candidates=objdump
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
c6f04a |
if $ccenv_tool --version | grep -i Binutils > /dev/null; then
|
|
|
c6f04a |
ccenv_objdump_bfd="$ccenv_tool"
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog 'ccenv_objdump_bfd'
|
|
|
487309 |
|
|
|
eb4330 |
# objdump (llvm)
|
|
|
487309 |
ccenv_tool_prolog 'objdump (llvm)'
|
|
|
eb4330 |
ccenv_candidates=llvm-objdump
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
c6f04a |
if $ccenv_tool --version | grep -i LLVM > /dev/null; then
|
|
|
c6f04a |
ccenv_objdump_llvm="$ccenv_tool"
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog 'ccenv_objdump_llvm'
|
|
|
487309 |
|
|
|
eb4330 |
# readelf (bfd)
|
|
|
487309 |
ccenv_tool_prolog 'readelf (bfd)'
|
|
|
eb4330 |
ccenv_candidates=readelf
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
c6f04a |
if $ccenv_tool --version | grep -i Binutils > /dev/null; then
|
|
|
c6f04a |
ccenv_readelf_bfd="$ccenv_tool"
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog 'ccenv_readelf_bfd'
|
|
|
487309 |
|
|
|
eb4330 |
# readelf (llvm)
|
|
|
487309 |
ccenv_tool_prolog 'readelf (llvm)'
|
|
|
eb4330 |
ccenv_candidates=llvm-readelf
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
c6f04a |
if $ccenv_tool --version | grep -i LLVM > /dev/null; then
|
|
|
c6f04a |
ccenv_readelf_llvm="$ccenv_tool"
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
|
|
|
ed2324 |
ccenv_tool_variant_epilog 'ccenv_readelf_llvm'
|
|
|
487309 |
|
|
|
eb4330 |
# as
|
|
|
eb4330 |
if [ -n "$ccenv_cc" ]; then
|
|
|
a0a8cc |
ccenv_as='$('"$ccenv_makevar_prefix"'CC) -c -x assembler'
|
|
|
eb4330 |
elif [ -n "$mb_agnostic" ]; then
|
|
|
eb4330 |
ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
|
|
|
eb4330 |
elif [ "$mb_zealous" = 'gcc' ]; then
|
|
|
eb4330 |
ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
|
|
|
eb4330 |
elif [ -n "$mb_zealous" = 'llvm' ]; then
|
|
|
eb4330 |
ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
|
|
|
eb4330 |
elif [ "$mb_toolchain" = 'gcc' ]; then
|
|
|
eb4330 |
ccenv_as='$('"$ccenv_makevar_prefix"'AS_ASM)'
|
|
|
eb4330 |
elif [ "$mb_toolchain" = 'llvm' ]; then
|
|
|
eb4330 |
ccenv_as='$('"$ccenv_makevar_prefix"'AS_MC)'
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
# ld
|
|
|
eb4330 |
if [ -n "$ccenv_cc" ]; then
|
|
|
eb4330 |
ccenv_ld='$('"$ccenv_makevar_prefix"'CC) -nostdlib -nostartfiles'
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_c_compiler_candidates()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
if [ -n "$mb_compiler" ]; then
|
|
|
eb4330 |
ccenv_candidates="$mb_compiler"
|
|
|
eb4330 |
|
|
|
eb4330 |
elif [ -n "$mb_agnostic" ]; then
|
|
|
eb4330 |
ccenv_candidates="c99 c11 cc"
|
|
|
eb4330 |
|
|
|
eb4330 |
elif [ "$mb_zealous" = 'gcc' ]; then
|
|
|
eb4330 |
ccenv_candidates="gcc"
|
|
|
eb4330 |
|
|
|
eb4330 |
elif [ "$mb_zealous" = 'llvm' ]; then
|
|
|
eb4330 |
ccenv_candidates="clang"
|
|
|
eb4330 |
|
|
|
eb4330 |
elif [ "$mb_toolchain" = 'gcc' ]; then
|
|
|
eb4330 |
ccenv_candidates="gcc c99 c11 cc clang"
|
|
|
eb4330 |
|
|
|
eb4330 |
elif [ "$mb_toolchain" = 'llvm' ]; then
|
|
|
eb4330 |
ccenv_candidates="clang c99 c11 cc gcc"
|
|
|
eb4330 |
|
|
|
eb4330 |
elif [ -n "$mb_toolchain" ]; then
|
|
|
eb4330 |
ccenv_candidates="$mb_toolchain c99 c11 cc gcc clang"
|
|
|
eb4330 |
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_candidates="c99 c11 cc gcc clang"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_cc()
|
|
|
eb4330 |
{
|
|
|
487309 |
ccenv_tool_prolog 'C compiler'
|
|
|
487309 |
|
|
|
eb4330 |
if [ -z "$ccenv_cc" ]; then
|
|
|
eb4330 |
ccenv_set_c_compiler_candidates
|
|
|
fb505a |
ccenv_find_tool -dumpmachine
|
|
|
eb4330 |
ccenv_cc="$ccenv_tool"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
|
|
|
eb4330 |
ccenv_cc="$mb_compiler"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_cc_cmd="$ccenv_cc"
|
|
|
c519de |
ccenv_errors=
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_cfgtype" = 'native' ]; then
|
|
|
0d8567 |
ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3)
|
|
|
ec706e |
ccenv_cchost=$ccenv_host
|
|
|
487309 |
ccenv_tool_epilog "$ccenv_cc"
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -n "$mb_cchost" ]; then
|
|
|
eb4330 |
ccenv_host="$mb_cchost"
|
|
|
eb4330 |
elif [ -n "$mb_host" ]; then
|
|
|
eb4330 |
ccenv_host="$mb_host"
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_host=
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -z "$ccenv_host" ]; then
|
|
|
0d8567 |
ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3)
|
|
|
eb4330 |
ccenv_cchost=$ccenv_host
|
|
|
eb4330 |
else
|
|
|
1ea231 |
ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
|
|
|
eb4330 |
ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -"
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -z "$mb_user_cc" ]; then
|
|
|
4da44e |
$(printf %s "$ccenv_cmd") < /dev/null > /dev/null \
|
|
|
eb4330 |
2>"$ccenv_tmp" || true
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_errors=$(cat "$ccenv_tmp")
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -z "$ccenv_errors" ]; then
|
|
|
eb4330 |
ccenv_tflags="--target=$ccenv_host"
|
|
|
eb4330 |
ccenv_cc="$ccenv_cc $ccenv_tflags"
|
|
|
0d8567 |
else
|
|
|
0d8567 |
printf '%s' "$ccenv_errors" >&3
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
1ea231 |
rm -f "$ccenv_tmp"
|
|
|
1ea231 |
unset ccenv_tmp
|
|
|
1ea231 |
|
|
|
0d8567 |
ccenv_cchost=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3)
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_cchost" != "$ccenv_host" ]; then
|
|
|
0d8567 |
printf 'error!\n' >&2
|
|
|
eb4330 |
printf 'ccenv:\n' >&2
|
|
|
eb4330 |
printf 'ccenv: ccenv_host: %s \n' $ccenv_host >&2
|
|
|
eb4330 |
printf 'ccenv: ccenv_cchost: %s \n' $ccenv_cchost >&2
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -z "$ccenv_tflags" ]; then
|
|
|
eb4330 |
printf 'ccenv:\n' >&2
|
|
|
eb4330 |
printf 'ccenv: ccenv_host and ccenv_cchost do not match, most likely because:\n' >&2
|
|
|
eb4330 |
printf 'ccenv: (1) you explicitly set CC (or passed --compiler=...)\n' >&2
|
|
|
eb4330 |
printf 'ccenv: (2) the selected compiler does not accept --target=...\n' >&2
|
|
|
eb4330 |
printf 'ccenv: (3) the host reported by -dumpmachine differs from the one you requested.\n' >&2
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -n "$ccenv_errors" ]; then
|
|
|
eb4330 |
printf 'ccenv:\n' >&2
|
|
|
eb4330 |
printf 'ccenv: something went wrong, see the command and compiler message below.\n\n' >&2
|
|
|
eb4330 |
printf 'cmd: %s < /dev/null > /dev/null\n' "$ccenv_cmd" >&2
|
|
|
eb4330 |
printf '%s\n\n' "$ccenv_errors" >&2
|
|
|
eb4330 |
else
|
|
|
eb4330 |
printf 'ccenv:\n' >&2
|
|
|
eb4330 |
printf 'ccenv: something went wrong, bailing out.\n\n' >&2
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
return 2
|
|
|
eb4330 |
fi
|
|
|
487309 |
|
|
|
487309 |
ccenv_tool_epilog "$ccenv_cc"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_cpp()
|
|
|
eb4330 |
{
|
|
|
487309 |
ccenv_tool_prolog 'C pre-processor'
|
|
|
487309 |
|
|
|
eb4330 |
case "$ccenv_cc_cmd" in
|
|
|
eb4330 |
cc | c99 | c11 | gcc)
|
|
|
eb4330 |
ccenv_cpp_prefix=
|
|
|
eb4330 |
ccenv_candidates="cpp" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
clang )
|
|
|
eb4330 |
ccenv_cpp_prefix=
|
|
|
eb4330 |
ccenv_candidates="clang-cpp" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
*-cc )
|
|
|
eb4330 |
ccenv_cpp_prefix=${ccenv_cc_cmd%-cc*}-
|
|
|
eb4330 |
ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
*-c99 )
|
|
|
eb4330 |
ccenv_cpp_prefix=${ccenv_cc_cmd%-c99*}-
|
|
|
eb4330 |
ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
*-c11 )
|
|
|
eb4330 |
ccenv_cpp_prefix=${ccenv_cc_cmd%-c11*}-
|
|
|
eb4330 |
ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
*-gcc )
|
|
|
eb4330 |
ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
|
|
|
eb4330 |
ccenv_candidates="${ccenv_cpp_prefix}cpp" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
*-clang )
|
|
|
eb4330 |
ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
|
|
|
eb4330 |
ccenv_candidates="${ccenv_cpp_prefix}clang-cpp" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
* )
|
|
|
eb4330 |
ccenv_cpp="$ccenv_cc -E"
|
|
|
487309 |
ccenv_tool_epilog "$ccenv_cpp"
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
esac
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_tool" = false ]; then
|
|
|
eb4330 |
ccenv_cpp="$ccenv_cc -E"
|
|
|
eb4330 |
elif [ -n "$ccenv_tflags" ]; then
|
|
|
eb4330 |
ccenv_cpp="$ccenv_tool $ccenv_tflags"
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_cpp="$ccenv_tool"
|
|
|
eb4330 |
fi
|
|
|
487309 |
|
|
|
487309 |
ccenv_tool_epilog "$ccenv_cpp"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_cxx()
|
|
|
eb4330 |
{
|
|
|
487309 |
ccenv_tool_prolog 'C++ compiler'
|
|
|
487309 |
|
|
|
eb4330 |
case "$ccenv_cc_cmd" in
|
|
|
eb4330 |
cc | c99 | c11 )
|
|
|
eb4330 |
ccenv_cxx_prefix=
|
|
|
eb4330 |
ccenv_candidates="cxx c++" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
gcc )
|
|
|
eb4330 |
ccenv_cxx_prefix=
|
|
|
eb4330 |
ccenv_candidates="g++" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
clang )
|
|
|
eb4330 |
ccenv_cxx_prefix=
|
|
|
eb4330 |
ccenv_candidates="clang++" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
*-gcc )
|
|
|
eb4330 |
ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}-
|
|
|
eb4330 |
ccenv_candidates="${ccenv_cpp_prefix}g++" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
*-clang )
|
|
|
eb4330 |
ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}-
|
|
|
eb4330 |
ccenv_candidates="${ccenv_cpp_prefix}clang++" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
*cc )
|
|
|
eb4330 |
ccenv_cxx_prefix=${ccenv_cc_cmd%cc*}
|
|
|
eb4330 |
ccenv_candidates="${ccenv_cpp_prefix}++" ;;
|
|
|
eb4330 |
|
|
|
eb4330 |
* )
|
|
|
eb4330 |
ccenv_cxx="$ccenv_cc -xc++"
|
|
|
487309 |
ccenv_tool_epilog "$ccenv_cxx"
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
esac
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_find_tool
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ "$ccenv_tool" = false ]; then
|
|
|
eb4330 |
ccenv_cxx="$ccenv_cc -xc++"
|
|
|
eb4330 |
elif [ -n "$ccenv_tflags" ]; then
|
|
|
eb4330 |
ccenv_cxx="$ccenv_tool $ccenv_tflags"
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_cxx="$ccenv_tool"
|
|
|
eb4330 |
fi
|
|
|
487309 |
|
|
|
487309 |
ccenv_tool_epilog "$ccenv_cxx"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_cc_host()
|
|
|
eb4330 |
{
|
|
|
0e4b02 |
ccenv_attr_prolog 'system'
|
|
|
eb4330 |
ccenv_cc_host="$ccenv_cchost"
|
|
|
487309 |
ccenv_attr_epilog "$ccenv_cc_host"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_cc_bits()
|
|
|
eb4330 |
{
|
|
|
487309 |
ccenv_attr_prolog 'bits'
|
|
|
487309 |
|
|
|
eb4330 |
ccenv_internal_size=
|
|
|
eb4330 |
ccenv_internal_type='void *'
|
|
|
eb4330 |
ccenv_internal_test='char x[(sizeof(%s) == %s/8) ? 1 : -1];'
|
|
|
eb4330 |
|
|
|
eb4330 |
for ccenv_internal_guess in 64 32 128; do
|
|
|
15e4c2 |
if [ -z "${ccenv_internal_size:-}" ]; then
|
|
|
409f71 |
ccenv_internal_str=$(printf "$ccenv_internal_test" \
|
|
|
409f71 |
"$ccenv_internal_type" \
|
|
|
eb4330 |
"$ccenv_internal_guess")
|
|
|
eb4330 |
|
|
|
49c0a4 |
printf '%s' "$ccenv_internal_str" \
|
|
|
49c0a4 |
| $ccenv_cc -S -xc - -o - \
|
|
|
49c0a4 |
$(printf '%s' "$ccenv_cflags") \
|
|
|
0d8567 |
> /dev/null 2>&3 \
|
|
|
eb4330 |
&& ccenv_internal_size=$ccenv_internal_guess
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
done
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_cc_bits=$ccenv_internal_size
|
|
|
487309 |
|
|
|
487309 |
ccenv_attr_epilog "$ccenv_cc_bits"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_cc_underscore()
|
|
|
eb4330 |
{
|
|
|
487309 |
ccenv_attr_prolog 'prepended underscores'
|
|
|
487309 |
|
|
|
eb4330 |
ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe'
|
|
|
eb4330 |
ccenv_fn_code='int %s(void){return 0;}'
|
|
|
eb4330 |
|
|
|
c6f04a |
if printf "$ccenv_fn_code" $ccenv_fn_name \
|
|
|
c6f04a |
| $ccenv_cc -xc - -S -o - \
|
|
|
c6f04a |
| grep "^_$ccenv_fn_name:" \
|
|
|
c6f04a |
> /dev/null; then
|
|
|
c6f04a |
ccenv_cc_underscore='_'
|
|
|
487309 |
ccenv_attr_epilog 'yes'
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
|
|
|
487309 |
ccenv_attr_epilog 'no'
|
|
|
487309 |
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_create_framework_executable()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
if [ -f $ccenv_image ]; then
|
|
|
eb4330 |
mv $ccenv_image $ccenv_image.tmp
|
|
|
eb4330 |
rm -f $ccenv_image.tmp
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
printf 'int main(void){return 0;}' \
|
|
|
eb4330 |
| $ccenv_cc -xc - \
|
|
|
eb4330 |
-o $ccenv_image \
|
|
|
56b073 |
2>/dev/null \
|
|
|
eb4330 |
|| return 1
|
|
|
eb4330 |
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_create_freestanding_executable()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
if [ -f $ccenv_image ]; then
|
|
|
eb4330 |
mv $ccenv_image $ccenv_image.tmp
|
|
|
eb4330 |
rm -f $ccenv_image.tmp
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -z "ccenv_cc_underscore" ]; then
|
|
|
eb4330 |
ccenv_start_fn='_start'
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_start_fn='start'
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
printf 'int %s(void){return 0;}' "$ccenv_start_fn" \
|
|
|
eb4330 |
| $ccenv_cc -xc - \
|
|
|
eb4330 |
-ffreestanding \
|
|
|
eb4330 |
-nostdlib -nostartfiles \
|
|
|
eb4330 |
-o $ccenv_image \
|
|
|
eb4330 |
|| return 1
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_freestd=yes
|
|
|
eb4330 |
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
487309 |
ccenv_set_cc_binfmt_error()
|
|
|
487309 |
{
|
|
|
487309 |
ccenv_attr_epilog '(unable to create executable)'
|
|
|
487309 |
}
|
|
|
487309 |
|
|
|
eb4330 |
ccenv_set_cc_binfmt()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
ccenv_use_perk=
|
|
|
72602c |
ccenv_use_otool=
|
|
|
eb4330 |
ccenv_use_readelf=
|
|
|
eb4330 |
ccenv_use_readobj=
|
|
|
eb4330 |
ccenv_use_bfd_objdump=
|
|
|
eb4330 |
ccenv_use_llvm_objdump=
|
|
|
eb4330 |
|
|
|
487309 |
ccenv_attr_prolog 'binary format'
|
|
|
487309 |
|
|
|
eb4330 |
ccenv_create_framework_executable \
|
|
|
eb4330 |
|| ccenv_create_freestanding_executable \
|
|
|
487309 |
|| ccenv_set_cc_binfmt_error \
|
|
|
eb4330 |
|| return 0
|
|
|
eb4330 |
|
|
|
eb4330 |
# PE / perk
|
|
|
eb4330 |
if [ -n "$ccenv_perk" ]; then
|
|
|
0d8567 |
if $ccenv_perk $ccenv_image 2>&3; then
|
|
|
c6f04a |
ccenv_cc_binfmt='PE'
|
|
|
c6f04a |
ccenv_use_perk=yes
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
# ELF / readelf
|
|
|
eb4330 |
if [ -n "$ccenv_readelf" ] && [ -z "$ccenv_cc_binfmt" ]; then
|
|
|
0d8567 |
if $ccenv_readelf -h $ccenv_image 2>&3 \
|
|
|
c6f04a |
| grep 'Magic:' | sed -e 's/[ ]*//g' \
|
|
|
c6f04a |
| grep 'Magic:7f454c46' \
|
|
|
c6f04a |
> /dev/null; then
|
|
|
c6f04a |
ccenv_cc_binfmt='ELF'
|
|
|
c6f04a |
ccenv_use_readelf=yes
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
# a marble of astonishing design:
|
|
|
eb4330 |
# llvm-readelf also parses PE and Mach-O
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -n "$ccenv_readelf_llvm" ]; then
|
|
|
eb4330 |
ccenv_readany="$ccenv_readelf_llvm"
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_readany="$ccenv_readelf"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
# PE / readelf
|
|
|
eb4330 |
if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
|
|
|
0d8567 |
if $ccenv_readany -h $ccenv_image 2>&3 \
|
|
|
c6f04a |
| grep 'Magic:' | sed -e 's/[ ]*//g' \
|
|
|
c6f04a |
| grep 'Magic:MZ' \
|
|
|
c6f04a |
> /dev/null; then
|
|
|
c6f04a |
ccenv_cc_binfmt='PE'
|
|
|
c6f04a |
ccenv_use_readelf=yes
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
72602c |
# MACHO-64 / otool
|
|
|
72602c |
if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
|
|
|
0d8567 |
if $ccenv_otool -hv $ccenv_image 2>&3 \
|
|
|
c6f04a |
| grep -i 'MH_MAGIC_64' \
|
|
|
c6f04a |
> /dev/null; then
|
|
|
c6f04a |
ccenv_cc_binfmt='MACHO'
|
|
|
c6f04a |
ccenv_use_otool=yes
|
|
|
c6f04a |
fi
|
|
|
72602c |
fi
|
|
|
72602c |
|
|
|
72602c |
# MACHO-32 / otool
|
|
|
72602c |
if [ -n "$ccenv_otool" ] && [ -z "$ccenv_cc_binfmt" ]; then
|
|
|
0d8567 |
if $ccenv_otool -hv $ccenv_image 2>&3 \
|
|
|
c6f04a |
| grep -i 'MH_MAGIC' \
|
|
|
c6f04a |
> /dev/null; then
|
|
|
c6f04a |
ccenv_cc_binfmt='MACHO'
|
|
|
c6f04a |
ccenv_use_otool=yes
|
|
|
c6f04a |
fi
|
|
|
72602c |
fi
|
|
|
72602c |
|
|
|
eb4330 |
# MACHO-64 / readelf
|
|
|
eb4330 |
if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
|
|
|
0d8567 |
if $ccenv_readany -h $ccenv_image 2>&3 \
|
|
|
c6f04a |
| grep -i 'Magic:' | sed -e 's/[ ]*//g' \
|
|
|
c6f04a |
| grep -i '(0xfeedfacf)' \
|
|
|
c6f04a |
> /dev/null; then
|
|
|
c6f04a |
ccenv_cc_binfmt='MACHO'
|
|
|
c6f04a |
ccenv_use_readelf=yes
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
# MACHO-32 / readelf
|
|
|
eb4330 |
if [ -n "$ccenv_readany" ] && [ -z "$ccenv_cc_binfmt" ]; then
|
|
|
0d8567 |
if $ccenv_readany -h $ccenv_image 2>&3 \
|
|
|
c6f04a |
| grep -i 'Magic:' | sed -e 's/[ ]*//g' \
|
|
|
c6f04a |
| grep -i '(0xcafebabe)' \
|
|
|
c6f04a |
> /dev/null; then
|
|
|
c6f04a |
ccenv_cc_binfmt='MACHO'
|
|
|
c6f04a |
ccenv_use_readelf=yes
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
# MACHO / readobj
|
|
|
eb4330 |
if [ -n "$ccenv_readobj" ] && [ -z "$ccenv_cc_binfmt" ]; then
|
|
|
0d8567 |
if $ccenv_readobj $ccenv_image 2>&3 \
|
|
|
c6f04a |
| grep -i 'Format:' | sed 's/ /_/g' \
|
|
|
c6f04a |
| grep -i '_Mach-O_' \
|
|
|
c6f04a |
> /dev/null; then
|
|
|
c6f04a |
ccenv_cc_binfmt='MACHO'
|
|
|
c6f04a |
ccenv_use_readobj=yes
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
# MACHO / objdump (llvm)
|
|
|
eb4330 |
if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
|
|
|
c6f04a |
if $ccenv_objdump -section-headers $ccenv_image \
|
|
|
0d8567 |
2>&3 \
|
|
|
c6f04a |
| grep -i 'file format Mach-O' \
|
|
|
c6f04a |
> /dev/null; then
|
|
|
c6f04a |
ccenv_cc_binfmt='MACHO'
|
|
|
c6f04a |
ccenv_use_objdump=yes
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
# MACHO / objdump (bfd)
|
|
|
eb4330 |
if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
|
|
|
0d8567 |
$ccenv_objdump -h $ccenv_image 2>&3 \
|
|
|
eb4330 |
| grep -i 'file format Mach-O' \
|
|
|
eb4330 |
> /dev/null \
|
|
|
eb4330 |
&& ccenv_cc_binfmt='MACHO' \
|
|
|
eb4330 |
&& ccenv_use_objdump=yes
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
# PE / objdump (bfd)
|
|
|
eb4330 |
if [ -n "$ccenv_objdump" ] && [ -z "$ccenv_cc_binfmt" ]; then
|
|
|
0d8567 |
if $ccenv_objdump -h $ccenv_image 2>&3 \
|
|
|
c6f04a |
| grep -i 'file format pei-' \
|
|
|
c6f04a |
> /dev/null; then
|
|
|
c6f04a |
ccenv_cc_binfmt='PE'
|
|
|
c6f04a |
ccenv_use_bfd_objdump=yes
|
|
|
c6f04a |
fi
|
|
|
eb4330 |
fi
|
|
|
487309 |
|
|
|
487309 |
ccenv_attr_epilog "$ccenv_cc_binfmt"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os_pe()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
if [ -n "$ccenv_freestd" ]; then
|
|
|
eb4330 |
case "$ccenv_cchost" in
|
|
|
eb4330 |
*-midipix | *-midipix-* )
|
|
|
eb4330 |
ccenv_os='midipix' ;;
|
|
|
eb4330 |
*-mingw | *-mingw32 | *-mingw64 )
|
|
|
eb4330 |
ccenv_os='mingw' ;;
|
|
|
eb4330 |
*-mingw-* | *-mingw32-* | *-mingw64 )
|
|
|
eb4330 |
ccenv_os='mingw' ;;
|
|
|
eb4330 |
*-msys | *-msys2 | *-msys-* | *-msys2-* )
|
|
|
eb4330 |
ccenv_os='msys' ;;
|
|
|
eb4330 |
*-cygwin | *-cygwin-* )
|
|
|
eb4330 |
ccenv_os='cygwin' ;;
|
|
|
eb4330 |
esac
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -n "$ccenv_os" ]; then
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -n "$ccenv_use_perk" ]; then
|
|
|
eb4330 |
ccenv_framework=$($ccenv_perk -y $ccenv_image)
|
|
|
eb4330 |
ccenv_os=${ccenv_framework#*-*-*-*}
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
|
|
|
eb4330 |
$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
|
|
|
eb4330 |
| grep 'cygwin1.dll' > /dev/null \
|
|
|
eb4330 |
&& ccenv_os='cygwin'
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
|
|
|
eb4330 |
$ccenv_objdump_bfd -x $ccenv_image | grep -i 'DLL Name' \
|
|
|
eb4330 |
| grep 'msys-2.0.dll' > /dev/null \
|
|
|
eb4330 |
&& ccenv_os='msys'
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -z "$ccenv_os" ] && [ -n "$ccenv_objdump_bfd" ]; then
|
|
|
eb4330 |
$ccenv_objdump_bfd -x $ccenv_image \
|
|
|
eb4330 |
| grep -i 'DLL Name' | grep '.CRT' \
|
|
|
eb4330 |
> /dev/null \
|
|
|
eb4330 |
&& $ccenv_objdump_bfd -x $ccenv_image \
|
|
|
eb4330 |
| grep -i 'DLL Name' | grep '.bss' \
|
|
|
eb4330 |
> /dev/null \
|
|
|
eb4330 |
&& $ccenv_objdump_bfd -x $ccenv_image \
|
|
|
eb4330 |
| grep -i 'DLL Name' | grep '.tls' \
|
|
|
eb4330 |
> /dev/null \
|
|
|
eb4330 |
&& ccenv_os='mingw'
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os_macho()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
case "$ccenv_cchost" in
|
|
|
eb4330 |
*-apple-darwin* )
|
|
|
eb4330 |
ccenv_os='darwin' ;;
|
|
|
eb4330 |
esac
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os()
|
|
|
eb4330 |
{
|
|
|
487309 |
ccenv_attr_prolog 'os name'
|
|
|
487309 |
|
|
|
eb4330 |
case "$ccenv_cc_binfmt" in
|
|
|
eb4330 |
PE )
|
|
|
eb4330 |
ccenv_set_os_pe ;;
|
|
|
eb4330 |
MACHO )
|
|
|
eb4330 |
ccenv_set_os_macho ;;
|
|
|
eb4330 |
esac
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -n "$ccenv_os" ]; then
|
|
|
487309 |
ccenv_attr_epilog "$ccenv_os"
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
case "$ccenv_cchost" in
|
|
|
eb4330 |
*-*-*-* )
|
|
|
c6a6d5 |
ccenv_tip=${ccenv_cchost%-*}
|
|
|
eb4330 |
ccenv_os=${ccenv_tip#*-*-}
|
|
|
eb4330 |
;;
|
|
|
c6a6d5 |
*-*-musl | *-*-gnu )
|
|
|
c6a6d5 |
ccenv_tip=${ccenv_cchost%-*}
|
|
|
eb4330 |
ccenv_os=${ccenv_tip#*-}
|
|
|
eb4330 |
;;
|
|
|
c6a6d5 |
*-*-* )
|
|
|
c6a6d5 |
ccenv_os=${ccenv_cchost#*-*-}
|
|
|
c6a6d5 |
;;
|
|
|
c6a6d5 |
*-* )
|
|
|
c6a6d5 |
ccenv_os=${ccenv_cchost#*-}
|
|
|
c6a6d5 |
;;
|
|
|
eb4330 |
esac
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -z "$ccenv_os" ]; then
|
|
|
eb4330 |
ccenv_os='anyos'
|
|
|
eb4330 |
fi
|
|
|
487309 |
|
|
|
487309 |
ccenv_attr_epilog "$ccenv_os"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os_flags()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
case "$ccenv_os" in
|
|
|
eb4330 |
darwin )
|
|
|
eb4330 |
ccenv_cflags_os='-D_DARWIN_C_SOURCE'
|
|
|
eb4330 |
ccenv_cflags_pic='-fPIC'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
midipix )
|
|
|
eb4330 |
ccenv_cflags_os=
|
|
|
eb4330 |
ccenv_cflags_pic='-fPIC'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
cygwin )
|
|
|
eb4330 |
ccenv_cflags_os=
|
|
|
eb4330 |
ccenv_cflags_pic=
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
msys | msys* | mingw | mingw* )
|
|
|
eb4330 |
ccenv_cflags_os='-U__STRICT_ANSI__'
|
|
|
eb4330 |
ccenv_cflags_pic=
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
* )
|
|
|
eb4330 |
ccenv_cflags_os=
|
|
|
eb4330 |
ccenv_cflags_pic='-fPIC'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
esac
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os_semantics()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
# binary_format - core_api - ex_api - dependency_resolution
|
|
|
eb4330 |
|
|
|
487309 |
ccenv_attr_prolog 'os semantics'
|
|
|
487309 |
|
|
|
eb4330 |
case "$ccenv_os" in
|
|
|
eb4330 |
linux )
|
|
|
eb4330 |
ccenv_os_semantics='elf-posix-linux-ldso'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
bsd )
|
|
|
eb4330 |
ccenv_os_semantics='elf-posix-bsd-ldso'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
darwin )
|
|
|
eb4330 |
ccenv_os_semantics='macho-posix-osx-ldso'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
midipix )
|
|
|
eb4330 |
ccenv_os_semantics='pe-posix-winnt-ldso'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
cygwin )
|
|
|
eb4330 |
ccenv_os_semantics='pe-hybrid-winnt-unsafe'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
msys )
|
|
|
eb4330 |
ccenv_os_semantics='pe-hybrid-winnt-unsafe'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
mingw )
|
|
|
eb4330 |
ccenv_os_semantics='pe-win32-winnt-unsafe'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
esac
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -n "$ccenv_os_semantics" ]; then
|
|
|
487309 |
ccenv_attr_epilog "$ccenv_os_semantics"
|
|
|
eb4330 |
return 0
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ -n "$ccenv_cc_binfmt" ]; then
|
|
|
eb4330 |
ccenv_os_semantics_pattern='%s-posix-anyos-unknown'
|
|
|
eb4330 |
ccenv_os_semantics=$(printf \
|
|
|
eb4330 |
"$ccenv_os_semantics_pattern" \
|
|
|
eb4330 |
"$ccenv_cc_binfmt" \
|
|
|
eb4330 |
| tr '[:upper:]' '[:lower:]')
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_os_semantics='unknown-posix-anyos-unknown'
|
|
|
eb4330 |
fi
|
|
|
487309 |
|
|
|
487309 |
ccenv_attr_epilog "$ccenv_os_semantics"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
95c797 |
ccenv_set_os_dso_format()
|
|
|
95c797 |
{
|
|
|
95c797 |
ccenv_attr_prolog 'os dso format'
|
|
|
95c797 |
|
|
|
95c797 |
case "$ccenv_cc_arfmt" in
|
|
|
95c797 |
common )
|
|
|
95c797 |
ccenv_cc_sofmt="$ccenv_cc_binfmt"
|
|
|
95c797 |
;;
|
|
|
95c797 |
|
|
|
95c797 |
bigaf )
|
|
|
95c797 |
ccenv_libgcc_s_a_header=$(od -b -N8 \
|
|
|
95c797 |
$($ccenv_cc -print-file-name=libgcc_s.a) \
|
|
|
95c797 |
2>/dev/null \
|
|
|
95c797 |
| head -n1)
|
|
|
95c797 |
|
|
|
95c797 |
ccenv_libgcc_s_so_header=$(od -b -N8 \
|
|
|
95c797 |
$($ccenv_cc -print-file-name=libgcc_s.so) \
|
|
|
95c797 |
2>/dev/null \
|
|
|
95c797 |
| head -n1)
|
|
|
95c797 |
|
|
|
95c797 |
if [ "$ccenv_libgcc_s_a_header" = "$ccenv_bigaf_header" ]; then
|
|
|
95c797 |
ccenv_cc_sofmt='bigaf'
|
|
|
95c797 |
elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_bigaf_header" ]; then
|
|
|
95c797 |
ccenv_cc_sofmt='bigaf'
|
|
|
95c797 |
else
|
|
|
95c797 |
ccenv_cc_sofmt="$ccenv_cc_binfmt"
|
|
|
95c797 |
fi
|
|
|
95c797 |
;;
|
|
|
95c797 |
|
|
|
95c797 |
aiaff )
|
|
|
95c797 |
ccenv_libgcc_s_a_header=$(od -b -N8 \
|
|
|
95c797 |
$($ccenv_cc -print-file-name=libgcc_s.a) \
|
|
|
95c797 |
| head -n1)
|
|
|
95c797 |
|
|
|
95c797 |
ccenv_libgcc_s_so_header=$(od -b -N8 \
|
|
|
95c797 |
$($ccenv_cc -print-file-name=libgcc_s.so) \
|
|
|
95c797 |
| head -n1)
|
|
|
95c797 |
|
|
|
95c797 |
if [ "$ccenv_libgcc_s_a_header" = "$ccenv_aiaff_header" ]; then
|
|
|
95c797 |
ccenv_cc_sofmt='aiaff'
|
|
|
95c797 |
elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_aiaff_header" ]; then
|
|
|
95c797 |
ccenv_cc_sofmt='aiaff'
|
|
|
95c797 |
else
|
|
|
95c797 |
ccenv_cc_sofmt="$ccenv_cc_binfmt"
|
|
|
95c797 |
fi
|
|
|
95c797 |
;;
|
|
|
95c797 |
esac
|
|
|
95c797 |
|
|
|
18acfc |
if [ "$ccenv_cfgtype" = 'host' ]; then
|
|
|
18acfc |
case "$ccenv_cc_sofmt" in
|
|
|
18acfc |
bigaf | aiaff )
|
|
|
18acfc |
mb_shared_lib_cmd='$(AR) -rcs'
|
|
|
18acfc |
mb_shared_lib_ldflags=
|
|
|
18acfc |
;;
|
|
|
18acfc |
|
|
|
18acfc |
* )
|
|
|
18acfc |
mb_shared_lib_cmd='$(CC) -shared -o'
|
|
|
18acfc |
mb_shared_lib_ldflags='$(LDFLAGS_SHARED)'
|
|
|
18acfc |
;;
|
|
|
18acfc |
esac
|
|
|
18acfc |
fi
|
|
|
18acfc |
|
|
|
95c797 |
ccenv_attr_epilog "$ccenv_cc_sofmt"
|
|
|
95c797 |
}
|
|
|
95c797 |
|
|
|
eb4330 |
ccenv_set_os_dso_exrules()
|
|
|
eb4330 |
{
|
|
|
487309 |
ccenv_attr_prolog 'os dso exrules'
|
|
|
487309 |
|
|
|
eb4330 |
case "$ccenv_os" in
|
|
|
eb4330 |
midipix )
|
|
|
eb4330 |
ccenv_os_dso_exrules='pe-mdso'
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
* )
|
|
|
eb4330 |
if [ "$ccenv_cc_binfmt" = 'PE' ]; then
|
|
|
eb4330 |
ccenv_os_dso_exrules='pe-dlltool'
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_os_dso_exrules='default'
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
esac
|
|
|
487309 |
|
|
|
487309 |
ccenv_attr_epilog "$ccenv_os_dso_exrules"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os_dso_linkage()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
# todo: PIC, PIE, and friends
|
|
|
487309 |
ccenv_attr_prolog 'os linkage'
|
|
|
eb4330 |
ccenv_os_dso_linkage='default'
|
|
|
487309 |
ccenv_attr_epilog "$ccenv_os_dso_linkage"
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os_dso_patterns_darwin()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
ccenv_os_app_prefix=
|
|
|
eb4330 |
ccenv_os_app_suffix=
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_lib_prefix=lib
|
|
|
eb4330 |
ccenv_os_lib_suffix=.dylib
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_implib_ext=.invalid
|
|
|
eb4330 |
ccenv_os_libdef_ext=.invalid
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_archive_ext=.a
|
|
|
eb4330 |
ccenv_os_soname=symlink
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_lib_prefixed_suffix=
|
|
|
eb4330 |
ccenv_os_lib_suffixed_suffix='$(OS_LIB_SUFFIX)'
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os_dso_patterns_mdso()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
ccenv_os_app_prefix=
|
|
|
eb4330 |
ccenv_os_app_suffix=
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_lib_prefix=lib
|
|
|
eb4330 |
ccenv_os_lib_suffix=.so
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_implib_ext=.lib.a
|
|
|
eb4330 |
ccenv_os_libdef_ext=.so.def
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_archive_ext=.a
|
|
|
eb4330 |
ccenv_os_soname=symlink
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
|
|
|
eb4330 |
ccenv_os_lib_suffixed_suffix=
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os_dso_patterns_dlltool()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
ccenv_os_app_prefix=
|
|
|
eb4330 |
ccenv_os_app_suffix=.exe
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_lib_prefix=lib
|
|
|
eb4330 |
ccenv_os_lib_suffix=.dll
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_implib_ext=.dll.a
|
|
|
eb4330 |
ccenv_os_libdef_ext=.def
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_archive_ext=.a
|
|
|
eb4330 |
ccenv_os_soname=copy
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
|
|
|
eb4330 |
ccenv_os_lib_suffixed_suffix=
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os_dso_patterns_default()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
ccenv_os_app_prefix=
|
|
|
eb4330 |
ccenv_os_app_suffix=
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_lib_prefix=lib
|
|
|
eb4330 |
ccenv_os_lib_suffix=.so
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_implib_ext=.invalid
|
|
|
eb4330 |
ccenv_os_libdef_ext=.invalid
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_archive_ext=.a
|
|
|
eb4330 |
ccenv_os_soname=symlink
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_os_lib_prefixed_suffix='$(OS_LIB_SUFFIX)'
|
|
|
eb4330 |
ccenv_os_lib_suffixed_suffix=
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os_dso_patterns()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
# sover: .so.x.y.z
|
|
|
eb4330 |
# verso: .x.y.z.so
|
|
|
eb4330 |
|
|
|
eb4330 |
case "$ccenv_os" in
|
|
|
eb4330 |
darwin )
|
|
|
eb4330 |
ccenv_set_os_dso_patterns_darwin
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
midipix )
|
|
|
eb4330 |
ccenv_set_os_dso_patterns_mdso
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
cygwin | msys | mingw )
|
|
|
eb4330 |
ccenv_set_os_dso_patterns_dlltool
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
* )
|
|
|
eb4330 |
ccenv_set_os_dso_patterns_default
|
|
|
eb4330 |
;;
|
|
|
eb4330 |
esac
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
6598d3 |
ccenv_set_os_pe_switches()
|
|
|
6598d3 |
{
|
|
|
9a7d8a |
if [ "$ccenv_cc_binfmt" = 'PE' ] && [ -z "$ccenv_pe_subsystem" ]; then
|
|
|
6598d3 |
case "$ccenv_os" in
|
|
|
6598d3 |
midipix | mingw )
|
|
|
6598d3 |
ccenv_pe_subsystem='windows'
|
|
|
6598d3 |
;;
|
|
|
6598d3 |
* )
|
|
|
6598d3 |
ccenv_pe_subsystem='console'
|
|
|
6598d3 |
;;
|
|
|
6598d3 |
esac
|
|
|
6598d3 |
fi
|
|
|
6598d3 |
}
|
|
|
6598d3 |
|
|
|
eb4330 |
ccenv_output_defs()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
ccenv_in="$mb_project_dir/sofort/ccenv/ccenv.in"
|
|
|
eb4330 |
ccenv_mk="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
|
|
|
25b012 |
ccenv_tmp=
|
|
|
eb4330 |
|
|
|
6598d3 |
if [ "$ccenv_cc_binfmt" = 'PE' ]; then
|
|
|
6598d3 |
ccenv_pe="$mb_project_dir/sofort/ccenv/pedefs.in"
|
|
|
6598d3 |
ccenv_in="$ccenv_in $ccenv_pe"
|
|
|
6598d3 |
fi
|
|
|
6598d3 |
|
|
|
eb4330 |
if [ $ccenv_cfgtype = 'native' ]; then
|
|
|
eb4330 |
|
|
|
1ea231 |
ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
|
|
|
eb4330 |
|
|
|
6fdafe |
sed \
|
|
|
f4c2b9 |
-e 's/^[[:space:]]*$/@/g' \
|
|
|
6fdafe |
-e 's/^/NATIVE_/' \
|
|
|
6fdafe |
-e 's/NATIVE_@//g' \
|
|
|
6fdafe |
-e 's/NATIVE_#/#/g' \
|
|
|
6fdafe |
-e 's/ =/=/g' \
|
|
|
6fdafe |
-e 's/ +=/+=/g' \
|
|
|
6598d3 |
$ccenv_in > "$ccenv_tmp"
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_in="$ccenv_tmp"
|
|
|
1ea231 |
else
|
|
|
25b012 |
unset ccenv_tmp
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
|
|
|
eb4330 |
| grep -v '^#')
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_exvars="ccenv_cfgtype ccenv_makevar_prefix"
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_sed_substs=" \
|
|
|
aecab0 |
$(for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do \
|
|
|
eb4330 |
printf '%s"$%s"%s' "-e 's/@$__var@/'" \
|
|
|
eb4330 |
"$__var" "'/g' "; \
|
|
|
eb4330 |
done)"
|
|
|
eb4330 |
|
|
|
6598d3 |
eval sed $ccenv_sed_substs $ccenv_in \
|
|
|
7a2822 |
| sed -e 's/[[:blank:]]*$//g' \
|
|
|
eb4330 |
> "$ccenv_mk"
|
|
|
eb4330 |
|
|
|
44cc21 |
if [ "$ccenv_cfgtype" = 'host' ]; then
|
|
|
aecab0 |
for __var in $(printf '%s' "$ccenv_vars"); do
|
|
|
44cc21 |
ccenv_src_var=$__var
|
|
|
44cc21 |
ccenv_dst_var=mb_${__var#*ccenv_}
|
|
|
44cc21 |
ccenv_var_expr='${'$ccenv_src_var':-}'
|
|
|
44cc21 |
eval $ccenv_dst_var=$ccenv_var_expr
|
|
|
44cc21 |
|
|
|
44cc21 |
done
|
|
|
44cc21 |
|
|
|
44cc21 |
mb_host=$ccenv_host
|
|
|
44cc21 |
mb_cchost=$ccenv_cchost
|
|
|
44cc21 |
else
|
|
|
aecab0 |
for __var in $(printf '%s' "$ccenv_vars"); do
|
|
|
44cc21 |
ccenv_src_var=$__var
|
|
|
44cc21 |
ccenv_dst_var=mb_native_${__var#*ccenv_}
|
|
|
44cc21 |
ccenv_var_expr='${'$ccenv_src_var':-}'
|
|
|
44cc21 |
eval "$ccenv_dst_var=$ccenv_var_expr"
|
|
|
44cc21 |
done
|
|
|
44cc21 |
|
|
|
44cc21 |
mb_native_host=$ccenv_host
|
|
|
44cc21 |
mb_native_cchost=$ccenv_cchost
|
|
|
44cc21 |
fi
|
|
|
1ea231 |
|
|
|
1ea231 |
if [ -n "${ccenv_tmp:-}" ]; then
|
|
|
1ea231 |
rm -f "$ccenv_tmp"
|
|
|
1ea231 |
unset ccenv_tmp
|
|
|
1ea231 |
fi
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
8c2980 |
ccenv_dso_verify()
|
|
|
8c2980 |
{
|
|
|
8c2980 |
ccenv_str='int foo(int x){return ++x;}'
|
|
|
8c2980 |
ccenv_cmd="$ccenv_cc -xc - -shared -o a.out"
|
|
|
8c2980 |
|
|
|
8c2980 |
rm -f a.out
|
|
|
8c2980 |
|
|
|
4da44e |
printf '%s' "$ccenv_str" | $(printf %s "$ccenv_cmd") \
|
|
|
0d8567 |
> /dev/null 2>&3 \
|
|
|
8c2980 |
|| mb_disable_shared=yes
|
|
|
8c2980 |
|
|
|
8c2980 |
rm -f a.out
|
|
|
8c2980 |
}
|
|
|
8c2980 |
|
|
|
eb4330 |
ccenv_clean_up()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
rm -f $ccenv_image
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_common_init()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
. "$mb_project_dir/sofort/ccenv/ccenv.vars"
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_cfgtype=$1
|
|
|
eb4330 |
ccenv_cfgfile="$mb_pwd/ccenv/$ccenv_cfgtype.mk"
|
|
|
eb4330 |
ccenv_freestd=
|
|
|
ec706e |
ccenv_cchost=
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ $ccenv_cfgtype = 'native' ]; then
|
|
|
eb4330 |
ccenv_makevar_prefix='NATIVE_'
|
|
|
eb4330 |
ccenv_image='./ccenv/native.a.out'
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_makevar_prefix=
|
|
|
eb4330 |
ccenv_image='./ccenv/host.a.out'
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ $ccenv_cfgtype = 'native' ]; then
|
|
|
eb4330 |
ccenv_prefixes=
|
|
|
eb4330 |
elif [ -n "$mb_cross_compile" ]; then
|
|
|
eb4330 |
ccenv_prefixes="$mb_cross_compile"
|
|
|
eb4330 |
elif [ -n "$mb_host" ]; then
|
|
|
eb4330 |
ccenv_prefixes="$mb_host-"
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_prefixes=
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
|
|
|
eb4330 |
if [ $ccenv_cfgtype = 'host' ]; then
|
|
|
eb4330 |
ccenv_tflags=
|
|
|
918e18 |
ccenv_cflags=$(${mb_make} -s -f "$mb_pwd/Makefile.tmp" OS_DSO_EXRULES=default .cflags-host)
|
|
|
52d597 |
|
|
|
eb4330 |
ccenv_cc="$mb_user_cc"
|
|
|
eb4330 |
ccenv_cpp="$mb_user_cpp"
|
|
|
eb4330 |
ccenv_cxx="$mb_user_cxx"
|
|
|
6598d3 |
|
|
|
6598d3 |
ccenv_pe_subsystem="$mb_pe_subsystem"
|
|
|
6598d3 |
ccenv_pe_image_base="$mb_pe_image_base"
|
|
|
eb4330 |
else
|
|
|
eb4330 |
ccenv_tflags=
|
|
|
918e18 |
ccenv_cflags=$(${mb_make} -s -f "$mb_pwd/Makefile.tmp" OS_DSO_EXRULES=default .cflags-native)
|
|
|
eb4330 |
ccenv_cc="$mb_native_cc"
|
|
|
eb4330 |
ccenv_cpp="$mb_native_cpp"
|
|
|
eb4330 |
ccenv_cxx="$mb_native_cxx"
|
|
|
6598d3 |
|
|
|
6598d3 |
ccenv_pe_subsystem="$mb_native_pe_subsystem"
|
|
|
6598d3 |
ccenv_pe_image_base="$mb_native_pe_image_base"
|
|
|
eb4330 |
fi
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_characteristics()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
ccenv_set_cc_host
|
|
|
eb4330 |
ccenv_set_cc_bits
|
|
|
eb4330 |
ccenv_set_cc_binfmt
|
|
|
487309 |
ccenv_set_cc_underscore
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_toolchain_variables()
|
|
|
eb4330 |
{
|
|
|
eb4330 |
ccenv_common_init $1
|
|
|
eb4330 |
ccenv_set_cc
|
|
|
eb4330 |
ccenv_set_cpp
|
|
|
eb4330 |
ccenv_set_cxx
|
|
|
eb4330 |
ccenv_set_primary_tools
|
|
|
eb4330 |
ccenv_set_tool_variants
|
|
|
eb4330 |
ccenv_set_characteristics
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_os
|
|
|
eb4330 |
ccenv_set_os_flags
|
|
|
eb4330 |
ccenv_set_os_semantics
|
|
|
95c797 |
ccenv_set_os_dso_format
|
|
|
eb4330 |
ccenv_set_os_dso_exrules
|
|
|
eb4330 |
ccenv_set_os_dso_linkage
|
|
|
eb4330 |
ccenv_set_os_dso_patterns
|
|
|
6598d3 |
ccenv_set_os_pe_switches
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_output_defs
|
|
|
eb4330 |
ccenv_clean_up
|
|
|
52d597 |
|
|
|
cb89b6 |
eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\'
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_host_variables()
|
|
|
eb4330 |
{
|
|
|
487309 |
output_script_status ${mb_script} \
|
|
|
93d557 |
'detect and query host (targeted) system'
|
|
|
487309 |
|
|
|
eb4330 |
ccenv_set_toolchain_variables 'host'
|
|
|
8c2980 |
ccenv_dso_verify
|
|
|
eb4330 |
}
|
|
|
eb4330 |
|
|
|
eb4330 |
ccenv_set_native_variables()
|
|
|
eb4330 |
{
|
|
|
487309 |
output_script_status ${mb_script} \
|
|
|
93d557 |
'detect and query native (local build) system'
|
|
|
487309 |
|
|
|
55f528 |
if [ _$mb_ccenv_skip_native != _yes ]; then
|
|
|
55f528 |
ccenv_set_toolchain_variables 'native'
|
|
|
55f528 |
fi
|
|
|
eb4330 |
}
|