From 6bc94edee1076301fd02854c8b3298900896ea49 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Fri, 8 Jul 2011 04:25:39 +1000 Subject: Update to the latest autosetup Mainly for msys/mingw support Signed-off-by: Steve Bennett --- autosetup/cc.tcl | 147 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 116 insertions(+), 31 deletions(-) (limited to 'autosetup/cc.tcl') diff --git a/autosetup/cc.tcl b/autosetup/cc.tcl index 54c4e8f..c95f8dd 100644 --- a/autosetup/cc.tcl +++ b/autosetup/cc.tcl @@ -59,6 +59,13 @@ proc cctest_define {name} { cctest -code "#ifndef $name\n#error not defined\n#endif" } +# Checks for the existence of the given name either as +# a macro (#define) or an rvalue (such as an enum) +# +proc cctest_decl {name} { + cctest -code "#ifndef $name\n(void)$name;\n#endif" +} + # @cc-check-sizeof type ... # # Checks the size of the given types (between 1 and 32, inclusive). @@ -128,6 +135,27 @@ proc cc-check-defines {args} { } } +# @cc-check-decls name ... +# +# Checks that each given name is either a preprocessor symbol or rvalue +# such as an enum. Note that the define used for a decl is HAVE_DECL_xxx +# rather than HAVE_xxx +proc cc-check-decls {args} { + set ret 1 + foreach name $args { + msg-checking "Checking for $name..." + set r [cctest_decl $name] + define-feature "decl $name" $r + if {$r} { + msg-result "ok" + } else { + msg-result "not found" + set ret 0 + } + } + return $ret +} + # @cc-check-functions function ... # # Checks that the given functions exist (can be linked) @@ -149,7 +177,7 @@ proc cc-check-members {args} { # @cc-check-function-in-lib function libs ?otherlibs? # -# Checks that the given given function can be found on one of the libs. +# Checks that the given given function can be found in one of the libs. # # First checks for no library required, then checks each of the libraries # in turn. @@ -158,7 +186,7 @@ proc cc-check-members {args} { # to -l$lib where the function was found, or "" if no library required. # In addition, -l$lib is added to the LIBS define. # -# If additional libraries may be needed to linked, they should be specified +# If additional libraries may be needed for linking, they should be specified # as $extralibs as "-lotherlib1 -lotherlib2". # These libraries are not automatically added to LIBS. # @@ -299,6 +327,22 @@ proc cc-get-settings {} { return $::autosetup(ccsettings) } +# Similar to cc-add-settings, but each given setting +# simply replaces the existing value. +# +# Returns the previous settings +proc cc-update-settings {args} { + set prev [cc-get-settings] + array set new $prev + + foreach {name value} $args { + set new($name) $value + } + cc-store-settings $new + + return $prev +} + # @cc-with settings ?{ script }? # # Sets the given 'cctest' settings and then runs the tests in 'script'. @@ -388,10 +432,17 @@ proc cctest {args} { set lines $opts(-source) } else { foreach i $opts(-includes) { + if {$opts(-code) ne "" && ![feature-checked $i]} { + # Compiling real code with an unchecked header file + # Quickly (and silently) check for it now + + # Remove all -includes from settings before checking + set saveopts [cc-update-settings -includes {}] + msg-quiet cc-check-includes $i + cc-store-settings $saveopts + } if {$opts(-code) eq "" || [have-feature $i]} { lappend source "#include <$i>" - } elseif {![feature-checked $i]} { - user-notice "Warning: using #include <$i> which has not been checked -- ignoring" } } lappend source {*}$opts(-declare) @@ -435,6 +486,7 @@ proc cctest {args} { # complete source to be compiled. Get the result from cache if # we can if {[info exists ::cc_cache($cmdline,$lines)]} { + msg-checking "(cached) " set ok $::cc_cache($cmdline,$lines) if {$::autosetup(debug)} { configlog "From cache (ok=$ok): [join $cmdline]" @@ -448,7 +500,7 @@ proc cctest {args} { writefile $src $lines\n set ok 1 - if {[catch {exec {*}$cmdline 2>@1} result errinfo]} { + if {[catch {exec-with-stderr {*}$cmdline} result errinfo]} { configlog "Failed: [join $cmdline]" configlog $result configlog "============" @@ -471,51 +523,73 @@ proc cctest {args} { return $ok } -# @make-autoconf-h outfile ?auto-patterns=HAVE_*? ?unquoted-patterns=SIZEOF_*? +# @make-autoconf-h outfile ?auto-patterns=HAVE_*? ?bare-patterns=SIZEOF_*? +# +# Deprecated - see make-config-header +proc make-autoconf-h {file {autopatterns {HAVE_*}} {barepatterns {SIZEOF_* HAVE_DECL_*}}} { + user-notice "*** make-autoconf-h is deprecated -- use make-config-header instead" + make-config-header $file -auto $autopatterns -bare $barepatterns +} + +# @make-config-header outfile ?-auto patternlist? ?-bare patternlist? ?-none patternlist? ?-str patternlist? ... # # Examines all defined variables which match the given patterns # and writes an include file, $file, which defines each of these. -# Variables which match 'auto-patterns' are output as follows: +# Variables which match '-auto' are output as follows: # - defines which have the value "0" are ignored. # - defines which have integer values are defined as the integer value. # - any other value is defined as a string, e.g. "value" +# Variables which match '-bare' are defined as-is. +# Variables which match '-str' are defined as a string, e.g. "value" +# Variables which match '-none' are omitted. +# +# Note that order is important. The first pattern which matches is selected +# Default behaviour is: +# +# -bare {SIZEOF_* HAVE_DECL_*} -auto HAVE_* -none * # -# Variables which match 'unquoted-patterns' are defined unquoted. -# # If the file would be unchanged, it is not written. -proc make-autoconf-h {file {autopatterns {HAVE_*}} {unquotedpatterns {SIZEOF_*}}} { +proc make-config-header {file args} { set guard _[string toupper [regsub -all {[^a-zA-Z0-9]} [file tail $file] _]] file mkdir [file dirname $file] set lines {} lappend lines "#ifndef $guard" lappend lines "#define $guard" - # Work out the type of each variable - array set types {} - foreach pattern $autopatterns { - foreach n [array names ::define $pattern] { - set types($n) auto - } - } - foreach pattern $unquotedpatterns { - foreach n [array names ::define $pattern] { - set types($n) unquoted - } - } - foreach n [lsort [array names types]] { - if {$types($n) eq "auto"} { - # Automatically determine the type - if {$::define($n) eq "0"} { - lappend lines "/* #undef $n */" + # Add some defaults + lappend args -bare {SIZEOF_* HAVE_DECL_*} -auto HAVE_* + + foreach n [lsort [dict keys [all-defines]]] { + set value [get-define $n] + set type [calc-define-output-type $n $args] + switch -exact -- $type { + -bare { + # Just output the value unchanged + } + -none { continue } - if {![string is integer -strict $::define($n)]} { - lappend lines "#define $n \"$::define($n)\"" + -str { + set value \"$value\" + } + -auto { + # Automatically determine the type + if {$value eq "0"} { + lappend lines "/* #undef $n */" + continue + } + if {![string is integer -strict $value]} { + set value \"$value\" + } + } + "" { continue } + default { + autosetup-error "Unknown type in make-config-header: $type" + } } - # Unquoted - lappend lines "#define $n $::define($n)" + lappend lines "#define $n $value" } lappend lines "#endif" set buf [join $lines \n] @@ -524,6 +598,17 @@ proc make-autoconf-h {file {autopatterns {HAVE_*}} {unquotedpatterns {SIZEOF_*}} } } +proc calc-define-output-type {name spec} { + foreach {type patterns} $spec { + foreach pattern $patterns { + if {[string match $pattern $name]} { + return $type + } + } + } + return "" +} + # Initialise some values from the environment or commandline or default settings foreach i {LDFLAGS LIBS CPPFLAGS LINKFLAGS {CFLAGS "-g -O2"} {CC_FOR_BUILD cc}} { lassign $i var default -- cgit v1.1