jim.c: preserve source info on interpolation
[jimtcl.git] / autosetup / local.tcl
blob36aff8684b4dad1f5200dd2efdb8c7415e01a596
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 # Check direct dependencies
59 if [ext-get $ext check 1] {
60 # "check" conditions are met
61 } else {
62 # not met
63 incr depinfo(n)
66 if {$depinfo(n) == 0} {
67 # Now extension dependencies
68 foreach i [ext-get $ext dep] {
69 set status [check-extension-status $i $required]
70 #puts "$ext: dep $i $required => $status"
71 incr depinfo($status)
72 if {$depinfo(n)} {
73 break
78 #parray depinfo
80 if {$depinfo(n)} {
81 msg-checking "Extension $ext..."
82 if {$required eq "required"} {
83 user-error "dependencies not met"
85 msg-result "disabled (dependencies)"
86 return [ext-set-status $ext n]
89 # Selected as a module?
90 if {$ext in $withinfo(mod)} {
91 if {[ext-has $ext tcl]} {
92 # Easy, a Tcl module
93 msg-result "Extension $ext...tcl"
94 } elseif {[ext-has $ext static]} {
95 user-error "Extension $ext can't be a module"
96 } else {
97 msg-result "Extension $ext...module"
98 foreach i [ext-get $ext libdep] {
99 define-append LDLIBS_$ext [get-define $i ""]
102 return [ext-set-status $ext m]
105 # Selected as a static extension?
106 if {[ext-has $ext shared]} {
107 user-error "Extension $ext can only be selected as a module"
108 } elseif {$ext in $withinfo(ext) || $required eq "$required"} {
109 msg-result "Extension $ext...enabled"
110 } elseif {$ext in $withinfo(maybe)} {
111 msg-result "Extension $ext...enabled (default)"
112 } else {
113 # Could be selected, but isn't (yet)
114 return [ext-set-status $ext x]
116 foreach i [ext-get $ext libdep] {
117 define-append LDLIBS [get-define $i ""]
119 return [ext-set-status $ext y]
122 # Examines the user options (the $withinfo array)
123 # and the extension database ($extdb) to determine
124 # what is selected, and in what way.
126 # The results are available via ext-get-status
127 # And a dictionary is returned containing four keys:
128 # static-c extensions which are static C
129 # static-tcl extensions which are static Tcl
130 # module-c extensions which are C modules
131 # module-tcl extensions which are Tcl modules
132 proc check-extensions {} {
133 global extdb withinfo
135 # Check valid extension names
136 foreach i [concat $withinfo(ext) $withinfo(mod)] {
137 if {![dict exists $extdb attrs $i]} {
138 user-error "Unknown extension: $i"
142 set extlist [lsort [dict keys [dict get $extdb attrs]]]
144 set withinfo(maybe) {}
146 # Now work out the default status. We have.
147 # normal case, include !optional if possible
148 # --without=default, don't include optional
149 if {$withinfo(nodefault)} {
150 lappend withinfo(maybe) stdlib
151 } else {
152 foreach i $extlist {
153 if {![ext-has $i optional]} {
154 lappend withinfo(maybe) $i
159 foreach i $extlist {
160 define LDLIBS_$i ""
163 foreach i [concat $withinfo(ext) $withinfo(mod)] {
164 check-extension-status $i required
166 foreach i $withinfo(maybe) {
167 check-extension-status $i wanted
170 array set extinfo {static-c {} static-tcl {} module-c {} module-tcl {}}
172 foreach i $extlist {
173 set status [ext-get-status $i]
174 set tcl [ext-has $i tcl]
175 switch $status,$tcl {
176 y,1 {
177 define jim_ext_$i
178 lappend extinfo(static-tcl) $i
180 y,0 {
181 define jim_ext_$i
182 lappend extinfo(static-c) $i
183 # If there are any static C++ extensions, jimsh must be linked using
184 # the C++ compiler
185 if {[ext-has $i cpp]} {
186 define HAVE_CXX_EXTENSIONS
189 m,1 { lappend extinfo(module-tcl) $i }
190 m,0 { lappend extinfo(module-c) $i }
193 return [array get extinfo]