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