1 | # setupvfs.tcl -- new tclkit-{cli,gui} generation bootstrap
|
---|
2 | #
|
---|
3 | # jcw, 2006-11-16
|
---|
4 |
|
---|
5 | proc history {args} {} ;# since this runs so early, all debugging support helps
|
---|
6 |
|
---|
7 | if {[lindex $argv 0] ne "-init-"} {
|
---|
8 | puts stderr "setupvfs.tcl has to be run by kit-cli with the '-init-' flag"
|
---|
9 | exit 1
|
---|
10 | }
|
---|
11 |
|
---|
12 | set argv [lrange $argv 2 end] ;# strip off the leading "-init- setupvfs.tcl"
|
---|
13 |
|
---|
14 | set debugOpt 0
|
---|
15 | set encOpt 0
|
---|
16 | set msgsOpt 0
|
---|
17 | set threadOpt 0
|
---|
18 | set tzOpt 0
|
---|
19 |
|
---|
20 | while {1} {
|
---|
21 | switch -- [lindex $argv 0] {
|
---|
22 | -d { incr debugOpt }
|
---|
23 | -e { incr encOpt }
|
---|
24 | -m { incr msgsOpt }
|
---|
25 | -t { incr threadOpt }
|
---|
26 | -z { incr tzOpt }
|
---|
27 | default { break }
|
---|
28 | }
|
---|
29 | set argv [lrange $argv 1 end]
|
---|
30 | }
|
---|
31 |
|
---|
32 | if {[llength $argv] != 2} {
|
---|
33 | puts stderr "Usage: [file tail [info nameofexe]] -init- [info script]\
|
---|
34 | ?-d? ?-e? ?-m? ?-t? ?-z? destfile (cli|gui)
|
---|
35 | -d output some debugging info from this setup script
|
---|
36 | -e include all encodings i.s.o. 7 basic ones (encodings/)
|
---|
37 | -m include all localized message files (tcl 8.5, msgs/)
|
---|
38 | -t include the thread extension as shared lib in vfs
|
---|
39 | -z include timezone data files (tcl 8.5, tzdata/)"
|
---|
40 | exit 1
|
---|
41 | }
|
---|
42 |
|
---|
43 | load {} zlib
|
---|
44 | load {} vfs
|
---|
45 | load {} sqlite3
|
---|
46 | load {} xotcl
|
---|
47 | load {} tdom
|
---|
48 | load {} g2lite
|
---|
49 | load {} usb
|
---|
50 | load {} swt
|
---|
51 | load {} csr
|
---|
52 |
|
---|
53 | # map of proper version numbers to replace @ markers in paths given to vfscopy
|
---|
54 | # this relies on having all necessary extensions already loaded at this point
|
---|
55 | set versmap [list tcl8@ tcl$tcl_version tk8@ tk$tcl_version \
|
---|
56 | zlib1@ zlib[package require zlib] \
|
---|
57 | vfs1@ vfs[package require vfs] \
|
---|
58 | sqlite3@ sqlite[package require sqlite3] \
|
---|
59 | xotcl1@ xotcl[package require XOTcl] \
|
---|
60 | tdom0@ tdom[package require tdom] \
|
---|
61 | g2lite0@ g2lite[package require g2lite] \
|
---|
62 | usb0@ usb[package require usb] \
|
---|
63 | swt0@ swt[package require swt] \
|
---|
64 | csr0@ csr[package require csr]]
|
---|
65 |
|
---|
66 | if {$debugOpt} {
|
---|
67 | puts "Starting [info script]"
|
---|
68 | puts " exe: [info nameofexe]"
|
---|
69 | puts " argv: $argv"
|
---|
70 | puts " tcltk: $tcl_version"
|
---|
71 | puts " loaded: [info loaded]"
|
---|
72 | puts " versmap: $versmap"
|
---|
73 | puts ""
|
---|
74 | }
|
---|
75 |
|
---|
76 | set tcl_library ../tcl/library
|
---|
77 | source ../tcl/library/init.tcl ;# for tcl::CopyDirectory
|
---|
78 |
|
---|
79 | # Create package index files for the static extensions.
|
---|
80 | set exts {swt csr usb g2lite XOTcl zlib}
|
---|
81 | foreach ext $exts {
|
---|
82 | load {} $ext
|
---|
83 | set dst [file join lib "[string tolower $ext][package provide $ext]" pkgIndex.tcl]
|
---|
84 | puts $dst
|
---|
85 | set index($dst) "package ifneeded $ext [package provide $ext] {load {} [string tolower $ext]}"
|
---|
86 | }
|
---|
87 | set index(lib/sqlite[package provide sqlite3]/pkgIndex.tcl) "package ifneeded sqlite3 [package provide sqlite3] {load {} sqlite3}"\
|
---|
88 |
|
---|
89 | set clifiles {
|
---|
90 | boot.tcl
|
---|
91 | main.tcl
|
---|
92 | config.tcl
|
---|
93 | lib/tcl8@/auto.tcl
|
---|
94 | lib/tcl8@/history.tcl
|
---|
95 | lib/tcl8@/init.tcl
|
---|
96 | lib/tcl8@/opt0.4
|
---|
97 | lib/tcl8@/package.tcl
|
---|
98 | lib/tcl8@/parray.tcl
|
---|
99 | lib/tcl8@/safe.tcl
|
---|
100 | lib/tcl8@/tclIndex
|
---|
101 | lib/tcl8@/word.tcl
|
---|
102 | lib/vfs1@/mk4vfs.tcl
|
---|
103 | lib/vfs1@/pkgIndex.tcl
|
---|
104 | lib/vfs1@/starkit.tcl
|
---|
105 | lib/vfs1@/vfslib.tcl
|
---|
106 | lib/vfs1@/vfsUtils.tcl
|
---|
107 | lib/vfs1@/zipvfs.tcl
|
---|
108 | lib/sqlite3@/pkgIndex.tcl
|
---|
109 | lib/xotcl1@/pkgIndex.tcl
|
---|
110 | lib/tdom0@/pkgIndex.tcl
|
---|
111 | lib/tdom0@/tdom.tcl
|
---|
112 | lib/g2lite0@/pkgIndex.tcl
|
---|
113 | lib/usb0@/pkgIndex.tcl
|
---|
114 | lib/swt0@/pkgIndex.tcl
|
---|
115 | lib/csr0@/pkgIndex.tcl
|
---|
116 | lib/zlib1@/pkgIndex.tcl
|
---|
117 | lib/tcllib1.14/pkgIndex.tcl
|
---|
118 | lib/tcllib1.14/asn
|
---|
119 | lib/tcllib1.14/base64
|
---|
120 | lib/tcllib1.14/comm
|
---|
121 | lib/tcllib1.14/cmdline
|
---|
122 | lib/tcllib1.14/fileutil
|
---|
123 | lib/tcllib1.14/ldap
|
---|
124 | lib/tcllib1.14/log
|
---|
125 | lib/tcllib1.14/math
|
---|
126 | lib/tcllib1.14/snit
|
---|
127 | lib/tcllib1.14/uri}
|
---|
128 |
|
---|
129 | set guifiles {
|
---|
130 | tclkit.ico
|
---|
131 | lib/tk8@/bgerror.tcl
|
---|
132 | lib/tk8@/button.tcl
|
---|
133 | lib/tk8@/choosedir.tcl
|
---|
134 | lib/tk8@/clrpick.tcl
|
---|
135 | lib/tk8@/comdlg.tcl
|
---|
136 | lib/tk8@/console.tcl
|
---|
137 | lib/tk8@/dialog.tcl
|
---|
138 | lib/tk8@/entry.tcl
|
---|
139 | lib/tk8@/focus.tcl
|
---|
140 | lib/tk8@/listbox.tcl
|
---|
141 | lib/tk8@/menu.tcl
|
---|
142 | lib/tk8@/mkpsenc.tcl
|
---|
143 | lib/tk8@/msgbox.tcl
|
---|
144 | lib/tk8@/msgs
|
---|
145 | lib/tk8@/obsolete.tcl
|
---|
146 | lib/tk8@/optMenu.tcl
|
---|
147 | lib/tk8@/palette.tcl
|
---|
148 | lib/tk8@/panedwindow.tcl
|
---|
149 | lib/tk8@/pkgIndex.tcl
|
---|
150 | lib/tk8@/safetk.tcl
|
---|
151 | lib/tk8@/scale.tcl
|
---|
152 | lib/tk8@/scrlbar.tcl
|
---|
153 | lib/tk8@/spinbox.tcl
|
---|
154 | lib/tk8@/tclIndex
|
---|
155 | lib/tk8@/tearoff.tcl
|
---|
156 | lib/tk8@/text.tcl
|
---|
157 | lib/tk8@/tk.tcl
|
---|
158 | lib/tk8@/tkfbox.tcl
|
---|
159 | lib/tk8@/unsupported.tcl
|
---|
160 | lib/tk8@/xmfbox.tcl
|
---|
161 | lib/BLT2.4/pkgIndex.tcl
|
---|
162 | lib/BLT2.4/graph.tcl
|
---|
163 | lib/BLT2.4/tabnotebook.tcl
|
---|
164 | lib/BLT2.4/treeview.cur
|
---|
165 | lib/BLT2.4/treeview.xbm
|
---|
166 | lib/BLT2.4/treeview.tcl
|
---|
167 | lib/BLT2.4/treeview_m.xbm
|
---|
168 | lib/BLT2.4/bltCanvEps.pro
|
---|
169 | lib/BLT2.4/bltGraph.pro
|
---|
170 | }
|
---|
171 |
|
---|
172 | if {$encOpt} {
|
---|
173 | lappend clifiles lib/tcl8@/encoding
|
---|
174 | } else {
|
---|
175 | lappend clifiles lib/tcl8@/encoding/ascii.enc \
|
---|
176 | lib/tcl8@/encoding/cp1251.enc \
|
---|
177 | lib/tcl8@/encoding/cp1252.enc \
|
---|
178 | lib/tcl8@/encoding/iso8859-1.enc \
|
---|
179 | lib/tcl8@/encoding/iso8859-2.enc \
|
---|
180 | lib/tcl8@/encoding/iso8859-15.enc \
|
---|
181 | lib/tcl8@/encoding/koi8-r.enc \
|
---|
182 | lib/tcl8@/encoding/macRoman.enc
|
---|
183 | }
|
---|
184 |
|
---|
185 | if {$threadOpt} {
|
---|
186 | lappend clifiles lib/[glob -tails -dir build/lib thread2*]
|
---|
187 | }
|
---|
188 |
|
---|
189 | if {$tcl_version eq "8.4"} {
|
---|
190 | lappend clifiles lib/tcl8@/http2.5 \
|
---|
191 | lib/tcl8@/ldAout.tcl \
|
---|
192 | lib/tcl8@/msgcat1.3 \
|
---|
193 | lib/tcl8@/tcltest2.2
|
---|
194 | } else {
|
---|
195 | lappend clifiles lib/tcl8 \
|
---|
196 | lib/tcl8@/clock.tcl \
|
---|
197 | lib/tcl8@/tm.tcl
|
---|
198 |
|
---|
199 | lappend guifiles lib/tk8@/ttk
|
---|
200 |
|
---|
201 | if {$msgsOpt} {
|
---|
202 | lappend clifiles lib/tcl8@/msgs
|
---|
203 | }
|
---|
204 | if {$tzOpt} {
|
---|
205 | lappend clifiles lib/tcl8@/tzdata
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | # look for a/b/c in three places:
|
---|
210 | # 1) build/files/b-c
|
---|
211 | # 2) build/files/a/b/c
|
---|
212 | # 3) build/a/b/c
|
---|
213 |
|
---|
214 | proc timet_to_dos {time_t} {
|
---|
215 | set s [clock format $time_t -format {%Y %m %e %k %M %S}]
|
---|
216 | scan $s {%d %d %d %d %d %d} year month day hour min sec
|
---|
217 | expr {(($year-1980) << 25) | ($month << 21) | ($day << 16)
|
---|
218 | | ($hour << 11) | ($min << 5) | ($sec >> 1)}
|
---|
219 | }
|
---|
220 |
|
---|
221 | proc walk {path} {
|
---|
222 | set result {}
|
---|
223 | set files [glob -nocomplain -types f -directory $path *]
|
---|
224 | foreach file $files {
|
---|
225 | set excluded 0
|
---|
226 | foreach glob $excludes {
|
---|
227 | if {[string match $glob $file]} {
|
---|
228 | set excluded 1
|
---|
229 | break
|
---|
230 | }
|
---|
231 | }
|
---|
232 | if {!$excluded} {lappend result $file}
|
---|
233 | }
|
---|
234 | foreach dir [glob -nocomplain -types d -directory $path $match] {
|
---|
235 | set subdir [walk $dir $excludes $match]
|
---|
236 | if {[llength $subdir]>0} {
|
---|
237 | set result [concat $result $dir $subdir]
|
---|
238 | }
|
---|
239 | }
|
---|
240 | return $result
|
---|
241 | }
|
---|
242 |
|
---|
243 | proc mkzipfile {zipchan dst {comment {}}} {
|
---|
244 | global index
|
---|
245 |
|
---|
246 | set mtime [timet_to_dos [clock seconds]]
|
---|
247 | set utfpath [encoding convertto utf-8 $dst]
|
---|
248 | set utfcomment [encoding convertto utf-8 $comment]
|
---|
249 | set flags [expr {(1<<10)}] ;# use utf-8
|
---|
250 | set method 0 ;# store 0, deflate 8
|
---|
251 | set attr 0 ;# text or binary (default binary)
|
---|
252 | set extra ""
|
---|
253 | set crc 0
|
---|
254 | set csize 0
|
---|
255 | set version 20
|
---|
256 |
|
---|
257 | if {[info exists index($dst)]} {
|
---|
258 | set data $index($dst)
|
---|
259 | } else {
|
---|
260 | set a [file split $dst]
|
---|
261 | set src build/files/[lindex $a end-1]-[lindex $a end]
|
---|
262 | if {[file exists $src]} {
|
---|
263 | if {$::debugOpt} {
|
---|
264 | puts " $src ==> $dst"
|
---|
265 | }
|
---|
266 | } else {
|
---|
267 | set src build/files/$dst
|
---|
268 | if {[file exists $src]} {
|
---|
269 | if {$::debugOpt} {
|
---|
270 | puts " $src ==> $dst"
|
---|
271 | }
|
---|
272 | } else {
|
---|
273 | set src build/$dst
|
---|
274 | }
|
---|
275 | }
|
---|
276 | if {[file isfile $src]} {
|
---|
277 | set mtime [timet_to_dos [file mtime $src]]
|
---|
278 | set fin [open $src r]
|
---|
279 | fconfigure $fin -translation binary -encoding binary
|
---|
280 | set data [read $fin]
|
---|
281 | close $fin
|
---|
282 | } else {
|
---|
283 | error "cannot find $src"
|
---|
284 | }
|
---|
285 | }
|
---|
286 |
|
---|
287 | set attrex 0x81b60000 ;# 0o100666 (-rw-rw-rw-)
|
---|
288 | if {[file extension $dst] eq ".tcl"} {
|
---|
289 | set attr 1 ;# text
|
---|
290 | }
|
---|
291 |
|
---|
292 | set size [string length $data]
|
---|
293 | set crc [zlib crc32 $data]
|
---|
294 | set cdata [zlib deflate $data]
|
---|
295 | if {[string length $cdata] < $size} {
|
---|
296 | set method 8
|
---|
297 | set data $cdata
|
---|
298 | }
|
---|
299 | set csize [string length $data]
|
---|
300 |
|
---|
301 |
|
---|
302 | set local [binary format a4sssiiiiss PK\03\04 \
|
---|
303 | $version $flags $method $mtime $crc $csize $size \
|
---|
304 | [string length $utfpath] [string length $extra]]
|
---|
305 | append local $utfpath $extra
|
---|
306 |
|
---|
307 | set offset [tell $zipchan]
|
---|
308 | puts -nonewline $zipchan $local
|
---|
309 | puts -nonewline $zipchan $data
|
---|
310 |
|
---|
311 | set hdr [binary format a4ssssiiiisssssii PK\01\02 0x0317 \
|
---|
312 | $version $flags $method $mtime $crc $csize $size \
|
---|
313 | [string length $utfpath] [string length $extra]\
|
---|
314 | [string length $utfcomment] 0 $attr $attrex $offset]
|
---|
315 | append hdr $utfpath $extra $utfcomment
|
---|
316 |
|
---|
317 | return $hdr
|
---|
318 | }
|
---|
319 |
|
---|
320 | # copy file to vfs
|
---|
321 | proc vfscopy {zf argv} {
|
---|
322 | global versmap count cd
|
---|
323 |
|
---|
324 | foreach f $argv {
|
---|
325 | set dst [string map $versmap $f]
|
---|
326 |
|
---|
327 | if {[file isdirectory build/$dst]} {
|
---|
328 | vfscopy $zf [glob -nocomplain -tails -directory build $dst/*]
|
---|
329 | continue
|
---|
330 | }
|
---|
331 |
|
---|
332 | append cd [mkzipfile $zf $dst]
|
---|
333 | incr count
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 | set zf [open [lindex $argv 0] a]
|
---|
338 | fconfigure $zf -translation binary -encoding binary
|
---|
339 |
|
---|
340 | set count 0
|
---|
341 | set cd ""
|
---|
342 |
|
---|
343 | switch [lindex $argv 1] {
|
---|
344 | cli {
|
---|
345 | vfscopy $zf $clifiles
|
---|
346 | }
|
---|
347 | gui {
|
---|
348 | vfscopy $zf $clifiles
|
---|
349 | vfscopy $zf $guifiles
|
---|
350 | }
|
---|
351 | default {
|
---|
352 | puts stderr "Unknown type, must be cli or gui"
|
---|
353 | exit 1
|
---|
354 | }
|
---|
355 | }
|
---|
356 |
|
---|
357 | set cdoffset [tell $zf]
|
---|
358 | set endrec [binary format a4ssssiis PK\05\06 0 0 \
|
---|
359 | $count $count [string length $cd] $cdoffset 0]
|
---|
360 | puts -nonewline $zf $cd
|
---|
361 | puts -nonewline $zf $endrec
|
---|
362 | close $zf
|
---|
363 |
|
---|
364 | if {$debugOpt} {
|
---|
365 | puts "\nDone with [info script]"
|
---|
366 | }
|
---|