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