Add support for sub-interpreters
[jimtcl.git] / autosetup / local.tcl
bloba5da8b03843649109b8ae117526cc35a78bb4a9c
1 # The complex extension checking is done here.
3 global withinfo
4 global extdb
6 # Final determination of module status
7 dict set extdb status {}
9 # Returns 1 if the extension has the attribute
10 proc ext-has {ext attr} {
11 expr {$attr in [dict get $::extdb attrs $ext]}
14 # Returns an entry from the extension 'info' table, or $default otherwise
15 proc ext-get {ext key {default {}}} {
16 if {[dict exists $::extdb info $ext $key]} {
17 return [dict get $::extdb info $ext $key]
18 } else {
19 return $default
23 # Set the status of the extension to the given value, and returns the value
24 proc ext-set-status {ext value} {
25 dict set ::extdb status $ext $value
26 return $value
29 # Returns the status of the extension, or ? if unknown
30 proc ext-get-status {ext} {
31 if {[dict exists $::extdb status $ext]} {
32 return [dict get $::extdb status $ext]
34 return ?
37 proc check-extension-status {ext required} {
38 global withinfo
40 set status [ext-get-status $ext]
42 if {$ext in $withinfo(without)} {
43 # Disabled without further ado
44 msg-result "Extension $ext...disabled"
45 return [ext-set-status $ext n]
48 if {$status in {m y n}} {
49 return $status
52 # required is "required" if this extension *must* be enabled
53 # required is "wanted" if it is not fatal for this extension
54 # not to be enabled
56 array set depinfo {m 0 y 0 n 0}
58 # Stash the current value of LIBS
59 set LIBS [get-define LIBS]
61 # Check direct dependencies
62 if [ext-get $ext check 1] {
63 # "check" conditions are met
64 } else {
65 # not met
66 incr depinfo(n)
69 if {$ext in $withinfo(mod)} {
70 # This is a module, so ignore LIBS
71 # LDLIBS_$ext will contain the appropriate libs for this module
72 define LIBS $LIBS
75 if {$depinfo(n) == 0} {
76 # Now extension dependencies
77 foreach i [ext-get $ext dep] {
78 set status [check-extension-status $i $required]
79 #puts "$ext: dep $i $required => $status"
80 incr depinfo($status)
81 if {$depinfo(n)} {
82 break
87 #parray depinfo
89 if {$depinfo(n)} {
90 msg-checking "Extension $ext..."
91 if {$required eq "required"} {
92 user-error "dependencies not met"
94 msg-result "disabled (dependencies)"
95 return [ext-set-status $ext n]
98 # Selected as a module?
99 if {$ext in $withinfo(mod)} {
100 if {[ext-has $ext tcl]} {
101 # Easy, a Tcl module
102 msg-result "Extension $ext...tcl"
103 } elseif {[ext-has $ext static]} {
104 user-error "Extension $ext can't be a module"
105 } else {
106 msg-result "Extension $ext...module"
107 foreach i [ext-get $ext libdep] {
108 define-append LDLIBS_$ext [get-define $i ""]
111 return [ext-set-status $ext m]
114 # Selected as a static extension?
115 if {[ext-has $ext shared]} {
116 user-error "Extension $ext can only be selected as a module"
117 } elseif {$ext in $withinfo(ext) || $required eq "$required"} {
118 msg-result "Extension $ext...enabled"
119 } elseif {$ext in $withinfo(maybe)} {
120 msg-result "Extension $ext...enabled (default)"
121 } else {
122 # Could be selected, but isn't (yet)
123 return [ext-set-status $ext x]
125 foreach i [ext-get $ext libdep] {
126 define-append LDLIBS [get-define $i ""]
128 return [ext-set-status $ext y]
131 # Examines the user options (the $withinfo array)
132 # and the extension database ($extdb) to determine
133 # what is selected, and in what way.
135 # The results are available via ext-get-status
136 # And a dictionary is returned containing four keys:
137 # static-c extensions which are static C
138 # static-tcl extensions which are static Tcl
139 # module-c extensions which are C modules
140 # module-tcl extensions which are Tcl modules
141 proc check-extensions {} {
142 global extdb withinfo
144 # Check valid extension names
145 foreach i [concat $withinfo(ext) $withinfo(mod)] {
146 if {![dict exists $extdb attrs $i]} {
147 user-error "Unknown extension: $i"
151 set extlist [lsort [dict keys [dict get $extdb attrs]]]
153 set withinfo(maybe) {}
155 # Now work out the default status. We have.
156 # normal case, include !optional if possible
157 # --without=default, don't include optional
158 if {$withinfo(nodefault)} {
159 lappend withinfo(maybe) stdlib
160 } else {
161 foreach i $extlist {
162 if {![ext-has $i optional]} {
163 lappend withinfo(maybe) $i
168 foreach i $extlist {
169 define LDLIBS_$i ""
172 foreach i [concat $withinfo(ext) $withinfo(mod)] {
173 check-extension-status $i required
175 foreach i $withinfo(maybe) {
176 check-extension-status $i wanted
179 array set extinfo {static-c {} static-tcl {} module-c {} module-tcl {}}
181 foreach i $extlist {
182 set status [ext-get-status $i]
183 set tcl [ext-has $i tcl]
184 switch $status,$tcl {
185 y,1 {
186 define jim_ext_$i
187 lappend extinfo(static-tcl) $i
189 y,0 {
190 define jim_ext_$i
191 lappend extinfo(static-c) $i
192 # If there are any static C++ extensions, jimsh must be linked using
193 # the C++ compiler
194 if {[ext-has $i cpp]} {
195 define HAVE_CXX_EXTENSIONS
198 m,1 { lappend extinfo(module-tcl) $i }
199 m,0 { lappend extinfo(module-c) $i }
202 return [array get extinfo]