Artifact Content

Artifact bfbe220e80adeeb30c6123f20c308b9d99301513a641754908b1ed8e0faa31cb:


#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" ${1+"$@"}

proc install {location} {
    global baseDir

    foreach tm [glob [file join $baseDir *.tm]] {
        set baseName [file tail $tm]
        file copy -force -- $tm [file join $location $baseName]
    }

    return
}

proc build {} {
    global baseDir

    foreach dir [glob -types d [file join $baseDir src *]] {
        set tm [file tail $dir]
        set ifd [open [file join $dir version.txt] r]
        array unset versionInfo
        array set versionInfo [read $ifd]
        close $ifd

        set outputName [file join $baseDir $tm-]
        set version [format {%d.%d} $versionInfo(major) $versionInfo(minor)]
        if {[info exists versionInfo(patch)]} {
            append version "." $versionInfo(patch)
        }
        append outputName $version ".tm"
        set ofd [open $outputName w]
        set inFileList [list \
                            [file join $baseDir copyright.tcl] \
                            [file join $baseDir Dedication.tcl] \
                            [file join $dir $tm.tcl] \
        ]
        puts $ofd "package provide $tm $version"
        puts $ofd {}
        foreach ifn $inFileList {
            set ifd [open $ifn r]
            fcopy $ifd $ofd
            close $ifd
            puts $ofd {}
        }
        close $ofd
    }

    return
}

set baseDir [file dirname [info script]]
lassign $argv function location

switch -exact -- $function {
    build {
        build
    }
    install {
        if {$location eq {}} {
            set pattern "*[info tclversion]*"
            foreach dir [::tcl::tm::path list] {
                if {[string match -nocase $pattern $dir]} {
                    set location $dir
                }
            }
        }
        install $location
    }
}