#! /bin/bash
#*******************************************************************************
# E.S.O. - ALMA project
#
# "@(#) $Id: acsMakeTclLib,v 1.2 2010/09/20 14:25:08 mzampare Exp $" 
#
# who       when        what
# --------  ----------  ----------------------------------------------
# gfilippi  20/05/94    created
# gfilippi  07/09/94    makeXxxx utility renamed into acsMakeXxxx
# gfilippi  01/02/95    itcl_mkindex used to create TCL libraries
# gfilippi  03/02/95    add "lappend" to have the path to find itcl_mkindex
# gfilippi  21/02/95    run the tcl checker on each tcl-file
# gfilippi  04/03/95    make tcl checker customizable
# gfilippi  02/04/96    Tcl4 - use auto_mkindex again to create TCL libraries
# gfilippi  11/04/96    Tcl4 - temporarly use of seqWish instead of tclsh
# gfilippi  16/04/96    Tcl4 - use itclsh to have the correct auto_mkindex
# gfilippi  16/04/96    TMP_FILE name changed into /tmp/acsMakeTclLib_$$.tmp
# eallaert  1999-03-16  remove use of TMP_FILE (suggested long ago!)
# eallaert  2001-05-04  updated for use with Tcl-versions > 8.0
#


#*******************************************************************************
# ALMA - Atacama Large Millimeter Array
# Copyright (c) ESO - European Southern Observatory, 2002
# (in the framework of the ALMA collaboration).
# All rights reserved.
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
#*******************************************************************************

#************************************************************************
#   NAME
#   acsMakeTclLib - create a Tcl/Tk procedure library
# 
#   SYNOPSIS
#
#   acsMakeTclLib <tclChecker> <libName> <objectList> 
# 
#   DESCRIPTION
#   Utility used by acsMakefile to create an library of Tcl/Tk procedures.
#   It is not intended to be used as a standalone command.
#
#   An Tcl/Tk procedure is obtained starting from one or more tcl/tk 
#   script files in the src/ directory, copying them into a separate
#   directory called ../lib/lib<libName>.tcl and generating the 
#   tclIndex by using the auto_mkindex command. The use of auto_mkindex
#   allows ro treat both normal tcl and [incr Tcl] libraries.
#
#   (1) see also Tcl/Tk manual, 13.7 Autoloading, pag.138.
#
#
#   <tclChecker>  the program to be used as syntax checek for tcl files
#
#   <libName>     The name of the library directory. The output is named
#                 ../lib/lib<libName>.tcl
#
#   <objectList>  The list of the script files in the src/ directory.
#                 (Without neither directory nor .a suffix)
#
#   FILES
#   $ACSROOT/include/acsMakefile   
#
#   ENVIRONMENT
#
#   RETURN VALUES
#
#   SEE ALSO 
#   acsMakefile, Makefile, (GNU) make
#
#   BUGS    
#
#----------------------------------------------------------------------

if [ $# -ne 3 ]
then
    echo "" >&2
    echo "acsMakeTclLib <tclChecker> <libName> <objectList>" >&2
    echo "" >&2
    exit 1
fi

#
# set up more readable variables:
tclChecker=$1
libName=$2
objectList=$3

LIBRARY=../lib/lib${libName}.tcl

rm -rf $LIBRARY

mkdir $LIBRARY


for member in ${objectList}
do
    #
    # run the tcl checker on each tcl-file
    $tclChecker ${member}.tcl 1>&2

    #
    # copy it into the library directory
    cp ${member}.tcl $LIBRARY
done

# We need to determine the Tcl-shell to use for the tclIndex generation.
TCL_SHELL=tclsh

echo "package require Itcl; auto_mkindex $LIBRARY *.tcl; exit" | $TCL_SHELL

chmod -R 775 $LIBRARY

echo "           $LIBRARY  created"
#
# ___oOo___
