Salome HOME
c8d9a8a88ddc30b18033a9bd9ec565d6a4b4b124
[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 # Licence activation 
162
163 # Source of license environment file
164
165 echo '#------ License activation ------' >> ${install_work}/$SHRC 2>/dev/null
166 echo 'export LICENSE_FILE=/product/distene/dlim8.var.sh' >> ${install_work}/$SHRC 2>/dev/null
167 echo '' >> ${install_work}/$SHRC 2>/dev/null
168 echo 'if [ -e "${LICENSE_FILE}" ] ; then' >> ${install_work}/$SHRC 2>/dev/null
169 echo 'export SIMULOGD_LICENSE_FILE=29029@amun' >> ${install_work}/$SHRC 2>/dev/null
170 echo 'source ${LICENSE_FILE}' >> ${install_work}/$SHRC 2>/dev/null
171 echo 'fi' >> ${install_work}/$SHRC 2>/dev/null
172 echo '' >> ${install_work}/$SHRC 2>/dev/null
173
174 # 1. first dump all environment files into the $SHRC file
175 product_sequence="$2"
176 install_products="$3"
177 for i in $product_sequence ; do
178     env_file=${install_work}/env_${i}.sh
179     _env_file=${install_work}/_env_${i}.sh
180     if [ -e $_env_file ] ; then
181         cat $_env_file >> ${install_work}/$SHRC 2>/dev/null
182     elif [ -e $env_file ] ; then
183         echo $install_products | grep -q "\b${i}\b"
184         if [ $? -eq 1 ] ; then
185             cat $env_file | sed 's/^/## /' >> ${install_work}/$SHRC 2>/dev/null
186         else
187             cat $env_file >> ${install_work}/$SHRC 2>/dev/null
188         fi
189     fi
190 done
191
192 # 2. writing global functions to _salome.sh file
193 cat >> ${install_work}/_$SHRC <<EOF
194 ##########################################################################
195 # Functions exporta and exportp are used to append/prepend correspondingly 
196 # one directory or a set of directories separated by semicolon symbol (':')
197 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
198 # LD_RUN_PATH etc. 
199 # The main purpose is to replace default setenv command behavior:
200 # exporta, exportp also remove duplicated entries, shortening in that way
201 # the environment variables.
202 # If some directory being added is already included into the variable
203 # nothing is done for it.
204 # Note, that these functions work some slower that setenv command itself.
205 #
206 #### cleandup ###
207 # appends/prepends set of directories (second parameter) 
208 # to the another set of directories (first parameter) and
209 # removes duplicated entries;
210 # the third parameter defines the mode: 0 - append, 1 - prepend
211 cleandup() {
212 out_var=\`echo \$1 \$2 | awk -v dir=\$3 '{                   \\
213      na = split(\$2,a,":");                               \\
214      k1=0;                                               \\
215      bbb[k1++]="";                                       \\
216      ccc[""];                                            \\
217      if(\$1 != "<empty>") {                               \\
218        nb = split(\$1,b,":");                             \\
219        for(i=1;i<=nb;i++) {                              \\
220          if(!(b[i] in ccc) ) {                           \\
221            ccc[b[i]];                                    \\
222            bbb[k1++]=b[i];                               \\
223          };                                              \\
224        };                                                \\
225      };                                                  \\
226      k2=0;                                               \\
227      aaa[k2++]="";                                       \\
228      for(i=1;i<=na;i++) {                                \\
229        if(!(a[i] in ccc)) {                              \\
230          ccc[a[i]];                                      \\
231          aaa[k2++]=a[i];                                 \\
232        };                                                \\
233      };                                                  \\
234      ORS=":";                                            \\
235      if(dir) {                                           \\
236        for(i=1;i<k2;i++) {                               \\
237          print aaa[i];                                   \\
238        }                                                 \\
239        for(i=1;i<k1;i++) {                               \\
240          print bbb[i];                                   \\
241        }                                                 \\
242      }                                                   \\
243      else {                                              \\
244        for(i=1;i<k1;i++) {                               \\
245          print bbb[i];                                   \\
246        }                                                 \\
247        for(i=1;i<k2;i++) {                               \\
248          print aaa[i];                                   \\
249        }                                                 \\
250      }                                                   \\
251    }' | sed -e 's/\(.*\):/\1/g'\`
252 echo \$out_var
253 }
254 ### exporta ###
255 # appends directory or set of directories, separated by ':' (second parameter)
256 # to the variable (first parameter)
257 exporta () { 
258 xenv=\`printenv \$1\`
259 if [ -z "\$xenv" ]; then xenv="<empty>"; fi
260 out_var=\`cleandup \$xenv \$2 0\`
261 export \$1=\$out_var
262 }
263 ### exportp ###
264 # prepends directory or set of directories, separated by ':' (second parameter)
265 # to the variable (first parameter)
266 exportp () { 
267 xenv=\`printenv \$1\`
268 if [ -z "\$xenv" ]; then xenv="<empty>"; fi
269 out_var=\`cleandup \$xenv \$2 1\`
270 export \$1=\$out_var
271 }
272 ###########################################################################
273
274 EOF
275
276 # 3. writing global functions to _salome.csh file
277 cat >> ${install_work}/_$CSHRC <<EOF
278
279 ###########################################################################
280 # Aliases setenva and setenvp are used to append/prepend correspondingly 
281 # one directory or a set of directories separated by semicolon symbol (':')
282 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
283 # LD_RUN_PATH etc. 
284 # The main purpose is to replace default setenv command behavior:
285 # setenva, setenvp also remove duplicated entries, shortening in that way
286 # the environment variables.
287 # If some directory being added is already included into the variable
288 # nothing is done for it.
289 # Note, that these aliases work some slower that setenv command itself.
290 #
291 #### cleandup ###
292 # appends/prepends set of directories (second parameter) 
293 # to the another set of directories (first parameter) and
294 # removes duplicated entries;
295 # the third parameter defines the mode: 0 - append, 1 - prepend
296 alias cleandup "echo \!:1 \!:2 | awk -v dir=\!:3         \\\\
297 '"'{ na = split(\$2,a,":");                               \\\\
298      k1=0;                                               \\\\
299      bbb[k1++]="";                                       \\\\
300      ccc[""];                                            \\\\
301      if(\$1 != "<empty>") {                               \\\\
302        nb = split(\$1,b,":");                             \\\\
303        for(i=1;i<=nb;i++) {                              \\\\
304          if(!(b[i] in ccc) ) {                           \\\\
305            ccc[b[i]];                                    \\\\
306            bbb[k1++]=b[i];                               \\\\
307          };                                              \\\\
308        };                                                \\\\
309      };                                                  \\\\
310      k2=0;                                               \\\\
311      aaa[k2++]="";                                       \\\\
312      for(i=1;i<=na;i++) {                                \\\\
313        if(!(a[i] in ccc)) {                              \\\\
314          ccc[a[i]];                                      \\\\
315          aaa[k2++]=a[i];                                 \\\\
316        };                                                \\\\
317      };                                                  \\\\
318      ORS=":";                                            \\\\
319      if(dir) {                                           \\\\
320        for(i=1;i<k2;i++) {                               \\\\
321          print aaa[i];                                   \\\\
322        }                                                 \\\\
323        for(i=1;i<k1;i++) {                               \\\\
324          print bbb[i];                                   \\\\
325        }                                                 \\\\
326      }                                                   \\\\
327      else {                                              \\\\
328        for(i=1;i<k1;i++) {                               \\\\
329          print bbb[i];                                   \\\\
330        }                                                 \\\\
331        for(i=1;i<k2;i++) {                               \\\\
332          print aaa[i];                                   \\\\
333        }                                                 \\\\
334      }                                                   \\\\
335   }'"' | sed -e 's/\(.*\):/\1/g'"
336 ### setenva ###
337 # appends directory or set of directories, separated by ':' (second parameter)
338 # to the variable (first parameter)
339 alias setenva 'set a=\!:1 ; set b=\!:2 ;  \\
340                set c=\`printenv \$a\` ;      \\
341                set b=\`cleandup \$c \$b 0\` ; \\
342                setenv \$a \$b ;             \\
343                unset a, b, c'
344
345 ### setenvp ###
346 # prepends directory or set of directories, separated by ':' (second parameter)
347 # to the variable (first parameter)
348 alias setenvp 'set a=\!:1 ; set b=\!:2 ;  \\
349                set c=\`printenv \$a\` ;      \\
350                set b=\`cleandup \$c \$b 1\` ; \\
351                setenv \$a \$b ;             \\
352                unset a, b, c'
353 ###########################################################################
354
355 EOF
356 cat ${install_work}/$CSHRC >> ${install_work}/_$CSHRC
357
358 # 4. put the contents of salome.sh to _salome.sh replacing export by export(a|p) aliases where necessary
359 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
360 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
361 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
362 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
363
364 # Setting "/usr/X11R6/lib" path in LD_LIBRARY_PATH for the libGL.so.1 file
365 #if test `uname -m` = "x86_64" ; then
366 #echo '# Setting /usr/X11R6/lib64 path in LD_LIBRARY_PATH for the libGL.so.1 file' >> ${INSTALL_WORK}/_tmp2
367 #echo 'export LD_LIBRARY_PATH=/usr/X11R6/lib64:${LD_LIBRARY_PATH}' >> ${INSTALL_WORK}/_tmp2
368 #else
369 #echo '# Setting /usr/X11R6/lib path in LD_LIBRARY_PATH for the libGL.so.1 file' >> ${INSTALL_WORK}/_tmp2
370 #echo 'export LD_LIBRARY_PATH=/usr/X11R6/lib:${LD_LIBRARY_PATH}' >> ${INSTALL_WORK}/_tmp2
371 #fi
372
373 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$SHRC
374
375 # 5. Create a salome.csh file from salome.sh by replacing export by setenv, etc.
376 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${install_work}/$SHRC > ${INSTALL_WORK}/_tmp1 2>/dev/null
377 cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/$CSHRC
378
379 # 6. Create a _salome.csh file from _salome.sh by replacing export by setenv, exporta by setenva, etc.
380 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
381 sed -e 's%exporta \([[:alnum:]_[:blank:]]*\)%setenva \1%g'  ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
382 sed -e 's%exportp \([[:alnum:]_[:blank:]]*\)%setenvp \1%g'  ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
383 sed -e 's%if \[ -n "\${PYTHONPATH}" \] ; then%if ( ${?PYTHONPATH} ) then%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
384 sed -e 's%if \[ -n "\${ENV_FOR_LAUNCH}" \] ; then%if ( ${?ENV_FOR_LAUNCH} ) then%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
385 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
386 sed -e 's%^\([[:blank:]]*\)fi\([[:blank:]]*\)$%\1endif\2%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
387 sed -e 's%var.sh%var.csh%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
388 sed -e 's%if \[ -e "\${LICENSE_FILE}" \] ; then%if ( -e ${LICENSE_FILE} ) then%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
389
390 cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/_$CSHRC 2>/dev/null
391
392 rm -f ${INSTALL_WORK}/_tmp1 ${INSTALL_WORK}/_tmp2
393
394 if [ $# -eq 5 ] ; then
395     product_dir=$5
396     if [ -e ${product_dir} ] ; then
397         test -e ${product_dir}/$SHRC && mv ${product_dir}/$SHRC ${product_dir}/${SHRC}_`date +%F_%T`
398         cp ${install_work}/_$SHRC  ${product_dir}/$SHRC
399         test -e ${product_dir}/$CSHRC && mv ${product_dir}/$CSHRC ${product_dir}/${CSHRC}_`date +%F_%T`
400         cp ${install_work}/_$CSHRC ${product_dir}/$CSHRC
401     fi
402 fi
403 sed -e 's%setenv ENV_FOR_LAUNCH 1%setenv ENV_FOR_LAUNCH 0%' ${install_work}/_$CSHRC > ${install_root}/env_build.csh
404 sed -e 's%export ENV_FOR_LAUNCH=1%export ENV_FOR_LAUNCH=0%' ${install_work}/_$SHRC  > ${install_root}/env_build.sh
405
406 cp -f ${install_work}/_$CSHRC ${install_root}/env_products.csh
407 cp -f ${install_work}/_$SHRC  ${install_root}/env_products.sh
408
409 rm -f ${install_work}/_$SHRC ${install_work}/_$CSHRC
410 ### !!! copying build.csh and build.sh scripts
411 if [ -e ./build.csh ]; then
412     cp -f ./build.csh ${install_root}
413 fi
414 if [ -e ./build.sh ]; then
415     cp -f ./build.sh ${install_root}
416 fi
417 ### !!! copying release notes
418 for p in `ls ../` ; do
419     export pdf=`echo ${p} | sed s/[.]/" "/g | awk '{print $2}'`
420     if [ "${pdf}" = "pdf" ]; then
421         export RN=$p
422         if [ ! -e ${install_root}/${RN} ]; then
423             cp -f ../${RN} ${install_root}
424         fi
425     fi
426 done
427
428 }
429
430 #try use already existing product
431 try_existing()
432 {
433 product_dir=$1;  install_root=$2;  install_work=$3;
434 product_sequence="$4"; installed_products="$5";  product_type=$6
435 env_file=${product_dir}/env_${product_type}.sh
436 if [ -f ${env_file} ] ; then
437     cp -f ${env_file} ${install_work}/_env_${product_type}.sh
438     make_env ${install_root} ${install_work} "${product_sequence}" "${installed_products}"
439     source ${install_work}/$SHRC
440     check_version
441     if [ $? -eq 0 ] ; then
442         return 0
443     fi
444 fi
445 echo ${product_type} | grep -q '_src$'
446 if [ $? -eq 1 ] ; then
447     print_env_bin
448 else
449     print_env_src
450 fi
451 return 0
452 }
453
454 #check existance of lib passed as first parameter
455 #return 0 if lib exists
456 #if you pass second parameter search will be done in it 
457 #otherwise search will be done in $LD_LIBRARY_PATH
458 #you should use : as dilimeter if you are going to pass second parameter
459 check_lib_version(){
460 if [ -n "$2" ]; then
461    whereIs=$2
462 else
463    whereIs=$LD_LIBRARY_PATH
464 fi
465 for L in `echo ${whereIs} | sed -e"s%:% %g"` ;  do
466     ret=`find $L -name $1 2>/dev/null`
467     if [ -n "$ret" ] ; then
468         #echo "The $1 exists on yours system in a $L folder"
469         return 0
470     fi
471 done
472 return 1
473 }
474
475 find_in_path(){
476 file=$1;  shift; 
477 path=$*
478 for i in `echo ${path} | sed -e"s%:% %g"` ; do 
479     ret=`find $i -name $file -maxdepth 1 2>/dev/null`
480     if [ -n "$ret" ] ; then
481         ret=`echo $ret | sed -e"s%/\$file$%%g"`
482         echo $ret
483         return 0
484     fi
485 done
486 return 1
487 }
488
489 sort_path(){
490 arg1=$1;  val1=$2;  arg2=$3;  val2=$4
491 tmp="^$val1$|^$val1:|:$val1$|:$val1:"
492 #echo $val2 | grep -E "$tmp" >/dev/null 2>&1
493 #if [ $? -eq 0 ] ; then 
494 #    echo "$arg2"
495 #    return
496 #fi
497 to_tail=1
498 exclude_list="usr lib bin sbin etc"
499 for i in ${exclude_list} ; do
500     tmp="^/$i/|^/$i\$"
501     echo ${val1} | grep -E "$tmp" >/dev/null 2>&1
502     if [ $? == 0 ] ; then to_tail=0; break; fi
503 done
504 if [ $to_tail -eq 0 ] ; then
505     echo $arg2:$arg1
506 else
507     echo $arg1:$arg2
508 fi
509 return $to_tail
510 }
511
512 where_gcc(){
513 maj_ver=`echo $1 | awk -F. '{if(NF>0) print $1; else print 0}'`
514 min_ver=`echo $1 | awk -F. '{if(NF>1) print $2; else print 0}'`
515 rel_ver=`echo $1 | awk -F. '{if(NF>2) print $3; else print 0}'`
516 let ver=$maj_ver*10000+$min_ver*100+$rel_ver
517 newer=""
518 newerver=0
519 for i in `echo ${PATH}:/usr/bin:/usr/local/bin | sed -e"s%:% %g"` ; do 
520     ret=`find $i -name gcc -maxdepth 1 2>/dev/null`
521     if [ -n "$ret" ] ; then
522         maj_ver=`$ret -dumpversion | awk -F. '{if(NF>0) print $1; else print 0}'`
523         min_ver=`$ret -dumpversion | awk -F. '{if(NF>1) print $2; else print 0}'`
524         rel_ver=`$ret -dumpversion | awk -F. '{if(NF>2) print $3; else print 0}'`
525         let ver1=$maj_ver*10000+$min_ver*100+$rel_ver
526         if [ $ver1 -eq $ver ] ; then
527             ret=`echo $ret | sed -e"s%/gcc$%%g"`
528             echo $ret
529             return 0
530         fi
531         if [ $ver1 -gt $ver ] && [ $ver1 -gt $newerver ] ; then
532             let newerver=$ver1
533             newer=`echo $ret | sed -e"s%/gcc$%%g"`
534         fi
535     fi
536 done
537 if [ -n "$newer" ] ; then
538     echo $newer
539     return 0
540 fi
541 return 1
542 }
543
544 where_tcl(){
545 if test -z "${TCLHOME}"; then
546     TCLHOME=/usr
547 fi
548 tclcfg=`find ${TCLHOME}/lib -name "tclConfig.sh" 2> /dev/null`
549 file=""
550 maxver=0
551 for f in $tclcfg; do
552     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;}'`
553     if [ $maxver -lt $ver ]; then
554         maxver=$ver
555         file=$f
556     fi
557 done
558 if test -n "$file"; then
559     echo `dirname $file`
560     return 0
561 else
562     echo ""
563     return 1
564 fi
565 }
566
567 where_tk(){
568 if test -z "${TCLHOME}"; then
569     TCLHOME=/usr
570 fi
571 tclcfg=`find ${TCLHOME}/lib -name "tkConfig.sh" 2> /dev/null`
572 file=""
573 maxver=0
574 for f in $tclcfg; do
575     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;}'`
576     if [ $maxver -lt $ver ]; then
577         maxver=$ver
578         file=$f
579     fi
580 done
581 if test -n "$file"; then
582     echo `dirname $file`
583     return 0
584 else
585     echo ""
586     return 1
587 fi
588 }
589
590 where_dps(){
591 if test -f /usr/X11R6/include/DPS/dpsconfig.h ; then
592     echo "/usr/X11R6"
593     return 0
594 fi
595 if test -f /usr/include/DPS/dpsconfig.h ; then
596     echo "/usr"
597     return 0
598 fi
599 echo ""
600 return 1
601 }
602
603 where_gl_includes(){
604 for d in /usr/X11R6/include /usr/include ; do
605     if [ -d ${d}/GL ] && [ -f ${d}/GL/gl.h ] ; then
606         echo "$d"
607         return 0
608     fi
609 done
610 echo ""
611 return 1
612 }
613
614 where_gl_libs(){
615 # search libGL.so* file and correct libGL.la in the same directory
616 for d in /usr/X11R6/lib64 /usr/lib64 /usr/X11R6/lib /usr/lib ; do
617     if [ "`ls ${d}/libGL.so* 2>/dev/null`" ] && [ -f ${d}/libGL.la ]; then
618         libdir=`grep "libdir=" ${d}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%" -e "s%/*$%%g"`
619         if [ "$libdir" == "$d" ] ; then
620             echo "$d"
621             return 0
622         fi
623     fi
624 done
625 # search libGL.la file and check if this file is correct
626 for d in /usr/X11R6/lib64 /usr/lib64 /usr/X11R6/lib /usr/lib ; do
627     if [ -f ${d}/libGL.la ] ; then
628         libdir=`grep "libdir=" ${d}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%"`
629         if [ "`ls $libdir/libGL.so* 2>/dev/null`" ] ; then
630             echo "$d"
631             return 0
632         fi
633     fi
634 done
635 # then search libGL.so* file
636 for d in /usr/X11R6/lib64 /usr/lib64 /usr/X11R6/lib /usr/lib ; do
637     if [ "`ls ${d}/libGL.so* 2>/dev/null`" ] ; then
638         echo "$d"
639         return 0
640     fi
641 done
642 echo ""
643 return 1
644 }
645
646 modif_la_files(){
647 ldir=$1
648 if [ -z "$ldir" ] || [ ! -d "$ldir" ]; then return 1; fi
649
650 srcdir=`pwd`
651
652 #SALOME_MODULES="`env | awk -F_ '/[[:alnum:]]*_ROOT_DIR/ { print $1 }'`"
653 SALOME_MODULES="`env | awk -F_ '/[a-zA-Z0-9]*_ROOT_DIR/ { print $1 }'`"
654
655 cd $ldir
656 ldir=`pwd`
657 la_files=`find . -name "*.la"`
658
659 for l in X ${la_files}; do
660 if [ "$l" != "X" ] ; then
661     d=`dirname $l`
662     l=`basename $l`
663     cd $ldir; cd $d
664     # 1. process salome modules dependencies
665
666     for mod in $SALOME_MODULES; do
667         moddir=`printenv ${mod}_ROOT_DIR`
668         if [ -n "${moddir}" ] ; then
669             #echo $l $mod $moddir
670 #           sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}[^[:space:]/]*/\(lib\|lib64\)% \1${moddir}/${myldir}%g" $l > $l"_"
671 #           sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}[^[:space:]/]*/lib% \1${moddir}/lib%g" $l > $l"_"
672             sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}[^[:space:]/]*/lib% \1${moddir}/lib%g" \
673                 -e "s%^libdir='[^[:space:]]*${mod}[^[:space:]]*/\(lib.*\)'%libdir='${moddir}/\1'%g" $l > $l"_"
674             mv -f $l"_" $l
675             for mod1 in $SALOME_MODULES; do
676                 sed     -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod1}[^[:space:]]*/${mod1}_build%%g" $l > $l"_"
677                 mv -f $l"_" $l
678             done
679         fi
680     done
681
682     # 2. process CAS.CADE dependencies
683     casdir=`printenv CASROOT`/lib
684     if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/Linux/lib ; fi
685     if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/lin/lib ; fi
686     if [ -n "${CASROOT}" ] && [ -d "${casdir}" ] ; then
687         # echo $l $CASROOT $casdir
688         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*\(OCT\|CAS\)[^[:space:]/]*/Linux/lib% \1${casdir}%g" \
689             -e "s%[[:space:]]\(-L\)\?[^[:space:]]*\(OCT\|CAS\)[^[:space:]/]*/lin/lib% \1${casdir}%g"   \
690             -e "s%[[:space:]]\(-L\)\?[^[:space:]]*\(OCT\|CAS\)[^[:space:]/]*/lib% \1${casdir}%g" $l > $l"_"
691         mv -f $l"_" $l
692     fi
693     # 3. process omniORB dependencies
694     omnidir=`printenv OMNIORBDIR`/lib/i586_linux_2.0_glibc2.1
695     if [ ! -d ${omnidir} ] ; then omnidir=`printenv OMNIORBDIR`/lib ; fi
696     if [ -n "${OMNIORBDIR}" ] && [ -d "${omnidir}" ] ; then
697         # echo $l $OMNIORBDIR $omnidir
698         sed -e "s%-L[^[:space:]]*omni[^[:space:]]*%-L${omnidir}%g" \
699             -e "s%-R[^[:space:]]*omni[^[:space:]]*%-R${omnidir}%g" $l > $l"_"
700         mv -f $l"_" $l
701     fi
702     # 4. process VTK dependencies
703     if test `uname -m` = "x86_64" ; then
704     vtkdir=`printenv VTKHOME`/lib64/vtk-5.0
705     vtkldir=`printenv VTKHOME`/lib64
706     else
707     vtkdir=`printenv VTKHOME`/lib/vtk-5.0
708     vtkldir=`printenv VTKHOME`/lib
709     fi
710     if [ -n "${VTKHOME}" ] && [ -d "${vtkdir}" ] && [ -d "${vtkldir}" ] ; then
711         # echo $l $VTKHOME $vtkdir
712         sed -e "s%-L[^[:space:]]*VTK[^[:space:]]*/\(lib\|lib64\)/vtk\-5\.0%-L${vtkdir}%g" \
713             -e "s%-L[^[:space:]]*VTK[^[:space:]]*/\(lib\|lib64\)%-L${vtkldir}%g" $l > $l"_"
714         mv -f $l"_" $l
715     fi
716     # 5. process HDF dependencies
717     hdfdir=`printenv HDF5HOME`/lib
718     if [ -n "${HDF5HOME}" ] && [ -d "${hdfdir}" ] ; then
719         # echo $l $HDF5HOME $hdfdir
720         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*hdf[^[:space:]/]*/lib% \1${hdfdir}%g" $l > $l"_"
721         mv -f $l"_" $l
722     fi
723     # 6. process MED dependencies
724     meddir=`printenv MED2HOME`/lib
725     if [ -n "${MED2HOME}" ] && [ -d "${meddir}" ] ; then
726         # echo $l $MED2HOME $meddir
727         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*med[^[:space:]/]*/lib% \1${meddir}%g" $l > $l"_"
728         mv -f $l"_" $l
729     fi
730     # 7. process qwt dependencies
731     qwtdir=`find_in_path libqwt.so ${LD_LIBRARY_PATH}`
732     if [ -n "${qwtdir}" ] && [ -d "${qwtdir}" ] ; then
733         # echo $l $qwtdir
734         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*qwt[^[:space:]/]*/lib% \1${qwtdir}%g" $l > $l"_"
735         mv -f $l"_" $l
736     fi
737     # 8. process qt dependencies
738     qtdir=`printenv QTDIR`/lib
739     if [ -n "${QTDIR}" ] && [ -d "${qtdir}" ] ; then
740         # echo $l $QTDIR $qtdir
741         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*qt[^[:space:]/]*/lib% \1${qtdir}%g" $l > $l"_"
742         mv -f $l"_" $l
743     fi
744     # 9. process python dependencies
745     where_python=`which python`                 # e.g. /usr/bin/python
746     if [ -n "$where_python" ] ; then
747         where_python=`dirname $where_python`    # --> /usr/bin
748         where_python=`dirname $where_python`    # --> /usr
749         python_version=`python -c "import sys; print sys.version[:3]"`
750         # echo $l $where_python $python_version
751         sed -e "s%-L[^[:space:]]*python[0-9]\.[0-9]\([^[:space:]]*\)%-L${where_python}/lib/python${python_version}\1%g" $l > $l"_"
752         mv -f $l"_" $l
753     fi
754     # 10. process sip dependencies
755     sipdir=`find_in_path sip.so ${LD_LIBRARY_PATH}`
756     if [ -n "${sipdir}" ] && [ -d "${sipdir}" ] ; then
757         # echo $l $sipdir
758         sed -e "s%-L[^[:space:]]*sip[^[:space:]]*%-L${sipdir}%g" $l > $l"_"
759         mv -f $l"_" $l
760     fi
761     # 11. process PyQt dependencies
762     pyqtdir=`find_in_path qt.so ${LD_LIBRARY_PATH}`
763     if [ -n "${pyqtdir}" ] && [ -d "${pyqtdir}" ] ; then
764         # echo $l $pyqtdir
765         sed -e "s%-L[^[:space:]]*PyQt[^[:space:]]*%-L${pyqtdir}%g" $l > $l"_"
766         mv -f $l"_" $l
767     fi
768     # 12. process tcl/tk dependencies
769     tcldir=`printenv TCLHOME`/lib
770     if [ -n "${tcldir}" ] && [ -d "${tcldir}" ] ; then
771         # echo $l $TCLHOME $tcldir
772         sed -e "s%-L[^[:space:]]*tcltk[^[:space:]]*/lib%-L${tcldir}%g" $l > $l"_"
773         mv -f $l"_" $l
774     fi
775     # 13. process boost dependencies
776     boostdir=`printenv BOOSTDIR`/lib
777     if [ -n "${boostdir}" ] && [ -d "${boostdir}" ] ; then
778         # echo $l $BOOSTDIR $boostdir
779         sed -e "s%-L[^[:space:]]*boost[^[:space:]]*/lib%-L${boostdir}%g" $l > $l"_"
780         mv -f $l"_" $l
781     fi
782
783     blsurfdir=`printenv BLSURFHOME`/lib
784     if [ -n "${blsurfdir}" ] && [ -d "${blsurfdir}" ] ; then
785         # echo $l $BOOSTDIR $boostdir
786         sed -e "s%-L[^[:space:]]*blsurf[^[:space:]]*/lib%-L${blsurfdir}%g" $l > $l"_"
787         mv -f $l"_" $l
788     fi
789
790 #    # 14. modify libdir
791 #    #sed -e "s%^libdir='\(.*\)'%libdir='${PRODUCT_DIR}/lib/salome'%g" $l > $l"_"
792 #    mod=`basename $ldir | awk -F_ '{print $1}'`
793 #    moddir=`printenv ${mod}_ROOT_DIR`
794 #    sed -e "s%^libdir='[^[:space:]]*${mod}[^[:space:]]*/\(lib.*\)'%libdir='${moddir}/\1'%g" $l > $l"_"
795 #    mv -f $l"_" $l
796
797     # 15. process libxml dependencies
798     libxmldir=`printenv LIBXML_DIR`/lib
799     if [ ! -d ${libxmldir} ] ; then libxmldir=`printenv  LIBXML_DIR`/lib ; fi
800     sed -e "s%\(.*\)\([[:space:]].*/lib/libxml2.la[[:space:]]\)\(.*\)%\1 ${libxmldir}/libxml2.la \3%g" \
801         -e "s%-L[^[:space:]]*libxml2[^[:space:]]*/lib%-L${libxmldir}%g" $l > $l"_"
802     mv -f $l"_" $l      
803
804     # 16. process metis dependencies
805     metisdir=`printenv METISDIR`
806     if [ ! -d ${metisdir} ] ; then metisdir=`printenv  METISDIR` ; fi
807     sed -e "s%-L[^[:space:]]*metis[^[:space:]]*%-L${metisdir}%g" $l > $l"_"
808     mv -f $l"_" $l      
809
810     # 17. process scotch dependencies
811     scotchdir=`printenv SCOTCHDIR`/bin
812     if [ ! -d ${scotchdir} ] ; then scotchdir=`printenv SCOTCHDIR`/bin ; fi
813     sed    -e "s%-L[^[:space:]]*scotch[^[:space:]]*/bin%-L${scotchdir}%g" $l > $l"_"
814     mv -f $l"_" $l      
815
816     # 18. process libGL.la dependencies
817     if test `uname -m` = "x86_64" ; then
818     libGLpath=/usr/lib64/libGL.la
819     else
820     libGLpath=/usr/lib/libGL.la
821     fi
822         sed -e "s%$libGLpath%""%g" $l > $l"_"
823         mv -f $l"_" $l
824
825     # 19. process graphviz dependencies
826     graphvizdir=`printenv GRAPHVIZHOME`
827     if [ -n "${graphvizdir}" ] && [ -d "${graphvizdir}" ] ; then
828         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*graphviz-[0-9]\+\.[0-9]\+\.[0-9]\+% \1${graphvizdir}%g" $l > $l"_"
829         chmod -f --reference=$l $l"_"
830         mv -f $l"_" $l  
831     fi
832
833 fi
834 done
835
836 cd $srcdir
837 return 0
838 }