Version 10 of Windows batch script for 'compiling' starpacks

Updated 2005-11-01 09:54:58

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 oder kind of .lnk (Link)-files?
  • Documente everything, translate it to the english language, create some examples

    @echo off
 rem csp.bat - Compile StarPack
 rem (C) M.Hoffmann, 2003-2005
 rem 31.10.2005
 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 [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!)
     setlocal
     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)
     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
 :found!
 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 import.Index aus dem Repository
 rem --- (evtl. alternativ nack Links schauen, oder anhand Dummyverzeichnissen kopieren)
     if exist %p%.vfs\lib\import.Done del %p%.vfs\lib\import.Done
     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
           xcopy %r%\%%i %p%.vfs\lib\%%~ni /e /i /h /k /q
           echo %%~ni >>%p%.vfs\lib\import.Done
        )
     )
 rem --- Einkopieren, Ende
     if exist %p%.exe (attrib -r %p%.exe & del %p%.exe)
     %x% wrap %p% -verbose -runtime %t%
     ren %p% %p%.exe & attrib +r %p%.exe
     if exist %p%.bat del %p%.bat
 rem --- Einkopierte Module wieder entfernen
     if exist %p%.vfs\lib\import.Done (
        for /F %%i in (%p%.vfs\lib\import.Done) do (
           rd /s /q %p%.vfs\lib\%%i
        )
        del %p%.vfs\lib\import.Done
     )
 :EOF
     endlocal

Notes

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 22.10.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 (in Arbeit)
 rem (siehe CSP.BAT!!!)
     setlocal
 rem spaeter auch eine Updatemoeglichkeit ermoeglichen (update j/n?)
     if "%1"=="" (echo Fehler: Projektname fehlt! & goto :EOF)
     if exist "%1" if not "%2."=="-new." (echo Ordner "%1" existiert bereits! & goto :EOF) else (rd "%1" /s /q)
     (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...
     for %%i in (bin doc lib tools) do md %%i
 rem nun Standardmodule/Gerueste einkopieren (von WO? Updates?)
      >lib\import.Index echo # Hier die Namen der benoetigten Packages eintragen.
     >>lib\import.Index echo # Diese Dateien werden beim Umwandeln mittels CSP
     >>lib\import.Index echo # aus einem zentralen Repository temporaer einkopiert.
     echo Projekt %1 wurde angelegt!
 :EOF
     endlocal

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 [L1 ]) 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.