1#!/bin/sh 2# the next line restarts using wish \ 3exec wish8.4 "$0" "$@" 4 5# This utility creates stand-alone executables from Snack Tcl scripts 6 7if {[string equal $tcl_platform(os) "Linux"]} { 8 set platform linux 9} 10if {[string equal $tcl_platform(platform) "windows"]} { 11 set platform windows 12} 13 14if {[info exists argv] == 0} { set argv "" } 15set appname [file rootname [lindex $argv 0]] 16if {$appname == ""} { 17 pack [label .l1 -text "This utility creates\nstand-alone executables"] 18 update 19 set appname [file rootname [lindex [file split \ 20 [tk_getOpenFile -filetypes {{{Tcl scripts} {.tcl}}}]] end]] 21 if {$appname == ""} return 22} 23 24set outdir [pwd] 25 26if {[string equal $platform "linux"]} { 27 set tclkit tclkit-linux-x86 28 set runtime tclkit-linux-x86 29 set shlibext .so 30 set binext "" 31 set target linux 32 set wrapdir /tmp 33} elseif {[string equal $platform "windows"]} { 34# set tclkit tclkit-win32-sh.upx.exe 35 set tclkit tclkit-win32-sh.exe 36 set runtime tclkit-win32.exe 37 set shlibext .dll 38 set binext .exe 39 set target windows 40 if {[info exists ::env(TEMP)] && $::env(TEMP) != ""} { 41 set wrapdir $::env(TEMP) 42 } elseif {[info exists ::env(TMP)] && $::env(TMP) != ""} { 43 set wrapdir $::env(TMP) 44 } else { 45 set wrapdir "" 46 } 47} 48 49set f1 [open $appname.tcl r] 50set f2 [open $wrapdir/$appname.tcl w] 51while {[eof $f1] == 0} { 52 set line [gets $f1] 53 if [string match {package require*snack*} $line] { 54 set doSnack 1 55 puts $f2 "catch {package require Tk}" 56 } 57 if [string match {package require*sound*} $line] { 58 set doSound 1 59 } 60 if [string match {source *} $line] { 61 set f3 [open [lindex [split $line] end] r] 62 puts $f2 [read -nonewline $f3] 63 close $f3 64 continue 65 } 66 puts $f2 $line 67} 68close $f1 69close $f2 70 71if {[string equal $platform "linux"]} { 72 file copy -force $tclkit $wrapdir/tclkit 73 file copy -force sdx $wrapdir/ 74} 75if {[string equal $platform "windows"]} { 76 file copy -force $tclkit $wrapdir/tclkitsh.exe 77 file copy -force sdx.kit $wrapdir/ 78 file copy -force sdx.bat $wrapdir/ 79 file copy -force sdx $wrapdir/ 80} 81 82 83cd $wrapdir 84file delete -force $appname.vfs 85if {[string equal $platform "linux"]} { 86 exec sdx qwrap $appname.tcl 87 exec sdx unwrap $appname.kit 88} else { 89 exec tclsh84 sdx qwrap $appname.tcl 90 exec tclsh84 sdx unwrap $appname.kit 91} 92 93foreach file [lrange $argv 1 end] { 94 set dstfile [file join $appname.vfs/ $file] 95 file copy $outdir/$file $dstfile 96} 97 98 99# Get the Snack package's directory and copy into $appname.vfs/lib/ 100cd $outdir 101package require snack 102set tmp [package ifneeded snack [package provide snack]] 103set tmp [lindex [lindex [split $tmp ";"] 0] end] 104set snackdir [file dirname $tmp] 105set snackdirname [file tail [file dirname $tmp]] 106 107file mkdir $wrapdir/$appname.vfs/lib/ 108file mkdir $wrapdir/$appname.vfs/lib/$snackdirname 109if {[info exists doSnack]} { 110 file copy $snackdir/libsnack$shlibext $wrapdir/$appname.vfs/lib/$snackdirname 111} else { 112 file copy $snackdir/libsound$shlibext $wrapdir/$appname.vfs/lib/$snackdirname 113} 114file copy $snackdir/snack.tcl $wrapdir/$appname.vfs/lib/$snackdirname 115file copy $snackdir/pkgIndex.tcl $wrapdir/$appname.vfs/lib/$snackdirname 116 117 118# Do wrapping 119 120cd $wrapdir 121if {[string equal $platform "linux"]} { 122 exec sdx wrap $appname -runtime $outdir/$runtime 123} else { 124 exec tclsh84 sdx wrap $appname -runtime $outdir/$runtime 125} 126file copy -force $appname $outdir/$appname$binext 127 128exit 129