|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use system |
|
|
|
|
|
options {} |
|
|
|
|
|
|
|
|
|
|
|
proc cctest_function {function} { |
|
|
cctest -link 1 -declare "extern void $function\(void);" -code "$function\();" |
|
|
} |
|
|
|
|
|
|
|
|
proc cctest_type {type} { |
|
|
cctest -code "$type _x;" |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc cctest_member {struct_member} { |
|
|
|
|
|
regexp {^([^.]+)[.](.*)$} $struct_member -> struct member |
|
|
cctest -code "static $struct _s; return sizeof(_s.$member);" |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc cctest_define {name} { |
|
|
cctest -code "#ifndef $name\n#error not defined\n#endif" |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cctest_decl {name} { |
|
|
cctest -code "#ifndef $name\n(void)$name;\n#endif" |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-check-sizeof {args} { |
|
|
foreach type $args { |
|
|
msg-checking "Checking for sizeof $type..." |
|
|
set size unknown |
|
|
|
|
|
foreach i {4 8 1 2 16 32} { |
|
|
if {[cctest -code "static int _x\[sizeof($type) == $i ? 1 : -1\] = { 1 };"]} { |
|
|
set size $i |
|
|
break |
|
|
} |
|
|
} |
|
|
msg-result $size |
|
|
set define [feature-define-name $type SIZEOF_] |
|
|
define $define $size |
|
|
} |
|
|
|
|
|
get-define $define |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-check-some-feature {list script} { |
|
|
set ret 1 |
|
|
foreach each $list { |
|
|
if {![check-feature $each $script]} { |
|
|
set ret 0 |
|
|
} |
|
|
} |
|
|
return $ret |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-check-includes {args} { |
|
|
cc-check-some-feature $args { |
|
|
set with {} |
|
|
if {[dict exists $::autosetup(cc-include-deps) $each]} { |
|
|
set deps [dict keys [dict get $::autosetup(cc-include-deps) $each]] |
|
|
msg-quiet cc-check-includes {*}$deps |
|
|
foreach i $deps { |
|
|
if {[have-feature $i]} { |
|
|
lappend with $i |
|
|
} |
|
|
} |
|
|
} |
|
|
if {[llength $with]} { |
|
|
cc-with [list -includes $with] { |
|
|
cctest -includes $each |
|
|
} |
|
|
} else { |
|
|
cctest -includes $each |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-include-needs {file args} { |
|
|
foreach depfile $args { |
|
|
dict set ::autosetup(cc-include-deps) $file $depfile 1 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-check-types {args} { |
|
|
cc-check-some-feature $args { |
|
|
cctest_type $each |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-check-defines {args} { |
|
|
cc-check-some-feature $args { |
|
|
cctest_define $each |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-check-functions {args} { |
|
|
cc-check-some-feature $args { |
|
|
cctest_function $each |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-check-members {args} { |
|
|
cc-check-some-feature $args { |
|
|
cctest_member $each |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-check-function-in-lib {function libs {otherlibs {}}} { |
|
|
msg-checking "Checking libs for $function..." |
|
|
set found 0 |
|
|
cc-with [list -libs $otherlibs] { |
|
|
if {[cctest_function $function]} { |
|
|
msg-result "none needed" |
|
|
define lib_$function "" |
|
|
incr found |
|
|
} else { |
|
|
foreach lib $libs { |
|
|
cc-with [list -libs -l$lib] { |
|
|
if {[cctest_function $function]} { |
|
|
msg-result -l$lib |
|
|
define lib_$function -l$lib |
|
|
|
|
|
define LIBS "-l$lib [get-define LIBS]" |
|
|
incr found |
|
|
break |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
define-feature $function $found |
|
|
if {!$found} { |
|
|
msg-result "no" |
|
|
} |
|
|
return $found |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-check-tools {args} { |
|
|
foreach tool $args { |
|
|
set TOOL [string toupper $tool] |
|
|
set exe [get-env $TOOL [get-define cross]$tool] |
|
|
if {[find-executable $exe]} { |
|
|
define $TOOL $exe |
|
|
continue |
|
|
} |
|
|
if {[find-executable $tool]} { |
|
|
msg-result "Warning: Failed to find $exe, falling back to $tool which may be incorrect" |
|
|
define $TOOL $tool |
|
|
continue |
|
|
} |
|
|
user-error "Failed to find $exe" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-check-progs {args} { |
|
|
set failed 0 |
|
|
foreach prog $args { |
|
|
set PROG [string toupper $prog] |
|
|
msg-checking "Checking for $prog..." |
|
|
if {![find-executable $prog]} { |
|
|
msg-result no |
|
|
define $PROG false |
|
|
incr failed |
|
|
} else { |
|
|
msg-result ok |
|
|
define $PROG $prog |
|
|
} |
|
|
} |
|
|
expr {!$failed} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-path-progs {args} { |
|
|
set failed 0 |
|
|
foreach prog $args { |
|
|
set PROG [string toupper $prog] |
|
|
msg-checking "Checking for $prog..." |
|
|
set path [find-executable-path $prog] |
|
|
if {$path eq ""} { |
|
|
msg-result no |
|
|
define $PROG false |
|
|
incr failed |
|
|
} else { |
|
|
msg-result $path |
|
|
define $PROG $path |
|
|
} |
|
|
} |
|
|
expr {!$failed} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-add-settings {settings} { |
|
|
if {[llength $settings] % 2} { |
|
|
autosetup-error "settings list is missing a value: $settings" |
|
|
} |
|
|
|
|
|
set prev [cc-get-settings] |
|
|
|
|
|
|
|
|
llength $prev |
|
|
|
|
|
array set new $prev |
|
|
|
|
|
foreach {name value} $settings { |
|
|
switch -exact -- $name { |
|
|
-cflags - -includes { |
|
|
|
|
|
lappend new($name) {*}[list-non-empty $value] |
|
|
} |
|
|
-declare { |
|
|
lappend new($name) $value |
|
|
} |
|
|
-libs { |
|
|
|
|
|
set new($name) [list {*}[list-non-empty $value] {*}$new($name)] |
|
|
} |
|
|
-link - -lang - -nooutput { |
|
|
set new($name) $value |
|
|
} |
|
|
-source - -sourcefile - -code { |
|
|
|
|
|
set new($name) $value |
|
|
} |
|
|
default { |
|
|
autosetup-error "unknown cctest setting: $name" |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
cc-store-settings [array get new] |
|
|
|
|
|
return $prev |
|
|
} |
|
|
|
|
|
proc cc-store-settings {new} { |
|
|
set ::autosetup(ccsettings) $new |
|
|
} |
|
|
|
|
|
proc cc-get-settings {} { |
|
|
return $::autosetup(ccsettings) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-update-settings {args} { |
|
|
set prev [cc-get-settings] |
|
|
cc-store-settings [dict merge $prev $args] |
|
|
return $prev |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cc-with {settings args} { |
|
|
if {[llength $args] == 0} { |
|
|
cc-add-settings $settings |
|
|
} elseif {[llength $args] > 1} { |
|
|
autosetup-error "usage: cc-with settings ?script?" |
|
|
} else { |
|
|
set save [cc-add-settings $settings] |
|
|
set rc [catch {uplevel 1 [lindex $args 0]} result info] |
|
|
cc-store-settings $save |
|
|
if {$rc != 0} { |
|
|
return -code [dict get $info -code] $result |
|
|
} |
|
|
return $result |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc cctest {args} { |
|
|
set tmp conftest__ |
|
|
|
|
|
|
|
|
cc-with $args { |
|
|
array set opts [cc-get-settings] |
|
|
} |
|
|
|
|
|
if {[info exists opts(-sourcefile)]} { |
|
|
set opts(-source) [readfile [get-define srcdir]/$opts(-sourcefile) "#error can't find $opts(-sourcefile)"] |
|
|
} |
|
|
if {[info exists opts(-source)]} { |
|
|
set lines $opts(-source) |
|
|
} else { |
|
|
foreach i $opts(-includes) { |
|
|
if {$opts(-code) ne "" && ![feature-checked $i]} { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>" |
|
|
} |
|
|
} |
|
|
lappend source {*}$opts(-declare) |
|
|
lappend source "int main(void) {" |
|
|
lappend source $opts(-code) |
|
|
lappend source "return 0;" |
|
|
lappend source "}" |
|
|
|
|
|
set lines [join $source \n] |
|
|
} |
|
|
|
|
|
|
|
|
set cmdline {} |
|
|
lappend cmdline {*}[get-define CCACHE] |
|
|
switch -exact -- $opts(-lang) { |
|
|
c++ { |
|
|
set src conftest__.cpp |
|
|
lappend cmdline {*}[get-define CXX] |
|
|
set cflags [get-define CXXFLAGS] |
|
|
} |
|
|
c { |
|
|
set src conftest__.c |
|
|
lappend cmdline {*}[get-define CC] |
|
|
set cflags [get-define CFLAGS] |
|
|
} |
|
|
default { |
|
|
autosetup-error "cctest called with unknown language: $opts(-lang)" |
|
|
} |
|
|
} |
|
|
|
|
|
if {$opts(-link)} { |
|
|
lappend cmdline {*}[get-define LDFLAGS] |
|
|
} else { |
|
|
lappend cflags {*}[get-define CPPFLAGS] |
|
|
set tmp conftest__.o |
|
|
lappend cmdline -c |
|
|
} |
|
|
lappend cmdline {*}$opts(-cflags) {*}[get-define cc-default-debug ""] {*}$cflags |
|
|
lappend cmdline $src -o $tmp |
|
|
if {$opts(-link)} { |
|
|
lappend cmdline {*}$opts(-libs) {*}[get-define LIBS] |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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]" |
|
|
configlog "============" |
|
|
configlog $lines |
|
|
configlog "============" |
|
|
} |
|
|
return $ok |
|
|
} |
|
|
|
|
|
writefile $src $lines\n |
|
|
|
|
|
set ok 1 |
|
|
set err [catch {exec-with-stderr {*}$cmdline} result errinfo] |
|
|
if {$err || ($opts(-nooutput) && [string length $result])} { |
|
|
configlog "Failed: [join $cmdline]" |
|
|
configlog $result |
|
|
configlog "============" |
|
|
configlog "The failed code was:" |
|
|
configlog $lines |
|
|
configlog "============" |
|
|
set ok 0 |
|
|
} elseif {$::autosetup(debug)} { |
|
|
configlog "Compiled OK: [join $cmdline]" |
|
|
configlog "============" |
|
|
configlog $lines |
|
|
configlog "============" |
|
|
} |
|
|
file delete $src |
|
|
file delete $tmp |
|
|
|
|
|
|
|
|
set ::cc_cache($cmdline,$lines) $ok |
|
|
|
|
|
return $ok |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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" |
|
|
|
|
|
|
|
|
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 { |
|
|
|
|
|
} |
|
|
-none { |
|
|
continue |
|
|
} |
|
|
-str { |
|
|
set value \"[string map [list \\ \\\\ \" \\\"] $value]\" |
|
|
} |
|
|
-auto { |
|
|
# Automatically determine the type |
|
|
if {$value eq "0"} { |
|
|
lappend lines "/* #undef $n */" |
|
|
continue |
|
|
} |
|
|
if {![string is integer -strict $value]} { |
|
|
set value \"[string map [list \\ \\\\ \" \\\"] $value]\" |
|
|
} |
|
|
} |
|
|
"" { |
|
|
continue |
|
|
} |
|
|
default { |
|
|
autosetup-error "Unknown type in make-config-header: $type" |
|
|
} |
|
|
} |
|
|
lappend lines "#define $n $value" |
|
|
} |
|
|
lappend lines "#endif" |
|
|
set buf [join $lines \n] |
|
|
write-if-changed $file $buf { |
|
|
msg-result "Created $file" |
|
|
} |
|
|
} |
|
|
|
|
|
proc calc-define-output-type {name spec} { |
|
|
foreach {type patterns} $spec { |
|
|
foreach pattern $patterns { |
|
|
if {[string match $pattern $name]} { |
|
|
return $type |
|
|
} |
|
|
} |
|
|
} |
|
|
return "" |
|
|
} |
|
|
|
|
|
proc cc-init {} { |
|
|
global autosetup |
|
|
|
|
|
# Initialise some values from the environment or commandline or default settings |
|
|
foreach i {LDFLAGS LIBS CPPFLAGS LINKFLAGS CFLAGS} { |
|
|
lassign $i var default |
|
|
define $var [get-env $var $default] |
|
|
} |
|
|
|
|
|
if {[env-is-set CC]} { |
|
|
# Set by the user, so don't try anything else |
|
|
set try [list [get-env CC ""]] |
|
|
} else { |
|
|
# Try some reasonable options |
|
|
set try [list [get-define cross]cc [get-define cross]gcc] |
|
|
} |
|
|
define CC [find-an-executable {*}$try] |
|
|
if {[get-define CC] eq ""} { |
|
|
user-error "Could not find a C compiler. Tried: [join $try ", "]" |
|
|
} |
|
|
|
|
|
define CPP [get-env CPP "[get-define CC] -E"] |
|
|
|
|
|
# XXX: Could avoid looking for a C++ compiler until requested |
|
|
# If CXX isn't found, it is set to the empty string. |
|
|
if {[env-is-set CXX]} { |
|
|
define CXX [find-an-executable -required [get-env CXX ""]] |
|
|
} else { |
|
|
define CXX [find-an-executable [get-define cross]c++ [get-define cross]g++] |
|
|
} |
|
|
|
|
|
# CXXFLAGS default to CFLAGS if not specified |
|
|
define CXXFLAGS [get-env CXXFLAGS [get-define CFLAGS]] |
|
|
|
|
|
# May need a CC_FOR_BUILD, so look for one |
|
|
define CC_FOR_BUILD [find-an-executable [get-env CC_FOR_BUILD ""] cc gcc false] |
|
|
|
|
|
# These start empty and never come from the user or environment |
|
|
define AS_CFLAGS "" |
|
|
define AS_CPPFLAGS "" |
|
|
define AS_CXXFLAGS "" |
|
|
|
|
|
define CCACHE [find-an-executable [get-env CCACHE ccache]] |
|
|
|
|
|
# If any of these are set in the environment, propagate them to the AUTOREMAKE commandline |
|
|
foreach i {CC CXX CCACHE CPP CFLAGS CXXFLAGS CXXFLAGS LDFLAGS LIBS CROSS CPPFLAGS LINKFLAGS CC_FOR_BUILD LD} { |
|
|
if {[env-is-set $i]} { |
|
|
# Note: If the variable is set on the command line, get-env will return that value |
|
|
# so the command line will continue to override the environment |
|
|
define-append-argv AUTOREMAKE $i=[get-env $i ""] |
|
|
} |
|
|
} |
|
|
|
|
|
# Initial cctest settings |
|
|
cc-store-settings {-cflags {} -includes {} -declare {} -link 0 -lang c -libs {} -code {} -nooutput 0} |
|
|
set autosetup(cc-include-deps) {} |
|
|
|
|
|
msg-result "C compiler...[get-define CCACHE] [get-define CC] [get-define CFLAGS] [get-define CPPFLAGS]" |
|
|
if {[get-define CXX] ne "false"} { |
|
|
msg-result "C++ compiler...[get-define CCACHE] [get-define CXX] [get-define CXXFLAGS] [get-define CPPFLAGS]" |
|
|
} |
|
|
msg-result "Build C compiler...[get-define CC_FOR_BUILD]" |
|
|
|
|
|
# On Darwin, we prefer to use -g0 to avoid creating .dSYM directories |
|
|
# but some compilers may not support it, so test here. |
|
|
switch -glob -- [get-define host] { |
|
|
*-*-darwin* { |
|
|
if {[cctest -cflags {-g0}]} { |
|
|
define cc-default-debug -g0 |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if {![cc-check-includes stdlib.h]} { |
|
|
user-error "Compiler does not work. See config.log" |
|
|
} |
|
|
} |
|
|
|
|
|
cc-init |
|
|
|