Updated 2008-11-02 12:32:52 by hae

csp.bat (compile starpack)

The following routine is a work in progress. Things to be done are:

  • I'm not sure where it's best to take the names of the modules to copy in from; up for now I take them out of a /vfs/lib/import.Index-file, but perhaps it's possible to scan the main-script for package require- and source-commands (but not with windows batch language); but currently I think that's too complicated; I want to keep everything simple. Or should one define dummy dirs beneath vfs/lib or kind of .lnk (Link)-files?
  • Documente everything, translate it to the english language, create some examples

Meanwhile, the scripts have grown up and I make heavy use of them in my daily work.... I think they need to be translated to be understandable....
    @echo off
 rem csp.bat - Compile StarPack
 rem (C) M.Hoffmann, 2003-2006
 rem 06.04.2006
 rem v2.0: generische Version (zuvor: individuelle compile.bat`s)
 rem Arg: sh = Textmode-Tclprogramm erzeugen (sonst GUI-Tkprogramm)
 rem Gebrauch:
 rem  im Rootverzeichnis eines mittels CSP oder INITSDX erstellten Projekt-
 rem  Ordners folgendes aufrufen:
 rem  csp [-runtime runtimeprog] [sh]
 rem Spaeter anhand import.Index in /lib etc. unmittelbar vor dem Compilestep die
 rem benoetigten Module einkopieren, anschliessend wieder loeschen (sind ja im VFS!)
 rem 06.04.: -runtime ergänzt
     if not %1.==-runtime. goto next1
     set runtime=%1
     if not %1.==. (if not %1.==sh. (echo falscher Parameter, erlaubt leer oder sh & goto :EOF))
 rem ermitteln lib-Verzeichnis einer Activestate-Installation, wird als Repository-Root angenommen
     for %%i in (tclsh.exe) do set r=%%~dp$PATH:i
     if %r%.==. (echo ActiveStateTcl nicht auffindbar & goto :EOF)
     set r=%r%..\lib
 rem ermitteln Dateispec TCL-Runtime (sh)
     if not %runtime%.==. (set t=%runtime% & goto next2)
     for %%i in (tclkit%1-win32.exe tclkit%1.exe) do if not "%%~$PATH:i"=="" set t=%%~$PATH:i
     if %t%.==. (echo Tclkit[sh]-Runtime nicht auffindbar & goto :EOF)
 rem ermitteln Aufrufverfahren für Starkit-Developer-Extensions (SDX)
     for %%i in (tclkitsh.exe tclkitsh-win32.exe sdx.exe) do if not "%%~$PATH:i"=="" set x=%%~$PATH:i
     if %x%.==. (echo Tclkitsh-Runtime oder sdx.exe nicht auffindbar & goto :EOF)
     if %x:~-7%==sdx.exe goto found!
     for %%i in (sdx.kit) do if not "%%~$PATH:i"=="" (set x=%x% %%~$PATH:i & goto found!)
     echo sdx.kit nicht auffindbar & goto :EOF
     echo Runtime: %t%
     echo Sdx    : %x%
 rem ermitteln Projektname
     for /d %%i in (.\*.vfs) do set p=%%~ni
     if %p%.==. (echo Ordner "./<project>.vfs" fehlt & goto :EOF)
     echo Projekt: %p%
 rem --- Einkopieren benoetigter Module anhand VOM USER angelegter import.Index aus dem Repository
 rem --- (evtl. alternativ nack Links schauen, oder anhand Dummyverzeichnissen kopieren)
     if exist %p%.vfs\lib\import.tcl del %p%.vfs\lib\import.tcl
     if exist %p%.vfs\lib\import.Index for /F %%i in (%p%.vfs\lib\import.Index) do (
	rem nichts überschreiben!
	if not exist %p%.vfs\lib\%%~ni (
	   echo *Import: %%i -^> %%~ni
	   if not exist %r%\%%i (echo Modul '%r%\%%i' fehlt! & goto :EOF)
	   xcopy %r%\%%i %p%.vfs\lib\%%~ni /e /i /h /k /q
	   rem Voraussetzung: Paketname==PackageName!
	echo package require %%~ni >>%p%.vfs\lib\import.tcl
 rem --- Einkopieren benoetigter Module anhand AUS DEM TEMPLATE einkopierter importSys.Index aus dem Repository
 rem --- (evtl. alternativ nack Links schauen, oder anhand Dummyverzeichnissen kopieren)
     if exist %p%.vfs\lib\importSys.tcl del %p%.vfs\lib\importSys.tcl
     if exist %p%.vfs\lib\importSys.Index for /F %%i in (%p%.vfs\lib\importSys.Index) do (
	rem immer überschreiben!
	echo *Import: %%i -^> %%~ni
	if not exist %r%\%%i (echo Modul '%r%\%%i' fehlt! & goto :EOF)
	xcopy %r%\%%i %p%.vfs\lib\%%~ni /e /i /h /k /q /y
	rem Voraussetzung: Paketname==PackageName!
	echo package require %%~ni >>%p%.vfs\lib\importSys.tcl
 rem --- Einkopieren, Ende
     if exist %p%.exe (attrib -r %p%.exe & del %p%.exe)
     rem -verbose entfernt
     %x% wrap %p% -runtime %t%
     ren %p% %p%.exe & attrib +r %p%.exe
     if exist %p%.bat del %p%.bat
 rem --- Bereinigung
     for /D %%i in (%p%.vfs\lib\*.RT_only) do rd /s /q %%i
 rem --- Einkopierte Module wieder entfernen
     if exist %p%.vfs\lib\import.tcl (
	for /F "tokens=3" %%i in (%p%.vfs\lib\import.tcl) do (
	   echo Entferne '%p%.vfs\lib\%%i'
	   rd  /s /q %p%.vfs\lib\%%i
	   md  %p%.vfs\lib\%%i.RT_only
     if exist %p%.vfs\lib\importSys.tcl (
	for /F "tokens=3" %%i in (%p%.vfs\lib\importSys.tcl) do (
	   echo Entferne '%p%.vfs\lib\%%i'
	   rd  /s /q %p%.vfs\lib\%%i
	   md  %p%.vfs\lib\%%i.RT_only


The script makes certain presumptions:

  • common routines are expected to be found beneath the lib-path of an tcl-installation (e.g. ActiveState). To found such an installation, tclsh is searched and its path (usually ...bin) is concatenated with ..\lib (for this to work, the bin path of the TCL-installation must be in the system-search-path). The reason for this that I not only produce standalone starpacks/-kits but also use bare tcl scripts which often require the same modules.
  • one of tclkitsh-win32.exe, tclkitsh.exe, tclkit-win32.exe, tclkit.exe must be found in the system-search-path.
  • one of sdx.kit or sdx.exe (created by me) must be in the system-search-path.
  • when calling csp, the "project"dir had to be the current working directory (pwd) and the projectdir had to contain a project.VFS subdirectory

To use csp, simply call

  • csp to create a starpack for tk-programs (contain the tclkit.exe as a runtime) - or -
  • csp sh to create a starpack for command-line-programs (contain the smaller tclkitsh as a runtime, no Tk available)

To help me generating the neccessary project structure, I'm using a second script which is also subject of changes. I plan to integrate there copying of default-templates and common codeblocks etc. This routine is called isp.bat (init starpack):
    @echo off
 rem isp.bat - Initialize StarPack
 rem (C) M.Hoffmann, 2003-2005
 rem 11.11.2005
 rem v2.0 (zuvor: INITSDX)
 rem Arg: projektname [-new]
 rem Legt im aktuellen Verzeichnis eine Projekt-Ordnerstruktur an und kopiert
 rem  Standard-Module nach dort
 rem (TODO: sauberes Handling von -new; sollte heissen: -update)
 rem (siehe CSP.BAT!!!)
 rem ermitteln lib-Verzeichnis einer Activestate-Installation, wird von CSP für Repository-Root
 rem und von dieser Prozedur für Template-Root verwendet!!!
     for %%i in (tclsh.exe) do set r=%%~dp$PATH:i
     if %r%.==. (echo ActiveStateTcl nicht auffindbar & goto :EOF)
     set r=%r%..\lib\usr\vfs_tpl
     if not exist %r% (echo Templatepfad %r% nicht auffindbar & goto :EOF)
 rem spaeter auch eine Updatemoeglichkeit ermoeglichen (update j/n?)
     if "%1"=="" (echo Fehler: Projektname fehlt! & goto :EOF)
     rem Wegen Updatemöglichkeit  else (rd "%1" /s /q) entfernt:
     if exist "%1" if not "%2."=="-new." (echo Ordner "%1" existiert bereits! & goto :EOF)
     (md %1 & cd %1 & md %1.vfs & cd %1.vfs) || (echo Fehler md/cd "%1(.vfs)" & goto :EOF)
 rem die folgende Ordnerliste noch gemaess Starkit/pack-VFS-Standard anpassen (siehe Doc`s)
 rem keine weiteren Fehlerpruefungen, warum sollte auch nun noch etwas schiefgehen...
 rem (dieser Schritt könnte entfallen, da Verzeichnisse aus dem Template einkopiert werden!)
     for %%i in (bin doc lib) do md %%i
 rem nun Standardmodule/Gerueste einkopieren
 rem (wird zukünftig wohl auch mittels Template einkopiert!)
     rem Momentan immer Template GENERIC verwenden, später über arg wählbar+default
     xcopy %r%\generic\*.* /e /i /h /k /q /r
     rem Update sauber handeln!
     if not exist lib/import.Index (cd.>lib/import.Index)
     echo Projekt %1 wurde angelegt/modifiziert!

These two little scripts are the successors of various older scripts and programs, which I copied over and over again in the various project dirs, not to say that they needed manual modification afterwords.... Now I get tired of repeating this into eternity. Perhaps it would be better to code the scripts itself in TCL, because Windows batch scripts with more than a few lines tend to be nearly unreadable...

This solution has the following main drawback:

  • Up for now, whole directory trees are imported, which are often overfilled with big documentation files and test scripts, which unneccessarily increase the starpack size. To avoid this, manually copy and modify those modules to the VFS/LIB directory. Modules which are already present in the VFS/LIB are NOT imported again (if the name matches exactly!).

RLH I have a batch file (here [1]) that does this on the wiki. It copies everything in and creates the starpack and then deletes everything leaving just the EXE and the original script. This might not be what you are talking about though. MHo: Uff, just had an edit conflict, but thanx to the wiki, nothing's lost! I will look at your routines.

FPX: See also Building Starkits and Starpacks using a Makefile.