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