4 # Final determination of module status
5 dict
set extdb status
{}
7 # Returns 1 if the extension has the attribute
8 proc ext-has
{ext attr
} {
9 expr {$attr in
[dict get
$::extdb attrs
$ext]}
12 # Returns an entry from the extension 'info' table, or $default otherwise
13 proc ext-get
{ext key
{default {}}} {
14 if {[dict exists
$::extdb info $ext $key]} {
15 return [dict get
$::extdb info $ext $key]
21 # Set the status of the extension to the given value, and returns the value
22 proc ext-set-status
{ext value
} {
23 dict
set ::extdb status
$ext $value
27 # Returns the status of the extension, or ? if unknown
28 proc ext-get-status
{ext
} {
29 if {[dict exists
$::extdb status
$ext]} {
30 return [dict get
$::extdb status
$ext]
35 proc check-extension-status
{ext required
} {
38 set status
[ext-get-status
$ext]
40 if {$ext in
$withinfo(without
)} {
41 # Disabled without further ado
42 msg-result
"Extension $ext...disabled"
43 return [ext-set-status
$ext n
]
46 if {$status in
{m y n
}} {
50 # required is "required" if this extension *must* be enabled
51 # required is "wanted" if it is not fatal for this extension
54 array set depinfo
{m
0 y
0 n
0}
56 # Stash the current value of LIBS
57 set LIBS
[get-define LIBS
]
60 set pkgconfig
[ext-get
$ext pkg-config
]
61 if {$pkgconfig ne
""} {
62 # pkg-config support is optional, so explicitly initialse it here
63 if {[pkg-config-init
0]} {
64 lassign
$pkgconfig pkg args
66 if {[pkg-config
{*}$pkgconfig]} {
67 # Found via pkg-config so ignore check and libdep
72 if {!$use_pkgconfig} {
73 # Check direct dependencies
74 if [ext-get
$ext check
1] {
75 # "check" conditions are met
82 if {$ext in
$withinfo(mod
)} {
83 # This is a module, so ignore LIBS
84 # LDLIBS_$ext will contain the appropriate libs for this module
88 if {$depinfo(n
) == 0} {
89 # Now extension dependencies
90 foreach i
[ext-get
$ext dep
] {
91 set status
[check-extension-status
$i $required]
92 #puts "$ext: dep $i $required => $status"
103 msg-checking
"Extension $ext..."
104 if {$required eq
"required"} {
105 user-error
"dependencies not met"
107 msg-result
"disabled (dependencies)"
108 return [ext-set-status
$ext n
]
111 # Selected as a module?
112 if {$ext in
$withinfo(mod
)} {
113 if {[ext-has
$ext tcl
]} {
115 msg-result
"Extension $ext...tcl"
116 } elseif
{[ext-has
$ext static
]} {
117 user-error
"Extension $ext can't be a module"
119 msg-result
"Extension $ext...module"
120 if {$use_pkgconfig} {
121 define-append LDLIBS_
$ext [pkg-config-get
$pkg LIBS
]
122 define-append LDFLAGS
[pkg-config-get
$pkg LDFLAGS
]
123 define-append CCOPTS
[pkg-config-get
$pkg CFLAGS
]
125 foreach i
[ext-get
$ext libdep
] {
126 define-append LDLIBS_
$ext [get-define
$i ""]
130 return [ext-set-status
$ext m
]
133 # Selected as a static extension?
134 if {[ext-has
$ext shared
]} {
135 user-error
"Extension $ext can only be selected as a module"
136 } elseif
{$ext in
$withinfo(ext
) ||
$required eq
"$required"} {
137 msg-result
"Extension $ext...enabled"
138 } elseif
{$ext in
$withinfo(maybe
)} {
139 msg-result
"Extension $ext...enabled (default)"
141 # Could be selected, but isn't (yet)
142 return [ext-set-status
$ext x
]
144 if {$use_pkgconfig} {
145 define-append LDLIBS
[pkg-config-get
$pkg LIBS
]
146 define-append LDFLAGS
[pkg-config-get
$pkg LDFLAGS
]
147 define-append CCOPTS
[pkg-config-get
$pkg CFLAGS
]
149 foreach i
[ext-get
$ext libdep
] {
150 define-append LDLIBS
[get-define
$i ""]
153 return [ext-set-status
$ext y
]
156 # Examines the user options (the $withinfo array)
157 # and the extension database ($extdb) to determine
158 # what is selected, and in what way.
160 # The results are available via ext-get-status
161 # And a dictionary is returned containing four keys:
162 # static-c extensions which are static C
163 # static-tcl extensions which are static Tcl
164 # module-c extensions which are C modules
165 # module-tcl extensions which are Tcl modules
166 proc check-extensions
{} {
167 global extdb withinfo
169 # Check valid extension names
170 foreach i
[concat $withinfo(ext
) $withinfo(mod
)] {
171 if {![dict exists
$extdb attrs
$i]} {
172 user-error
"Unknown extension: $i"
176 set extlist
[lsort [dict keys
[dict get
$extdb attrs
]]]
178 set withinfo
(maybe
) {}
180 # Now work out the default status. We have.
181 # normal case, include !optional if possible
182 # --without=default, don't include optional
183 if {$withinfo(nodefault
)} {
184 lappend withinfo
(maybe
) stdlib
187 if {![ext-has
$i optional
]} {
188 lappend withinfo
(maybe
) $i
197 foreach i
[concat $withinfo(ext
) $withinfo(mod
)] {
198 check-extension-status
$i required
200 foreach i
$withinfo(maybe
) {
201 check-extension-status
$i wanted
204 array set extinfo
{static-c
{} static-tcl
{} module-c
{} module-tcl
{}}
207 set status
[ext-get-status
$i]
208 set tcl
[ext-has
$i tcl
]
209 switch $status,$tcl {
212 lappend extinfo
(static-tcl
) $i
216 lappend extinfo
(static-c
) $i
217 # If there are any static C++ extensions, jimsh must be linked using
219 if {[ext-has
$i cpp
]} {
220 define HAVE_CXX_EXTENSIONS
223 m
,1 { lappend extinfo
(module-tcl
) $i }
224 m
,0 { lappend extinfo
(module-c
) $i }
227 return [array get extinfo
]