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