#!/bin/sh  
# \
  exec tclsh "$0" "$@"

set version 1.30
set name OAGTclTk-$version
puts "Building $name RPM"




set tclDir [lindex $auto_path 0]
set rank 0
foreach d $auto_path {
	if {$d == "/usr/share/tcltk"} {
	    if {$rank < 5} {
            set tclDir "/share/tcltk"
            set rank 5
	    }
	}
	if {[string range $d 0 13] == "/usr/lib64/tcl"} {
	    if {$rank < 4} {
            set tclDir "/lib64/tcl"
            set rank 4
	    }
	}
	if {[string range $d 0 11] == "/usr/lib/tcl"} {
	    if {$rank < 3} {
            set tclDir "/lib/tcl"
            set rank 3
	    }
	}
	if {$d == "/usr/lib64"} {
	    if {$rank < 2} {
            set tclDir "/lib64"
            set rank 2
	    }
	}
	if {$d == "/usr/lib"} {
	    if {$rank < 1} {
            set tclDir "/lib"
            set rank 1
	    }
	}
}





exec ./rpmdev-setuptree
exec ../../../../../epics/extensions/bin/linux-x86_64/replaceText OAGTclTk.spec $env(HOME)/rpmbuild/SPECS/OAGTclTk.spec -original=TCLDIR -replacement=$tclDir
exec rm -rf $env(HOME)/rpmbuild/BUILD/$name
exec mkdir $env(HOME)/rpmbuild/BUILD/$name
set binFiles "../../../../../epics/base/bin/linux-x86_64/caRepeater
../oagapp/PVmonitor
../oagapp/apsHelp
../oagapp/apsSDDSEpicsHelp
../oagapp/EditRequestFile
../oagapp/ExperimentDesigner
../oagapp/geneticOptimizer
../oagapp/ImageReviewer
../oagapp/InvRespMatrix
../oagapp/maintainReadback
../oagapp/OAGapps
../oagapp/optimizeInterface
../oagapp/OscillatePVs
../oagapp/quickExperiment
../oagapp/quickMonitor
../oagapp/quickResponseMeasurement
../oagapp/quickSDDSControllaw
../oagapp/quickSDDSDataManip
../oagapp/quickSDDSFeedforward
../oagapp/quickSDDSFit
../oagapp/quickSDDSMath
../oagapp/quickSDDSplot
../oagapp/quickSDDSDSP
../oagapp/quickSDDSStatistics
../oagapp/quickWaveformMonitor
../oagapp/RampPVs
../oagapp/sddsedit
../oagapp/sddsExportData
../oagapp/sddsLoggerCorrelator
../oagapp/sddsplotLineEditor
../oagapp/wishClock
../oagapp/fileSync
../oagapp/tclKnobs
../oagapp/tksddsplot
../oagapp/txt2Tabbed
../../keutils/tkprobe"
foreach f $binFiles {
    exec chmod a+rx $f
    exec chmod a-w $f
    exec cp -f $f $env(HOME)/rpmbuild/BUILD/${name}/
}
set libFiles "[glob ../../../lib/linux-x86_64/*.tcl] ../../../lib/linux-x86_64/tclIndex"
foreach f $libFiles {
    exec chmod a+r $f
    exec chmod a-wx $f
    exec cp -f $f $env(HOME)/rpmbuild/BUILD/${name}/
}
set auFiles [glob ../../../lib/linux-x86_64/*.au]
foreach f $auFiles {
    exec chmod a+r $f
    exec chmod a-wx $f
    exec cp -f $f $env(HOME)/rpmbuild/BUILD/${name}/
}
exec cp -f ../../tcltkinterp/extensions/sdds/pkgIndex.tcl $env(HOME)/rpmbuild/BUILD/${name}/pkgIndex.tcl.sdds
exec cp -f ../../tcltkinterp/extensions/rpn/pkgIndex.tcl $env(HOME)/rpmbuild/BUILD/${name}/pkgIndex.tcl.rpn
exec cp -f ../../tcltkinterp/extensions/ca/pkgIndex.tcl $env(HOME)/rpmbuild/BUILD/${name}/pkgIndex.tcl.ca
exec cp -f ../../tcltkinterp/extensions/os/pkgIndex.tcl $env(HOME)/rpmbuild/BUILD/${name}/pkgIndex.tcl.os
foreach f [glob ../../../lib/linux-x86_64/*.so] {
  exec cp -f $f $env(HOME)/rpmbuild/BUILD/${name}/
}
cd $env(HOME)/rpmbuild/BUILD
exec tar -cvf ../SOURCES/${name}.tar $name
exec rm -f ../SOURCES/${name}.tar.gz
exec gzip -9 ../SOURCES/${name}.tar
cd ../SPECS
if {[catch {exec rpmbuild -bb --quiet --clean --target x86_64 \
              --buildroot $env(HOME)/rpmbuild/BUILDROOT OAGTclTk.spec} results]} {
}
exec rm -f ../SOURCES/${name}.tar.gz
puts $results


puts "New RPM file in ~/rpmbuild/RPMS/x86_64"

