########################################################################
#
# This is a rule file to be run by bras (wsd.iitb.fhg.de/~kir/brashome/).
#
# $Revision: 1.9 $, $Date: 2001/01/21 15:15:15 $
#
#
# USAGE:
# bras tgz
#   make .tar.gz
# bras rpm
#   make rpm from tgz
# bras publish-index 
#   edit index.html and copy it to server
# bras publish
#   make rpm and publish-index and copy rpm, tgz and index.html to server 
#
########################################################################

proc VERSION {= v} {
  global VERSION
  set VERSION $v
}
source .version

## My assorted goodies for tcl have `forfile'
package require agft
namespace import ::agft::forfile


getenv RPMDIR [file join [glob ~] rpm RPMS noarch]
getenv TGZDIR [file join [glob ~] rpm SOURCES]

set TGZ [file join $TGZDIR clig-$VERSION.tar.gz]
set RPM [file join $RPMDIR clig-$VERSION-0.noarch.rpm]


## find the list of all files cvs knows about
set in [open "|cvs -q log -h" r]
set CVSDEPS {}
forfile line $in {
  if {[regexp {^Working file: *(.*)} $line d file]} {
    set f [string trim $file "\t "]
    if {[file exist $f]} {
      lappend CVSDEPS [string trim $file "\t "]
    }
  }
}


Always tgz $TGZ {
  # just a link to make the tgz
}

Always rpm $RPM {
  # just a link to make the rpm
}


Newer $TGZ $CVSDEPS {
  ship -d $TGZDIR -F -e tcl/clig clig.spec tcllib/version.tcl
}

Newer $RPM $TGZ {
  rpm -tb --quiet --target noarch $TGZ
}

Always publish-index {} {
  sed -e "s/|VERSION|/$VERSION/g" <index.html >index.tmp
  scp index.tmp wsd:.public_html/clighome/index.html 2>@stderr
  scp  dir.ttml wsd:.public_html/clighome 2>@stderr
  rm index.tmp
}

Always publish [concat $RPM clig.ps.gz publish-index] {
  tar xzfO $TGZ clig-$VERSION/CHANGES >CHANGES
  scp $RPM $TGZ CHANGES clig.ps.gz example/cmdline.cli \
      wsd:.public_html/clighome 2>@stderr
  rm CHANGES
}


Newer clig.ps.gz [glob man/*.man] {
  sed -e "s/|Version|/$VERSION/g" -e "s/\"0.0.0\"/$VERSION/" $deps \
      | groff -fH -rC1 -tmandoc -Tps \
      | gzip \
      > clig.ps.gz
}

Newer man/clig.man tcl/cmdline.cli {
  ./tcl/clig -t man -m man/clig -mx .man [lindex $deps 0]
}
