Salome HOME
Fix another bug with *.la files
[tools/install.git] / config_files / common.sh
index 917e4840b8033b18b658c367f272756d81aabc01..8d9fd0f62d174d24a464fd58ccaf85026524218f 100755 (executable)
@@ -18,7 +18,6 @@
 export DELIM="------"
 export SHRC="salome.sh"
 export CSHRC="salome.csh"
-export DEBUG=1
 
 #this function takes several parameters
 #first parameter contains descriptor of output file
@@ -29,28 +28,32 @@ check_job()
 {
   out=$1
   shift
-  echo -e "`pwd` -> $* >> $out" 
-  if [ $DEBUG == 0 ] ; then
-    $* | tee $out
+  errfile=/tmp/errlog
+  if [ -n "$INSTALL_WORK" ] ; then errfile=$INSTALL_WORK/errlog; fi
+  cmd="`pwd` -> $*"
+  if [ "$out" != "1" ] ; then cmd="$cmd >> $out" ; fi
+  echo -e $cmd
+  if [ "$out" != "1" ] ; then
+      $* >> $out 2>$errfile
   else
-    if [ $out == "1" ] ; then
       $*
-    else
-      $* >> $out 2>&1
-    fi 
   fi
   if [ "$?" -ne "0" ] ; then
     if [ $out != "1" ] ; then
       cat $out
+      cat $errfile >&2
+      cat $errfile >> $out
     fi
-    echo -n " " >&2
-    echo -e "NOT DONE !!! => $*"
-    echo -n "Would you like to continue to install this product: (Y,N) [Y] : "
-    read rep;
-    rep=`echo $rep  | tr "[A-Z]" "[a-z]"`
-    if test -z $rep || [ $rep = "y" ] ; then
-      return 1
-    fi
+    # VSR : 10/11/05: disable answer mode ==>
+    #echo -n " " >&2
+    #echo -e "NOT DONE !!! => $*"
+    #echo -n "Would you like to continue to install this product: (Y,N) [Y] : "
+    #read rep;
+    #rep=`echo $rep  | tr "[A-Z]" "[a-z]"`
+    #if test -z $rep || [ $rep = "y" ] ; then
+    #  return 1
+    #fi
+    # VSR : 10/11/05: disable answer mode <==
     exit 1
   fi
   return 0
@@ -127,7 +130,8 @@ done
 # 1. first dump all environment files into the $SHRC file
 product_sequence="$2"
 for i in $product_sequence ; do
-    cat ${install_work}/env_${i}.sh >> ${install_work}/$SHRC 2>/dev/null
+    env_file=${install_work}/env_${i}.sh
+    ( test -e $env_file && cat $env_file >> ${install_work}/$SHRC 2>/dev/null )
 done
 
 # 2. writing global functions to _salome.sh file
@@ -299,10 +303,11 @@ if [ $# -eq 4 ] ; then
        cp -f ${install_work}/_$CSHRC ${product_dir}/$CSHRC
     fi
 fi
-sed -e 's%setenv ENV_FOR_LAUNCH 1%setenv ENV_FOR_LAUNCH 0%' ${install_work}/_$CSHRC > ${install_root}/env_products.csh
-sed -e 's%export ENV_FOR_LAUNCH=1%export ENV_FOR_LAUNCH=0%' ${install_work}/_$SHRC  > ${install_root}/env_products.sh
-rm -f ${install_work}/_$SHRC
-rm -f ${install_work}/_$CSHRC
+sed -e 's%setenv ENV_FOR_LAUNCH 1%setenv ENV_FOR_LAUNCH 0%' ${install_work}/_$CSHRC > ${install_root}/env_build.csh
+sed -e 's%export ENV_FOR_LAUNCH=1%export ENV_FOR_LAUNCH=0%' ${install_work}/_$SHRC  > ${install_root}/env_build.sh
+cp -f ${install_work}/_$CSHRC ${install_root}/env_products.csh
+cp -f ${install_work}/_$SHRC  ${install_root}/env_products.sh
+rm -f ${install_work}/_$SHRC ${install_work}/_$CSHRC
 ### !!! copying build.csh script
 if [ -e ./build.csh ]; then
     cp -f ./build.csh ${install_root}
@@ -325,6 +330,9 @@ if [ -f ${env_file} ] ; then
            print_env
            return 0    
        fi
+    else
+       rm -f ${install_work}/env_${product_type}.sh
+       make_env ${install_root} ${install_work} "${product_sequence}"
     fi
 fi
 return 1;
@@ -355,7 +363,7 @@ find_in_path(){
 file=$1;  shift; 
 path=$*
 for i in `echo ${path} | sed -e"s%:% %g"` ; do 
-    ret=`find $i -name $file 2>/dev/null`
+    ret=`find $i -name $file -maxdepth 1 2>/dev/null`
     if [ -n "$ret" ] ; then
        ret=`echo $ret | sed -e"s%/\$file$%%g"`
        echo $ret
@@ -386,4 +394,217 @@ else
     echo $arg1:$arg2
 fi
 return $to_tail
-}
\ No newline at end of file
+}
+
+where_gcc(){
+maj_ver=`echo $1 | awk -F. '{if(NF>0) print $1; else print 0}'`
+min_ver=`echo $1 | awk -F. '{if(NF>1) print $2; else print 0}'`
+rel_ver=`echo $1 | awk -F. '{if(NF>2) print $3; else print 0}'`
+let ver=$maj_ver*10000+$min_ver*100+$rel_ver
+newer=""
+newerver=0
+for i in `echo ${PATH}:/usr/bin:/usr/local/bin | sed -e"s%:% %g"` ; do 
+    ret=`find $i -name gcc -maxdepth 1 2>/dev/null`
+    if [ -n "$ret" ] ; then
+       maj_ver=`$ret -dumpversion | awk -F. '{if(NF>0) print $1; else print 0}'`
+       min_ver=`$ret -dumpversion | awk -F. '{if(NF>1) print $2; else print 0}'`
+       rel_ver=`$ret -dumpversion | awk -F. '{if(NF>2) print $3; else print 0}'`
+       let ver1=$maj_ver*10000+$min_ver*100+$rel_ver
+       if [ $ver1 -eq $ver ] ; then
+           ret=`echo $ret | sed -e"s%/gcc$%%g"`
+           echo $ret
+           return 0
+       fi
+       if [ $ver1 -gt $ver ] && [ $ver1 -gt $newerver ] ; then
+           let newerver=$ver1
+           newer=`echo $ret | sed -e"s%/gcc$%%g"`
+       fi
+    fi
+done
+if [ -n "$newer" ] ; then
+    echo $newer
+    return 0
+fi
+return 1
+}
+
+where_tcl(){
+if test -z "${TCLHOME}"; then
+    TCLHOME=/usr
+fi
+tclcfg=`find ${TCLHOME}/lib -name "tclConfig.sh" 2> /dev/null`
+file=""
+maxver=0
+for f in $tclcfg; do
+    ver=`cat $f | grep -e "TCL_VERSION=.*" | sed -e "s%TCL_VERSION=[\'|\"]\(.*\)[\'|\"]%\1%g" | awk -F. '{x=0;for(i=1;i<=3;i++){x=x*100;if(i<=NF)x+=$i;}print x;}'`
+    if [ $maxver -lt $ver ]; then
+        maxver=$ver
+       file=$f
+    fi
+done
+if test -n "$file"; then
+    echo `dirname $file`
+    return 0
+else
+    echo ""
+    return 1
+fi
+}
+
+where_tk(){
+if test -z "${TCLHOME}"; then
+    TCLHOME=/usr
+fi
+tclcfg=`find ${TCLHOME}/lib -name "tkConfig.sh" 2> /dev/null`
+file=""
+maxver=0
+for f in $tclcfg; do
+    ver=`cat $f | grep -e "TK_VERSION=.*" | sed -e "s%TK_VERSION=[\'|\"]\(.*\)[\'|\"]%\1%g" | awk -F. '{x=0;for(i=1;i<=3;i++){x=x*100;if(i<=NF)x+=$i;}print x;}'`
+    if [ $maxver -lt $ver ]; then
+        maxver=$ver
+       file=$f
+    fi
+done
+if test -n "$file"; then
+    echo `dirname $file`
+    return 0
+else
+    echo ""
+    return 1
+fi
+}
+
+where_dps(){
+if test -f /usr/X11R6/include/DPS/dpsconfig.h ; then
+    echo "/usr/X11R6"
+    return 0
+fi
+if test -f /usr/include/DPS/dpsconfig.h ; then
+    echo "/usr"
+    return 0
+fi
+echo ""
+return 1
+}
+
+modif_la_files(){
+ldir=$1
+if [ -z "$ldir" ] || [ ! -d "$ldir" ]; then return 1; fi
+
+srcdir=`pwd`
+
+SALOME_MODULES="`env | awk -F_ '/[[:alnum:]]*_ROOT_DIR/ { print $1 }'`"
+
+cd $ldir
+ldir=`pwd`
+la_files=`find . -name "*.la"`
+
+for l in X ${la_files}; do
+if [ "$l" != "X" ] ; then
+    d=`dirname $l`
+    l=`basename $l`
+    cd $ldir; cd $d
+    # 1. process salome modules dependencies
+    for mod in $SALOME_MODULES; do
+       moddir=`printenv ${mod}_ROOT_DIR`
+       if [ -n "${moddir}" ] ; then
+           #echo $l $mod $moddir
+           sed -e "s%\(-L\)\?[^[:space:]]*${mod}[^[:space:]/]*/lib%\1${moddir}/lib%g" $l > $l"_"
+           mv -f $l"_" $l
+       fi
+    done
+    # 2. process CAS.CADE dependencies
+    casdir=`printenv CASROOT`/lib
+    if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/Linux/lib ; fi
+    if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/lin/lib ; fi
+    if [ -n "${CASROOT}" ] && [ -d "${casdir}" ] ; then
+       # echo $l $CASROOT $casdir
+       sed -e "s%-L[^[:space:]]*\(OCT\|CAS\)[^[:space:]]*%-L${casdir}%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 3. process omniORB dependencies
+    omnidir=`printenv OMNIORBDIR`/lib/i586_linux_2.0_glibc2.1
+    if [ ! -d ${omnidir} ] ; then omnidir=`printenv OMNIORBDIR`/lib ; fi
+    if [ -n "${OMNIORBDIR}" ] && [ -d "${omnidir}" ] ; then
+       # echo $l $OMNIORBDIR $omnidir
+       sed -e "s%-L[^[:space:]]*omni[^[:space:]]*%-L${omnidir}%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 4. process VTK dependencies
+    vtkdir=`printenv VTKHOME`/lib/vtk
+    if [ -n "${VTKHOME}" ] && [ -d "${vtkdir}" ] ; then
+       # echo $l $VTKHOME $vtkdir
+       sed -e "s%-L[^[:space:]]*VTK[^[:space:]]*/lib/vtk%-L${vtkdir}%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 5. process HDF dependencies
+    hdfdir=`printenv HDF5HOME`/lib
+    if [ -n "${HDF5HOME}" ] && [ -d "${hdfdir}" ] ; then
+       # echo $l $HDF5HOME $hdfdir
+       sed -e "s%-L[^[:space:]]*hdf[^[:space:]]*/lib%-L${hdfdir}%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 6. process MED dependencies
+    meddir=`printenv MED2HOME`/lib
+    if [ -n "${MED2HOME}" ] && [ -d "${meddir}" ] ; then
+       # echo $l $MED2HOME $meddir
+       sed -e "s%-L[^[:space:]]*med[^[:space:]]*/lib%-L${meddir}%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 7. process qwt dependencies
+    qwtdir=`find_in_path libqwt.so ${LD_LIBRARY_PATH}`
+    if [ -n "${qwtdir}" ] && [ -d "${qwtdir}" ] ; then
+       # echo $l $qwtdir
+       sed -e "s%-L[^[:space:]]*qwt[^[:space:]]*/lib%-L${qwtdir}%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 8. process qt dependencies
+    qtdir=`printenv QTDIR`/lib
+    if [ -n "${QTDIR}" ] && [ -d "${qtdir}" ] ; then
+       # echo $l $QTDIR $qtdir
+       sed -e "s%-L[^[:space:]]*qt[^[:space:]]*/lib%-L${qtdir}%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 9. process python dependencies
+    where_python=`which python`                 # e.g. /usr/bin/python
+    if [ -n "$where_python" ] ; then
+        where_python=`dirname $where_python`    # --> /usr/bin
+        where_python=`dirname $where_python`    # --> /usr
+       python_version=`python -c "import sys; print sys.version[:3]"`
+       # echo $l $where_python $python_version
+       sed -e "s%-L[^[:space:]]*python[0-9]\.[0-9]\([^[:space:]]*\)%-L${where_python}/lib/python${python_version}\1%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 10. process sip dependencies
+    sipdir=`find_in_path sip.so ${LD_LIBRARY_PATH}`
+    if [ -n "${sipdir}" ] && [ -d "${sipdir}" ] ; then
+       # echo $l $sipdir
+       sed -e "s%-L[^[:space:]]*sip[^[:space:]]*%-L${sipdir}%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 11. process PyQt dependencies
+    pyqtdir=`find_in_path qt.so ${LD_LIBRARY_PATH}`
+    if [ -n "${pyqtdir}" ] && [ -d "${pyqtdir}" ] ; then
+       # echo $l $pyqtdir
+       sed -e "s%-L[^[:space:]]*PyQt[^[:space:]]*%-L${pyqtdir}%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 12. process tcl/tk dependencies
+    tcldir=`printenv TCLHOME`/lib
+    if [ -n "${tcldir}" ] && [ -d "${tcldir}" ] ; then
+       # echo $l $TCLHOME $tcldir
+       sed -e "s%-L[^[:space:]]*tcltk[^[:space:]]*/lib%-L${tcldir}%g" $l > $l"_"
+       mv -f $l"_" $l
+    fi
+    # 13. modify libdir
+    #sed -e "s%^libdir='\(.*\)'%libdir='${PRODUCT_DIR}/lib/salome'%g" $l > $l"_"
+    mod=`basename $ldir | awk -F_ '{print $1}'`
+    moddir=`printenv ${mod}_ROOT_DIR`
+    sed -e "s%^libdir='[^[:space:]]*${mod}[^[:space:]]*/\(lib.*\)'%libdir='${moddir}/\1'%g" $l > $l"_"
+    mv -f $l"_" $l
+fi
+done
+
+cd $srcdir
+return 0
+}