diff options
Diffstat (limited to 'sofort')
39 files changed, 2132 insertions, 309 deletions
diff --git a/sofort/ccenv/ccenv.in b/sofort/ccenv/ccenv.in index f12c78e..0daff84 100644 --- a/sofort/ccenv/ccenv.in +++ b/sofort/ccenv/ccenv.in @@ -1,86 +1,96 @@ # @ccenv_cfgtype@ system flavor -OS = @ccenv_os@ -OS_SEMANTICS = @ccenv_os_semantics@ +OS = @ccenv_os@ +OS_SEMANTICS = @ccenv_os_semantics@ -OS_DSO_EXRULES = @ccenv_os_dso_exrules@ -OS_DSO_LINKAGE = @ccenv_os_dso_linkage@ +OS_DSO_EXRULES = @ccenv_os_dso_exrules@ +OS_DSO_LINKAGE = @ccenv_os_dso_linkage@ -OS_APP_PREFIX = @ccenv_os_app_prefix@ -OS_APP_SUFFIX = @ccenv_os_app_suffix@ +OS_APP_PREFIX = @ccenv_os_app_prefix@ +OS_APP_SUFFIX = @ccenv_os_app_suffix@ -OS_LIB_PREFIX = @ccenv_os_lib_prefix@ -OS_LIB_SUFFIX = @ccenv_os_lib_suffix@ +OS_LIB_PREFIX = @ccenv_os_lib_prefix@ +OS_LIB_SUFFIX = @ccenv_os_lib_suffix@ -OS_IMPLIB_EXT = @ccenv_os_implib_ext@ -OS_LIBDEF_EXT = @ccenv_os_libdef_ext@ +OS_IMPLIB_EXT = @ccenv_os_implib_ext@ +OS_LIBDEF_EXT = @ccenv_os_libdef_ext@ -OS_ARCHIVE_EXT = @ccenv_os_archive_ext@ -OS_SONAME = @ccenv_os_soname@ +OS_ARCHIVE_EXT = @ccenv_os_archive_ext@ +OS_SONAME = @ccenv_os_soname@ -OS_LIB_PREFIXED_SUFFIX = @ccenv_os_lib_prefixed_suffix@ -OS_LIB_SUFFIXED_SUFFIX = @ccenv_os_lib_suffixed_suffix@ +OS_LIB_PREFIXED_SUFFIX = @ccenv_os_lib_prefixed_suffix@ +OS_LIB_SUFFIXED_SUFFIX = @ccenv_os_lib_suffixed_suffix@ # @ccenv_cfgtype@ characteristics -CC_HOST = @ccenv_cc_host@ -CC_BITS = @ccenv_cc_bits@ +CC_HOST = @ccenv_cc_host@ +CC_BITS = @ccenv_cc_bits@ -CC_BINFMT = @ccenv_cc_binfmt@ -CC_UNDERSCORE = @ccenv_cc_underscore@ +CC_ARFMT = @ccenv_cc_arfmt@ +CC_SOFMT = @ccenv_cc_sofmt@ +CC_BINFMT = @ccenv_cc_binfmt@ +CC_UNDERSCORE = @ccenv_cc_underscore@ +CC_ENVIRONMENT = @ccenv_cc_environment@ -CC_ARCH_BFD = @ccenv_cc_arch_bfd@ -CC_ARCH_LLVM = @ccenv_cc_arch_llvm@ +CC_ARCH_BFD = @ccenv_cc_arch_bfd@ +CC_ARCH_LLVM = @ccenv_cc_arch_llvm@ # incompatible tool variants -AS_ASM = @ccenv_as_asm@ -AS_LL = @ccenv_as_ll@ -AS_MC = @ccenv_as_mc@ +AS_ASM = @ccenv_as_asm@ +AS_LL = @ccenv_as_ll@ +AS_MC = @ccenv_as_mc@ -LD_BFD = @ccenv_ld_bfd@ -LD_GOLD = @ccenv_ld_gold@ -LD_LLD = @ccenv_ld_lld@ +LD_BFD = @ccenv_ld_bfd@ +LD_GOLD = @ccenv_ld_gold@ +LD_LLD = @ccenv_ld_lld@ -OBJDUMP_BFD = @ccenv_objdump_bfd@ -OBJDUMP_LLVM = @ccenv_objdump_llvm@ +OBJDUMP_BFD = @ccenv_objdump_bfd@ +OBJDUMP_LLVM = @ccenv_objdump_llvm@ -READELF_BFD = @ccenv_readelf_bfd@ -READELF_LLVM = @ccenv_readelf_llvm@ +READELF_BFD = @ccenv_readelf_bfd@ +READELF_LLVM = @ccenv_readelf_llvm@ # @ccenv_cfgtype@ primary tools -CC = @ccenv_cc@ -CPP = @ccenv_cpp@ -CXX = @ccenv_cxx@ - -AR = @ccenv_ar@ -NM = @ccenv_nm@ -OBJDUMP = @ccenv_objdump@ -RANLIB = @ccenv_ranlib@ -SIZE = @ccenv_size@ -STRIP = @ccenv_strip@ -STRINGS = @ccenv_strings@ - -ADDR2LINE = @ccenv_addr2line@ -COV = @ccenv_cov@ -CXXFILT = @ccenv_cxxfilt@ -OBJCOPY = @ccenv_objcopy@ - -ELFEDIT = @ccenv_elfedit@ -READELF = @ccenv_readelf@ -READOBJ = @ccenv_readobj@ - -PERK = @ccenv_perk@ -MDSO = @ccenv_mdso@ -DLLTOOL = @ccenv_dlltool@ - -WINDMC = @ccenv_windmc@ -WINDRC = @ccenv_windrc@ +CC = @ccenv_cc@ +CPP = @ccenv_cpp@ +CXX = @ccenv_cxx@ + +AR = @ccenv_ar@ +NM = @ccenv_nm@ +OBJDUMP = @ccenv_objdump@ +RANLIB = @ccenv_ranlib@ +SIZE = @ccenv_size@ +STRIP = @ccenv_strip@ +STRINGS = @ccenv_strings@ + +ADDR2LINE = @ccenv_addr2line@ +COV = @ccenv_cov@ +CXXFILT = @ccenv_cxxfilt@ +OBJCOPY = @ccenv_objcopy@ + +ELFEDIT = @ccenv_elfedit@ +READELF = @ccenv_readelf@ +READOBJ = @ccenv_readobj@ + +PERK = @ccenv_perk@ +MDSO = @ccenv_mdso@ +DLLTOOL = @ccenv_dlltool@ + +WINDMC = @ccenv_windmc@ +WINDRC = @ccenv_windrc@ + +PKGCONF = @ccenv_pkgconf@ # @ccenv_cfgtype@ secondary tools # note: the direct use of $(@ccenv_makevar_prefix@LD) is highly discouraged -AS = @ccenv_as@ -LD = @ccenv_ld@ +AS = @ccenv_as@ +LD = @ccenv_ld@ -# @ccenv_cfgtype@ cflags -CFLAGS_OS += -DOS_LIB_SUFFIX=\"@ccenv_os_lib_suffix@\" -CFLAGS_OS += @ccenv_cflags_os@ -CFLAGS_PIC += @ccenv_cflags_pic@ +# @ccenv_cfgtype@ visibility attributes +CFLAGS_ATTR_VISIBILITY_DEFAULT = -D_ATTR_VISIBILITY_DEFAULT=@ccenv_attr_visibility_default@ +CFLAGS_ATTR_VISIBILITY_HIDDEN = -D_ATTR_VISIBILITY_HIDDEN=@ccenv_attr_visibility_hidden@ +CFLAGS_ATTR_VISIBILITY_INTERNAL = -D_ATTR_VISIBILITY_INTERNAL=@ccenv_attr_visibility_internal@ +CFLAGS_ATTR_VISIBILITY_PROTECTED = -D_ATTR_VISIBILITY_PROTECTED=@ccenv_attr_visibility_protected@ +# @ccenv_cfgtype@ cflags +CFLAGS_OS += -DOS_LIB_SUFFIX=\"@ccenv_os_lib_suffix@\" +CFLAGS_OS += @ccenv_cflags_os@ +CFLAGS_PIC += @ccenv_cflags_pic@ 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() diff --git a/sofort/ccenv/ccenv.vars b/sofort/ccenv/ccenv.vars index 4775b37..054b638 100644 --- a/sofort/ccenv/ccenv.vars +++ b/sofort/ccenv/ccenv.vars @@ -24,8 +24,11 @@ ccenv_os_lib_suffixed_suffix= ccenv_cc_host= ccenv_cc_bits= +ccenv_cc_arfmt= +ccenv_cc_sofmt= ccenv_cc_binfmt= ccenv_cc_underscore= +ccenv_cc_environment= ccenv_cc_arch_bfd= ccenv_cc_arch_llvm= @@ -77,6 +80,14 @@ ccenv_dlltool= ccenv_windmc= ccenv_windrc= +ccenv_pkgconf= + +# visibility attributes +ccenv_attr_visibility_default= +ccenv_attr_visibility_hidden= +ccenv_attr_visibility_internal= +ccenv_attr_visibility_protected= + # cflags ccenv_cflags_os= ccenv_cflags_pic= diff --git a/sofort/ccenv/ccswitch.strs b/sofort/ccenv/ccswitch.strs new file mode 100644 index 0000000..277e02e --- /dev/null +++ b/sofort/ccenv/ccswitch.strs @@ -0,0 +1,51 @@ +# ccswitch.strs: project-agnostic list of compiler switches, +# for which support is tested by default. + +# when -foo is supported by the host or native compiler, add +# ``CFLAGS_foo = -foo'' to the respective ccenv variable file +# (that is, ccenv/host.mk or ccenv/native.mk). + +# the make variable prefix is _CFLAGS_ or _NATIVE_CFLAGS_ +# (_LDFLAGS_ or _NATIVE_LDFLAGS for -Wl, linker options), +# to which the compiler-switch, minus leading dashes and +# trailing equal-sign or comma, is appended; non-leading +# dashes and non-trailing equal-signs and commas are then +# substituted with underscores. + +# the project-agnostic list below can be supplemented by a +# project-specific one, named project/config/ccswitch.strs. + +# toolchain switches +-dumpmachine +-print-file-name= + +# flavors and variants +-std=c89 +-std=c99 +-std=c11 + +# linker switches +-Wl,--print-map +-Wl,--no-undefined +-Wl,--verbose + +# errors and warnings +-Wall +-Werror +-Wextra +-Wundef +-Wpedantic + +# debugging +-g +-g0 +-g1 +-g2 +-g3 + +# optimization +-O0 +-O1 +-O2 +-O3 +-Os diff --git a/sofort/ccenv/pedefs.in b/sofort/ccenv/pedefs.in index 300d990..008b271 100644 --- a/sofort/ccenv/pedefs.in +++ b/sofort/ccenv/pedefs.in @@ -1,4 +1,4 @@ # @ccenv_cfgtype@ pe switches -PE_SUBSYSTEM = @ccenv_pe_subsystem@ -PE_IMAGE_BASE = @ccenv_pe_image_base@ +PE_SUBSYSTEM = @ccenv_pe_subsystem@ +PE_IMAGE_BASE = @ccenv_pe_image_base@ diff --git a/sofort/cfgtest/cfgtest.sh b/sofort/cfgtest/cfgtest.sh new file mode 100644 index 0000000..7bb27a0 --- /dev/null +++ b/sofort/cfgtest/cfgtest.sh @@ -0,0 +1,939 @@ +# cfgtest.sh: sofort's config test framework, +# for use from within a project's custom cfgdefs.sh. + +# this file is covered by COPYING.SOFORT. + +# in the common scenario, host-specific tests are preceded +# by a single invocation of cfgtest_host_section, whereas +# native (build) system tests are preceded by the invocation +# of cfgtest_native_section. + +# cfgdefs fraework variables: +# mb_cfgtest_cc: the compiler used for the current test +# mb_cfgtest_pkgconf: the pkgconf utility used for the current test +# mb_cfgtest_cflags: the compiler flags used for the current test +# mb_cfgtest_cfgtype: the type of the current test (host/native) +# mb_cfgtest_makevar: the make variable affected by the current test +# mb_cfgtest_headers: headers for ad-hoc inclusion with the current test +# mb_cfgtest_attr: if supported, the compiler-specific attribute definition + + +cfgtest_newline() +{ + printf '\n' >> $mb_pwd/cfgdefs.mk +} + + +cfgtest_comment() +{ + mb_internal_str='#' + + for mb_internal_arg ; do + mb_internal_str="$mb_internal_str $mb_internal_arg" + done + + printf '%s\n' "$mb_internal_str" >> $mb_pwd/cfgdefs.mk +} + + +cfgtest_host_section() +{ + mb_cfgtest_cc="$ccenv_host_cc" + mb_cfgtest_pkgconf="${ccenv_host_pkgconf:-false}" + mb_cfgtest_cfgtype='host' + mb_cfgtest_stdin_input=${ccenv_host_stdin_input:-} + mb_cfgtest_environment=${ccenv_host_cc_environment:-} + + mb_cfgtest_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \ + OS_DSO_EXRULES=default \ + OS_SONAME=symlink \ + OS_ARCHIVE_EXT='.a' \ + .cflags-host) + + mb_cfgtest_cflags="${mb_cfgtest_cflags#*: }" + + mb_cfgtest_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \ + OS_DSO_EXRULES=default \ + OS_SONAME=symlink \ + OS_ARCHIVE_EXT='.a' \ + .ldflags-host) + + mb_cfgtest_ldflags="${mb_cfgtest_ldflags#*: }" +} + + +cfgtest_native_section() +{ + mb_cfgtest_cc="$ccenv_native_cc" + mb_cfgtest_pkgconf="${ccenv_native_pkgconf:-false}" + mb_cfgtest_cfgtype='native' + mb_cfgtest_stdin_input=${ccenv_native_stdin_input:-} + mb_cfgtest_environment=${ccenv_native_cc_environment:-} + + mb_cfgtest_cflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \ + OS_DSO_EXRULES=default \ + OS_SONAME=symlink \ + OS_ARCHIVE_EXT='.a' \ + .cflags-native) + + mb_cfgtest_cflags="${mb_cfgtest_cflags#*: }" + + mb_cfgtest_ldflags=$(${mb_make} -n -f "$mb_pwd/Makefile.tmp" \ + OS_DSO_EXRULES=default \ + OS_SONAME=symlink \ + OS_ARCHIVE_EXT='.a' \ + .ldflags-native) + + mb_cfgtest_ldflags="${mb_cfgtest_ldflags#*: }" +} + + +cfgtest_prolog() +{ + cfgtest_line_dots='...........................' + cfgtest_line_dots="${cfgtest_line_dots}${cfgtest_line_dots}" + cfgtest_tool_desc=" == trying ${mb_cfgtest_cfgtype} ${1}: ${2}" + cfgtest_tool_dlen="${#cfgtest_line_dots}" + + printf '\n%s\n' '________________________' >&3 + printf "cfgtest: probing for ${mb_cfgtest_cfgtype} ${1}: ${2}\n\n" >&3 + + if [ "${cfgtest_silent:-}" != 'yes' ]; then + printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s" \ + "${cfgtest_tool_desc} ${mb_line_dots}" + fi +} + + +cfgtest_epilog() +{ + cfgtest_line_dots='...............' + cfgtest_tool_dlen="$((${#cfgtest_line_dots} - ${#2}))" + + if [ "${cfgtest_silent:-}" != 'yes' ]; then + printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s %s.\n" \ + "${cfgtest_line_dots}" "${2}" + fi + + if [ "${1}" = 'snippet' ] && [ -f 'a.out' ]; then + rm -f 'a.out' + fi + + if [ "$mb_cfgtest_stdin_input" = 'no' ]; then + rm 'cfgtest_c3RyaWN0X21vZGUK.c' + fi + + if [ "${1}" = 'snippet' ] && [ "${2}" = '(error)' ]; then + printf '\n\ncfgtest: the %s compiler %s %s.\n' \ + "$mb_cfgtest_cfgtype" \ + 'failed to compile the above code' \ + "${1}" >&3 + printf '%s\n' '------------------------' >&3 + return 1 + fi + + if [ "${1}" = 'attr' ] && [ "${2}" = '(error)' ]; then + printf '\n\ncfgtest: the %s compiler %s %s_ attribute.\n' \ + "$mb_cfgtest_cfgtype" \ + 'does not appear to support the _' \ + "${3}" >&3 + printf '%s\n' '------------------------' >&3 + return 1 + fi + + if [ "${2}" = '-----' ] || [ "${2}" = '(missing)' ]; then + printf '\n\ncfgtest: %s %s is missing or cannot be found.\n' "${1}" "${3}" >&3 + printf '%s\n' '------------------------' >&3 + return 1 + elif [ "${1}" = 'size-of-type' ] && [ "${2}" = '(error)' ]; then + printf '\n\ncfgtest: could not determine size of type `%s.\n' "${3}'" >&3 + printf '%s\n' '------------------------' >&3 + return 1 + elif [ "${1}" = 'switch' ] && [ "${2}" = '(error)' ]; then + printf '\n\ncfgtest: the switch `%s is not supported by the %s compiler.\n' \ + "${3}'" "$mb_cfgtest_cfgtype" >&3 + printf '%s\n' '------------------------' >&3 + return 1 + elif [ "${2}" = '(error)' ]; then + printf '\n\ncfgtest: %s `%s is not defined or cannot be used.\n' "${1}" "${3}'" >&3 + printf '%s\n' '------------------------' >&3 + return 1 + fi +} + + +cfgtest_entity_size_prolog() +{ + cfgtest_line_dots='.......................' + cfgtest_line_dots="${cfgtest_line_dots}${cfgtest_line_dots}" + cfgtest_tool_desc=" == checking size of ${mb_cfgtest_cfgtype} type: ${@}" + cfgtest_tool_dlen="${#cfgtest_line_dots}" + + printf '\n%s\n' '________________________' >&3 + printf "cfgtest: checking size of ${mb_cfgtest_cfgtype} type: ${@}\n\n" >&3 + + printf "%${cfgtest_tool_dlen}.${cfgtest_tool_dlen}s" \ + "${cfgtest_tool_desc} ${mb_line_dots}" +} + + +cfgtest_makevar_set() +{ + if [ -n "${@}" ]; then + mb_internal_str='= ' + else + mb_internal_str='=' + fi + + printf '%-25s%s%s\n' "$mb_cfgtest_makevar" "$mb_internal_str" "${@}" \ + >> $mb_pwd/cfgdefs.mk + + unset cfgtest_internal_unit_test +} + + +cfgtest_makevar_append() +{ + mb_internal_str='+=' + + for mb_internal_arg ; do + if ! [ -z "$mb_internal_arg" ]; then + mb_internal_str="$mb_internal_str $mb_internal_arg" + fi + done + + printf '%-24s%s\n' "$mb_cfgtest_makevar" "$mb_internal_str" \ + >> $mb_pwd/cfgdefs.mk + + unset cfgtest_internal_unit_test +} + + +cfgtest_cflags_append() +{ + if [ $mb_cfgtest_cfgtype = 'host' ]; then + mb_internal_makevar='CFLAGS_CONFIG' + else + mb_internal_makevar='NATIVE_CFLAGS' + fi + + mb_cfgtest_makevar_saved=$mb_cfgtest_makevar + mb_cfgtest_makevar=$mb_internal_makevar + + cfgtest_makevar_append "$@" + mb_cfgtest_makevar=$mb_cfgtest_makevar_saved +} + + +cfgtest_ldflags_append() +{ + if [ $mb_cfgtest_cfgtype = 'host' ]; then + mb_internal_makevar='LDFLAGS_CONFIG' + else + mb_internal_makevar='NATIVE_LDFLAGS' + fi + + mb_cfgtest_makevar_saved=$mb_cfgtest_makevar + mb_cfgtest_makevar=$mb_internal_makevar + + cfgtest_makevar_append "$@" + mb_cfgtest_makevar=$mb_cfgtest_makevar_saved +} + + +cfgtest_common_init() +{ + # cfgtest variables + cfgtest_type="${1:-}" + + if [ "$mb_cfgtest_stdin_input" = 'no' ]; then + if [ "$cfgtest_type" = 'lib' ]; then + cfgtest_fmt='%s cfgtest_c3RyaWN0X21vZGUK.c -o a.out' + elif [ "$cfgtest_type" = 'ldflag' ]; then + cfgtest_fmt='%s cfgtest_c3RyaWN0X21vZGUK.c -o a.out' + else + cfgtest_fmt='%s -c cfgtest_c3RyaWN0X21vZGUK.c -o a.out' + fi + elif [ "$cfgtest_type" = 'asm' ]; then + cfgtest_fmt='%s -c -xc - -o a.out' + elif [ "$cfgtest_type" = 'attr' ]; then + cfgtest_fmt='%s -c -xc - -o a.out -Werror' + elif [ "$cfgtest_type" = 'lib' ]; then + cfgtest_fmt='%s -xc - -o a.out' + elif [ "$cfgtest_type" = 'ldflag' ]; then + cfgtest_fmt='%s -xc - -o a.out' + else + cfgtest_fmt='%s -S -xc - -o -' + fi + + + if [ "$cfgtest_type" = 'lib' ]; then + cfgtest_cmd=$(printf "$cfgtest_fmt %s %s %s" \ + "$mb_cfgtest_cc" \ + "$mb_cfgtest_cflags" \ + "$mb_cfgtest_ldflags" \ + "$cfgtest_libs") + + elif [ "$cfgtest_type" = 'ldflag' ]; then + cfgtest_cmd=$(printf "$cfgtest_fmt %s %s %s" \ + "$mb_cfgtest_cc" \ + "$mb_cfgtest_cflags" \ + "$mb_cfgtest_ldflags" \ + "$cfgtest_switches") + + elif [ "$cfgtest_type" = 'switch' ]; then + cfgtest_cmd=$(printf "$cfgtest_fmt %s %s" \ + "$mb_cfgtest_cc" \ + "$mb_cfgtest_cflags" \ + "$cfgtest_switches") + else + cfgtest_cmd=$(printf "$cfgtest_fmt %s" \ + "$mb_cfgtest_cc" \ + "$mb_cfgtest_cflags") + fi + + + if [ -n "$mb_cfgtest_headers" ]; then + cfgtest_inc=$(printf '#include <%s>\n' $mb_cfgtest_headers) + cfgtest_src=$(printf '%s\n_\n' "$cfgtest_inc" \ + | m4 -D_="$cfgtest_code_snippet") + else + cfgtest_inc= + cfgtest_src="$cfgtest_code_snippet" + fi + + + # config.log + printf "$cfgtest_fmt" "$mb_cfgtest_cc" >&3 + + for cfgtest_cflag in $(printf '%s' "$mb_cfgtest_cflags"); do + printf ' \\\n\t%s' "$cfgtest_cflag" >&3 + done + + for cfgtest_ldflag in $(printf '%s' "$mb_cfgtest_ldflags"); do + printf ' \\\n\t%s' "$cfgtest_ldflag" >&3 + done + + if [ "$cfgtest_type" = 'lib' ]; then + for cfgtest_lib in $(printf '%s' "$cfgtest_libs"); do + printf ' \\\n\t%s' "$cfgtest_lib" >&3 + done + + elif [ "$cfgtest_type" = 'switch' ] || [ "$cfgtest_type" = 'ldflag' ]; then + for cfgtest_switch in $(printf '%s' "$cfgtest_switches"); do + printf ' \\\n\t%s' "$cfgtest_switch" >&3 + done + fi + + printf ' \\\n' >&3 + printf '<< _SRCEOF\n%s\n' "$cfgtest_src" >&3 + printf '_SRCEOF\n\n\n' >&3 + + if [ "$mb_cfgtest_stdin_input" = 'no' ]; then + printf '%s' "$cfgtest_src" > 'cfgtest_c3RyaWN0X21vZGUK.c' + cfgtest_src= + fi +} + + +cfgtest_header_presence() +{ + #init + cfgtest_prolog 'header' "${1}" + + cfgtest_code_snippet=$(printf '#include <%s>\n' "${1}") + cfgtest_code_onedecl='int fn(void){return 0;}' + + cfgtest_code_snippet=$(printf '%s\n%s\n' \ + "$cfgtest_code_snippet" \ + "$cfgtest_code_onedecl") + + cfgtest_common_init + + # execute + printf '%s\n' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + || cfgtest_epilog 'header' '-----' "<${1}>" \ + || return + + # result + mb_internal_str=$(printf '%s%s' '-DHAVE_' "${1}" \ + | sed -e 's/\./_/g' -e 's@/@_@g' \ + | tr "[:lower:]" "[:upper:]") + + if [ -z ${cfgtest_internal_unit_test:-} ]; then + cfgtest_cflags_append "$mb_internal_str" + else + cfgtest_makevar_append "$mb_internal_str" + fi + + printf 'cfgtest: %s header <%s> was found and may be included.\n' \ + "$mb_cfgtest_cfgtype" "${1}" >&3 + printf '%s\n' '------------------------' >&3 + + cfgtest_epilog 'header' "${1}" +} + + +cfgtest_header_absence() +{ + #init + cfgtest_prolog 'header absence' "${1}" + + cfgtest_code_snippet=$(printf '#include <%s>\n' "${1}") + cfgtest_code_onedecl='int fn(void){return 0;}' + + cfgtest_code_snippet=$(printf '%s\n%s\n' \ + "$cfgtest_code_snippet" \ + "$cfgtest_code_onedecl") + + cfgtest_common_init + + # execute + printf '%s\n' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + && printf 'cfgtest: %s header <%s>: no error.' \ + "$mb_cfgtest_cfgtype" "${1}" >&3 \ + && cfgtest_epilog 'header' "${1}" \ + && return + + # result + mb_internal_str=$(printf '%s%s' '-DHAVE_NO_' "$@" \ + | sed -e 's/\./_/g' -e 's@/@_@g' \ + | tr "[:lower:]" "[:upper:]") + + if [ -z ${cfgtest_internal_unit_test:-} ]; then + cfgtest_cflags_append "$mb_internal_str" + else + cfgtest_makevar_append "$mb_internal_str" + fi + + printf 'cfgtest: %s header <%s> may not be included.\n' \ + "$mb_cfgtest_cfgtype" "${1}" >&3 + printf '%s\n' '------------------------' >&3 + + cfgtest_epilog 'header' '-----' "${1}" +} + + +cfgtest_interface_presence() +{ + # init + cfgtest_prolog 'interface' "${1}" + + cfgtest_code_snippet=$(printf 'void (*addr)() = (void (*)())&%s;\n' "${1}") + + cfgtest_common_init + + # execute + printf '%s\n' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + || cfgtest_epilog 'interface' '(error)' "${1}" \ + || return + + # result + mb_internal_str=$(printf '%s%s' '-DHAVE_' "$@" \ + | sed -e 's/\./_/g' \ + | tr "[:lower:]" "[:upper:]") + + if [ -z ${cfgtest_internal_unit_test:-} ]; then + cfgtest_cflags_append "$mb_internal_str" + else + cfgtest_makevar_append "$mb_internal_str" + fi + + printf 'cfgtest: %s interface `%s'"'"' is available.\n' \ + "$mb_cfgtest_cfgtype" "${1}" >&3 + printf '%s\n' '------------------------' >&3 + + cfgtest_epilog 'interface' "${1}" + + return 0 +} + + +cfgtest_decl_presence() +{ + # init + cfgtest_prolog 'decl' "${1}" + + cfgtest_code_snippet=$(printf 'void * any = (void *)(%s);' "${1}") + + cfgtest_common_init + + # execute + printf '%s\n' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + || cfgtest_epilog 'decl' '(error)' "${1}" \ + || return + + # does the argument solely consist of the macro or enum member name? + mb_internal_str=$(printf '%s' "$@" | tr -d '[a-z][A-Z][0-9][_]') + + if [ -n "$mb_internal_str" ]; then + cfgtest_epilog 'decl' '(defined)' + return 0 + fi + + # result + mb_internal_str=$(printf '%s%s' '-DHAVE_DECL_' "$@" \ + | sed -e 's/\./_/g' \ + | tr "[:lower:]" "[:upper:]") + + if [ -z ${cfgtest_internal_unit_test:-} ]; then + cfgtest_cflags_append "$mb_internal_str" + else + cfgtest_makevar_append "$mb_internal_str" + fi + + printf 'cfgtest: `%s'"'"' is defined for the %s system.\n' \ + "${1}" "$mb_cfgtest_cfgtype" >&3 + printf '%s\n' '------------------------' >&3 + + cfgtest_epilog 'decl' '(defined)' + + return 0 +} + + +cfgtest_type_size() +{ + cfgtest_entity_size_prolog "$@" + + mb_internal_size='' + mb_internal_test='char x[(sizeof(%s) == %s) ? 1 : -1];' + + for mb_internal_guess in 8 4 2 1 16 32 64 128; do + if [ -z $mb_internal_size ]; then + printf '# guess %s ===>\n' "$mb_internal_guess" >&3 + + mb_internal_type="$@" + + cfgtest_code_snippet=$(printf "$mb_internal_test" \ + "$mb_internal_type" "$mb_internal_guess") + + cfgtest_common_init + + printf '%s\n' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + && mb_internal_size=$mb_internal_guess + + printf '\n' >&3 + fi + done + + # unrecognized type, or type size not within range + if [ -z $mb_internal_size ]; then + cfgtest_epilog 'size-of-type' '(error)' "@" + return 1 + fi + + # -DSIZEOF_TYPE=SIZE + mb_internal_str=$(printf '%s%s=%s' '-DSIZEOF_' \ + "$mb_internal_type" \ + "$mb_internal_size" \ + | sed -e 's/\ /_/g' -e 's/*/P/g' \ + | tr "[:lower:]" "[:upper:]") + + if [ -z ${cfgtest_internal_unit_test:-} ]; then + cfgtest_cflags_append "$mb_internal_str" + else + cfgtest_makevar_append "$mb_internal_str" + fi + + printf 'cfgtest: size of type `%s'"'"' determined to be %s\n' \ + "${@}" "$mb_internal_size" >&3 + printf '%s\n' '------------------------' >&3 + + cfgtest_epilog 'size-of-type' "$mb_internal_size" + + return 0 +} + + +cfgtest_attr_visibility() +{ + # init + cfgtest_prolog 'compiler visibility attr' "${1}" + + cfgtest_attr_syntax='__attribute__((__visibility__("'"${1}"'")))' + cfgtest_code_snippet="$cfgtest_attr_syntax"' int f_'"${1}"'(void);' + + cfgtest_common_init 'attr' + + # execute + cfgtest_ret=1 + + printf '%s\n' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + || cfgtest_epilog 'attr' '(error)' "${1}" \ + || return + + # result + mb_cfgtest_attr=$(printf '__attribute__\\(\\(__visibility__\\(\\"%s\\"\\)\\)\\)' "${1}") + + cfgtest_ret=0 + + printf 'cfgtest: %s compiler: above attribute is supported; see also ccenv/%s.mk.\n\n' \ + "$mb_cfgtest_cfgtype" "$mb_cfgtest_cfgtype" >&3 + + cfgtest_epilog 'attr' '(ok)' + + return 0 +} + + +cfgtest_code_snippet_asm() +{ + # init + cfgtest_prolog 'support of code snippet' '<...>' + + cfgtest_code_snippet="$@" + + cfgtest_common_init 'asm' + + # execute + cfgtest_ret=1 + + printf '%s\n' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + || cfgtest_epilog 'snippet' '(error)' \ + || return + + # result + cfgtest_ret=0 + + printf 'cfgtest: %s compiler: above code snippet compiled successfully.\n\n' \ + "$mb_cfgtest_cfgtype" >&3 + + cfgtest_epilog 'snippet' '(ok)' + + return 0 +} + + +cfgtest_macro_definition() +{ + # init + cfgtest_prolog 'macro definition' "${1}" + + cfgtest_code_snippet=$(printf '%s\n' \ + "#ifndef ${1}" \ + "#error macro ${1} is not defined." \ + "#endif") + + cfgtest_common_init 'macro' + + # execute + cfgtest_ret=1 + + printf '%s\n' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + || cfgtest_epilog 'macro' '(error)' "${1}" \ + || return + + # result + cfgtest_ret=0 + + printf 'cfgtest: %s compiler: above macro definition test compiled successfully.\n\n' \ + "$mb_cfgtest_cfgtype" >&3 + + cfgtest_epilog 'macro' '(defined)' + + return 0 +} + + +cfgtest_library_presence() +{ + # init + cfgtest_libs= + cfgtest_spc= + + for cfgtest_lib in ${@}; do + cfgtest_libs="$cfgtest_libs$cfgtest_spc$cfgtest_lib" + cfgtest_spc=' ' + done + + if [ "${1}" = "$cfgtest_libs" ]; then + cfgtest_prolog 'library' "${1#*-l}" + else + cfgtest_prolog 'lib module' '(see config.log)' + fi + + if [ "$mb_cfgtest_environment" = 'freestanding' ]; then + if [ -z "ccenv_cc_underscore" ]; then + cfgtest_code_snippet='int start(void){return 0;}' + else + cfgtest_code_snippet='int _start(void){return 0;}' + fi + else + cfgtest_code_snippet='int main(void){return 0;}' + fi + + cfgtest_common_init 'lib' + + # execute + printf '%s\n' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + || cfgtest_epilog 'library' '-----' "$@" \ + || return 1 + + # result + printf 'cfgtest: `%s'"'"' was accepted by the linker driver.\n' \ + "$cfgtest_libs" >&3 + printf '%s\n' '------------------------' >&3 + + cfgtest_epilog 'library' '(present)' + + return 0 +} + + +cfgtest_package_exists() +{ + # init + cfgtest_pkg= + + for cfgtest_arg in ${@}; do + case "$cfgtest_arg" in + -*) + ;; + + *) + cfgtest_pkg="$cfgtest_arg" + ;; + esac + done + + cfgtest_prolog 'package' "$cfgtest_pkg" + + # execute + "$mb_cfgtest_pkgconf" "${@}" \ + > /dev/null 2>&3 \ + || cfgtest_epilog 'package' '(missing)' "$cfgtest_pkg" \ + || return 1 + + # result + printf 'cfgtest: package `%s'"'"' was found.\n' \ + "$cfgtest_pkg" >&3 + printf '%s\n' '------------------------' >&3 + + cfgtest_epilog 'package' '(exists)' "$cfgtest_pkg" + + return 0 +} + + +cfgtest_package_config() +{ + # init + if ! cfgtest_package_exists "${@}"; then + return 0 + fi + + cfgtest_pkg= + + for cfgtest_arg in ${@}; do + case "$cfgtest_arg" in + -*) + ;; + + *) + cfgtest_pkg="$cfgtest_arg" + ;; + esac + done + + cfgtest_makevar_prefix= + cfgtest_pkgconf_prefix= + + if [ "$mb_cfgtest_cfgtype" = 'native' ]; then + cfgtest_makevar_prefix='_NATIVE' + else + if [ -n "${mb_sysroot}" ]; then + cfgtest_pkgconf_prefix="--define-variable=prefix=${mb_sysroot}" + fi + fi + + cfgtest_newline + cfgtest_comment 'package config:' "$cfgtest_pkg" + + # foo.pc + cfgtest_pkgconf_path=$("$mb_cfgtest_pkgconf" \ + --path "${@}" \ + 2>/dev/null || true) + + if [ -z "$cfgtest_pkgconf_path" ]; then + cfgtest_pkgconf_path=$("$mb_cfgtest_pkgconf" \ + --debug "${@}" 2>&1 \ + | grep ".pc'$" \ + | head -n1 \ + || true) + + cfgtest_pkgconf_path="${cfgtest_pkgconf_path##* \'}" + cfgtest_pkgconf_path="${cfgtest_pkgconf_path%%\'}" + fi + + mb_cfgtest_makevar=$(printf '%s_PKGCONF_%s' \ + "$cfgtest_makevar_prefix" "$cfgtest_pkg" \ + | tr '[[:lower:]]' '[[:upper:]]' \ + | sed -e 's/-/_/g') + + cfgtest_makevar_set "$cfgtest_pkgconf_path" + + # --cflags + cfgtest_pkgconf_path=$("$mb_cfgtest_pkgconf" \ + "$cfgtest_pkgconf_prefix" \ + --cflags "${@}" \ + | sed 's/[ \t]*$//') + + mb_cfgtest_makevar=$(printf '%s_CFLAGS_%s' \ + "$cfgtest_makevar_prefix" "$cfgtest_pkg" \ + | tr '[[:lower:]]' '[[:upper:]]' \ + | sed -e 's/-/_/g') + + cfgtest_makevar_set "$cfgtest_pkgconf_path" + + # --ldflags + cfgtest_pkgconf_path=$("$mb_cfgtest_pkgconf" \ + "$cfgtest_pkgconf_prefix" \ + --libs "${@}" \ + | sed 's/[ \t]*$//') + + mb_cfgtest_makevar=$(printf '%s_LDFLAGS_%s' \ + "$cfgtest_makevar_prefix" "$cfgtest_pkg" \ + | tr '[[:lower:]]' '[[:upper:]]' \ + | sed -e 's/-/_/g') + + cfgtest_makevar_set "$cfgtest_pkgconf_path" + + return 0 +} + + +cfgtest_compiler_switch() +{ + # init + cfgtest_switches= + cfgtest_spc= + + for cfgtest_switch in $(printf '%s' "${@}"); do + cfgtest_switches="$cfgtest_switches$cfgtest_spc$cfgtest_switch" + cfgtest_spc=' ' + done + + if [ -n "${cfgtest_switch_arg:-}" ]; then + cfgtest_prolog 'compiler switch' "${cfgtest_switches%=*}" + + elif [ "${1}" = "$cfgtest_switches" ]; then + cfgtest_prolog 'compiler switch' "$cfgtest_switches" + + else + cfgtest_prolog 'compiler switch combination' "$cfgtest_switches" + fi + + case "${1}" in + -Wl,*) + if [ "$mb_cfgtest_environment" = 'freestanding' ]; then + cfgtest_switches="$cfgtest_switches -nostdlib -nostartfiles" + + if [ -z "ccenv_cc_underscore" ]; then + cfgtest_code_snippet='int start(void){return 0;}' + else + cfgtest_code_snippet='int _start(void){return 0;}' + fi + else + cfgtest_code_snippet='int main(void){return 0;}' + fi + + cfgtest_common_init 'ldflag' + ;; + + *) + cfgtest_code_snippet='int fn(void){return 0;}' + cfgtest_common_init 'switch' + ;; + esac + + # execute + printf '%s\n' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + || cfgtest_epilog 'switch' '(error)' "$@" \ + || return 1 + + # result + printf 'cfgtest: the switch `%s was accepted by the compiler.\n' \ + "$cfgtest_switches'" >&3 + printf '%s\n' '------------------------' >&3 + + cfgtest_epilog 'switch' '(accepted)' + + return 0 +} + + +cfgtest_compiler_switch_arg() +{ + cfgtest_switch_arg='yes' + + if cfgtest_compiler_switch "${@}"; then + cfgtest_ret=0 + else + cfgtest_ret=1 + fi + + unset cfgtest_switch_arg + + return $cfgtest_ret +} + + +cfgtest_unit_header_presence() +{ + cfgtest_internal_unit_test='unit_test' + cfgtest_header_presence "$@" || return 1 + return 0 +} + + +cfgtest_unit_header_absence() +{ + cfgtest_internal_unit_test='unit_test' + cfgtest_header_absence "$@" || return 1 + return 0 +} + + +cfgtest_unit_interface_presence() +{ + cfgtest_internal_unit_test='unit_test' + cfgtest_interface_presence "$@" || return 1 + return 0 +} + + +cfgtest_unit_decl_presence() +{ + cfgtest_internal_unit_test='unit_test' + cfgtest_decl_presence "$@" || return 1 + return 0 +} + + +cfgtest_unit_type_size() +{ + cfgtest_internal_unit_test='unit_test' + cfgtest_type_size "$@" || return 1 + return 0 +} diff --git a/sofort/config/config.vars b/sofort/config/config.vars index 524b746..38d5616 100644 --- a/sofort/config/config.vars +++ b/sofort/config/config.vars @@ -37,6 +37,11 @@ srcball srcball_url srcball_sha256 + +make +makefile +makemode + build host cchost @@ -47,9 +52,14 @@ compiler toolchain zealous sysroot +freestanding cross_compile +config_shell shell +pkgconf +pkgconfig + prefix exec_prefix bindir @@ -120,6 +130,9 @@ native_cfghost native_cflags native_ldflags +native_pkgconf +native_pkgconfig + native_pe_subsystem native_pe_image_base @@ -130,4 +143,9 @@ disable_shared disable_static use_custom_cfgdefs +use_custom_cfginit +use_custom_cfgfini use_custom_usrdefs + +shared_lib_cmd +shared_lib_ldflags diff --git a/sofort/config/opt.vars b/sofort/config/opt.vars new file mode 100644 index 0000000..e71ea56 --- /dev/null +++ b/sofort/config/opt.vars @@ -0,0 +1,9 @@ +version_opt + +shared_library_opt +static_library_opt + +app_frontend_opt +app_linking_opt + +install_headers_opt diff --git a/sofort/core/_flavor/flavor_app_frontend_disabled.mk b/sofort/core/_flavor/flavor_app_frontend_disabled.mk new file mode 100644 index 0000000..31ad23a --- /dev/null +++ b/sofort/core/_flavor/flavor_app_frontend_disabled.mk @@ -0,0 +1,6 @@ +# flavor_app_frontend_disabled.mk: handling of frontend build options. +# this file is covered by COPYING.SOFORT. + +app-tag: +package-install-app: +package-install-extras: diff --git a/sofort/core/_flavor/flavor_app_frontend_enabled.mk b/sofort/core/_flavor/flavor_app_frontend_enabled.mk new file mode 100644 index 0000000..ebbc256 --- /dev/null +++ b/sofort/core/_flavor/flavor_app_frontend_enabled.mk @@ -0,0 +1,6 @@ +# flavor_app_frontend_enabled.mk: handling of frontend build options. +# this file is covered by COPYING.SOFORT. + +app-tag: package-app app.tag +package-install-app: install-app +package-install-extras: install-extras diff --git a/sofort/core/_flavor/flavor_app_linking_all_shared.mk b/sofort/core/_flavor/flavor_app_linking_all_shared.mk new file mode 100644 index 0000000..fe89318 --- /dev/null +++ b/sofort/core/_flavor/flavor_app_linking_all_shared.mk @@ -0,0 +1,7 @@ +# flavor_app_linking_all_shared.mk: handling of frontend linking options. +# this file is covered by COPYING.SOFORT. + +PACKAGE_APP = $(SHARED_APP) + +package-app: shared-app +app.tag: $(SHARED_APP) diff --git a/sofort/core/_flavor/flavor_app_linking_all_static.mk b/sofort/core/_flavor/flavor_app_linking_all_static.mk new file mode 100644 index 0000000..7a5f620 --- /dev/null +++ b/sofort/core/_flavor/flavor_app_linking_all_static.mk @@ -0,0 +1,7 @@ +# flavor_app_linking_all_static.mk: handling of frontend linking options. +# this file is covered by COPYING.SOFORT. + +PACKAGE_APP = $(STATIC_APP) + +package-app: static-app +app.tag: $(STATIC_APP) diff --git a/sofort/core/_flavor/flavor_app_linking_default.mk b/sofort/core/_flavor/flavor_app_linking_default.mk new file mode 100644 index 0000000..b0c1d34 --- /dev/null +++ b/sofort/core/_flavor/flavor_app_linking_default.mk @@ -0,0 +1,7 @@ +# flavor_app_linking_default.mk: handling of frontend linking options. +# this file is covered by COPYING.SOFORT. + +PACKAGE_APP = $(DEFAULT_APP) + +package-app: default-app +app.tag: $(DEFAULT_APP) diff --git a/sofort/core/_flavor/flavor_install_headers_custom.mk b/sofort/core/_flavor/flavor_install_headers_custom.mk new file mode 100644 index 0000000..4f8da97 --- /dev/null +++ b/sofort/core/_flavor/flavor_install_headers_custom.mk @@ -0,0 +1,4 @@ +# flavor_install_headers_custom.mk: handling of header installation option. +# this file is covered by COPYING.SOFORT. + +install-headers:install-headers-custom diff --git a/sofort/core/_flavor/flavor_install_headers_default.mk b/sofort/core/_flavor/flavor_install_headers_default.mk new file mode 100644 index 0000000..f8b49c4 --- /dev/null +++ b/sofort/core/_flavor/flavor_install_headers_default.mk @@ -0,0 +1,4 @@ +# flavor_install_headers_default.mk: handling of header installation option. +# this file is covered by COPYING.SOFORT. + +install-headers:install-headers-default diff --git a/sofort/core/_flavor/flavor_shared_library_disabled.mk b/sofort/core/_flavor/flavor_shared_library_disabled.mk new file mode 100644 index 0000000..9846e1b --- /dev/null +++ b/sofort/core/_flavor/flavor_shared_library_disabled.mk @@ -0,0 +1,5 @@ +# flavor_shared_library_disabled.mk: handling of shared library dependencies. +# this file is covered by COPYING.SOFORT. + +package-shared: +package-install-shared: diff --git a/sofort/core/_flavor/flavor_shared_library_enabled.mk b/sofort/core/_flavor/flavor_shared_library_enabled.mk new file mode 100644 index 0000000..2e54d21 --- /dev/null +++ b/sofort/core/_flavor/flavor_shared_library_enabled.mk @@ -0,0 +1,5 @@ +# flavor_shared_library_enabled.mk: handling of shared library dependencies. +# this file is covered by COPYING.SOFORT. + +package-shared: shared +package-install-shared: install-shared diff --git a/sofort/core/_flavor/flavor_static_library_disabled.mk b/sofort/core/_flavor/flavor_static_library_disabled.mk new file mode 100644 index 0000000..e46d186 --- /dev/null +++ b/sofort/core/_flavor/flavor_static_library_disabled.mk @@ -0,0 +1,5 @@ +# flavor_static_library_disabled.mk: handling of static library dependencies. +# this file is covered by COPYING.SOFORT. + +package-static: +package-install-static: diff --git a/sofort/core/_flavor/flavor_static_library_enabled.mk b/sofort/core/_flavor/flavor_static_library_enabled.mk new file mode 100644 index 0000000..20d4bd8 --- /dev/null +++ b/sofort/core/_flavor/flavor_static_library_enabled.mk @@ -0,0 +1,5 @@ +# flavor_static_library_enabled.mk: handling of static library dependencies. +# this file is covered by COPYING.SOFORT. + +package-static: static +package-install-static: install-static diff --git a/sofort/core/_infer/infer_modern.mk b/sofort/core/_infer/infer_modern.mk new file mode 100644 index 0000000..aaf3361 --- /dev/null +++ b/sofort/core/_infer/infer_modern.mk @@ -0,0 +1,22 @@ +# infer_modern.mk: modern make target- and inference rules. +# this file is covered by COPYING.SOFORT. + +src/%.ao: $(SOURCE_DIR)/src/%.c + $(CC) -c -o $@ $< $(CFLAGS_APP) + +src/%.lo: $(SOURCE_DIR)/src/%.c + $(CC) -c -o $@ $< $(CFLAGS_SHARED) + +src/%.o: $(SOURCE_DIR)/src/%.c + $(CC) -c -o $@ $< $(CFLAGS_STATIC) + +$(SHARED_LIB): + $(SHARED_LIB_CMD) $@ $^ $(SHARED_LIB_LDFLAGS) $(LDFLAGS_IMPLIB) + +lib/%$(OS_ARCHIVE_EXT): + mkdir -p lib + rm -f $@ + $(AR) rcs $@ $^ + +srcs.tag: + touch $@ diff --git a/sofort/core/_infer/infer_posix.mk b/sofort/core/_infer/infer_posix.mk new file mode 100644 index 0000000..ae990e8 --- /dev/null +++ b/sofort/core/_infer/infer_posix.mk @@ -0,0 +1,27 @@ +# infer_posix.mk: posix make target- and inference rules. +# this file is covered by COPYING.SOFORT. + +.c.ao: + $(CC) -c -o $@ $< $(CFLAGS_APP) + +.c.lo: + $(CC) -c -o $@ $< $(CFLAGS_SHARED) + +.c.o: + $(CC) -c -o $@ $< $(CFLAGS_STATIC) + +$(SHARED_LIB): + $(SHARED_LIB_CMD) $@ $(SHARED_OBJS) $(SHARED_LIB_LDFLAGS) $(LDFLAGS_IMPLIB) + +$(STATIC_LIB): + mkdir -p lib + rm -f $@ + $(AR) rcs $@ $(STATIC_OBJS) + +srcs.tag: tree.tag + +srcs.tag: + $(PROJECT_DIR)/sofort/tools/srctree.sh \ + --srctree=$(SOURCE_DIR) -- \ + $(COMMON_SRCS) $(APP_SRCS) + touch $@ diff --git a/sofort/core/_version/_soname/version_soname_copy.mk b/sofort/core/_version/_soname/version_soname_copy.mk new file mode 100644 index 0000000..c176d5a --- /dev/null +++ b/sofort/core/_version/_soname/version_soname_copy.mk @@ -0,0 +1,8 @@ +# version_soname_copy.mk: handling of shared library versioning schemes. +# this file is covered by COPYING.SOFORT. + +install-soname: install-lib + cp $(SHARED_LIB) $(DESTDIR)$(LIBDIR)/$(DSO_SONAME) + +$(SHARED_SONAME): $(SHARED_LIB) + cp $(SHARED_LIB) $(SHARED_SONAME) diff --git a/sofort/core/_version/_soname/version_soname_symlink.mk b/sofort/core/_version/_soname/version_soname_symlink.mk new file mode 100644 index 0000000..963b891 --- /dev/null +++ b/sofort/core/_version/_soname/version_soname_symlink.mk @@ -0,0 +1,12 @@ +# version_soname_symlink.mk: handling of shared library versioning schemes. +# this file is covered by COPYING.SOFORT. + +$(SHARED_SONAME): $(SHARED_LIB) + rm -f $@.tmp + ln -s $(DSO_VER) $@.tmp + mv $@.tmp $@ + +install-soname: install-lib + rm -f $(SHARED_SONAME).tmp + ln -s $(DSO_VER) $(SHARED_SONAME).tmp + mv $(SHARED_SONAME).tmp $(DESTDIR)$(LIBDIR)/$(DSO_SONAME) diff --git a/sofort/core/_version/version_none.mk b/sofort/core/_version/version_none.mk new file mode 100644 index 0000000..d8fc570 --- /dev/null +++ b/sofort/core/_version/version_none.mk @@ -0,0 +1,10 @@ +# version_none.mk: handling of shared library versioning schemes. +# this file is covered by COPYING.SOFORT. + +VER_XYZ = +VER_SONAME = + +package-shared-soname: +package-shared-solink: +package-install-soname: +package-install-solink: diff --git a/sofort/core/_version/version_used.mk b/sofort/core/_version/version_used.mk new file mode 100644 index 0000000..4724cee --- /dev/null +++ b/sofort/core/_version/version_used.mk @@ -0,0 +1,26 @@ +# version_used.mk: handling of shared library versioning schemes. +# this file is covered by COPYING.SOFORT. + +VER_XYZ = .$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) +VER_SONAME = .$(VER_MAJOR) + +package-shared-soname: shared-soname +package-shared-solink: shared-solink +package-install-soname: install-soname +package-install-solink: install-solink + + + +# libfoo.so (common) +install-solink: install-lib + rm -f $(SHARED_SOLINK).tmp + ln -s $(DSO_VER) $(SHARED_SOLINK).tmp + mv $(SHARED_SOLINK).tmp $(DESTDIR)$(LIBDIR)/$(DSO_SOLINK) + +$(SHARED_SOLINK): $(SHARED_LIB) + rm -f $@.tmp + ln -s $(DSO_VER) $@.tmp + mv $@.tmp $@ + +# libfoo.so.x (symlink or copy) +include $(PROJECT_DIR)/sofort/core/_version/_soname/version_soname_$(OS_SONAME).mk diff --git a/sofort/core/defs.mk b/sofort/core/defs.mk index 7e120bc..2622cff 100644 --- a/sofort/core/defs.mk +++ b/sofort/core/defs.mk @@ -9,7 +9,7 @@ ARCH_LOBJS += $(ARCH_SRCS:.c=.lo) ARCH_OBJS += $(ARCH_SRCS:.c=.o) APP_LOBJS += $(APP_SRCS:.c=.lo) -APP_OBJS += $(APP_SRCS:.c=.o) +APP_OBJS += $(APP_SRCS:.c=.ao) SHARED_OBJS += $(COMMON_LOBJS) $(ARCH_LOBJS) STATIC_OBJS += $(COMMON_OBJS) $(ARCH_OBJS) diff --git a/sofort/core/flavor.mk b/sofort/core/flavor.mk index 85c41a2..6a7c97a 100644 --- a/sofort/core/flavor.mk +++ b/sofort/core/flavor.mk @@ -1,73 +1,12 @@ # flavor.mk: top-level handling of build flavors. # this file is covered by COPYING.SOFORT. -ifneq ($(OS_DSO_EXRULES),) include $(PROJECT_DIR)/sofort/exrules/$(OS_DSO_EXRULES).mk -endif -ifeq ($(DISABLE_STATIC),yes) -package-static: -package-install-static: -else -package-static: static -package-install-static: install-static -endif +include $(PROJECT_DIR)/sofort/core/_flavor/flavor_static_library_$(STATIC_LIBRARY_OPT).mk +include $(PROJECT_DIR)/sofort/core/_flavor/flavor_shared_library_$(SHARED_LIBRARY_OPT).mk -ifeq ($(DISABLE_SHARED),yes) -package-shared: -package-install-shared: -else -package-shared: shared -package-install-shared: install-shared -endif +include $(PROJECT_DIR)/sofort/core/_flavor/flavor_app_frontend_$(APP_FRONTEND_OPT).mk +include $(PROJECT_DIR)/sofort/core/_flavor/flavor_app_linking_$(APP_LINKING_OPT).mk - - -ifeq ($(DISABLE_FRONTEND),yes) -app-tag: -package-install-app: -package-install-extras: -else -app-tag: package-app app.tag -package-install-app: install-app -package-install-extras: install-extras -endif - - - -ifeq ($(ALL_STATIC),yes) - -package-app: static-app -app: PACKAGE_APP = $(STATIC_APP) -app-tag: PACKAGE_APP = $(STATIC_APP) -app.tag: $(STATIC_APP) - - -else ifeq ($(ALL_SHARED),yes) - -package-app: shared-app -app: PACKAGE_APP = $(SHARED_APP) -app-tag: PACKAGE_APP = $(SHARED_APP) -app.tag: $(SHARED_APP) - - -else - -package-app: default-app -app: PACKAGE_APP = $(DEFAULT_APP) -app-tag: PACKAGE_APP = $(DEFAULT_APP) -app.tag: $(DEFAULT_APP) - -endif - - - -ifeq ($(CUSTOM_INSTALL_HEADERS),yes) - -install-headers:install-headers-custom - -else - -install-headers:install-headers-default - -endif +include $(PROJECT_DIR)/sofort/core/_flavor/flavor_install_headers_$(INSTALL_HEADERS_OPT).mk diff --git a/sofort/core/infer.mk b/sofort/core/infer.mk new file mode 100644 index 0000000..8a1c6dd --- /dev/null +++ b/sofort/core/infer.mk @@ -0,0 +1,4 @@ +# infer.mk: top-level handling of inference rules. +# this file is covered by COPYING.SOFORT. + +include $(PROJECT_DIR)/sofort/core/_infer/infer_$(MAKEMODE).mk diff --git a/sofort/core/modern.m4 b/sofort/core/modern.m4 new file mode 100644 index 0000000..ad75ca9 --- /dev/null +++ b/sofort/core/modern.m4 @@ -0,0 +1,117 @@ +dnl modern.m4: a modern and simple framework for using the m4 macro language +dnl +dnl This file is covered by COPYING.SOFORT. +dnl +dnl 1) make all standard m4 builtins m4_ prefixed. +dnl 2) set the left-bracket and right-bracket symbols the begin-quote and end-quote strings. +dnl 3) make a single underscore symbol the equivalent of the standard dnl builtin. +dnl 4) provide the m4_toupper(), m4_tolower(), and m4_pathvar() macros. +dnl 5) provide the m4_srclist() and m4_srcitem() macros. +dnl 6) provide the m4_fillerdots(), m4_fillerdash(), and m4_fillerline() macros. +dnl 7) provide the m4_whitespace() and m4_spacealign() macros. +dnl 8) provide the m4_alignlen(), m4_leftalign(), and m4_rightalign() macros. +dnl 9) provide the m4_tab(), m4_tabtab(), and m4_tabtabtab() macros. +dnl +divert(-1) + +define(m4_changecom,defn(`changecom')) +define(m4_changequote,defn(`changequote')) +define(m4_decr,defn(`decr')) +define(m4_define,defn(`define')) +define(m4_defn,defn(`defn')) +define(m4_divert,defn(`divert')) +define(m4_divnum,defn(`divnum')) +define(m4_dnl,defn(`dnl')) +define(m4_dumpdef,defn(`dumpdef')) +define(m4_errprint,defn(`errprint')) +define(m4_eval,defn(`eval')) +define(m4_ifdef,defn(`ifdef')) +define(m4_ifelse,defn(`ifelse')) +define(m4_include,defn(`include')) +define(m4_incr,defn(`incr')) +define(m4_index,defn(`index')) +define(m4_len,defn(`len')) +define(m4_m4exit,defn(`m4exit')) +define(m4_m4wrap,defn(`m4wrap')) +define(m4_maketemp,defn(`maketemp')) +define(m4_mkstemp,defn(`mkstemp')) +define(m4_popdef,defn(`popdef')) +define(m4_pushdef,defn(`pushdef')) +define(m4_shift,defn(`shift')) +define(m4_sinclude,defn(`sinclude')) +define(m4_substr,defn(`substr')) +define(m4_syscmd,defn(`syscmd')) +define(m4_sysval,defn(`sysval')) +define(m4_traceoff,defn(`traceoff')) +define(m4_traceon,defn(`traceon')) +define(m4_translit,defn(`translit')) +define(m4_undefine,defn(`undefine')) +define(m4_undivert,defn(`undivert')) + +m4_changequote([,]) + +m4_undefine([changecom]) +m4_undefine([changequote]) +m4_undefine([decr]) +m4_undefine([define]) +m4_undefine([defn]) +m4_undefine([divert]) +m4_undefine([divnum]) +m4_undefine([dnl]) +m4_undefine([dumpdef]) +m4_undefine([errprint]) +m4_undefine([eval]) +m4_undefine([ifdef]) +m4_undefine([ifelse]) +m4_undefine([include]) +m4_undefine([incr]) +m4_undefine([index]) +m4_undefine([len]) +m4_undefine([m4exit]) +m4_undefine([m4wrap]) +m4_undefine([maketemp]) +m4_undefine([mkstemp]) +m4_undefine([popdef]) +m4_undefine([pushdef]) +m4_undefine([shift]) +m4_undefine([sinclude]) +m4_undefine([substr]) +m4_undefine([syscmd]) +m4_undefine([sysval]) +m4_undefine([traceoff]) +m4_undefine([traceon]) +m4_undefine([translit]) +m4_undefine([undefine]) +m4_undefine([undivert]) + +m4_define([_],m4_defn([m4_dnl])) + +m4_define([m4_toupper],[m4_translit([[$1]],[[abcdefghijklmnopqrstuvwxyz]],[[ABCDEFGHIJKLMNOPQRSTUVWXYZ]])]) +m4_define([m4_tolower],[m4_translit([[$1]],[[ABCDEFGHIJKLMNOPQRSTUVWXYZ]],[[abcdefghijklmnopqrstuvwxyz]])]) +m4_define([m4_pathvar],[m4_translit(m4_toupper([[$1]]),[/-],[__])]) + +m4_define([m4_srclist],[[$1] = \]) +m4_define([m4_srcitem],[m4_tab[$1] \]) + +m4_define([m4_fillerdots],[................................]) +m4_define([m4_fillerdash],[--------------------------------]) +m4_define([m4_fillerline],[m4_fillerdots[]m4_fillerdots[]m4_fillerdots[]]) + +m4_define([m4_whitespace],[m4_translit(m4_fillerdots,[[.]],[[ ]])]) +m4_define([m4_spacealign],[m4_translit(m4_fillerline,[[.]],[[ ]])]) + +m4_define([m4_alignlen],[m4_eval([$1]-m4_len([$2]))]) +m4_define([m4_leftalign],[m4_substr(m4_spacealign,0,m4_alignlen([$1],[$2]))[$2]]) +m4_define([m4_rightalign],[[$2]m4_substr(m4_spacealign,0,m4_alignlen([$1],[$2]))]) + + +m4_define([m4_tab],_ + [$1])) + +m4_define([m4_tabtab],_ + [$1]) + +m4_define([m4_tabtabtab],_ + [$1]) + +m4_divert(0)_ diff --git a/sofort/core/pkgconf.mk b/sofort/core/pkgconf.mk index 0edc395..5ada069 100644 --- a/sofort/core/pkgconf.mk +++ b/sofort/core/pkgconf.mk @@ -1,14 +1,10 @@ # pkgconf.mk: rules for pkgconf manifest generation. # this file is covered by COPYING.SOFORT. -ifeq ($(PKGCONF),no) - -install-pkgconf: - -else - PKGCONF_VERSION = $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) +.pkgconf: + build/$(PACKAGE).pc: .pkgconf dirs.tag build/$(PACKAGE).pc: @@ -41,5 +37,3 @@ install-shared: install-pkgconf install-static: install-pkgconf .PHONY: .pkgconf install-pkgconf - -endif diff --git a/sofort/core/version.mk b/sofort/core/version.mk index eb6c2f2..ad693ab 100644 --- a/sofort/core/version.mk +++ b/sofort/core/version.mk @@ -7,60 +7,4 @@ CFLAGS_VERSION += -D$(VER_NAMESPACE)_TAG_VER_MAJOR=$(VER_MAJOR) CFLAGS_VERSION += -D$(VER_NAMESPACE)_TAG_VER_MINOR=$(VER_MINOR) CFLAGS_VERSION += -D$(VER_NAMESPACE)_TAG_VER_PATCH=$(VER_PATCH) -ifeq ($(AVOID_VERSION),yes) - -VER_XYZ = -VER_SONAME = - -package-shared-soname: -package-shared-solink: -package-install-soname: -package-install-solink: - -else - -VER_XYZ = .$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) -VER_SONAME = .$(VER_MAJOR) - -package-shared-soname: shared-soname -package-shared-solink: shared-solink -package-install-soname: install-soname -package-install-solink: install-solink - - - -# libfoo.so (common) -install-solink: install-lib - rm -f $(SHARED_SOLINK).tmp - ln -s $(DSO_VER) $(SHARED_SOLINK).tmp - mv $(SHARED_SOLINK).tmp $(DESTDIR)$(LIBDIR)/$(DSO_SOLINK) - -$(SHARED_SOLINK): $(SHARED_LIB) - rm -f $@.tmp - ln -s $(DSO_VER) $@.tmp - mv $@.tmp $@ - -# libfoo.so.x (symlink) -ifeq ($(OS_SONAME),symlink) -$(SHARED_SONAME): $(SHARED_LIB) - rm -f $@.tmp - ln -s $(DSO_VER) $@.tmp - mv $@.tmp $@ - -install-soname: install-lib - rm -f $(SHARED_SONAME).tmp - ln -s $(DSO_VER) $(SHARED_SONAME).tmp - mv $(SHARED_SONAME).tmp $(DESTDIR)$(LIBDIR)/$(DSO_SONAME) -endif - - -# libfoo.so.x (copy) -ifeq ($(OS_SONAME),copy) -install-soname: install-lib - cp $(SHARED_LIB) $(DESTDIR)$(LIBDIR)/$(DSO_SONAME) - -$(SHARED_SONAME): $(SHARED_LIB) - cp $(SHARED_LIB) $(SHARED_SONAME) -endif - -endif +include $(PROJECT_DIR)/sofort/core/_version/version_$(VERSION_OPT).mk diff --git a/sofort/exrules/_pe/pe_mdso_version_none.mk b/sofort/exrules/_pe/pe_mdso_version_none.mk new file mode 100644 index 0000000..cf5e350 --- /dev/null +++ b/sofort/exrules/_pe/pe_mdso_version_none.mk @@ -0,0 +1,2 @@ +# pe_mdso_version_none.mk: PE shared library rules for targets using mdso. +# this file is covered by COPYING.SOFORT. diff --git a/sofort/exrules/_pe/pe_mdso_version_used.mk b/sofort/exrules/_pe/pe_mdso_version_used.mk new file mode 100644 index 0000000..fac0246 --- /dev/null +++ b/sofort/exrules/_pe/pe_mdso_version_used.mk @@ -0,0 +1,5 @@ +# pe_mdso_version_used.mk: PE shared library rules for targets using mdso. +# this file is covered by COPYING.SOFORT. + +$(IMPLIB_SONAME): $(IMPLIB_DEF) + $(MDSO) -m $(CC_BITS) -i $(IMPLIB_SONAME) -n $(DSO_SONAME) $(IMPLIB_DEF) diff --git a/sofort/exrules/_pe/pe_version_none.mk b/sofort/exrules/_pe/pe_version_none.mk new file mode 100644 index 0000000..df33976 --- /dev/null +++ b/sofort/exrules/_pe/pe_version_none.mk @@ -0,0 +1,7 @@ +# pe_version_none.mk: handling of PE shared library versioning schemes. +# this file is covered by COPYING.SOFORT. + +package-implib-soname: +package-implib-solink: +package-install-implib-soname: +package-install-implib-solink: diff --git a/sofort/exrules/_pe/pe_version_used.mk b/sofort/exrules/_pe/pe_version_used.mk new file mode 100644 index 0000000..8710dae --- /dev/null +++ b/sofort/exrules/_pe/pe_version_used.mk @@ -0,0 +1,23 @@ +# pe_version_used.mk: handling of PE shared library versioning schemes. +# this file is covered by COPYING.SOFORT. + +package-implib-soname: implib-soname +package-implib-solink: implib-solink +package-install-implib-soname: install-implib-soname +package-install-implib-solink: install-implib-solink + + +$(IMPLIB_SOLINK): $(IMPLIB_SONAME) + rm -f $(IMPLIB_SOLINK).tmp + ln -s $(IMP_SONAME) $(IMPLIB_SOLINK).tmp + mv $(IMPLIB_SOLINK).tmp $(IMPLIB_SOLINK) + +install-implib-soname: implib-soname + mkdir -p $(DESTDIR)$(LIBDIR) + cp $(IMPLIB_SONAME) $(DESTDIR)$(LIBDIR) + +install-implib-solink: implib-soname + mkdir -p $(DESTDIR)$(LIBDIR) + rm -f $(IMPLIB_SOLINK).tmp + ln -s $(IMP_SONAME) $(IMPLIB_SOLINK).tmp + mv $(IMPLIB_SOLINK).tmp $(DESTDIR)$(LIBDIR)/$(IMP_SOLINK) diff --git a/sofort/exrules/default.mk b/sofort/exrules/default.mk index b830cd0..9844f37 100644 --- a/sofort/exrules/default.mk +++ b/sofort/exrules/default.mk @@ -8,4 +8,10 @@ DSO_REF_SOLINK = $(SHARED_SOLINK) LDFLAGS_SHARED += -Wl,-soname LDFLAGS_SHARED += -Wl,$(DSO_SONAME) +implib: + +install-implib: + +clean-implib: + .PHONY: $(IMPLIB_DEF) $(IMPLIB_VER) $(IMPLIB_SONAME) $(IMPLIB_SOLINK) diff --git a/sofort/exrules/pe-mdso.mk b/sofort/exrules/pe-mdso.mk index 9a3b941..0c380e0 100644 --- a/sofort/exrules/pe-mdso.mk +++ b/sofort/exrules/pe-mdso.mk @@ -3,16 +3,9 @@ include $(PROJECT_DIR)/sofort/exrules/pe-common.mk -$(IMPLIB_VER): $(IMPLIB_DEF) - $(MDSO) -m $(CC_BITS) -i $(IMPLIB_VER) -n $(DSO_VER) -l $(DSO_LIBPATH) $< +$(IMPLIB_VER): $(IMPLIB_DEF) + $(MDSO) -m $(CC_BITS) -i $(IMPLIB_VER) -n $(DSO_VER) -l $(DSO_LIBPATH) $(IMPLIB_DEF) -ifeq ($(AVOID_VERSION),yes) - -else - -$(IMPLIB_SONAME): $(IMPLIB_DEF) - $(MDSO) -m $(CC_BITS) -i $(IMPLIB_SONAME) -n $(DSO_SONAME) $(IMPLIB_DEF) - -endif +include $(PROJECT_DIR)/sofort/exrules/_pe/pe_mdso_version_$(VERSION_OPT).mk include $(PROJECT_DIR)/sofort/exrules/pe-version.mk diff --git a/sofort/exrules/pe-version.mk b/sofort/exrules/pe-version.mk index 97ad4ca..7f5b658 100644 --- a/sofort/exrules/pe-version.mk +++ b/sofort/exrules/pe-version.mk @@ -1,34 +1,4 @@ # pe-version.mk: handling of PE shared library versioning schemes. # this file is covered by COPYING.SOFORT. -ifeq ($(AVOID_VERSION),yes) - -package-implib-soname: -package-implib-solink: -package-install-implib-soname: -package-install-implib-solink: - -else - -package-implib-soname: implib-soname -package-implib-solink: implib-solink -package-install-implib-soname: install-implib-soname -package-install-implib-solink: install-implib-solink - - -$(IMPLIB_SOLINK): $(IMPLIB_SONAME) - rm -f $(IMPLIB_SOLINK).tmp - ln -s $(IMP_SONAME) $(IMPLIB_SOLINK).tmp - mv $(IMPLIB_SOLINK).tmp $(IMPLIB_SOLINK) - -install-implib-soname: implib-soname - mkdir -p $(DESTDIR)$(LIBDIR) - cp $(IMPLIB_SONAME) $(DESTDIR)$(LIBDIR) - -install-implib-solink: implib-soname - mkdir -p $(DESTDIR)$(LIBDIR) - rm -f $(IMPLIB_SOLINK).tmp - ln -s $(IMP_SONAME) $(IMPLIB_SOLINK).tmp - mv $(IMPLIB_SOLINK).tmp $(DESTDIR)$(LIBDIR)/$(IMP_SOLINK) - -endif +include $(PROJECT_DIR)/sofort/exrules/_pe/pe_version_$(VERSION_OPT).mk diff --git a/sofort/tools/srctree.sh b/sofort/tools/srctree.sh new file mode 100755 index 0000000..90a1d89 --- /dev/null +++ b/sofort/tools/srctree.sh @@ -0,0 +1,83 @@ +#!/bin/sh + +# srctree.sh: support for out-of-tree builds in posix make mode. +# this file is covered by COPYING.SOFORT. + +set -eu + +usage() +{ +cat << EOF >&2 + +Usage: + --help show this HELP message + --srctree=SRCTREE set source directory + +EOF +exit 1 +} + + +# one +workdir=$(pwd -P) +srctree= +argloop= + + +for arg ; do + case "$arg" in + --help) + usage + ;; + + --srctree=*) + srctree=${arg#*=} + ;; + + --) + argloop='done' + ;; + + *) + if [ -z "$argloop" ]; then + printf 'Invalid option: %s\n' "$arg" >&2 + usage + fi + ;; + esac +done + + +# two +if [ -z "$srctree" ] ; then + usage +fi + +cd -- "$srctree" +srctree=$(pwd -P) +cd -- "$workdir" + +if [ "$srctree" = "$workdir" ]; then + exit 0 +fi + + +# three +for arg ; do + case "$arg" in + --srctree=*) + ;; + + --) + ;; + + *) + stat "$arg" > /dev/null 2>&1 \ + || ln -s -- "$srctree/$arg" "$arg" + ;; + esac +done + + +# all done +exit 0 |