Deconstructing CMT setup.sh

From Daya Bay

Jump to: navigation, search

The purpose of this topic is to help me, and anyone else who is interested, to understand what is actually done by a setup.sh file generated by a command such as the following.

 cmt config


Execution of base setup.sh file

The following is an extract of the first section of a typical CMT setup.sh file.

  if test "${CMTROOT}" = ""; then
    CMTROOT=/project/projectdirs/dayabay/gaudi_v19r4_ws/CMT/v1r20p20070208 export  CMTROOT
  fi
  . ${CMTROOT}/mgr/setup.sh

If the CMTROOT environmental variable is not set, then this file sets it, presumably to the value used by the cmt config command used create this file in the first place.

Deconstructing the base setup.sh file

To summarize what this file does is does the following (the rest of this section gives the details):

  • Defines the environmental variables CMTROOT and CMTBIN.
  • Defines a set of ZSH functions if they are supported.
  • Updates your PATH and CLASSPATH variables to this installation.

Setting CMT environmental variables

The following is an extract of the first section of the base setup.sh file (with spurious comments removed for clarity).

 CMTROOT=/project/projectdirs/dayabay/gaudi_v19r4_ws/CMT/v1r20p20070208; export CMTROOT
 
 CMTBIN=`uname`-`uname -m | sed -e 's# ##g'`; export CMTBIN
 
 if test "${CMTCONFIG}" = "" ; then
   CMTCONFIG=`${CMTROOT}/mgr/cmt_system.sh`; export CMTCONFIG
 fi

Thus, the file starts by making sure the CMTROOT environmental variable is set to point to its own installation.

Next is sets the CMTBIN environmental variable to the architecture on which it is running. On PDSF this turns out to be Linux-i686, which on a PPC Macintosh it is Darwin-PowerMacintosh. This variable, along with CMTROOT, is used locate the cmt executable for the current platform.

Finally the CMTCONFIG is set for the current architecture. On PDSF this turns out to be i386_linux24.

ZSH functions

The next section of the base setup.sh file looks like the following.

 eval function b {} 1>/dev/null 2>&1
 if test "$?" = "0"; then
   . ${CMTROOT}/src/setup.zsh
 fi

This checks that the current shell supports Z shell functions, and if so it declares the functions contained in this installations src/setup.zsh file, but as bash does not support this, this issue is not dealt with any further.

Updating your PATH and CLASSPATH variables

After which the following section occurs.

 newpath=""
 for p in `echo ${PATH} | sed 's/:/ /g'`; do
   if test ! "`echo ${p} | egrep CMT`" ; then
     if test "${newpath}" = "" ; then
       newpath=${p}
     else
       newpath=${newpath}:${p}
     fi
   fi
 done
 
 PATH=${newpath}:${CMTROOT}/${CMTBIN}; export PATH
 alias cmt='${CMTROOT}/${CMTBIN}/cmt.exe'; export cmt

This removes any existing instance of CMT from your PATH variable and, whether one existed or not, adds the path to the cmt executable to the end of it. Then it defines an alias for the cmt command.

The final section of the file is as follows.

 newpath=""
 for p in `echo ${CLASSPATH} | sed 's/:/ /g'`; do
   if test ! "`echo ${p} | egrep CMT`" ; then
     if test "${newpath}" = "" ; then
       newpath=${p}
     else
       newpath=${newpath}:${p}
     fi
   fi
 done
 
 CLASSPATH=${newpath}:${CMTROOT}/java/cmt.jar; export CLASSPATH
 
 alias jcmt='(java cmt_parser)'; export jcmt

This does much the same as changing the ,tt>PATH</tt> variable, except this time it is updating java's CLASSPATH variable along with defining the jcmt alias.

Defining all of the package's environmental variables

The rest of the setup.sh file is as follows.

 tempfile=`${CMTROOT}/mgr/cmt -quiet build temporary_name`
 if test ! $? = 0 ; then tempfile=/tmp/cmt.$$; fi
 ${CMTROOT}/mgr/cmt setup -sh -pack=dayabay -version=gaudi_v19r4_ws \
     -path=/project/projectdirs  -no_cleanup $* >${tempfile}; . ${tempfile}
 /bin/rm -f ${tempfile}

The first couple of lines are used to set the tempfile environmental variable to a suitable value. The next line executes the cmt setup command that parses the current requirements for the package a creates the necessary environmental variable definitions and executes them. Finally, the last line cleans up the temporary file.

Personal tools