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