3
exec tclsh "$0" ${1+"$@"}
4
set me [file normalize [info script]]
5
set packages {icounter}
7
global argv tcl_platform tag
9
if {![llength $argv]} {
10
if {$tcl_platform(platform) eq "windows"} {
21
proc usage {{status 1}} {
23
if {($errorInfo ne {}) &&
24
![string match {invalid command name "_*"*} $errorInfo]
26
puts stderr $::errorInfo
32
foreach c [lsort -dict [info commands _*]] {
33
set c [string range $c 1 end]
37
puts stderr "$prefix$argv0 $c args...\n"
39
puts stderr "$prefix$argv0 $c $res\n"
58
if {[lindex $args 0] eq "-nonewline"} {
60
set args [lrange $args 1 end]
62
if {[llength $args] == 2} {
63
lassign $args chan text
64
if {$chan ni {stdout stderr}} {
65
::_puts {*}[lrange [info level 0] 1 end]
69
set text [lindex $args 0]
72
# chan <=> tag, if not overriden
73
if {[string match {Files left*} $text]} {
77
if {$tag eq {}} { set tag $chan }
80
.t insert end-1c $text $tag
90
catch { file attributes $path -permissions u+x }
93
proc grep {file pattern} {
94
set lines [split [read [set chan [open $file r]]] \n]
96
return [lsearch -all -inline -glob $lines $pattern]
99
set provisions [grep $file {*package provide*}]
101
return [lindex $provisions 0 3]
103
proc Hhelp {} { return "\n\tPrint this help" }
108
proc Hrecipes {} { return "\n\tList all brew commands, without details." }
111
foreach c [info commands _*] {
112
lappend r [string range $c 1 end]
114
puts [lsort -dict $r]
117
proc Hinstall {} { return "?destination?\n\tInstall all packages.\n\tdestination = path of package directory, default \[info library\]." }
118
proc _install {{ldir {}}} {
120
if {[llength [info level 0]] < 2} {
121
set ldir [info library]
122
set idir [file dirname [file dirname $ldir]]/include
124
set idir [file dirname $ldir]/include
127
# Create directories, might not exist.
131
package require critcl::app
133
foreach p $packages {
136
set src [file dirname $::me]/$p.tcl
137
set version [version $src]
139
file delete -force [pwd]/BUILD
140
critcl::app::main [list -cache [pwd]/BUILD -libdir $ldir -includedir $idir -pkg $src]
142
if {![file exists $ldir/$p]} {
143
set ::NOTE {warn {DONE, with FAILURES}}
147
file delete -force $ldir/$p$version
148
file rename $ldir/$p $ldir/$p$version
150
puts -nonewline "Installed package: "
152
puts $ldir/$p$version
156
proc Hdebug {} { return "?destination?\n\tInstall all packages, build for debugging.\n\tdestination = path of package directory, default \[info library\]." }
157
proc _debug {{ldir {}}} {
159
if {[llength [info level 0]] < 2} {
160
set ldir [info library]
161
set idir [file dirname [file dirname $ldir]]/include
163
set idir [file dirname $ldir]/include
166
# Create directories, might not exist.
170
package require critcl::app
172
foreach p $packages {
175
set src [file dirname $::me]/$p.tcl
176
set version [version $src]
178
file delete -force [pwd]/BUILD.$p
179
critcl::app::main [list -keep -debug symbols -cache [pwd]/BUILD.$p -libdir $ldir -includedir $idir -pkg $src]
181
if {![file exists $ldir/$p]} {
182
set ::NOTE {warn {DONE, with FAILURES}}
186
file delete -force $ldir/$p$version
187
file rename $ldir/$p $ldir/$p$version
189
puts -nonewline "Installed package: "
191
puts $ldir/$p$version
195
proc Hgui {} { return "\n\tInstall all packages, and application.\n\tDone from a small GUI." }
199
package require widget::scrolledwindow
201
wm protocol . WM_DELETE_WINDOW ::_exit
203
label .l -text {Install Path: }
204
entry .e -textvariable ::INSTALLPATH
205
button .i -command Install -text Install
207
widget::scrolledwindow .st -borderwidth 1 -relief sunken
211
.t tag configure stdout -font {Helvetica 8}
212
.t tag configure stderr -background red -font {Helvetica 12}
213
.t tag configure ok -background green -font {Helvetica 8}
214
.t tag configure warn -background yellow -font {Helvetica 12}
216
grid .l -row 0 -column 0 -sticky new
217
grid .e -row 0 -column 1 -sticky new
218
grid .i -row 0 -column 2 -sticky new
219
grid .st -row 1 -column 0 -sticky swen -columnspan 2
221
grid rowconfigure . 0 -weight 0
222
grid rowconfigure . 1 -weight 1
224
grid columnconfigure . 0 -weight 0
225
grid columnconfigure . 1 -weight 1
226
grid columnconfigure . 2 -weight 0
228
set INSTALLPATH [info library]
230
# Redirect all output into our log window, and disable uncontrolled exit.
231
rename ::puts ::_puts
233
rename ::exit ::_exit
234
rename ::myexit ::exit
236
# And start to interact with the user.
241
global INSTALLPATH NOTE
242
.i configure -state disabled
246
_install $INSTALLPATH
250
puts [lindex $NOTE 1]
253
.i configure -state normal
254
.i configure -command ::_exit -text Exit -bg green
262
proc Hwrap4tea {} { return "?destination?\n\tGenerate a source package with TEA-based build system wrapped around critcl.\n\tdestination = path of source package directory, default is sub-directory 'tea' of the CWD." }
263
proc _wrap4tea {{dst {}}} {
266
if {[llength [info level 0]] < 2} {
267
set dst [file join [pwd] tea]
272
package require critcl::app
274
foreach p $packages {
275
set src [file dirname $::me]/$p.tcl
276
set version [version $src]
278
file delete -force [pwd]/BUILD
279
critcl::app::main [list -cache [pwd]/BUILD -libdir $dst -tea $src]
280
file delete -force $dst/$p$version
281
file rename $dst/$p $dst/$p$version
283
puts "Wrapped package: $dst/$p$version"