#!./xotclsh
if {$argc < 1} {
  puts stderr "appendPkgIndex.xotcl: missing lib pkg dir"
  exit
}

set libPkgDir [lindex $argv 0]
set pkgFile $libPkgDir/pkgIndex.tcl

if {[file exists $pkgFile]} {
  set IN [open ./pkgIndex-xotcl.add]
  set r [read $IN]
  close $IN

  #if {[regexp "package ifneeded XOTcl" $r]} {
  #  puts stderr "+++ did not append ./pkgIndex-xotcl.add to $pkgFile -- information seems to be already present"
  #} else {
    set OUT [open $pkgFile a]
    puts -nonewline $OUT $r
    close $OUT
    puts stderr "+++ appended ./pkgIndex-xotcl.add to $pkgFile"
  #}
} else {
  file copy ./pkgIndex-xotcl.add $pkgFile
  puts stderr "+++ copied ./pkgIndex-xotcl.add to $pkgFile"
}
