Salome HOME
Update copyright notes
[tools/install.git] / config_files / common.sh
1 #!/bin/sh
2
3 ####################################################################################
4 #  File      : common.sh
5 #  Created   : Thu Dec 18 12:01:00 2002
6 #  Author    : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
7 #  Project   : SALOME
8 #  Module    : Installation Wizard
9 #  Copyright : 2002-2006 CEA
10 #
11 #  This script is the part of the SALOME installation procedure.
12 #
13 ####################################################################################
14
15 export DELIM="------"
16 export SHRC="salome.sh"
17 export CSHRC="salome.csh"
18
19 #this function takes several parameters
20 #first parameter contains descriptor of output file
21 #next parameters is command for execution
22 #in case of bad result of execution ask user about furher steps
23 #(user can cancel installation procedure)
24 check_job()
25 {
26   out=$1
27   shift
28   errfile=/tmp/errlog
29   if [ -n "$INSTALL_WORK" ] ; then errfile=$INSTALL_WORK/errlog; fi
30   cmd="`pwd` -> $*"
31   if [ "$out" != "1" ] ; then cmd="$cmd >> $out" ; fi
32   echo -e $cmd
33   if [ "$out" != "1" ] ; then
34       $* >> $out 2>$errfile
35   else
36       $*
37   fi
38   if [ "$?" -ne "0" ] ; then
39     if [ $out != "1" ] ; then
40       cat $out
41       cat $errfile >&2
42       cat $errfile >> $out
43     fi
44     # VSR : 10/11/05: disable answer mode ==>
45     #echo -n " " >&2
46     #echo -e "NOT DONE !!! => $*"
47     #echo -n "Would you like to continue to install this product: (Y,N) [Y] : "
48     #read rep;
49     #rep=`echo $rep  | tr "[A-Z]" "[a-z]"`
50     #if test -z $rep || [ $rep = "y" ] ; then
51     #  return 1
52     #fi
53     # VSR : 10/11/05: disable answer mode <==
54     exit 1
55   fi
56   return 0
57 }
58
59 #invoke check_job function
60 #all output will be put into terminal
61 check_jb()
62 {
63   check_job 1 $*
64   return
65 }
66
67 # make directory
68 makedir()
69 {
70   rm -rf "$1" > /dev/null
71   mkdir -p "$1"
72 }
73
74 #create environment for sh and csh
75 make_env()
76 {
77 install_root=$1;  shift
78 install_work=$1; 
79 for i in $SHRC $CSHRC ; do
80     if [ -e ${install_work}/$i ]; then
81         rm ${install_work}/$i
82     fi
83     touch ${install_work}/$i
84 done
85
86 if [ $# -eq 3 ] ; then
87     product_name=$3;
88     product_env=${install_work}/env_${product_name}.sh
89     (test -e ${product_env} && rm ${product_env} )
90 fi
91 ### !!! writing salome.sh file !!!  -> define INSTALL_ROOT
92 cat >> ${install_work}/$SHRC <<EOF
93 #${DELIM} Setting products installation directory ${DELIM}
94 export INSTALL_ROOT=${install_root}
95
96 #${DELIM} Environment switch: 0 for SALOME building, 1 for SALOME launching ${DELIM}
97 export ENV_FOR_LAUNCH=1
98
99 EOF
100 ### !!! The next is for RedHat 9 only !!! 
101 if [ -f /etc/redhat-release ] ; then
102   grep -e "Red Hat Linux release 9" /etc/redhat-release > /dev/null
103   if [ $? -eq 0 ] ; then
104     cat >> ${install_work}/$SHRC <<EOF
105 #${DELIM} Force RH9 to use old implementation of threads ${DELIM}
106 export LD_ASSUME_KERNEL=2.4.18
107
108 EOF
109   fi
110 fi
111 ### !!! writing salome.csh file !!! -> set inital variables
112 pre_vars="PATH LD_LIBRARY_PATH LD_RUN_PATH PYTHONPATH TCLLIBPATH"
113 for i in $pre_vars ; do
114 cat >> ${install_work}/$CSHRC <<EOF
115 #${DELIM} setting initial ${i} ${DELIM}
116 if (! (\$?${i}) ) then
117   setenv $i
118 endif
119
120 EOF
121 done
122
123 ### !!! writing salome.(c)sh files !!! -> dump products environment files, changing 'export' by 'setenv(a|p)' where necessary
124 ### Note, that for performance reasons temporary environment files used during installation procedure itself
125 ### are created without using setenv(a|p) aliases.
126
127 # 1. first dump all environment files into the $SHRC file
128 product_sequence="$2"
129 for i in $product_sequence ; do
130     env_file=${install_work}/env_${i}.sh
131     ( test -e $env_file && cat $env_file >> ${install_work}/$SHRC 2>/dev/null )
132 done
133
134 # 2. writing global functions to _salome.sh file
135 cat >> ${install_work}/_$SHRC <<EOF
136 ##########################################################################
137 # Functions exporta and exportp are used to append/prepend correspondingly 
138 # one directory or a set of directories separated by semicolon symbol (':')
139 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
140 # LD_RUN_PATH etc. 
141 # The main purpose is to replace default setenv command behavior:
142 # exporta, exportp also remove duplicated entries, shortening in that way
143 # the environment variables.
144 # If some directory being added is already included into the variable
145 # nothing is done for it.
146 # Note, that these functions work some slower that setenv command itself.
147 #
148 #### cleandup ###
149 # appends/prepends set of directories (second parameter) 
150 # to the another set of directories (first parameter) and
151 # removes duplicated entries;
152 # the third parameter defines the mode: 0 - append, 1 - prepend
153 cleandup() {
154 out_var=\`echo \$1 \$2 | awk -v dir=\$3 '{                   \\
155      na = split(\$2,a,":");                               \\
156      k1=0;                                               \\
157      bbb[k1++]="";                                       \\
158      ccc[""];                                            \\
159      if(\$1 != "<empty>") {                               \\
160        nb = split(\$1,b,":");                             \\
161        for(i=1;i<=nb;i++) {                              \\
162          if(!(b[i] in ccc) ) {                           \\
163            ccc[b[i]];                                    \\
164            bbb[k1++]=b[i];                               \\
165          };                                              \\
166        };                                                \\
167      };                                                  \\
168      k2=0;                                               \\
169      aaa[k2++]="";                                       \\
170      for(i=1;i<=na;i++) {                                \\
171        if(!(a[i] in ccc)) {                              \\
172          ccc[a[i]];                                      \\
173          aaa[k2++]=a[i];                                 \\
174        };                                                \\
175      };                                                  \\
176      ORS=":";                                            \\
177      if(dir) {                                           \\
178        for(i=1;i<k2;i++) {                               \\
179          print aaa[i];                                   \\
180        }                                                 \\
181        for(i=1;i<k1;i++) {                               \\
182          print bbb[i];                                   \\
183        }                                                 \\
184      }                                                   \\
185      else {                                              \\
186        for(i=1;i<k1;i++) {                               \\
187          print bbb[i];                                   \\
188        }                                                 \\
189        for(i=1;i<k2;i++) {                               \\
190          print aaa[i];                                   \\
191        }                                                 \\
192      }                                                   \\
193    }' | sed -e 's/\(.*\):/\1/g'\`
194 echo \$out_var
195 }
196 ### exporta ###
197 # appends directory or set of directories, separated by ':' (second parameter)
198 # to the variable (first parameter)
199 exporta () { 
200 xenv=\`printenv \$1\`
201 if [ -z "\$xenv" ]; then xenv="<empty>"; fi
202 out_var=\`cleandup \$xenv \$2 0\`
203 export \$1=\$out_var
204 }
205 ### exportp ###
206 # prepends directory or set of directories, separated by ':' (second parameter)
207 # to the variable (first parameter)
208 exportp () { 
209 xenv=\`printenv \$1\`
210 if [ -z "\$xenv" ]; then xenv="<empty>"; fi
211 out_var=\`cleandup \$xenv \$2 1\`
212 export \$1=\$out_var
213 }
214 ###########################################################################
215
216 EOF
217
218 # 3. writing global functions to _salome.csh file
219 cat >> ${install_work}/_$CSHRC <<EOF
220
221 ###########################################################################
222 # Aliases setenva and setenvp are used to append/prepend correspondingly 
223 # one directory or a set of directories separated by semicolon symbol (':')
224 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
225 # LD_RUN_PATH etc. 
226 # The main purpose is to replace default setenv command behavior:
227 # setenva, setenvp also remove duplicated entries, shortening in that way
228 # the environment variables.
229 # If some directory being added is already included into the variable
230 # nothing is done for it.
231 # Note, that these aliases work some slower that setenv command itself.
232 #
233 #### cleandup ###
234 # appends/prepends set of directories (second parameter) 
235 # to the another set of directories (first parameter) and
236 # removes duplicated entries;
237 # the third parameter defines the mode: 0 - append, 1 - prepend
238 alias cleandup "echo \!:1 \!:2 | awk -v dir=\!:3         \\\\
239 '"'{ na = split(\$2,a,":");                               \\\\
240      k1=0;                                               \\\\
241      bbb[k1++]="";                                       \\\\
242      ccc[""];                                            \\\\
243      if(\$1 != "<empty>") {                               \\\\
244        nb = split(\$1,b,":");                             \\\\
245        for(i=1;i<=nb;i++) {                              \\\\
246          if(!(b[i] in ccc) ) {                           \\\\
247            ccc[b[i]];                                    \\\\
248            bbb[k1++]=b[i];                               \\\\
249          };                                              \\\\
250        };                                                \\\\
251      };                                                  \\\\
252      k2=0;                                               \\\\
253      aaa[k2++]="";                                       \\\\
254      for(i=1;i<=na;i++) {                                \\\\
255        if(!(a[i] in ccc)) {                              \\\\
256          ccc[a[i]];                                      \\\\
257          aaa[k2++]=a[i];                                 \\\\
258        };                                                \\\\
259      };                                                  \\\\
260      ORS=":";                                            \\\\
261      if(dir) {                                           \\\\
262        for(i=1;i<k2;i++) {                               \\\\
263          print aaa[i];                                   \\\\
264        }                                                 \\\\
265        for(i=1;i<k1;i++) {                               \\\\
266          print bbb[i];                                   \\\\
267        }                                                 \\\\
268      }                                                   \\\\
269      else {                                              \\\\
270        for(i=1;i<k1;i++) {                               \\\\
271          print bbb[i];                                   \\\\
272        }                                                 \\\\
273        for(i=1;i<k2;i++) {                               \\\\
274          print aaa[i];                                   \\\\
275        }                                                 \\\\
276      }                                                   \\\\
277   }'"' | sed -e 's/\(.*\):/\1/g'"
278 ### setenva ###
279 # appends directory or set of directories, separated by ':' (second parameter)
280 # to the variable (first parameter)
281 alias setenva 'set a=\!:1 ; set b=\!:2 ;  \\
282                set c=\`printenv \$a\` ;      \\
283                set b=\`cleandup \$c \$b 0\` ; \\
284                setenv \$a \$b ;             \\
285                unset a, b, c'
286
287 ### setenvp ###
288 # prepends directory or set of directories, separated by ':' (second parameter)
289 # to the variable (first parameter)
290 alias setenvp 'set a=\!:1 ; set b=\!:2 ;  \\
291                set c=\`printenv \$a\` ;      \\
292                set b=\`cleandup \$c \$b 1\` ; \\
293                setenv \$a \$b ;             \\
294                unset a, b, c'
295 ###########################################################################
296
297 EOF
298 cat ${install_work}/$CSHRC >> ${install_work}/_$CSHRC
299
300 # 4. put the contents of salome.sh to _salome.sh replacing export by export(a|p) aliases where necessary
301 sed -e 's%export\([[:blank:]]*\)PATH=\$[{]\?PATH[}]\?:\(.*\)%exporta\1PATH \2%g' -e 's%export\([[:blank:]]*\)PATH=\(.*\):\$[{]\?PATH[}]\?%exportp\1PATH \2%g' ${install_work}/$SHRC > ${INSTALL_WORK}/_tmp1 2>/dev/null
302 sed -e 's%export\([[:blank:]]*\)LD_LIBRARY_PATH=\$[{]\?LD_LIBRARY_PATH[}]\?:\(.*\)%exporta\1LD_LIBRARY_PATH \2%g' -e 's%export\([[:blank:]]*\)LD_LIBRARY_PATH=\(.*\):\$[{]\?LD_LIBRARY_PATH[}]\?%exportp\1LD_LIBRARY_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
303 sed -e 's%export\([[:blank:]]*\)PYTHONPATH=\$[{]\?PYTHONPATH[}]\?:\(.*\)%exporta\1PYTHONPATH \2%g' -e 's%export\([[:blank:]]*\)PYTHONPATH=\(.*\):\$[{]\?PYTHONPATH[}]\?%exportp\1PYTHONPATH \2%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
304 sed -e 's%export\([[:blank:]]*\)LD_RUN_PATH=\$[{]\?LD_RUN_PATH[}]\?:\(.*\)%exporta\1LD_RUN_PATH \2%g' -e 's%export\([[:blank:]]*\)LD_RUN_PATH=\(.*\):\$[{]\?LD_RUN_PATH[}]\?%exportp\1LD_RUN_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2
305
306 # Setting "/usr/X11R6/lib" path in LD_LIBRARY_PATH for the libGL.so.1 file
307 if test `uname -m` = "x86_64" ; then
308 echo '# Setting /usr/X11R6/lib64 path in LD_LIBRARY_PATH for the libGL.so.1 file' >> ${INSTALL_WORK}/_tmp2
309 echo 'export LD_LIBRARY_PATH=/usr/X11R6/lib64:${LD_LIBRARY_PATH}' >> ${INSTALL_WORK}/_tmp2
310 else
311 echo '# Setting /usr/X11R6/lib path in LD_LIBRARY_PATH for the libGL.so.1 file' >> ${INSTALL_WORK}/_tmp2
312 echo 'export LD_LIBRARY_PATH=/usr/X11R6/lib:${LD_LIBRARY_PATH}' >> ${INSTALL_WORK}/_tmp2
313 fi
314
315 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$SHRC
316
317 # 5. Create a salome.csh file from salome.sh by replacing export by setenv, etc.
318 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${install_work}/$SHRC > ${INSTALL_WORK}/_tmp1 2>/dev/null
319 cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/$CSHRC
320
321 # 6. Create a _salome.csh file from _salome.sh by replacing export by setenv, exporta by setenva, etc.
322 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
323 sed -e 's%exporta \([[:alnum:]_[:blank:]]*\)%setenva \1%g'  ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
324 sed -e 's%exportp \([[:alnum:]_[:blank:]]*\)%setenvp \1%g'  ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
325 sed -e 's%if \[ -n "\${ENV_FOR_LAUNCH}" \] ; then%if ( ${?ENV_FOR_LAUNCH} ) then%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
326 sed -e 's%if \[ "\${ENV_FOR_LAUNCH}" == "1" \] ; then%if ( "\${ENV_FOR_LAUNCH}" == "1" ) then%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
327 sed -e 's%^\([[:blank:]]*\)fi\([[:blank:]]*\)$%\1endif\2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
328 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$CSHRC 2>/dev/null
329
330 rm -f ${INSTALL_WORK}/_tmp1 ${INSTALL_WORK}/_tmp2
331
332 if [ $# -eq 4 ] ; then
333     product_dir=$4
334     if [ -e ${product_dir} ] ; then
335         cp -f ${install_work}/_$SHRC  ${product_dir}/$SHRC
336         cp -f ${install_work}/_$CSHRC ${product_dir}/$CSHRC
337     fi
338 fi
339 sed -e 's%setenv ENV_FOR_LAUNCH 1%setenv ENV_FOR_LAUNCH 0%' ${install_work}/_$CSHRC > ${install_root}/env_build.csh
340 sed -e 's%export ENV_FOR_LAUNCH=1%export ENV_FOR_LAUNCH=0%' ${install_work}/_$SHRC  > ${install_root}/env_build.sh
341
342 cp -f ${install_work}/_$CSHRC ${install_root}/env_products.csh
343 cp -f ${install_work}/_$SHRC  ${install_root}/env_products.sh
344
345 rm -f ${install_work}/_$SHRC ${install_work}/_$CSHRC
346 ### !!! copying build.csh script
347 if [ -e ./build.csh ]; then
348     cp -f ./build.csh ${install_root}
349 fi
350 ### !!! copying release notes
351 for p in `ls ../` ; do
352     export pdf=`echo ${p} | sed s/[.]/" "/g | awk '{print $2}'`
353     if [ "${pdf}" = "pdf" ]; then
354         export RN=$p
355         if [ ! -e ${install_root}/${RN} ]; then
356             cp -f ../${RN} ${install_root}
357         fi
358     fi
359 done
360
361 }
362
363 #try use already existing product
364 try_existing()
365 {
366 product_dir=$1;  install_root=$2;  install_work=$3;  product_sequence="$4";  product_type=$5
367 env_file=${product_dir}/env_${product_type}.sh
368 if [ -f ${env_file} ] ; then
369     cp -f ${env_file} ${install_work}
370     make_env ${install_root} ${install_work} "${product_sequence}"
371     source ${install_work}/$SHRC
372     check_version
373     if [ $? -eq 0 ] ; then
374         if [ -d ${product_dir} ] && [ -w ${product_dir} ] ; then
375             #makedir ${product_dir}
376             print_env
377             return 0    
378         fi
379     else
380         rm -f ${install_work}/env_${product_type}.sh
381         make_env ${install_root} ${install_work} "${product_sequence}"
382     fi
383 fi
384 return 1;
385 }
386
387 #check existance of lib passed as first parameter
388 #return 0 if lib exists
389 #if you pass second parameter search will be done in it 
390 #otherwise search will be done in $LD_LIBRARY_PATH
391 #you should use : as dilimeter if you are going to pass second parameter
392 check_lib_version(){
393 if [ -n "$2" ]; then
394    whereIs=$2
395 else
396    whereIs=$LD_LIBRARY_PATH
397 fi
398 for L in `echo ${whereIs} | sed -e"s%:% %g"` ;  do
399     ret=`find $L -name $1 2>/dev/null`
400     if [ -n "$ret" ] ; then
401         #echo "The $1 exists on yours system in a $L folder"
402         return 0
403     fi
404 done
405 return 1
406 }
407
408 find_in_path(){
409 file=$1;  shift; 
410 path=$*
411 for i in `echo ${path} | sed -e"s%:% %g"` ; do 
412     ret=`find $i -name $file -maxdepth 1 2>/dev/null`
413     if [ -n "$ret" ] ; then
414         ret=`echo $ret | sed -e"s%/\$file$%%g"`
415         echo $ret
416         return 0
417     fi
418 done
419 return 1
420 }
421
422 sort_path(){
423 arg1=$1;  val1=$2;  arg2=$3;  val2=$4
424 tmp="^$val1$|^$val1:|:$val1$|:$val1:"
425 #echo $val2 | grep -E "$tmp" >/dev/null 2>&1
426 #if [ $? -eq 0 ] ; then 
427 #    echo "$arg2"
428 #    return
429 #fi
430 to_tail=1
431 exclude_list="usr lib bin sbin etc"
432 for i in ${exclude_list} ; do
433     tmp="^/$i/|^/$i\$"
434     echo ${val1} | grep -E "$tmp" >/dev/null 2>&1
435     if [ $? == 0 ] ; then to_tail=0; break; fi
436 done
437 if [ $to_tail -eq 0 ] ; then
438     echo $arg2:$arg1
439 else
440     echo $arg1:$arg2
441 fi
442 return $to_tail
443 }
444
445 where_gcc(){
446 maj_ver=`echo $1 | awk -F. '{if(NF>0) print $1; else print 0}'`
447 min_ver=`echo $1 | awk -F. '{if(NF>1) print $2; else print 0}'`
448 rel_ver=`echo $1 | awk -F. '{if(NF>2) print $3; else print 0}'`
449 let ver=$maj_ver*10000+$min_ver*100+$rel_ver
450 newer=""
451 newerver=0
452 for i in `echo ${PATH}:/usr/bin:/usr/local/bin | sed -e"s%:% %g"` ; do 
453     ret=`find $i -name gcc -maxdepth 1 2>/dev/null`
454     if [ -n "$ret" ] ; then
455         maj_ver=`$ret -dumpversion | awk -F. '{if(NF>0) print $1; else print 0}'`
456         min_ver=`$ret -dumpversion | awk -F. '{if(NF>1) print $2; else print 0}'`
457         rel_ver=`$ret -dumpversion | awk -F. '{if(NF>2) print $3; else print 0}'`
458         let ver1=$maj_ver*10000+$min_ver*100+$rel_ver
459         if [ $ver1 -eq $ver ] ; then
460             ret=`echo $ret | sed -e"s%/gcc$%%g"`
461             echo $ret
462             return 0
463         fi
464         if [ $ver1 -gt $ver ] && [ $ver1 -gt $newerver ] ; then
465             let newerver=$ver1
466             newer=`echo $ret | sed -e"s%/gcc$%%g"`
467         fi
468     fi
469 done
470 if [ -n "$newer" ] ; then
471     echo $newer
472     return 0
473 fi
474 return 1
475 }
476
477 where_tcl(){
478 if test -z "${TCLHOME}"; then
479     TCLHOME=/usr
480 fi
481 tclcfg=`find ${TCLHOME}/lib -name "tclConfig.sh" 2> /dev/null`
482 file=""
483 maxver=0
484 for f in $tclcfg; do
485     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;}'`
486     if [ $maxver -lt $ver ]; then
487         maxver=$ver
488         file=$f
489     fi
490 done
491 if test -n "$file"; then
492     echo `dirname $file`
493     return 0
494 else
495     echo ""
496     return 1
497 fi
498 }
499
500 where_tk(){
501 if test -z "${TCLHOME}"; then
502     TCLHOME=/usr
503 fi
504 tclcfg=`find ${TCLHOME}/lib -name "tkConfig.sh" 2> /dev/null`
505 file=""
506 maxver=0
507 for f in $tclcfg; do
508     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;}'`
509     if [ $maxver -lt $ver ]; then
510         maxver=$ver
511         file=$f
512     fi
513 done
514 if test -n "$file"; then
515     echo `dirname $file`
516     return 0
517 else
518     echo ""
519     return 1
520 fi
521 }
522
523 where_dps(){
524 if test -f /usr/X11R6/include/DPS/dpsconfig.h ; then
525     echo "/usr/X11R6"
526     return 0
527 fi
528 if test -f /usr/include/DPS/dpsconfig.h ; then
529     echo "/usr"
530     return 0
531 fi
532 echo ""
533 return 1
534 }
535
536 modif_la_files(){
537 ldir=$1
538 if [ -z "$ldir" ] || [ ! -d "$ldir" ]; then return 1; fi
539
540 srcdir=`pwd`
541
542 SALOME_MODULES="`env | awk -F_ '/[[:alnum:]]*_ROOT_DIR/ { print $1 }'`"
543
544 cd $ldir
545 ldir=`pwd`
546 la_files=`find . -name "*.la"`
547
548 for l in X ${la_files}; do
549 if [ "$l" != "X" ] ; then
550     d=`dirname $l`
551     l=`basename $l`
552     cd $ldir; cd $d
553     # 1. process salome modules dependencies
554     for mod in $SALOME_MODULES; do
555         moddir=`printenv ${mod}_ROOT_DIR`
556         if [ -n "${moddir}" ] ; then
557             #echo $l $mod $moddir
558             sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}[^[:space:]/]*/lib% \1${moddir}/lib%g" $l > $l"_"
559             mv -f $l"_" $l
560         fi
561     done
562     # 2. process CAS.CADE dependencies
563     casdir=`printenv CASROOT`/lib
564     if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/Linux/lib ; fi
565     if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/lin/lib ; fi
566     if [ -n "${CASROOT}" ] && [ -d "${casdir}" ] ; then
567         # echo $l $CASROOT $casdir
568         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*\(OCT\|CAS\)[^[:space:]/]*/Linux/lib% \1${casdir}%g" \
569             -e "s%[[:space:]]\(-L\)\?[^[:space:]]*\(OCT\|CAS\)[^[:space:]/]*/lin/lib% \1${casdir}%g"   \
570             -e "s%[[:space:]]\(-L\)\?[^[:space:]]*\(OCT\|CAS\)[^[:space:]/]*/lib% \1${casdir}%g" $l > $l"_"
571         mv -f $l"_" $l
572     fi
573     # 3. process omniORB dependencies
574     omnidir=`printenv OMNIORBDIR`/lib/i586_linux_2.0_glibc2.1
575     if [ ! -d ${omnidir} ] ; then omnidir=`printenv OMNIORBDIR`/lib ; fi
576     if [ -n "${OMNIORBDIR}" ] && [ -d "${omnidir}" ] ; then
577         # echo $l $OMNIORBDIR $omnidir
578         sed -e "s%-L[^[:space:]]*omni[^[:space:]]*%-L${omnidir}%g" $l > $l"_"
579         mv -f $l"_" $l
580     fi
581     # 4. process VTK dependencies
582     vtkdir=`printenv VTKHOME`/lib/vtk
583     if [ -n "${VTKHOME}" ] && [ -d "${vtkdir}" ] ; then
584         # echo $l $VTKHOME $vtkdir
585         sed -e "s%-L[^[:space:]]*VTK[^[:space:]]*/lib/vtk%-L${vtkdir}%g" $l > $l"_"
586         mv -f $l"_" $l
587     fi
588     # 5. process HDF dependencies
589     hdfdir=`printenv HDF5HOME`/lib
590     if [ -n "${HDF5HOME}" ] && [ -d "${hdfdir}" ] ; then
591         # echo $l $HDF5HOME $hdfdir
592         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*hdf[^[:space:]/]*/lib% \1${hdfdir}%g" $l > $l"_"
593         mv -f $l"_" $l
594     fi
595     # 6. process MED dependencies
596     meddir=`printenv MED2HOME`/lib
597     if [ -n "${MED2HOME}" ] && [ -d "${meddir}" ] ; then
598         # echo $l $MED2HOME $meddir
599         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*med[^[:space:]/]*/lib% \1${meddir}%g" $l > $l"_"
600         mv -f $l"_" $l
601     fi
602     # 7. process qwt dependencies
603     qwtdir=`find_in_path libqwt.so ${LD_LIBRARY_PATH}`
604     if [ -n "${qwtdir}" ] && [ -d "${qwtdir}" ] ; then
605         # echo $l $qwtdir
606         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*qwt[^[:space:]/]*/lib% \1${qwtdir}%g" $l > $l"_"
607         mv -f $l"_" $l
608     fi
609     # 8. process qt dependencies
610     qtdir=`printenv QTDIR`/lib
611     if [ -n "${QTDIR}" ] && [ -d "${qtdir}" ] ; then
612         # echo $l $QTDIR $qtdir
613         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*qt[^[:space:]/]*/lib% \1${qtdir}%g" $l > $l"_"
614         mv -f $l"_" $l
615     fi
616     # 9. process python dependencies
617     where_python=`which python`                 # e.g. /usr/bin/python
618     if [ -n "$where_python" ] ; then
619         where_python=`dirname $where_python`    # --> /usr/bin
620         where_python=`dirname $where_python`    # --> /usr
621         python_version=`python -c "import sys; print sys.version[:3]"`
622         # echo $l $where_python $python_version
623         sed -e "s%-L[^[:space:]]*python[0-9]\.[0-9]\([^[:space:]]*\)%-L${where_python}/lib/python${python_version}\1%g" $l > $l"_"
624         mv -f $l"_" $l
625     fi
626     # 10. process sip dependencies
627     sipdir=`find_in_path sip.so ${LD_LIBRARY_PATH}`
628     if [ -n "${sipdir}" ] && [ -d "${sipdir}" ] ; then
629         # echo $l $sipdir
630         sed -e "s%-L[^[:space:]]*sip[^[:space:]]*%-L${sipdir}%g" $l > $l"_"
631         mv -f $l"_" $l
632     fi
633     # 11. process PyQt dependencies
634     pyqtdir=`find_in_path qt.so ${LD_LIBRARY_PATH}`
635     if [ -n "${pyqtdir}" ] && [ -d "${pyqtdir}" ] ; then
636         # echo $l $pyqtdir
637         sed -e "s%-L[^[:space:]]*PyQt[^[:space:]]*%-L${pyqtdir}%g" $l > $l"_"
638         mv -f $l"_" $l
639     fi
640     # 12. process tcl/tk dependencies
641     tcldir=`printenv TCLHOME`/lib
642     if [ -n "${tcldir}" ] && [ -d "${tcldir}" ] ; then
643         # echo $l $TCLHOME $tcldir
644         sed -e "s%-L[^[:space:]]*tcltk[^[:space:]]*/lib%-L${tcldir}%g" $l > $l"_"
645         mv -f $l"_" $l
646     fi
647     # 13. process boost dependencies
648     boostdir=`printenv BOOSTDIR`/lib
649     if [ -n "${boostdir}" ] && [ -d "${boostdir}" ] ; then
650         # echo $l $BOOSTDIR $boostdir
651         sed -e "s%-L[^[:space:]]*boost[^[:space:]]*/lib%-L${boostdir}%g" $l > $l"_"
652         mv -f $l"_" $l
653     fi
654     # 14. modify libdir
655     #sed -e "s%^libdir='\(.*\)'%libdir='${PRODUCT_DIR}/lib/salome'%g" $l > $l"_"
656     mod=`basename $ldir | awk -F_ '{print $1}'`
657     moddir=`printenv ${mod}_ROOT_DIR`
658     sed -e "s%^libdir='[^[:space:]]*${mod}[^[:space:]]*/\(lib.*\)'%libdir='${moddir}/\1'%g" $l > $l"_"
659     mv -f $l"_" $l
660 fi
661 done
662
663 cd $srcdir
664 return 0
665 }