|
|
5eb84a |
|
|
|
395e41 |
# ccenv.sh: sofort's tool-finding bits,
|
|
|
395e41 |
# invoked from within the project-agnostic configure script.
|
|
|
395e41 |
|
|
|
2ccc78 |
# this file is covered by COPYING.SOFORT.
|
|
|
2ccc78 |
|
|
|
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 |
|
|
|
5eb84a |
# variables available to cfgdefs.sh and cfgfini.sh:
|
|
|
5eb84a |
# ccenv_host_cflags: expanded cflags, valid for the host compiler
|
|
|
5eb84a |
# ccenv_host_ldflags: expanded ldflags, valid for the host compiler
|
|
|
237052 |
# ccenv_host_sysroot: host sysroot, as reported by the host compiler
|
|
|
5eb84a |
# ccenv_native_cflags: expanded cflags, valid for the native compiler
|
|
|
5eb84a |
# ccenv_native_ldflags: expanded ldflags, valid for the native compiler
|
|
|
237052 |
# ccenv_native_sysroot: native sysroot, as reported by the native compiler
|
|
|
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 |
|
|
|
b4651d |
ccenv_tool_prolog()
|
|
|
b4651d |
{
|
|
|
3f14ab |
ccenv_line_dots='.....................................'
|
|
|
53dcc4 |
ccenv_tool_desc=" == checking for ${1}"
|
|
|
b4651d |
ccenv_tool_dlen="${#ccenv_line_dots}"
|
|
|
b4651d |
|
|
|
6f2654 |
printf '\n%s\n' '________________________' >&3
|
|
|
6f2654 |
printf "ccenv: checking for ${1}\n\n" >&3
|
|
|
b4651d |
printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s" \
|
|
|
3f14ab |
"${ccenv_tool_desc} ${mb_line_dots}"
|
|
|
b4651d |
}
|
|
|
b4651d |
|
|
|
b4651d |
|
|
|
b4651d |
ccenv_tool_epilog()
|
|
|
b4651d |
{
|
|
|
b4651d |
ccenv_line_dots='................................'
|
|
|
b4651d |
ccenv_tool_dlen="$((${#ccenv_line_dots} - ${#1}))"
|
|
|
b4651d |
|
|
|
9650a9 |
case ${ccenv_tool_dlen} in
|
|
|
9650a9 |
0 | -* )
|
|
|
9650a9 |
ccenv_tool_dlen='3' ;;
|
|
|
9650a9 |
esac
|
|
|
9650a9 |
|
|
|
3f14ab |
printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s %s.\n" \
|
|
|
b4651d |
"${ccenv_line_dots}" "${1}"
|
|
|
6f2654 |
|
|
|
6f2654 |
if [ "${1}" = 'false' ]; then
|
|
|
6f2654 |
printf '\n\nccenv: not (yet) found.\n' >&3
|
|
|
6f2654 |
else
|
|
|
6f2654 |
printf "\n\nccenv : found $(command -v ${1}).\n" >&3
|
|
|
6f2654 |
fi
|
|
|
6f2654 |
|
|
|
6f2654 |
printf '%s\n' '------------------------' >&3
|
|
|
b4651d |
}
|
|
|
b4651d |
|
|
|
b4651d |
|
|
|
77216f |
ccenv_tool_variant_epilog()
|
|
|
77216f |
{
|
|
|
77216f |
ccenv_expr=${1}='${'${1}':-false}'
|
|
|
77216f |
eval "$ccenv_expr"
|
|
|
77216f |
|
|
|
77216f |
ccenv_expr='${'${1}'}'
|
|
|
77216f |
eval ccenv_tool_epilog "$ccenv_expr"
|
|
|
77216f |
}
|
|
|
77216f |
|
|
|
77216f |
|
|
|
b4651d |
ccenv_attr_prolog()
|
|
|
b4651d |
{
|
|
|
3f14ab |
ccenv_line_dots=' .....................................'
|
|
|
3f14ab |
ccenv_attr_desc=" == detect ${ccenv_cfgtype} ${1}"
|
|
|
b4651d |
ccenv_attr_dlen="${#ccenv_line_dots}"
|
|
|
b4651d |
|
|
|
b4651d |
printf "%${ccenv_attr_dlen}.${ccenv_attr_dlen}s" \
|
|
|
b4651d |
"${ccenv_attr_desc} ${ccenv_line_dots}"
|
|
|
6f2654 |
|
|
|
6f2654 |
printf '\n%s\n' '________________________' >&3
|
|
|
6f2654 |
printf "ccenv: detecting ${1}\n\n" >&3
|
|
|
b4651d |
}
|
|
|
b4651d |
|
|
|
b4651d |
|
|
|
b4651d |
ccenv_attr_epilog()
|
|
|
b4651d |
{
|
|
|
6f2654 |
ccenv_line_dots='................................'
|
|
|
3f14ab |
ccenv_tool_dlen="$((${#ccenv_line_dots} - 1 - ${#1}))"
|
|
|
6f2654 |
|
|
|
9650a9 |
case ${ccenv_tool_dlen} in
|
|
|
9650a9 |
0 | -* )
|
|
|
9650a9 |
ccenv_tool_dlen='3' ;;
|
|
|
9650a9 |
esac
|
|
|
9650a9 |
|
|
|
3f14ab |
printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s %s.\n" \
|
|
|
6f2654 |
"${ccenv_line_dots}" "${1}"
|
|
|
6f2654 |
|
|
|
6f2654 |
printf '\n\nccenv: detected result: %s\n' "${1}" >&3
|
|
|
6f2654 |
printf '%s\n' '------------------------' >&3
|
|
|
b4651d |
}
|
|
|
b4651d |
|
|
|
b4651d |
|
|
|
395e41 |
ccenv_find_tool()
|
|
|
395e41 |
{
|
|
|
395e41 |
if [ -z "$ccenv_prefixes" ]; then
|
|
|
0177a6 |
for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do
|
|
|
f5ec0e |
ccenv_cmd_args="${@:-}"
|
|
|
f5ec0e |
|
|
|
f5ec0e |
if [ -z "$ccenv_cmd_args" ]; 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
|
|
|
6f2654 |
if "$ccenv_candidate" $@ > /dev/null 2>&3; 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"
|
|
|
2a413c |
ccenv_peep_tools="perk mdso dlltool windmc windres pkgconf"
|
|
|
395e41 |
|
|
|
0177a6 |
for __tool in $(printf '%s' "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do
|
|
|
b4651d |
ccenv_tool_prolog "$__tool"
|
|
|
b4651d |
|
|
|
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 |
|
|
|
68f972 |
elif [ "$__tool" = 'pkgconf' ]; then
|
|
|
68f972 |
ccenv_candidates="$__tool pkg-config"
|
|
|
68f972 |
|
|
|
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 |
|
|
|
d838d9 |
ccenv_tool=
|
|
|
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"
|
|
|
d838d9 |
ccenv_tool="$ccenv_var_val"
|
|
|
395e41 |
else
|
|
|
395e41 |
ccenv_find_tool
|
|
|
395e41 |
eval ccenv_$__tool="$ccenv_tool"
|
|
|
395e41 |
fi
|
|
|
b4651d |
|
|
|
b4651d |
ccenv_tool_epilog "$ccenv_tool"
|
|
|
395e41 |
done
|
|
|
395e41 |
|
|
|
395e41 |
# windrc
|
|
|
395e41 |
ccenv_windrc="$ccenv_windres"
|
|
|
0c9995 |
|
|
|
0c9995 |
# archive format preamble
|
|
|
dc0fb6 |
if [ -n "$ccenv_dumpmachine_switch" ]; then
|
|
|
061779 |
ccenv_libgcc_path=$($ccenv_cc -print-file-name=libgcc.a \
|
|
|
061779 |
2>/dev/null)
|
|
|
061779 |
|
|
|
061779 |
if [ -n "$ccenv_libgcc_path" ]; then
|
|
|
061779 |
ccenv_libgcc_a_header=$(od -b -N8 \
|
|
|
061779 |
$($ccenv_cc -print-file-name=libgcc.a) \
|
|
|
061779 |
| head -n1)
|
|
|
061779 |
else
|
|
|
061779 |
ccenv_libgcc_a_header=
|
|
|
061779 |
fi
|
|
|
dc0fb6 |
else
|
|
|
dc0fb6 |
ccenv_libgcc_a_header=
|
|
|
dc0fb6 |
fi
|
|
|
dc0fb6 |
|
|
|
dc0fb6 |
# ar (default)
|
|
|
0c9995 |
ccenv_cc_arfmt='common'
|
|
|
0c9995 |
|
|
|
0c9995 |
# ar (big)
|
|
|
0c9995 |
ccenv_bigaf_header=$(printf '%s\n' '<bigaf>' | od -b | head -n1)
|
|
|
0c9995 |
|
|
|
0c9995 |
if [ "$ccenv_libgcc_a_header" = "$ccenv_bigaf_header" ]; then
|
|
|
0c9995 |
ccenv_cc_arfmt='bigaf'
|
|
|
0c9995 |
|
|
|
0c9995 |
for __tool in $(printf '%s' "$ccenv_core_tools"); do
|
|
|
0c9995 |
ccenv_var_name=ccenv_$__tool
|
|
|
0c9995 |
ccenv_var_expr='${'$ccenv_var_name':-}'
|
|
|
0c9995 |
eval ccenv_var_val="$ccenv_var_expr"
|
|
|
0c9995 |
|
|
|
0c9995 |
if [ "$ccenv_var_val" != false ]; then
|
|
|
0c9995 |
ccenv_var_val="$ccenv_var_val -X64"
|
|
|
0c9995 |
ccenv_var_expr='${ccenv_var_val:-}'
|
|
|
0c9995 |
eval ccenv_$__tool="$ccenv_var_expr"
|
|
|
0c9995 |
fi
|
|
|
0c9995 |
done
|
|
|
0c9995 |
fi
|
|
|
0c9995 |
|
|
|
0c9995 |
# ar (small)
|
|
|
0c9995 |
ccenv_aiaff_header=$(printf '%s\n' '<aiaff>' | od -b | head -n1)
|
|
|
0c9995 |
|
|
|
0c9995 |
if [ "$ccenv_libgcc_a_header" = "$ccenv_aiaff_header" ]; then
|
|
|
0c9995 |
ccenv_cc_arfmt='aiaff'
|
|
|
0c9995 |
|
|
|
0c9995 |
for __tool in $(printf '%s' "$ccenv_core_tools"); do
|
|
|
0c9995 |
ccenv_var_name=ccenv_$__tool
|
|
|
0c9995 |
ccenv_var_expr='${'$ccenv_var_name':-}'
|
|
|
0c9995 |
eval ccenv_var_val="$ccenv_var_expr"
|
|
|
0c9995 |
|
|
|
0c9995 |
if [ "$ccenv_var_val" != false ]; then
|
|
|
0c9995 |
ccenv_var_val="$ccenv_var_val -X32"
|
|
|
0c9995 |
ccenv_var_expr='${ccenv_var_val:-}'
|
|
|
0c9995 |
eval ccenv_$__tool="$ccenv_var_expr"
|
|
|
0c9995 |
fi
|
|
|
0c9995 |
done
|
|
|
0c9995 |
fi
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_set_tool_variants()
|
|
|
395e41 |
{
|
|
|
395e41 |
# as (asm)
|
|
|
b4651d |
ccenv_tool_prolog 'as (asm)'
|
|
|
395e41 |
ccenv_candidates=as
|
|
|
395e41 |
ccenv_find_tool
|
|
|
395e41 |
|
|
|
395e41 |
if [ "$ccenv_tool" = false ]; then
|
|
|
395e41 |
ccenv_as_asm=
|
|
|
395e41 |
else
|
|
|
7ca037 |
$ccenv_tool --help 2>&1 | grep -i '.bc assembler' \
|
|
|
395e41 |
|| ccenv_as_asm="$ccenv_tool"
|
|
|
395e41 |
fi
|
|
|
395e41 |
|
|
|
77216f |
ccenv_tool_variant_epilog 'ccenv_as_asm'
|
|
|
b4651d |
|
|
|
395e41 |
# as (ll)
|
|
|
b4651d |
ccenv_tool_prolog '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 |
|
|
|
77216f |
ccenv_tool_variant_epilog 'ccenv_as_ll'
|
|
|
b4651d |
|
|
|
395e41 |
# as (mc)
|
|
|
b4651d |
ccenv_tool_prolog '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 |
|
|
|
77216f |
ccenv_tool_variant_epilog 'ccenv_as_mc'
|
|
|
b4651d |
|
|
|
395e41 |
# ld (bfd)
|
|
|
b4651d |
ccenv_tool_prolog '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 |
|
|
|
77216f |
ccenv_tool_variant_epilog 'ccenv_ld_bfd'
|
|
|
b4651d |
|
|
|
395e41 |
# ld (gold)
|
|
|
b4651d |
ccenv_tool_prolog '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 |
|
|
|
77216f |
ccenv_tool_variant_epilog 'ccenv_ld_gold'
|
|
|
b4651d |
|
|
|
395e41 |
# ld (lld)
|
|
|
b4651d |
ccenv_tool_prolog '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 |
|
|
|
77216f |
ccenv_tool_variant_epilog 'ccenv_ld_lld'
|
|
|
b4651d |
|
|
|
395e41 |
# objdump (bfd)
|
|
|
b4651d |
ccenv_tool_prolog '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 |
|
|
|
77216f |
ccenv_tool_variant_epilog 'ccenv_objdump_bfd'
|
|
|
b4651d |
|
|
|
395e41 |
# objdump (llvm)
|
|
|
b4651d |
ccenv_tool_prolog '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 |
|
|
|
77216f |
ccenv_tool_variant_epilog 'ccenv_objdump_llvm'
|
|
|
b4651d |
|
|
|
395e41 |
# readelf (bfd)
|
|
|
b4651d |
ccenv_tool_prolog '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 |
|
|
|
77216f |
ccenv_tool_variant_epilog 'ccenv_readelf_bfd'
|
|
|
b4651d |
|
|
|
395e41 |
# readelf (llvm)
|
|
|
b4651d |
ccenv_tool_prolog '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 |
|
|
|
77216f |
ccenv_tool_variant_epilog 'ccenv_readelf_llvm'
|
|
|
b4651d |
|
|
|
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
|
|
|
818afc |
ccenv_candidates="cc gcc clang c99 c11"
|
|
|
395e41 |
fi
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_set_cc()
|
|
|
395e41 |
{
|
|
|
b4651d |
ccenv_tool_prolog 'C compiler'
|
|
|
b4651d |
|
|
|
395e41 |
if [ -z "$ccenv_cc" ]; then
|
|
|
395e41 |
ccenv_set_c_compiler_candidates
|
|
|
dc0fb6 |
ccenv_find_tool
|
|
|
395e41 |
ccenv_cc="$ccenv_tool"
|
|
|
395e41 |
fi
|
|
|
395e41 |
|
|
|
dc0fb6 |
|
|
|
395e41 |
if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then
|
|
|
395e41 |
ccenv_cc="$mb_compiler"
|
|
|
395e41 |
fi
|
|
|
395e41 |
|
|
|
dc0fb6 |
ccenv_tool_epilog "$ccenv_cc"
|
|
|
dc0fb6 |
|
|
|
dc0fb6 |
|
|
|
dc0fb6 |
if [ $ccenv_cfgtype = 'host' ]; then
|
|
|
dc0fb6 |
ccenv_host_cc="$ccenv_cc"
|
|
|
dc0fb6 |
cfgtest_host_section
|
|
|
dc0fb6 |
ccenv_host_cc=
|
|
|
dc0fb6 |
else
|
|
|
dc0fb6 |
ccenv_native_cc="$ccenv_cc"
|
|
|
dc0fb6 |
cfgtest_native_section
|
|
|
dc0fb6 |
ccenv_native_cc=
|
|
|
dc0fb6 |
fi
|
|
|
dc0fb6 |
|
|
|
f3f81b |
cfgtest_silent='yes'
|
|
|
f3f81b |
|
|
|
dc0fb6 |
if cfgtest_compiler_switch -dumpmachine ; then
|
|
|
dc0fb6 |
ccenv_dumpmachine_switch='-dumpmachine'
|
|
|
dc0fb6 |
else
|
|
|
dc0fb6 |
ccenv_dumpmachine_switch=
|
|
|
dc0fb6 |
fi
|
|
|
dc0fb6 |
|
|
|
88e755 |
if cfgtest_code_snippet_asm 'typedef int dummy;' ; then
|
|
|
88e755 |
eval ccenv_${ccenv_cfgtype}_stdin_input='yes'
|
|
|
88e755 |
else
|
|
|
88e755 |
eval ccenv_${ccenv_cfgtype}_stdin_input='no'
|
|
|
88e755 |
fi
|
|
|
88e755 |
|
|
|
f3f81b |
unset cfgtest_silent
|
|
|
f3f81b |
|
|
|
395e41 |
ccenv_cc_cmd="$ccenv_cc"
|
|
|
f06755 |
ccenv_errors=
|
|
|
395e41 |
|
|
|
395e41 |
if [ "$ccenv_cfgtype" = 'native' ]; then
|
|
|
b37f09 |
ccenv_host=
|
|
|
b37f09 |
|
|
|
eec083 |
if [ -n "$mb_native_host" ]; then
|
|
|
eec083 |
ccenv_host="$mb_native_host"
|
|
|
eec083 |
|
|
|
eec083 |
elif [ -n "$ccenv_dumpmachine_switch" ]; then
|
|
|
dc0fb6 |
ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
|
|
|
dc0fb6 |
$ccenv_dumpmachine_switch 2>&3)
|
|
|
b37f09 |
|
|
|
b37f09 |
elif command -v slibtool > /dev/null 2>&1; then
|
|
|
24eb36 |
ccenv=$(slibtool --dumpmachine 2>/dev/null || true)
|
|
|
b37f09 |
fi
|
|
|
b37f09 |
|
|
|
b37f09 |
if [ -z "$ccenv_host" ]; then
|
|
|
eec083 |
ccenv_machine=$(uname -m 2>/dev/null)
|
|
|
eec083 |
ccenv_system=$(uname -s 2>/dev/null)
|
|
|
eec083 |
|
|
|
eec083 |
ccenv_machine="${ccenv_machine:-unknown}"
|
|
|
eec083 |
ccenv_system="${ccenv_system:-anyos}"
|
|
|
eec083 |
|
|
|
eec083 |
ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \
|
|
|
e94fc5 |
| tr '[[:upper:]]' '[[:lower:]]')
|
|
|
dc0fb6 |
fi
|
|
|
dc0fb6 |
|
|
|
b63bb7 |
ccenv_cchost=$ccenv_host
|
|
|
395e41 |
return 0
|
|
|
395e41 |
fi
|
|
|
395e41 |
|
|
|
dc0fb6 |
|
|
|
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 |
|
|
|
dc0fb6 |
if [ -z "$ccenv_host" ] && [ -n "$ccenv_dumpmachine_switch" ]; then
|
|
|
dc0fb6 |
ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
|
|
|
dc0fb6 |
$ccenv_dumpmachine_switch 2>&3)
|
|
|
395e41 |
ccenv_cchost=$ccenv_host
|
|
|
dc0fb6 |
|
|
|
dc0fb6 |
elif [ -z "$ccenv_host" ]; then
|
|
|
b37f09 |
# no -dumpmachine support and no --host argument implies native build
|
|
|
b37f09 |
if command -v slibtool > /dev/null 2>&1; then
|
|
|
24eb36 |
ccenv=$(slibtool --dumpmachine 2>/dev/null || true)
|
|
|
b37f09 |
fi
|
|
|
eec083 |
|
|
|
b37f09 |
if [ -z "$ccenv_host" ]; then
|
|
|
b37f09 |
ccenv_machine=$(uname -m 2>/dev/null)
|
|
|
b37f09 |
ccenv_system=$(uname -s 2>/dev/null)
|
|
|
b37f09 |
|
|
|
b37f09 |
ccenv_machine="${ccenv_machine:-unknown}"
|
|
|
b37f09 |
ccenv_system="${ccenv_system:-anyos}"
|
|
|
eec083 |
|
|
|
b37f09 |
ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \
|
|
|
b37f09 |
| tr '[[:upper:]]' '[[:lower:]]')
|
|
|
b37f09 |
fi
|
|
|
eec083 |
|
|
|
dc0fb6 |
ccenv_cchost=$ccenv_host
|
|
|
dc0fb6 |
|
|
|
dc0fb6 |
elif [ -n "$ccenv_dumpmachine_switch" ]; then
|
|
|
9c9c88 |
ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX)
|
|
|
395e41 |
ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -"
|
|
|
395e41 |
|
|
|
395e41 |
if [ -z "$mb_user_cc" ]; then
|
|
|
2cc159 |
$(printf %s "$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
|
|
|
dc0fb6 |
ccenv_tool_prolog 'C compiler for host'
|
|
|
395e41 |
ccenv_tflags="--target=$ccenv_host"
|
|
|
395e41 |
ccenv_cc="$ccenv_cc $ccenv_tflags"
|
|
|
dc0fb6 |
ccenv_tool_epilog "$ccenv_cc"
|
|
|
6f2654 |
else
|
|
|
6f2654 |
printf '%s' "$ccenv_errors" >&3
|
|
|
395e41 |
fi
|
|
|
395e41 |
fi
|
|
|
395e41 |
|
|
|
9c9c88 |
rm -f "$ccenv_tmp"
|
|
|
9c9c88 |
unset ccenv_tmp
|
|
|
9c9c88 |
|
|
|
dc0fb6 |
ccenv_cchost=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
|
|
|
dc0fb6 |
$ccenv_dumpmachine_switch 2>&3)
|
|
|
395e41 |
fi
|
|
|
395e41 |
|
|
|
58ec8d |
if [ -z "$ccenv_dumpmachine_switch" ] && [ -n "$ccenv_host" ]; then
|
|
|
58ec8d |
ccenv_cchost="$ccenv_host"
|
|
|
58ec8d |
|
|
|
58ec8d |
elif [ "$ccenv_cchost" != "$ccenv_host" ]; then
|
|
|
6f2654 |
printf 'error!\n' >&2
|
|
|
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 |
{
|
|
|
b4651d |
ccenv_tool_prolog 'C pre-processor'
|
|
|
b4651d |
|
|
|
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"
|
|
|
b4651d |
ccenv_tool_epilog "$ccenv_cpp"
|
|
|
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
|
|
|
b4651d |
|
|
|
b4651d |
ccenv_tool_epilog "$ccenv_cpp"
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_set_cxx()
|
|
|
395e41 |
{
|
|
|
b4651d |
ccenv_tool_prolog 'C++ compiler'
|
|
|
b4651d |
|
|
|
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 )
|
|
|
484058 |
ccenv_cxx_prefix=${ccenv_cc_cmd%-gcc*}-
|
|
|
484058 |
ccenv_candidates="${ccenv_cxx_prefix}g++" ;;
|
|
|
395e41 |
|
|
|
395e41 |
*-clang )
|
|
|
484058 |
ccenv_cxx_prefix=${ccenv_cc_cmd%-clang*}-
|
|
|
484058 |
ccenv_candidates="${ccenv_cxx_prefix}clang++" ;;
|
|
|
484058 |
|
|
|
484058 |
/*cc | /*c99 | /*c11 )
|
|
|
484058 |
ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
|
|
|
484058 |
ccenv_candidates="${ccenv_cxx_prefix}/cxx"
|
|
|
484058 |
ccenv_candidates="${ccenv_candidates} ${ccenv_cxx_prefix}/c++" ;;
|
|
|
484058 |
|
|
|
484058 |
/*gcc )
|
|
|
484058 |
ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
|
|
|
484058 |
ccenv_candidates="${ccenv_cxx_prefix}/g++" ;;
|
|
|
395e41 |
|
|
|
484058 |
/*clang )
|
|
|
484058 |
ccenv_cxx_prefix=${ccenv_cc_cmd%/*}
|
|
|
484058 |
ccenv_candidates="${ccenv_cxx_prefix}/clang++" ;;
|
|
|
395e41 |
|
|
|
395e41 |
* )
|
|
|
395e41 |
ccenv_cxx="$ccenv_cc -xc++"
|
|
|
b4651d |
ccenv_tool_epilog "$ccenv_cxx"
|
|
|
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
|
|
|
b4651d |
|
|
|
b4651d |
ccenv_tool_epilog "$ccenv_cxx"
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_set_cc_host()
|
|
|
395e41 |
{
|
|
|
1e4665 |
ccenv_attr_prolog 'system'
|
|
|
395e41 |
ccenv_cc_host="$ccenv_cchost"
|
|
|
b4651d |
ccenv_attr_epilog "$ccenv_cc_host"
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_set_cc_bits()
|
|
|
395e41 |
{
|
|
|
b4651d |
ccenv_attr_prolog 'bits'
|
|
|
b4651d |
|
|
|
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
|
|
|
12bc61 |
if [ -z "${ccenv_internal_size:-}" ]; then
|
|
|
58fbf4 |
ccenv_internal_str=$(printf "$ccenv_internal_test" \
|
|
|
58fbf4 |
"$ccenv_internal_type" \
|
|
|
395e41 |
"$ccenv_internal_guess")
|
|
|
395e41 |
|
|
|
42f22d |
ccenv_expr='ccenv_stdin_input=$ccenv_'${ccenv_cfgtype}'_stdin_input'
|
|
|
42f22d |
eval ${ccenv_expr}
|
|
|
42f22d |
|
|
|
42f22d |
if [ "$ccenv_stdin_input" = 'yes' ]; then
|
|
|
bdaa5d |
printf '%s' "$ccenv_internal_str" \
|
|
|
bdaa5d |
| eval $ccenv_cc -S -xc - -o - \
|
|
|
bdaa5d |
$(printf '%s' "$ccenv_cflags") \
|
|
|
bdaa5d |
> /dev/null 2>&3 \
|
|
|
bdaa5d |
&& ccenv_internal_size=$ccenv_internal_guess
|
|
|
bdaa5d |
else
|
|
|
bdaa5d |
ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
|
|
|
bdaa5d |
|
|
|
bdaa5d |
printf '%s' "$ccenv_internal_str" \
|
|
|
bdaa5d |
> "$ccenv_tmpname"
|
|
|
bdaa5d |
|
|
|
bdaa5d |
$ccenv_cc -c "$ccenv_tmpname" -o a.out \
|
|
|
bdaa5d |
> /dev/null 2>&3 \
|
|
|
bdaa5d |
&& ccenv_internal_size=$ccenv_internal_guess
|
|
|
bdaa5d |
|
|
|
bdaa5d |
rm "$ccenv_tmpname"
|
|
|
bdaa5d |
fi
|
|
|
395e41 |
fi
|
|
|
395e41 |
done
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_cc_bits=$ccenv_internal_size
|
|
|
b4651d |
|
|
|
b4651d |
ccenv_attr_epilog "$ccenv_cc_bits"
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_set_cc_underscore()
|
|
|
395e41 |
{
|
|
|
b4651d |
ccenv_attr_prolog 'prepended underscores'
|
|
|
b4651d |
|
|
|
395e41 |
ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe'
|
|
|
395e41 |
ccenv_fn_code='int %s(void){return 0;}'
|
|
|
395e41 |
|
|
|
74e621 |
ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
|
|
|
74e621 |
|
|
|
74e621 |
printf "$ccenv_fn_code" $ccenv_fn_name \
|
|
|
74e621 |
> "$ccenv_tmpname"
|
|
|
74e621 |
|
|
|
74e621 |
$ccenv_cc -c "$ccenv_tmpname" -o a.out \
|
|
|
74e621 |
> /dev/null 2>&3
|
|
|
74e621 |
|
|
|
74e621 |
if "$ccenv_nm" a.out | grep \
|
|
|
74e621 |
-e "^_$ccenv_fn_name" \
|
|
|
74e621 |
-e " _$ccenv_fn_name" \
|
|
|
74e621 |
> /dev/null; then
|
|
|
e574cf |
ccenv_cc_underscore='_'
|
|
|
b4651d |
ccenv_attr_epilog 'yes'
|
|
|
74e621 |
else
|
|
|
74e621 |
ccenv_attr_epilog 'no'
|
|
|
e574cf |
fi
|
|
|
395e41 |
|
|
|
74e621 |
rm "$ccenv_tmpname"
|
|
|
74e621 |
rm a.out
|
|
|
b4651d |
|
|
|
395e41 |
return 0
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_create_framework_executable()
|
|
|
395e41 |
{
|
|
|
dcb9bd |
if [ "$ccenv_cfgtype" = 'host' ]; then
|
|
|
dcb9bd |
if [ "$mb_freestanding" = 'yes' ]; then
|
|
|
dcb9bd |
return 1
|
|
|
dcb9bd |
fi
|
|
|
dcb9bd |
fi
|
|
|
dcb9bd |
|
|
|
395e41 |
if [ -f $ccenv_image ]; then
|
|
|
395e41 |
mv $ccenv_image $ccenv_image.tmp
|
|
|
395e41 |
rm -f $ccenv_image.tmp
|
|
|
395e41 |
fi
|
|
|
395e41 |
|
|
|
8abcca |
ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
|
|
|
8abcca |
|
|
|
395e41 |
printf 'int main(void){return 0;}' \
|
|
|
8abcca |
> "$ccenv_tmpname"
|
|
|
395e41 |
|
|
|
8abcca |
if $ccenv_cc "$ccenv_tmpname" -o $ccenv_image 2>&3; then
|
|
|
8abcca |
ccenv_ret=0
|
|
|
dcb9bd |
ccenv_cc_environment='hosted'
|
|
|
8abcca |
else
|
|
|
8abcca |
ccenv_ret=1
|
|
|
8abcca |
fi
|
|
|
8abcca |
|
|
|
8abcca |
rm "$ccenv_tmpname"
|
|
|
8abcca |
|
|
|
8abcca |
return $ccenv_ret
|
|
|
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 |
|
|
|
8abcca |
ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c'
|
|
|
395e41 |
|
|
|
8abcca |
printf 'int %s(void){return 0;}' "$ccenv_start_fn" \
|
|
|
8abcca |
> "$ccenv_tmpname"
|
|
|
395e41 |
|
|
|
8abcca |
if $ccenv_cc "$ccenv_tmpname" \
|
|
|
8abcca |
-ffreestanding \
|
|
|
8abcca |
-nostdlib -nostartfiles \
|
|
|
8abcca |
-o $ccenv_image \
|
|
|
8abcca |
2>&3; then
|
|
|
8abcca |
ccenv_ret=0
|
|
|
dcb9bd |
ccenv_cc_environment='freestanding'
|
|
|
8abcca |
else
|
|
|
8abcca |
ccenv_ret=1
|
|
|
8abcca |
fi
|
|
|
8abcca |
|
|
|
8abcca |
rm "$ccenv_tmpname"
|
|
|
8abcca |
|
|
|
8abcca |
return $ccenv_ret
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
b4651d |
ccenv_set_cc_binfmt_error()
|
|
|
b4651d |
{
|
|
|
b4651d |
ccenv_attr_epilog '(unable to create executable)'
|
|
|
b4651d |
}
|
|
|
b4651d |
|
|
|
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 |
|
|
|
b4651d |
ccenv_attr_prolog 'binary format'
|
|
|
b4651d |
|
|
|
395e41 |
ccenv_create_framework_executable \
|
|
|
395e41 |
|| ccenv_create_freestanding_executable \
|
|
|
b4651d |
|| ccenv_set_cc_binfmt_error \
|
|
|
395e41 |
|| return 0
|
|
|
395e41 |
|
|
|
395e41 |
# PE / perk
|
|
|
395e41 |
if [ -n "$ccenv_perk" ]; then
|
|
|
6f2654 |
if $ccenv_perk $ccenv_image 2>&3; 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
|
|
|
6f2654 |
if $ccenv_readelf -h $ccenv_image 2>&3 \
|
|
|
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
|
|
|
6f2654 |
if $ccenv_readany -h $ccenv_image 2>&3 \
|
|
|
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
|
|
|
6f2654 |
if $ccenv_otool -hv $ccenv_image 2>&3 \
|
|
|
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
|
|
|
6f2654 |
if $ccenv_otool -hv $ccenv_image 2>&3 \
|
|
|
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
|
|
|
6f2654 |
if $ccenv_readany -h $ccenv_image 2>&3 \
|
|
|
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
|
|
|
6f2654 |
if $ccenv_readany -h $ccenv_image 2>&3 \
|
|
|
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
|
|
|
6f2654 |
if $ccenv_readobj $ccenv_image 2>&3 \
|
|
|
928ffa |
| grep -i 'Format:' \
|
|
|
928ffa |
| sed -e '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 \
|
|
|
6f2654 |
2>&3 \
|
|
|
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
|
|
|
6f2654 |
$ccenv_objdump -h $ccenv_image 2>&3 \
|
|
|
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
|
|
|
6f2654 |
if $ccenv_objdump -h $ccenv_image 2>&3 \
|
|
|
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
|
|
|
b4651d |
|
|
|
b4651d |
ccenv_attr_epilog "$ccenv_cc_binfmt"
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_set_os_pe()
|
|
|
395e41 |
{
|
|
|
dcb9bd |
if [ "$ccenv_cc_environment" = 'freestanding' ]; 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 |
{
|
|
|
b4651d |
ccenv_attr_prolog 'os name'
|
|
|
b4651d |
|
|
|
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
|
|
|
b4651d |
ccenv_attr_epilog "$ccenv_os"
|
|
|
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
|
|
|
b4651d |
|
|
|
b4651d |
ccenv_attr_epilog "$ccenv_os"
|
|
|
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 |
|
|
|
b4651d |
ccenv_attr_prolog 'os semantics'
|
|
|
b4651d |
|
|
|
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
|
|
|
b4651d |
ccenv_attr_epilog "$ccenv_os_semantics"
|
|
|
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
|
|
|
b4651d |
|
|
|
b4651d |
ccenv_attr_epilog "$ccenv_os_semantics"
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
7b4c88 |
ccenv_set_os_dso_format()
|
|
|
7b4c88 |
{
|
|
|
7b4c88 |
ccenv_attr_prolog 'os dso format'
|
|
|
7b4c88 |
|
|
|
7b4c88 |
case "$ccenv_cc_arfmt" in
|
|
|
7b4c88 |
common )
|
|
|
7b4c88 |
ccenv_cc_sofmt="$ccenv_cc_binfmt"
|
|
|
7b4c88 |
;;
|
|
|
7b4c88 |
|
|
|
7b4c88 |
bigaf )
|
|
|
7b4c88 |
ccenv_libgcc_s_a_header=$(od -b -N8 \
|
|
|
7b4c88 |
$($ccenv_cc -print-file-name=libgcc_s.a) \
|
|
|
7b4c88 |
2>/dev/null \
|
|
|
7b4c88 |
| head -n1)
|
|
|
7b4c88 |
|
|
|
7b4c88 |
ccenv_libgcc_s_so_header=$(od -b -N8 \
|
|
|
7b4c88 |
$($ccenv_cc -print-file-name=libgcc_s.so) \
|
|
|
7b4c88 |
2>/dev/null \
|
|
|
7b4c88 |
| head -n1)
|
|
|
7b4c88 |
|
|
|
7b4c88 |
if [ "$ccenv_libgcc_s_a_header" = "$ccenv_bigaf_header" ]; then
|
|
|
7b4c88 |
ccenv_cc_sofmt='bigaf'
|
|
|
7b4c88 |
elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_bigaf_header" ]; then
|
|
|
7b4c88 |
ccenv_cc_sofmt='bigaf'
|
|
|
7b4c88 |
else
|
|
|
7b4c88 |
ccenv_cc_sofmt="$ccenv_cc_binfmt"
|
|
|
7b4c88 |
fi
|
|
|
7b4c88 |
;;
|
|
|
7b4c88 |
|
|
|
7b4c88 |
aiaff )
|
|
|
7b4c88 |
ccenv_libgcc_s_a_header=$(od -b -N8 \
|
|
|
7b4c88 |
$($ccenv_cc -print-file-name=libgcc_s.a) \
|
|
|
7b4c88 |
| head -n1)
|
|
|
7b4c88 |
|
|
|
7b4c88 |
ccenv_libgcc_s_so_header=$(od -b -N8 \
|
|
|
7b4c88 |
$($ccenv_cc -print-file-name=libgcc_s.so) \
|
|
|
7b4c88 |
| head -n1)
|
|
|
7b4c88 |
|
|
|
7b4c88 |
if [ "$ccenv_libgcc_s_a_header" = "$ccenv_aiaff_header" ]; then
|
|
|
7b4c88 |
ccenv_cc_sofmt='aiaff'
|
|
|
7b4c88 |
elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_aiaff_header" ]; then
|
|
|
7b4c88 |
ccenv_cc_sofmt='aiaff'
|
|
|
7b4c88 |
else
|
|
|
7b4c88 |
ccenv_cc_sofmt="$ccenv_cc_binfmt"
|
|
|
7b4c88 |
fi
|
|
|
7b4c88 |
;;
|
|
|
7b4c88 |
esac
|
|
|
7b4c88 |
|
|
|
497793 |
if [ "$ccenv_cfgtype" = 'host' ]; then
|
|
|
497793 |
case "$ccenv_cc_sofmt" in
|
|
|
497793 |
bigaf | aiaff )
|
|
|
497793 |
mb_shared_lib_cmd='$(AR) -rcs'
|
|
|
497793 |
mb_shared_lib_ldflags=
|
|
|
497793 |
;;
|
|
|
497793 |
|
|
|
497793 |
* )
|
|
|
497793 |
mb_shared_lib_cmd='$(CC) -shared -o'
|
|
|
497793 |
mb_shared_lib_ldflags='$(LDFLAGS_SHARED)'
|
|
|
497793 |
;;
|
|
|
497793 |
esac
|
|
|
497793 |
fi
|
|
|
497793 |
|
|
|
7b4c88 |
ccenv_attr_epilog "$ccenv_cc_sofmt"
|
|
|
7b4c88 |
}
|
|
|
7b4c88 |
|
|
|
395e41 |
ccenv_set_os_dso_exrules()
|
|
|
395e41 |
{
|
|
|
b4651d |
ccenv_attr_prolog 'os dso exrules'
|
|
|
b4651d |
|
|
|
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
|
|
|
b4651d |
|
|
|
b4651d |
ccenv_attr_epilog "$ccenv_os_dso_exrules"
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_set_os_dso_linkage()
|
|
|
395e41 |
{
|
|
|
395e41 |
# todo: PIC, PIE, and friends
|
|
|
b4651d |
ccenv_attr_prolog 'os linkage'
|
|
|
395e41 |
ccenv_os_dso_linkage='default'
|
|
|
b4651d |
ccenv_attr_epilog "$ccenv_os_dso_linkage"
|
|
|
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
|
|
|
0f30a0 |
|
|
|
0f30a0 |
if [ "$ccenv_cc_binfmt" = 'PE' ]; then
|
|
|
0f30a0 |
if ! cfgtest_macro_definition '__PE__'; then
|
|
|
0f30a0 |
ccenv_cflags_os="${ccenv_cflags_os} -D__PE__"
|
|
|
0f30a0 |
fi
|
|
|
0f30a0 |
|
|
|
0f30a0 |
if ! cfgtest_macro_definition '__dllexport'; then
|
|
|
0f30a0 |
ccenv_cflags_os="${ccenv_cflags_os} -D__dllexport=__attribute__\(\(__dllexport__\)\)"
|
|
|
0f30a0 |
fi
|
|
|
0f30a0 |
|
|
|
0f30a0 |
if ! cfgtest_macro_definition '__dllimport'; then
|
|
|
0f30a0 |
ccenv_cflags_os="${ccenv_cflags_os} -D__dllimport=__attribute__\(\(__dllimport__\)\)"
|
|
|
0f30a0 |
fi
|
|
|
0f30a0 |
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 |
|
|
|
2cff86 |
sed \
|
|
|
478787 |
-e 's/^[[:space:]]*$/@/g' \
|
|
|
2cff86 |
-e 's/^/NATIVE_/' \
|
|
|
2cff86 |
-e 's/NATIVE_@//g' \
|
|
|
2cff86 |
-e 's/NATIVE_#/#/g' \
|
|
|
2cff86 |
-e 's/ =/=/g' \
|
|
|
2cff86 |
-e 's/ +=/+=/g' \
|
|
|
0586b1 |
$(printf '%s ' $ccenv_in) \
|
|
|
0586b1 |
> "$ccenv_tmp"
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_in="$ccenv_tmp"
|
|
|
9c9c88 |
else
|
|
|
64ac18 |
unset ccenv_tmp
|
|
|
395e41 |
fi
|
|
|
395e41 |
|
|
|
34a725 |
ccenv_var_defs=
|
|
|
d054d6 |
ccenv_sed_substs="-e s/@ccenv_cfgtype@/${ccenv_cfgtype}/g"
|
|
|
34a725 |
|
|
|
395e41 |
ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \
|
|
|
34a725 |
| grep -v '^#');
|
|
|
395e41 |
|
|
|
d054d6 |
ccenv_exvars="ccenv_makevar_prefix"
|
|
|
395e41 |
|
|
|
34a725 |
for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do
|
|
|
34a725 |
ccenv_sed_subst=$(printf '%s %s%s%s' \
|
|
|
34a725 |
'-e' "'s^@$__var@" \
|
|
|
34a725 |
"^___${__var}___" \
|
|
|
34a725 |
"^g'")
|
|
|
34a725 |
|
|
|
34a725 |
ccenv_sed_substs="$ccenv_sed_substs $ccenv_sed_subst"
|
|
|
34a725 |
|
|
|
34a725 |
ccenv_var_def=$(printf '%s%s="${%s}"' "-D" "___${__var}___" "${__var}")
|
|
|
34a725 |
eval ccenv_var_defs='"$ccenv_var_defs "$ccenv_var_def'
|
|
|
34a725 |
done
|
|
|
395e41 |
|
|
|
34a725 |
eval sed $ccenv_sed_substs $(printf '%s ' $ccenv_in) \
|
|
|
34a725 |
| eval m4 $ccenv_var_defs - \
|
|
|
34a725 |
| 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
|
|
|
889ceb |
|
|
|
5eb84a |
|
|
|
5eb84a |
if [ "${ccenv_cfgtype}" = 'host' ]; then
|
|
|
5eb84a |
ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-host)
|
|
|
5eb84a |
ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-host)
|
|
|
5eb84a |
else
|
|
|
5eb84a |
ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-native)
|
|
|
5eb84a |
ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-native)
|
|
|
5eb84a |
fi
|
|
|
5eb84a |
|
|
|
5eb84a |
ccenv_cflags="${ccenv_cflags#*: }"
|
|
|
5eb84a |
ccenv_ldflags="${ccenv_ldflags#*: }"
|
|
|
5eb84a |
|
|
|
237052 |
ccenv_sysroot=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \
|
|
|
237052 |
-print-sysroot 2>/dev/null || true)
|
|
|
237052 |
|
|
|
5eb84a |
eval 'ccenv_'${ccenv_cfgtype}'_cflags'=\'$ccenv_cflags\'
|
|
|
5eb84a |
eval 'ccenv_'${ccenv_cfgtype}'_ldflags'=\'$ccenv_ldflags\'
|
|
|
237052 |
eval 'ccenv_'${ccenv_cfgtype}'_sysroot'=\'$ccenv_sysroot\'
|
|
|
5eb84a |
|
|
|
889ceb |
eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\'
|
|
|
52446b |
eval 'ccenv_'${ccenv_cfgtype}'_cc_environment'=\'$ccenv_cc_environment\'
|
|
|
9bd00b |
eval 'ccenv_'${ccenv_cfgtype}'_dumpmachine_switch'=\'$ccenv_dumpmachine_switch\'
|
|
|
9d7f3e |
eval 'ccenv_'${ccenv_cfgtype}'_pkgconf'=\'$ccenv_pkgconf\'
|
|
|
5eb84a |
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
6e7e5b |
ccenv_set_cc_sysroot_vars()
|
|
|
6e7e5b |
{
|
|
|
6e7e5b |
if [ "$ccenv_cfgtype" = 'native' ] || [ -z "$mb_sysroot" ]; then
|
|
|
6e7e5b |
return 0
|
|
|
6e7e5b |
fi
|
|
|
6e7e5b |
|
|
|
6e7e5b |
cfgtest_host_section
|
|
|
6e7e5b |
ccenv_switch_var="--sysroot=${mb_sysroot}"
|
|
|
6e7e5b |
|
|
|
6e7e5b |
if cfgtest_compiler_switch_arg "${ccenv_switch_var}"; then
|
|
|
6e7e5b |
printf '\n# %s sysroot: cflags and ldflags\n' "$ccenv_cfgtype" \
|
|
|
6e7e5b |
>> "$ccenv_mk"
|
|
|
6e7e5b |
|
|
|
6e7e5b |
for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do
|
|
|
6e7e5b |
printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
|
|
|
6e7e5b |
>> "$ccenv_mk"
|
|
|
6e7e5b |
done
|
|
|
6e7e5b |
else
|
|
|
6e7e5b |
printf '\n# %s sysroot: cflags and ldflags %s\n' "$ccenv_cfgtype" \
|
|
|
6e7e5b |
'(not supported: see config.log)' \
|
|
|
6e7e5b |
>> "$ccenv_mk"
|
|
|
6e7e5b |
|
|
|
6e7e5b |
for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do
|
|
|
6e7e5b |
printf '%-40s=\n' "${ccenv_make_var}" \
|
|
|
6e7e5b |
>> "$ccenv_mk"
|
|
|
6e7e5b |
done
|
|
|
6e7e5b |
fi
|
|
|
6e7e5b |
}
|
|
|
6e7e5b |
|
|
|
2b8960 |
ccenv_set_cc_switch_vars()
|
|
|
2b8960 |
{
|
|
|
2dc388 |
printf '\n# %s cflags: supported compiler switches\n' "$ccenv_cfgtype" \
|
|
|
2dc388 |
>> "$ccenv_mk"
|
|
|
2dc388 |
|
|
|
2b8960 |
if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
|
|
|
108c0d |
ccenv_switch_vars=$(cat \
|
|
|
2b8960 |
$mb_project_dir/sofort/ccenv/ccswitch.strs \
|
|
|
2b8960 |
$mb_project_dir/project/config/ccswitch.strs \
|
|
|
108c0d |
| grep -v -e '^#' -e '^-Wl,' \
|
|
|
108c0d |
| sort -u)
|
|
|
2b8960 |
else
|
|
|
49e7a5 |
ccenv_switch_vars=$(grep -v -e '^#' -e '^-Wl,' \
|
|
|
2b8960 |
$mb_project_dir/sofort/ccenv/ccswitch.strs \
|
|
|
2b8960 |
| sort -u)
|
|
|
2b8960 |
fi
|
|
|
2b8960 |
|
|
|
2b8960 |
if [ $ccenv_cfgtype = 'host' ]; then
|
|
|
2b8960 |
ccenv_makevar_prefix='_CFLAGS_'
|
|
|
2b8960 |
cfgtest_host_section
|
|
|
2b8960 |
else
|
|
|
2b8960 |
ccenv_makevar_prefix='_NATIVE_CFLAGS_'
|
|
|
2b8960 |
cfgtest_native_section
|
|
|
2b8960 |
fi
|
|
|
2b8960 |
|
|
|
2b8960 |
for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
|
|
|
2b8960 |
ccenv_make_var=${ccenv_switch_var%=}
|
|
|
2b8960 |
ccenv_make_var=${ccenv_make_var%,}
|
|
|
2b8960 |
|
|
|
2b8960 |
ccenv_make_var=${ccenv_make_var##---}
|
|
|
2b8960 |
ccenv_make_var=${ccenv_make_var##--}
|
|
|
2b8960 |
ccenv_make_var=${ccenv_make_var##-}
|
|
|
2b8960 |
|
|
|
2b8960 |
ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
|
|
|
2b8960 |
| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
|
|
|
2b8960 |
|
|
|
2b8960 |
ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
|
|
|
2b8960 |
|
|
|
2b8960 |
if cfgtest_compiler_switch "$ccenv_switch_var"; then
|
|
|
2b8960 |
ccenv_switch_var=${ccenv_switch_var%=}
|
|
|
2b8960 |
ccenv_switch_var=${ccenv_switch_var%,}
|
|
|
2b8960 |
|
|
|
fa380e |
printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
|
|
|
2b8960 |
>> "$ccenv_mk"
|
|
|
2b8960 |
else
|
|
|
fa380e |
printf '%-40s=\n' "${ccenv_make_var}" \
|
|
|
2b8960 |
>> "$ccenv_mk"
|
|
|
2b8960 |
fi
|
|
|
2b8960 |
done
|
|
|
2b8960 |
}
|
|
|
2b8960 |
|
|
|
49e7a5 |
ccenv_set_cc_linker_switch_vars()
|
|
|
49e7a5 |
{
|
|
|
49e7a5 |
printf '\n# %s ldflags: supported compiler switches\n' "$ccenv_cfgtype" \
|
|
|
49e7a5 |
>> "$ccenv_mk"
|
|
|
49e7a5 |
|
|
|
49e7a5 |
if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then
|
|
|
108c0d |
ccenv_switch_vars=$(cat \
|
|
|
49e7a5 |
$mb_project_dir/sofort/ccenv/ccswitch.strs \
|
|
|
49e7a5 |
$mb_project_dir/project/config/ccswitch.strs \
|
|
|
108c0d |
| grep -e '^-Wl,' \
|
|
|
49e7a5 |
| sort -u)
|
|
|
49e7a5 |
else
|
|
|
49e7a5 |
ccenv_switch_vars=$(grep -e '^-Wl,' \
|
|
|
49e7a5 |
$mb_project_dir/sofort/ccenv/ccswitch.strs \
|
|
|
49e7a5 |
| sort -u)
|
|
|
49e7a5 |
fi
|
|
|
49e7a5 |
|
|
|
49e7a5 |
if [ $ccenv_cfgtype = 'host' ]; then
|
|
|
49e7a5 |
ccenv_makevar_prefix='_LDFLAGS_'
|
|
|
49e7a5 |
cfgtest_host_section
|
|
|
49e7a5 |
else
|
|
|
49e7a5 |
ccenv_makevar_prefix='_NATIVE_LDFLAGS_'
|
|
|
49e7a5 |
cfgtest_native_section
|
|
|
49e7a5 |
fi
|
|
|
49e7a5 |
|
|
|
49e7a5 |
for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do
|
|
|
49e7a5 |
ccenv_make_var=${ccenv_switch_var%=}
|
|
|
49e7a5 |
ccenv_make_var=${ccenv_make_var%,}
|
|
|
49e7a5 |
|
|
|
49e7a5 |
ccenv_make_var=${ccenv_make_var##---}
|
|
|
49e7a5 |
ccenv_make_var=${ccenv_make_var##--}
|
|
|
49e7a5 |
ccenv_make_var=${ccenv_make_var##-}
|
|
|
49e7a5 |
|
|
|
49e7a5 |
ccenv_make_var=$(printf '%s' "$ccenv_make_var" \
|
|
|
49e7a5 |
| sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g')
|
|
|
49e7a5 |
|
|
|
49e7a5 |
ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}"
|
|
|
49e7a5 |
|
|
|
49e7a5 |
if cfgtest_compiler_switch "$ccenv_switch_var"; then
|
|
|
49e7a5 |
ccenv_switch_var=${ccenv_switch_var%=}
|
|
|
49e7a5 |
ccenv_switch_var=${ccenv_switch_var%,}
|
|
|
49e7a5 |
|
|
|
49e7a5 |
printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \
|
|
|
49e7a5 |
>> "$ccenv_mk"
|
|
|
49e7a5 |
else
|
|
|
49e7a5 |
printf '%-40s=\n' "${ccenv_make_var}" \
|
|
|
49e7a5 |
>> "$ccenv_mk"
|
|
|
49e7a5 |
fi
|
|
|
49e7a5 |
done
|
|
|
49e7a5 |
}
|
|
|
49e7a5 |
|
|
|
0dc17d |
ccenv_set_cc_attr_visibility_vars()
|
|
|
0dc17d |
{
|
|
|
0dc17d |
if cfgtest_attr_visibility 'default'; then
|
|
|
0dc17d |
ccenv_attr_visibility_default="$mb_cfgtest_attr"
|
|
|
0dc17d |
fi
|
|
|
0dc17d |
|
|
|
0dc17d |
if cfgtest_attr_visibility 'hidden'; then
|
|
|
0dc17d |
ccenv_attr_visibility_hidden="$mb_cfgtest_attr"
|
|
|
0dc17d |
fi
|
|
|
0dc17d |
|
|
|
0dc17d |
if cfgtest_attr_visibility 'internal'; then
|
|
|
0dc17d |
ccenv_attr_visibility_internal="$mb_cfgtest_attr"
|
|
|
0dc17d |
fi
|
|
|
0dc17d |
|
|
|
0dc17d |
if cfgtest_attr_visibility 'protected'; then
|
|
|
0dc17d |
ccenv_attr_visibility_protected="$mb_cfgtest_attr"
|
|
|
0dc17d |
fi
|
|
|
0dc17d |
}
|
|
|
0dc17d |
|
|
|
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 |
|
|
|
2cc159 |
printf '%s' "$ccenv_str" | $(printf %s "$ccenv_cmd") \
|
|
|
6f2654 |
> /dev/null 2>&3 \
|
|
|
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"
|
|
|
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=
|
|
|
66374b |
ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
|
|
|
f1133d |
OS_DSO_EXRULES=default \
|
|
|
f1133d |
OS_SONAME=symlink \
|
|
|
077d2f |
OS_ARCHIVE_EXT='.a' \
|
|
|
f1133d |
.cflags-host)
|
|
|
1df9cf |
|
|
|
66374b |
ccenv_cflags="${ccenv_cflags#*: }"
|
|
|
66374b |
|
|
|
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=
|
|
|
66374b |
ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \
|
|
|
f1133d |
OS_DSO_EXRULES=default \
|
|
|
f1133d |
OS_SONAME=symlink \
|
|
|
077d2f |
OS_ARCHIVE_EXT='.a' \
|
|
|
f1133d |
.cflags-native)
|
|
|
f1133d |
|
|
|
66374b |
ccenv_cflags="${ccenv_cflags#*: }"
|
|
|
66374b |
|
|
|
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_binfmt
|
|
|
b4651d |
ccenv_set_cc_underscore
|
|
|
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
|
|
|
7b4c88 |
ccenv_set_os_dso_format
|
|
|
395e41 |
ccenv_set_os_dso_exrules
|
|
|
395e41 |
ccenv_set_os_dso_linkage
|
|
|
395e41 |
ccenv_set_os_dso_patterns
|
|
|
5e8603 |
ccenv_set_os_pe_switches
|
|
|
0dc17d |
ccenv_set_cc_attr_visibility_vars
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_output_defs
|
|
|
395e41 |
ccenv_clean_up
|
|
|
2b8960 |
|
|
|
6e7e5b |
ccenv_set_cc_sysroot_vars
|
|
|
2b8960 |
ccenv_set_cc_switch_vars
|
|
|
49e7a5 |
ccenv_set_cc_linker_switch_vars
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_set_host_variables()
|
|
|
395e41 |
{
|
|
|
b4651d |
output_script_status ${mb_script} \
|
|
|
ca682d |
'detect and query host (targeted) system'
|
|
|
b4651d |
|
|
|
395e41 |
ccenv_set_toolchain_variables 'host'
|
|
|
9264a4 |
ccenv_dso_verify
|
|
|
395e41 |
}
|
|
|
395e41 |
|
|
|
395e41 |
ccenv_set_native_variables()
|
|
|
395e41 |
{
|
|
|
b4651d |
output_script_status ${mb_script} \
|
|
|
ca682d |
'detect and query native (local build) system'
|
|
|
b4651d |
|
|
|
8a9506 |
if [ _$mb_ccenv_skip_native != _yes ]; then
|
|
|
8a9506 |
ccenv_set_toolchain_variables 'native'
|
|
|
8a9506 |
fi
|
|
|
395e41 |
}
|