#!/bin/bash # Function: Compile CERNLIBs on CYGWIN. # Last modified by Zhiguo Yao on 15/07/2007 Cmd=$(basename $0) StepNumber=$1 OneStepOnly=$2 case $StepNumber in [0-7]) ;; *) StepNumber="";; esac if [ -z "$StepNumber" ]; then cat << EOF Syntax: $Cmd step_number [ one_step_only ] step_number: 0-7 0: from the very beginning, the build directories is cleaned; 1: from the build of lapack; 2: from the unpacking of CERNLIBs, the patch is applied; 3: from the build of the kuipc, scripts etc; 4: from the build of the libraries; 5: from the test of packlib; 6: from the test of geantlib; 7: from the test of mathlib. one_step_only: yes or no. Optional, default: no yes: run only one step; no: run all the steps from the starting step "step_number". EOF exit 1 fi case "$OneStepOnly" in y|Y|yes|YES|1) OneStepOnly=1;; *) OneStepOnly=0;; esac echo "StepNumber = $StepNumber" echo "OneStepOnly = $OneStepOnly" # Check gmake which gmake >& /dev/null || { echo "Please make a link from /usr/bin/make to /usr/bin/gmake, and run this script again."; exit 1; } # Current directory Cwd=$(pwd) # Current time DATE=$(date +%y%m%d_%H%M%S) LAPACKFILE="" for F in {src,tar,.}/{lapack-3*.tgz,lapack.tgz}; do [ -r $F ] || continue LAPACKFILE=$F done if [ -z "$LAPACKFILE" ]; then echo ">>> No LAPACK file is found!" echo ">>> It is the file named lapack.tgz or lapack-3*.tgz." while true; do echo -e ">>> Please specify it manually: \c" read LAPACKFILE [ -r $F ] || break done fi echo ">>> The LAPACK is $LAPACKFILE." SRCDIR="" for D in ./src ./tar .; do [ -r $D/src_Imakefile.tar.gz ] && { SRCDIR=$D; break; } done if [ -z "$SRCDIR" ]; then echo ">>> No CERNLIB repository directory is found!" echo ">>> It is the directory contains src_Imakefile.tar.gz and" echo ">>> other src_*.tar.gz files." while true; do echo -e ">>> Please specify it manually: \c" read SRCDIR [ -r $SRCDIR/src_Imakefile.tar.gz ] && break done fi echo ">>> The source of CERNLIB is found at $SRCDIR." echo ">>> Set environmental variables: " # Establish the environment variables for the build procedures # Depending on the system, other directories may need to be added to the PATH # e.g. for the build tools and alternative compilers. CERN_LEVEL=$(gunzip -c $SRCDIR/src_Imakefile.tar.gz | tar tf - | awk -F/ '{ print $1 }') CERN=$(pwd)/cern CERN_ROOT=$CERN/$CERN_LEVEL CVSCOSRC=$CERN/$CERN_LEVEL/src PATH=$CERN_ROOT/bin:$PATH export CERN export CERN_LEVEL export CERN_ROOT export CVSCOSRC export PATH echo "CERN = $CERN" echo "CERN_LEVEL = $CERN_LEVEL" echo "CERN_ROOT = \$CERN/\$CERN_LEVEL = $CERN_ROOT" # A function defined here to check the log file for make errors: error_check() { # Syntax: error_check log_file [ info1 info2 ... ] if tail -1 $1 | grep Error >& /dev/null; then shift 1 echo "*** Error at making $*!" exit 1 fi return 0 } if [ $StepNumber -eq 0 ]; then cd $Cwd echo "Cleaning the building directories ..." if [ -d $CERN_ROOT/build ]; then # rebuild the libraries cd $CERN_ROOT/build && find . -type f -name Makefile -exec rm {} \; # clean the whole building from the very beginning fi cd $Cwd rm -rf $CERN_ROOT/{build,bin,lib} [ $OneStepOnly = 1 ] && exit 0 fi if [ $StepNumber -le 1 ]; then cd $Cwd LAPACKUNTARDIR=$(tar -tzf $LAPACKFILE | head -1) OLDVER=0 case $LAPACKUNTARDIR in ./LAPACK|LAPACK) OLDVER=1;; ./lapack-3*|lapack-3*) OLDVER=0;; *) echo "Error, the $LAPACKFILE is not LAPACK file!"; exit 1;; esac echo ">>> Start to make LAPACK ..." Cmd="tar -xzf $LAPACKFILE" echo "$Cmd"; $Cmd if [ $OLDVER = 1 ]; then rm -f ./LAPACK/TIMING/*.in tar -xvzf lapack_cygpatch.tgz cd LAPACK else cd $LAPACKUNTARDIR cp -p make.inc.example make.inc [ -r Makefile.orig ] || mv -f Makefile Makefile.orig sed -e "s,^lib: lapacklib tmglib,#lib: lapacklib tmglib,g" \ -e "s,^#lib: blaslib lapacklib tmglib,lib: blaslib lapacklib tmglib,g" \ Makefile.orig > Makefile fi [ -d $CERN_ROOT/build/log ] || mkdir -p $CERN_ROOT/build/log LOG=$CERN_ROOT/build/log/lapack.$DATE gmake 2>&1 | tee $LOG error_check $LOG lapack in step 1 [ -d $CERN_ROOT/lib ] || mkdir -p $CERN_ROOT/lib cp -pf blas_LINUX.a $CERN/$CERN_LEVEL/lib/libblas.a || exit 1 cp -pf lapack_LINUX.a $CERN/$CERN_LEVEL/lib/liblapack3.a || exit 1 cp -pf tmglib_LINUX.a $CERN/$CERN_LEVEL/lib/libtmglib.a [ $OneStepOnly = 1 ] && exit 0 fi if [ $StepNumber -le 2 ]; then # Unpack the source files cd $Cwd list=$(ls $SRCDIR/src_*.gz) for ffile in $list; do echo ">>> Unpack $ffile ..." gunzip -c $ffile | tar -C $CERN -xf - done # Apply the patches for cygwin: # Clean the uppercase files, which are conflict with he lower case ones. # The cleaning is not always necessary unless 'check_case:strict' is # defined in variable CYGWIN rm -f \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4Fn.F \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4PnX.F \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4RA1.F \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4RA2.F \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4RA4.F \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4RA5.F \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4RD.F \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4RHJ.F \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4RL.F \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4RM.F \ $CERN_ROOT/src/mclibs/pdf/spdf/ctq4RlQ.F # Apply the patches in a tar file CYGPATCH="" for F in {src,tar,.}/cernlib2005_cygpatch.tgz; do [ -r $F ] || continue CYGPATCH=$F done if [ -n "$CYGPATCH" ]; then tar -xvzf $CYGPATCH -C $CERN_ROOT else echo "Error, cannot find file cernlib2005_cygpatch.tgz in src/, tar/ or ./" exit 1 fi # Create the build directory structure cd $CERN_ROOT for D in build bin lib build/log; do [ -d $D ] || mkdir -p $D done # Create the top level Makefile with imake cd $CERN_ROOT/build $CVSCOSRC/config/imake_boot || exit 1 [ $OneStepOnly = 1 ] && exit 0 fi if [ $StepNumber -le 3 ]; then cd $CERN_ROOT/build # Install kuipc and the scripts (cernlib, paw and gxint) in $CERN_ROOT/bin LOG=$CERN_ROOT/build/log/scripts.$DATE gmake bin/kuipc 2>&1 | tee $LOG error_check $LOG bin/kuipc in step 3 cd $CERN_ROOT/build gmake scripts/Makefile 2>&1 | tee -a $LOG error_check $LOG scripts/Makefile in step 3 cd $CERN_ROOT/build/scripts gmake install.bin 2>&1 | tee -a $LOG error_check $LOG install.bin of scripts in step 3 [ $OneStepOnly = 1 ] && exit 0 fi # # Install the libraries # if [ $StepNumber -le 4 ]; then LOG=$CERN_ROOT/build/log/lib.$DATE # First make geant321 using lower optimization level cd $CERN_ROOT/build gmake geant321/Makefile 2>&1 | tee $LOG error_check $LOG geant321/Makefile in step 4 cd $CERN_ROOT/build/geant321 gmake install.lib FDEBUGFLAGS=-O0 2>&1 | tee -a $LOG error_check $LOG install.lib of geant321 in step 4 cd $CERN_ROOT/build gmake 2>&1 | tee -a $LOG error_check $LOG all in step 4 cd $CERN_ROOT/build/packlib gmake install.bin 2>&1 | tee -a $LOG error_check $LOG install.bin of packlib in step 4 cd $CERN_ROOT/build/pawlib gmake install.bin 2>&1 | tee -a $LOG error_check $LOG install.bin of pawlib in step 4 [ $OneStepOnly = 1 ] && exit 0 fi # # Test the installations # if [ $StepNumber -le 5 ]; then cd $CERN_ROOT/build/packlib LOG=$CERN_ROOT/build/log/packlib_test.$DATE gmake test 2>&1 | tee $LOG error_check $LOG test of packlib in step 5 [ $OneStepOnly = 1 ] && exit 0 fi if [ $StepNumber -le 6 ]; then cd $CERN_ROOT/build/geant321 LOG=$CERN_ROOT/build/log/geant_test.$DATE gmake test 2>&1 | tee $LOG error_check $LOG test of geant in step 6 [ $OneStepOnly = 1 ] && exit 0 fi if [ $StepNumber -le 7 ]; then cd $CERN_ROOT/build/mathlib LOG=$CERN_ROOT/build/log/mathlib_test.$DATE gmake test 2>&1 | tee $LOG error_check $LOG test of mathlib in step 7 [ $OneStepOnly = 1 ] && exit 0 fi cat << EOF STEP $StepNumber is done (with OneStepOnly = $OneStepOnly). Note once more: CERN=$CERN CERN_LEVEL=$CERN_LEVEL CERN_ROOT=$CERN_ROOT Please move directory \$CERN ($CERN) to your favorite place, e.g., /cern, and make a link from '$CERN_LEVEL' to 'pro'. Finally don't forget to add the PATH. EOF exit 0