diff options
Diffstat (limited to 'sofort/ccenv/ccenv.sh')
-rw-r--r-- | sofort/ccenv/ccenv.sh | 674 |
1 files changed, 603 insertions, 71 deletions
diff --git a/sofort/ccenv/ccenv.sh b/sofort/ccenv/ccenv.sh index a376eb7..d975c6b 100644 --- a/sofort/ccenv/ccenv.sh +++ b/sofort/ccenv/ccenv.sh @@ -1,3 +1,4 @@ + # ccenv.sh: sofort's tool-finding bits, # invoked from within the project-agnostic configure script. @@ -24,6 +25,13 @@ # ccenv_cflags: the comprehensive cflags for the host being tested # ccenv_cchost: the host being tested, as reported by -dumpmachine +# variables available to cfgdefs.sh and cfgfini.sh: +# ccenv_host_cflags: expanded cflags, valid for the host compiler +# ccenv_host_ldflags: expanded ldflags, valid for the host compiler +# ccenv_host_sysroot: host sysroot, as reported by the host compiler +# ccenv_native_cflags: expanded cflags, valid for the native compiler +# ccenv_native_ldflags: expanded ldflags, valid for the native compiler +# ccenv_native_sysroot: native sysroot, as reported by the native compiler ccenv_usage() { @@ -68,6 +76,11 @@ ccenv_tool_epilog() ccenv_line_dots='................................' ccenv_tool_dlen="$((${#ccenv_line_dots} - ${#1}))" + case ${ccenv_tool_dlen} in + 0 | -* ) + ccenv_tool_dlen='3' ;; + esac + printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s %s.\n" \ "${ccenv_line_dots}" "${1}" @@ -110,6 +123,11 @@ ccenv_attr_epilog() ccenv_line_dots='................................' ccenv_tool_dlen="$((${#ccenv_line_dots} - 1 - ${#1}))" + case ${ccenv_tool_dlen} in + 0 | -* ) + ccenv_tool_dlen='3' ;; + esac + printf "%${ccenv_tool_dlen}.${ccenv_tool_dlen}s %s.\n" \ "${ccenv_line_dots}" "${1}" @@ -122,7 +140,9 @@ ccenv_find_tool() { if [ -z "$ccenv_prefixes" ]; then for ccenv_candidate in $(printf '%s' "$ccenv_candidates"); do - if [ -z ${@:-} ]; then + ccenv_cmd_args="${@:-}" + + if [ -z "$ccenv_cmd_args" ]; then if command -v "$ccenv_candidate" > /dev/null; then ccenv_tool="$ccenv_candidate" return 0 @@ -169,7 +189,7 @@ ccenv_set_primary_tools() { ccenv_core_tools="ar nm objdump ranlib size strip strings objcopy" ccenv_hack_tools="addr2line cov elfedit readelf readobj otool" - ccenv_peep_tools="perk mdso dlltool windmc windres" + ccenv_peep_tools="perk mdso dlltool windmc windres pkgconf" for __tool in $(printf '%s' "$ccenv_core_tools $ccenv_hack_tools $ccenv_peep_tools"); do ccenv_tool_prolog "$__tool" @@ -196,6 +216,9 @@ ccenv_set_primary_tools() ccenv_candidates="$ccenv_candidates gcc-$__tool" ccenv_candidates="$ccenv_candidates llvm-$__tool" + elif [ "$__tool" = 'pkgconf' ]; then + ccenv_candidates="$__tool pkg-config" + else ccenv_candidates="$__tool" ccenv_candidates="$ccenv_candidates gcc-$__tool" @@ -208,12 +231,14 @@ ccenv_set_primary_tools() ccenv_var_prefix='mb_native_' fi + ccenv_tool= ccenv_var_name=$ccenv_var_prefix$__tool ccenv_var_expr='${'$ccenv_var_name':-}' eval ccenv_var_val=$ccenv_var_expr if [ -n "$ccenv_var_val" ]; then eval ccenv_$__tool="$ccenv_var_val" + ccenv_tool="$ccenv_var_val" else ccenv_find_tool eval ccenv_$__tool="$ccenv_tool" @@ -224,6 +249,63 @@ ccenv_set_primary_tools() # windrc ccenv_windrc="$ccenv_windres" + + # archive format preamble + if [ -n "$ccenv_dumpmachine_switch" ]; then + ccenv_libgcc_path=$($ccenv_cc -print-file-name=libgcc.a \ + 2>/dev/null) + + if [ -n "$ccenv_libgcc_path" ]; then + ccenv_libgcc_a_header=$(od -b -N8 \ + $($ccenv_cc -print-file-name=libgcc.a) \ + | head -n1) + else + ccenv_libgcc_a_header= + fi + else + ccenv_libgcc_a_header= + fi + + # ar (default) + ccenv_cc_arfmt='common' + + # ar (big) + ccenv_bigaf_header=$(printf '%s\n' '<bigaf>' | od -b | head -n1) + + if [ "$ccenv_libgcc_a_header" = "$ccenv_bigaf_header" ]; then + ccenv_cc_arfmt='bigaf' + + for __tool in $(printf '%s' "$ccenv_core_tools"); do + ccenv_var_name=ccenv_$__tool + ccenv_var_expr='${'$ccenv_var_name':-}' + eval ccenv_var_val="$ccenv_var_expr" + + if [ "$ccenv_var_val" != false ]; then + ccenv_var_val="$ccenv_var_val -X64" + ccenv_var_expr='${ccenv_var_val:-}' + eval ccenv_$__tool="$ccenv_var_expr" + fi + done + fi + + # ar (small) + ccenv_aiaff_header=$(printf '%s\n' '<aiaff>' | od -b | head -n1) + + if [ "$ccenv_libgcc_a_header" = "$ccenv_aiaff_header" ]; then + ccenv_cc_arfmt='aiaff' + + for __tool in $(printf '%s' "$ccenv_core_tools"); do + ccenv_var_name=ccenv_$__tool + ccenv_var_expr='${'$ccenv_var_name':-}' + eval ccenv_var_val="$ccenv_var_expr" + + if [ "$ccenv_var_val" != false ]; then + ccenv_var_val="$ccenv_var_val -X32" + ccenv_var_expr='${ccenv_var_val:-}' + eval ccenv_$__tool="$ccenv_var_expr" + fi + done + fi } ccenv_set_tool_variants() @@ -236,7 +318,7 @@ ccenv_set_tool_variants() if [ "$ccenv_tool" = false ]; then ccenv_as_asm= else - $ccenv_tool --help | grep -i '.bc assembler' \ + $ccenv_tool --help 2>&1 | grep -i '.bc assembler' \ || ccenv_as_asm="$ccenv_tool" fi @@ -386,7 +468,7 @@ ccenv_set_c_compiler_candidates() ccenv_candidates="$mb_toolchain c99 c11 cc gcc clang" else - ccenv_candidates="c99 c11 cc gcc clang" + ccenv_candidates="cc gcc clang c99 c11" fi } @@ -397,24 +479,77 @@ ccenv_set_cc() if [ -z "$ccenv_cc" ]; then ccenv_set_c_compiler_candidates - ccenv_find_tool -dumpmachine + ccenv_find_tool ccenv_cc="$ccenv_tool" fi + if [ "$ccenv_cc" = false ] && [ -n "$mb_compiler" ]; then ccenv_cc="$mb_compiler" fi + ccenv_tool_epilog "$ccenv_cc" + + + if [ $ccenv_cfgtype = 'host' ]; then + ccenv_host_cc="$ccenv_cc" + cfgtest_host_section + ccenv_host_cc= + else + ccenv_native_cc="$ccenv_cc" + cfgtest_native_section + ccenv_native_cc= + fi + + cfgtest_silent='yes' + + if cfgtest_compiler_switch -dumpmachine ; then + ccenv_dumpmachine_switch='-dumpmachine' + else + ccenv_dumpmachine_switch= + fi + + if cfgtest_code_snippet_asm 'typedef int dummy;' ; then + eval ccenv_${ccenv_cfgtype}_stdin_input='yes' + else + eval ccenv_${ccenv_cfgtype}_stdin_input='no' + fi + + unset cfgtest_silent + ccenv_cc_cmd="$ccenv_cc" ccenv_errors= if [ "$ccenv_cfgtype" = 'native' ]; then - ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3) + ccenv_host= + + if [ -n "$mb_native_host" ]; then + ccenv_host="$mb_native_host" + + elif [ -n "$ccenv_dumpmachine_switch" ]; then + ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \ + $ccenv_dumpmachine_switch 2>&3) + + elif command -v slibtool > /dev/null 2>&1; then + ccenv=$(slibtool --dumpmachine 2>/dev/null || true) + fi + + if [ -z "$ccenv_host" ]; then + ccenv_machine=$(uname -m 2>/dev/null) + ccenv_system=$(uname -s 2>/dev/null) + + ccenv_machine="${ccenv_machine:-unknown}" + ccenv_system="${ccenv_system:-anyos}" + + ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \ + | tr '[[:upper:]]' '[[:lower:]]') + fi + ccenv_cchost=$ccenv_host - ccenv_tool_epilog "$ccenv_cc" return 0 fi + if [ -n "$mb_cchost" ]; then ccenv_host="$mb_cchost" elif [ -n "$mb_host" ]; then @@ -423,10 +558,31 @@ ccenv_set_cc() ccenv_host= fi - if [ -z "$ccenv_host" ]; then - ccenv_host=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3) + if [ -z "$ccenv_host" ] && [ -n "$ccenv_dumpmachine_switch" ]; then + ccenv_host=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \ + $ccenv_dumpmachine_switch 2>&3) ccenv_cchost=$ccenv_host - else + + elif [ -z "$ccenv_host" ]; then + # no -dumpmachine support and no --host argument implies native build + if command -v slibtool > /dev/null 2>&1; then + ccenv=$(slibtool --dumpmachine 2>/dev/null || true) + fi + + if [ -z "$ccenv_host" ]; then + ccenv_machine=$(uname -m 2>/dev/null) + ccenv_system=$(uname -s 2>/dev/null) + + ccenv_machine="${ccenv_machine:-unknown}" + ccenv_system="${ccenv_system:-anyos}" + + ccenv_host=$(printf '%s' "${ccenv_machine}-unknown-${ccenv_system}" \ + | tr '[[:upper:]]' '[[:lower:]]') + fi + + ccenv_cchost=$ccenv_host + + elif [ -n "$ccenv_dumpmachine_switch" ]; then ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX) ccenv_cmd="$ccenv_cc --target=$ccenv_host -E -xc -" @@ -437,8 +593,10 @@ ccenv_set_cc() ccenv_errors=$(cat "$ccenv_tmp") if [ -z "$ccenv_errors" ]; then + ccenv_tool_prolog 'C compiler for host' ccenv_tflags="--target=$ccenv_host" ccenv_cc="$ccenv_cc $ccenv_tflags" + ccenv_tool_epilog "$ccenv_cc" else printf '%s' "$ccenv_errors" >&3 fi @@ -447,10 +605,14 @@ ccenv_set_cc() rm -f "$ccenv_tmp" unset ccenv_tmp - ccenv_cchost=$($ccenv_cc $(printf '%s' "$ccenv_cflags") -dumpmachine 2>&3) + ccenv_cchost=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \ + $ccenv_dumpmachine_switch 2>&3) fi - if [ "$ccenv_cchost" != "$ccenv_host" ]; then + if [ -z "$ccenv_dumpmachine_switch" ] && [ -n "$ccenv_host" ]; then + ccenv_cchost="$ccenv_host" + + elif [ "$ccenv_cchost" != "$ccenv_host" ]; then printf 'error!\n' >&2 printf 'ccenv:\n' >&2 printf 'ccenv: ccenv_host: %s \n' $ccenv_host >&2 @@ -476,8 +638,6 @@ ccenv_set_cc() return 2 fi - - ccenv_tool_epilog "$ccenv_cc" } ccenv_set_cpp() @@ -550,16 +710,25 @@ ccenv_set_cxx() ccenv_candidates="clang++" ;; *-gcc ) - ccenv_cpp_prefix=${ccenv_cc_cmd%-gcc*}- - ccenv_candidates="${ccenv_cpp_prefix}g++" ;; + ccenv_cxx_prefix=${ccenv_cc_cmd%-gcc*}- + ccenv_candidates="${ccenv_cxx_prefix}g++" ;; *-clang ) - ccenv_cpp_prefix=${ccenv_cc_cmd%-clang*}- - ccenv_candidates="${ccenv_cpp_prefix}clang++" ;; + ccenv_cxx_prefix=${ccenv_cc_cmd%-clang*}- + ccenv_candidates="${ccenv_cxx_prefix}clang++" ;; - *cc ) - ccenv_cxx_prefix=${ccenv_cc_cmd%cc*} - ccenv_candidates="${ccenv_cpp_prefix}++" ;; + /*cc | /*c99 | /*c11 ) + ccenv_cxx_prefix=${ccenv_cc_cmd%/*} + ccenv_candidates="${ccenv_cxx_prefix}/cxx" + ccenv_candidates="${ccenv_candidates} ${ccenv_cxx_prefix}/c++" ;; + + /*gcc ) + ccenv_cxx_prefix=${ccenv_cc_cmd%/*} + ccenv_candidates="${ccenv_cxx_prefix}/g++" ;; + + /*clang ) + ccenv_cxx_prefix=${ccenv_cc_cmd%/*} + ccenv_candidates="${ccenv_cxx_prefix}/clang++" ;; * ) ccenv_cxx="$ccenv_cc -xc++" @@ -596,16 +765,32 @@ ccenv_set_cc_bits() ccenv_internal_test='char x[(sizeof(%s) == %s/8) ? 1 : -1];' for ccenv_internal_guess in 64 32 128; do - if [ -z $ccenv_internal_size ]; then + if [ -z "${ccenv_internal_size:-}" ]; then ccenv_internal_str=$(printf "$ccenv_internal_test" \ "$ccenv_internal_type" \ "$ccenv_internal_guess") - printf '%s' "$ccenv_internal_str" \ - | $ccenv_cc -S -xc - -o - \ - $(printf '%s' "$ccenv_cflags") \ - > /dev/null 2>&3 \ - && ccenv_internal_size=$ccenv_internal_guess + ccenv_expr='ccenv_stdin_input=$ccenv_'${ccenv_cfgtype}'_stdin_input' + eval ${ccenv_expr} + + if [ "$ccenv_stdin_input" = 'yes' ]; then + printf '%s' "$ccenv_internal_str" \ + | eval $ccenv_cc -S -xc - -o - \ + $(printf '%s' "$ccenv_cflags") \ + > /dev/null 2>&3 \ + && ccenv_internal_size=$ccenv_internal_guess + else + ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c' + + printf '%s' "$ccenv_internal_str" \ + > "$ccenv_tmpname" + + $ccenv_cc -c "$ccenv_tmpname" -o a.out \ + > /dev/null 2>&3 \ + && ccenv_internal_size=$ccenv_internal_guess + + rm "$ccenv_tmpname" + fi fi done @@ -621,32 +806,58 @@ ccenv_set_cc_underscore() ccenv_fn_name='ZmYaXyWbVe_UuTnSdReQrPsOcNoNrLe' ccenv_fn_code='int %s(void){return 0;}' - if printf "$ccenv_fn_code" $ccenv_fn_name \ - | $ccenv_cc -xc - -S -o - \ - | grep "^_$ccenv_fn_name:" \ - > /dev/null; then + ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c' + + printf "$ccenv_fn_code" $ccenv_fn_name \ + > "$ccenv_tmpname" + + $ccenv_cc -c "$ccenv_tmpname" -o a.out \ + > /dev/null 2>&3 + + if "$ccenv_nm" a.out | grep \ + -e "^_$ccenv_fn_name" \ + -e " _$ccenv_fn_name" \ + > /dev/null; then ccenv_cc_underscore='_' ccenv_attr_epilog 'yes' + else + ccenv_attr_epilog 'no' fi - ccenv_attr_epilog 'no' + rm "$ccenv_tmpname" + rm a.out return 0 } ccenv_create_framework_executable() { + if [ "$ccenv_cfgtype" = 'host' ]; then + if [ "$mb_freestanding" = 'yes' ]; then + return 1 + fi + fi + if [ -f $ccenv_image ]; then mv $ccenv_image $ccenv_image.tmp rm -f $ccenv_image.tmp fi + ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c' + printf 'int main(void){return 0;}' \ - | $ccenv_cc -xc - \ - -o $ccenv_image \ - || return 1 + > "$ccenv_tmpname" - return 0 + if $ccenv_cc "$ccenv_tmpname" -o $ccenv_image 2>&3; then + ccenv_ret=0 + ccenv_cc_environment='hosted' + else + ccenv_ret=1 + fi + + rm "$ccenv_tmpname" + + return $ccenv_ret } ccenv_create_freestanding_executable() @@ -662,16 +873,25 @@ ccenv_create_freestanding_executable() ccenv_start_fn='start' fi - printf 'int %s(void){return 0;}' "$ccenv_start_fn" \ - | $ccenv_cc -xc - \ - -ffreestanding \ - -nostdlib -nostartfiles \ - -o $ccenv_image \ - || return 1 + ccenv_tmpname='ccenv/c3RyaWN0X21vZGUK.c' - ccenv_freestd=yes + printf 'int %s(void){return 0;}' "$ccenv_start_fn" \ + > "$ccenv_tmpname" - return 0 + if $ccenv_cc "$ccenv_tmpname" \ + -ffreestanding \ + -nostdlib -nostartfiles \ + -o $ccenv_image \ + 2>&3; then + ccenv_ret=0 + ccenv_cc_environment='freestanding' + else + ccenv_ret=1 + fi + + rm "$ccenv_tmpname" + + return $ccenv_ret } ccenv_set_cc_binfmt_error() @@ -779,7 +999,8 @@ ccenv_set_cc_binfmt() # MACHO / readobj if [ -n "$ccenv_readobj" ] && [ -z "$ccenv_cc_binfmt" ]; then if $ccenv_readobj $ccenv_image 2>&3 \ - | grep -i 'Format:' | sed 's/ /_/g' \ + | grep -i 'Format:' \ + | sed -e 's/ /_/g' \ | grep -i '_Mach-O_' \ > /dev/null; then ccenv_cc_binfmt='MACHO' @@ -822,7 +1043,7 @@ ccenv_set_cc_binfmt() ccenv_set_os_pe() { - if [ -n "$ccenv_freestd" ]; then + if [ "$ccenv_cc_environment" = 'freestanding' ]; then case "$ccenv_cchost" in *-midipix | *-midipix-* ) ccenv_os='midipix' ;; @@ -897,14 +1118,20 @@ ccenv_set_os() fi case "$ccenv_cchost" in - *-*-*-* ) - ccenv_tip=${ccenv_cchost%-*} - ccenv_os=${ccenv_tip#*-*-} - ;; *-*-musl | *-*-gnu ) ccenv_tip=${ccenv_cchost%-*} ccenv_os=${ccenv_tip#*-} ;; + *-*-solaris* ) + ccenv_os='solaris' + ;; + *-*-*bsd* | *-*-dragonfly* ) + ccenv_os='bsd' + ;; + *-*-*-* ) + ccenv_tip=${ccenv_cchost%-*} + ccenv_os=${ccenv_tip#*-*-} + ;; *-*-* ) ccenv_os=${ccenv_cchost#*-*-} ;; @@ -994,6 +1221,71 @@ ccenv_set_os_semantics() ccenv_attr_epilog "$ccenv_os_semantics" } +ccenv_set_os_dso_format() +{ + ccenv_attr_prolog 'os dso format' + + case "$ccenv_cc_arfmt" in + common ) + ccenv_cc_sofmt="$ccenv_cc_binfmt" + ;; + + bigaf ) + ccenv_libgcc_s_a_header=$(od -b -N8 \ + $($ccenv_cc -print-file-name=libgcc_s.a) \ + 2>/dev/null \ + | head -n1) + + ccenv_libgcc_s_so_header=$(od -b -N8 \ + $($ccenv_cc -print-file-name=libgcc_s.so) \ + 2>/dev/null \ + | head -n1) + + if [ "$ccenv_libgcc_s_a_header" = "$ccenv_bigaf_header" ]; then + ccenv_cc_sofmt='bigaf' + elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_bigaf_header" ]; then + ccenv_cc_sofmt='bigaf' + else + ccenv_cc_sofmt="$ccenv_cc_binfmt" + fi + ;; + + aiaff ) + ccenv_libgcc_s_a_header=$(od -b -N8 \ + $($ccenv_cc -print-file-name=libgcc_s.a) \ + | head -n1) + + ccenv_libgcc_s_so_header=$(od -b -N8 \ + $($ccenv_cc -print-file-name=libgcc_s.so) \ + | head -n1) + + if [ "$ccenv_libgcc_s_a_header" = "$ccenv_aiaff_header" ]; then + ccenv_cc_sofmt='aiaff' + elif [ "$ccenv_libgcc_s_so_header" = "$ccenv_aiaff_header" ]; then + ccenv_cc_sofmt='aiaff' + else + ccenv_cc_sofmt="$ccenv_cc_binfmt" + fi + ;; + esac + + if [ "$ccenv_cfgtype" = 'host' ]; then + case "$ccenv_cc_sofmt" in + bigaf | aiaff ) + mb_shared_lib_cmd='$(AR) -rcs' + mb_shared_lib_ldflags= + ;; + + * ) + mb_shared_lib_cmd='$(CC) -shared -o' + mb_shared_lib_ldflags='$(LDFLAGS_SHARED)' + ;; + esac + fi + + ccenv_attr_epilog "$ccenv_cc_sofmt" +} + ccenv_set_os_dso_exrules() { ccenv_attr_prolog 'os dso exrules' @@ -1126,6 +1418,42 @@ ccenv_set_os_pe_switches() ;; esac fi + + if [ "$ccenv_cc_binfmt" = 'PE' ]; then + if ! cfgtest_macro_definition '__PE__'; then + ccenv_cflags_os="${ccenv_cflags_os} -D__PE__" + fi + + if ! cfgtest_macro_definition '__dllexport'; then + ccenv_cflags_os="${ccenv_cflags_os} -D__dllexport=__attribute__\(\(__dllexport__\)\)" + fi + + if ! cfgtest_macro_definition '__dllimport'; then + ccenv_cflags_os="${ccenv_cflags_os} -D__dllimport=__attribute__\(\(__dllimport__\)\)" + fi + fi +} + +ccenv_set_os_gate_switches() +{ + if [ "$ccenv_os" = 'solaris' ]; then + if ! cfgtest_macro_definition 'AT_FDCWD'; then + ccenv_cflags_os="${ccenv_cflags_os} -D__EXTENSIONS__" + fi + fi +} + +ccenv_set_os_bsd_switches() +{ + if [ "$ccenv_os" = 'bsd' ]; then + mb_cfgtest_headers='sys/mman.h' + + if ! cfgtest_macro_definition 'MAP_ANON'; then + ccenv_cflags_os="${ccenv_cflags_os} -D__BSD_VISIBLE" + fi + + mb_cfgtest_headers= + fi } ccenv_output_defs() @@ -1143,33 +1471,44 @@ ccenv_output_defs() ccenv_tmp=$(mktemp ./tmp_XXXXXXXXXXXXXXXX) - sed \ - -e 's/^\s*$/@/g' \ - -e 's/^/NATIVE_/' \ - -e 's/NATIVE_@//g' \ - -e 's/NATIVE_#/#/g' \ - -e 's/ =/=/g' \ - -e 's/ +=/+=/g' \ - $ccenv_in > "$ccenv_tmp" + sed \ + -e 's/^[[:space:]]*$/@/g' \ + -e 's/^/NATIVE_/' \ + -e 's/NATIVE_@//g' \ + -e 's/NATIVE_#/#/g' \ + -e 's/ =/=/g' \ + -e 's/ +=/+=/g' \ + $(printf '%s ' $ccenv_in) \ + > "$ccenv_tmp" ccenv_in="$ccenv_tmp" else unset ccenv_tmp fi + ccenv_var_defs= + ccenv_sed_substs="-e s/@ccenv_cfgtype@/${ccenv_cfgtype}/g" + ccenv_vars=$(cut -d'=' -f1 "$mb_project_dir/sofort/ccenv/ccenv.vars" \ - | grep -v '^#') + | grep -v '^#'); - ccenv_exvars="ccenv_cfgtype ccenv_makevar_prefix" + ccenv_exvars="ccenv_makevar_prefix" - ccenv_sed_substs=" \ - $(for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do \ - printf '%s"$%s"%s' "-e 's/@$__var@/'" \ - "$__var" "'/g' "; \ - done)" + for __var in $(printf '%s' "$ccenv_vars $ccenv_exvars"); do + ccenv_sed_subst=$(printf '%s %s%s%s' \ + '-e' "'s^@$__var@" \ + "^___${__var}___" \ + "^g'") - eval sed $ccenv_sed_substs $ccenv_in \ - | sed -e 's/[[:blank:]]*$//g' \ + ccenv_sed_substs="$ccenv_sed_substs $ccenv_sed_subst" + + ccenv_var_def=$(printf '%s%s="${%s}"' "-D" "___${__var}___" "${__var}") + eval ccenv_var_defs='"$ccenv_var_defs "$ccenv_var_def' + done + + eval sed $ccenv_sed_substs $(printf '%s ' $ccenv_in) \ + | eval m4 $ccenv_var_defs - \ + | sed -e 's/[[:blank:]]*$//g' \ > "$ccenv_mk" if [ "$ccenv_cfgtype" = 'host' ]; then @@ -1199,6 +1538,181 @@ ccenv_output_defs() rm -f "$ccenv_tmp" unset ccenv_tmp fi + + + if [ "${ccenv_cfgtype}" = 'host' ]; then + ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-host) + ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-host) + else + ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .cflags-native) + ccenv_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" .ldflags-native) + fi + + ccenv_cflags="${ccenv_cflags#*: }" + ccenv_ldflags="${ccenv_ldflags#*: }" + + ccenv_sysroot=$(eval $ccenv_cc $(printf '%s' "$ccenv_cflags") \ + -print-sysroot 2>/dev/null || true) + + eval 'ccenv_'${ccenv_cfgtype}'_cflags'=\'$ccenv_cflags\' + eval 'ccenv_'${ccenv_cfgtype}'_ldflags'=\'$ccenv_ldflags\' + eval 'ccenv_'${ccenv_cfgtype}'_sysroot'=\'$ccenv_sysroot\' + + eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\' + eval 'ccenv_'${ccenv_cfgtype}'_cc_environment'=\'$ccenv_cc_environment\' + eval 'ccenv_'${ccenv_cfgtype}'_dumpmachine_switch'=\'$ccenv_dumpmachine_switch\' + eval 'ccenv_'${ccenv_cfgtype}'_pkgconf'=\'$ccenv_pkgconf\' + +} + +ccenv_set_cc_sysroot_vars() +{ + if [ "$ccenv_cfgtype" = 'native' ] || [ -z "$mb_sysroot" ]; then + return 0 + fi + + cfgtest_host_section + ccenv_switch_var="--sysroot=${mb_sysroot}" + + if cfgtest_compiler_switch_arg "${ccenv_switch_var}"; then + printf '\n# %s sysroot: cflags and ldflags\n' "$ccenv_cfgtype" \ + >> "$ccenv_mk" + + for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do + printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \ + >> "$ccenv_mk" + done + else + printf '\n# %s sysroot: cflags and ldflags %s\n' "$ccenv_cfgtype" \ + '(not supported: see config.log)' \ + >> "$ccenv_mk" + + for ccenv_make_var in '_CFLAGS_SYSROOT' '_LDFLAGS_SYSROOT'; do + printf '%-40s=\n' "${ccenv_make_var}" \ + >> "$ccenv_mk" + done + fi +} + +ccenv_set_cc_switch_vars() +{ + printf '\n# %s cflags: supported compiler switches\n' "$ccenv_cfgtype" \ + >> "$ccenv_mk" + + if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then + ccenv_switch_vars=$(cat \ + $mb_project_dir/sofort/ccenv/ccswitch.strs \ + $mb_project_dir/project/config/ccswitch.strs \ + | grep -v -e '^#' -e '^-Wl,' \ + | sort -u) + else + ccenv_switch_vars=$(grep -v -e '^#' -e '^-Wl,' \ + $mb_project_dir/sofort/ccenv/ccswitch.strs \ + | sort -u) + fi + + if [ $ccenv_cfgtype = 'host' ]; then + ccenv_makevar_prefix='_CFLAGS_' + cfgtest_host_section + else + ccenv_makevar_prefix='_NATIVE_CFLAGS_' + cfgtest_native_section + fi + + for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do + ccenv_make_var=${ccenv_switch_var%=} + ccenv_make_var=${ccenv_make_var%,} + + ccenv_make_var=${ccenv_make_var##---} + ccenv_make_var=${ccenv_make_var##--} + ccenv_make_var=${ccenv_make_var##-} + + ccenv_make_var=$(printf '%s' "$ccenv_make_var" \ + | sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g') + + ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}" + + if cfgtest_compiler_switch "$ccenv_switch_var"; then + ccenv_switch_var=${ccenv_switch_var%=} + ccenv_switch_var=${ccenv_switch_var%,} + + printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \ + >> "$ccenv_mk" + else + printf '%-40s=\n' "${ccenv_make_var}" \ + >> "$ccenv_mk" + fi + done +} + +ccenv_set_cc_linker_switch_vars() +{ + printf '\n# %s ldflags: supported compiler switches\n' "$ccenv_cfgtype" \ + >> "$ccenv_mk" + + if [ -f $mb_project_dir/project/config/ccswitch.strs ]; then + ccenv_switch_vars=$(cat \ + $mb_project_dir/sofort/ccenv/ccswitch.strs \ + $mb_project_dir/project/config/ccswitch.strs \ + | grep -e '^-Wl,' \ + | sort -u) + else + ccenv_switch_vars=$(grep -e '^-Wl,' \ + $mb_project_dir/sofort/ccenv/ccswitch.strs \ + | sort -u) + fi + + if [ $ccenv_cfgtype = 'host' ]; then + ccenv_makevar_prefix='_LDFLAGS_' + cfgtest_host_section + else + ccenv_makevar_prefix='_NATIVE_LDFLAGS_' + cfgtest_native_section + fi + + for ccenv_switch_var in $(printf '%s' "$ccenv_switch_vars"); do + ccenv_make_var=${ccenv_switch_var%=} + ccenv_make_var=${ccenv_make_var%,} + + ccenv_make_var=${ccenv_make_var##---} + ccenv_make_var=${ccenv_make_var##--} + ccenv_make_var=${ccenv_make_var##-} + + ccenv_make_var=$(printf '%s' "$ccenv_make_var" \ + | sed -e 's/=/_/g' -e 's/-/_/g' -e 's/,/_/g') + + ccenv_make_var="${ccenv_makevar_prefix}${ccenv_make_var}" + + if cfgtest_compiler_switch "$ccenv_switch_var"; then + ccenv_switch_var=${ccenv_switch_var%=} + ccenv_switch_var=${ccenv_switch_var%,} + + printf '%-40s= %s\n' "${ccenv_make_var}" "${ccenv_switch_var}" \ + >> "$ccenv_mk" + else + printf '%-40s=\n' "${ccenv_make_var}" \ + >> "$ccenv_mk" + fi + done +} + +ccenv_set_cc_attr_visibility_vars() +{ + if cfgtest_attr_visibility 'default'; then + ccenv_attr_visibility_default="$mb_cfgtest_attr" + fi + + if cfgtest_attr_visibility 'hidden'; then + ccenv_attr_visibility_hidden="$mb_cfgtest_attr" + fi + + if cfgtest_attr_visibility 'internal'; then + ccenv_attr_visibility_internal="$mb_cfgtest_attr" + fi + + if cfgtest_attr_visibility 'protected'; then + ccenv_attr_visibility_protected="$mb_cfgtest_attr" + fi } ccenv_dso_verify() @@ -1226,7 +1740,6 @@ ccenv_common_init() ccenv_cfgtype=$1 ccenv_cfgfile="$mb_pwd/ccenv/$ccenv_cfgtype.mk" - ccenv_freestd= ccenv_cchost= if [ $ccenv_cfgtype = 'native' ]; then @@ -1249,7 +1762,13 @@ ccenv_common_init() if [ $ccenv_cfgtype = 'host' ]; then ccenv_tflags= - ccenv_cflags=$(make -s -f "$mb_pwd/Makefile.tmp" .cflags-host) + ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \ + OS_DSO_EXRULES=default \ + OS_SONAME=symlink \ + OS_ARCHIVE_EXT='.a' \ + .cflags-host) + + ccenv_cflags="${ccenv_cflags#*: }" ccenv_cc="$mb_user_cc" ccenv_cpp="$mb_user_cpp" @@ -1259,7 +1778,14 @@ ccenv_common_init() ccenv_pe_image_base="$mb_pe_image_base" else ccenv_tflags= - ccenv_cflags=$(make -s -f "$mb_pwd/Makefile.tmp" .cflags-native) + ccenv_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \ + OS_DSO_EXRULES=default \ + OS_SONAME=symlink \ + OS_ARCHIVE_EXT='.a' \ + .cflags-native) + + ccenv_cflags="${ccenv_cflags#*: }" + ccenv_cc="$mb_native_cc" ccenv_cpp="$mb_native_cpp" ccenv_cxx="$mb_native_cxx" @@ -1290,15 +1816,21 @@ ccenv_set_toolchain_variables() ccenv_set_os ccenv_set_os_flags ccenv_set_os_semantics + ccenv_set_os_dso_format ccenv_set_os_dso_exrules ccenv_set_os_dso_linkage ccenv_set_os_dso_patterns ccenv_set_os_pe_switches + ccenv_set_os_gate_switches + ccenv_set_os_bsd_switches + ccenv_set_cc_attr_visibility_vars ccenv_output_defs ccenv_clean_up - eval 'ccenv_'${ccenv_cfgtype}'_cc'=\'$ccenv_cc\' + ccenv_set_cc_sysroot_vars + ccenv_set_cc_switch_vars + ccenv_set_cc_linker_switch_vars } ccenv_set_host_variables() |