Salome HOME
Update SALOME version
[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="7.0.0"
23 export YACSGEN_VERSION="7.0.0"
24 export JOBMANAGER_VERSION="7.0.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 # netgen dir
674 netgendir=`printenv NETGENHOME`
675 # freetype dir
676 freetypedir=`printenv FREETYPEDIR`
677 # ftgl dir
678 ftgldir=`printenv FTGLDIR`
679 # gl2ps dir
680 gl2psdir=`printenv GL2PSHOME`
681 # freeimage dir
682 freeimagedir=`printenv FREEIMAGEDIR`
683 # tbb dir
684 tbbbasedir=`printenv TBBHOME`
685 TBBKERNEL='cc4.1.0_libc2.4_kernel2.6.16.21'
686 if test `uname -m` = "x86_64" ; then
687     export TBBMODE="intel64/$TBBKERNEL"
688 else
689     export TBBMODE="ia32/$TBBKERNEL"
690 fi
691 tbbdir=${tbbbasedir}/lib/$TBBMODE
692 # cgns dir
693 cgnslibdir=`printenv CGNSHOME`
694 # occt dir
695 casdir=`printenv CASROOT`/lib
696 if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/Linux/lib ; fi
697 if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/lin/lib ; fi
698 # omniorb dir
699 omnidir=`printenv OMNIORBDIR`/lib
700 # vtk dir
701 vtkpath=`printenv VTKHOME`
702 if [ `uname -m` = "x86_64" ] && [ -d ${vtkpath}/lib64 ] ; then
703     LIB_PREFIX=64
704 elif [ -d ${vtkpath}/lib ] ; then
705     LIB_PREFIX=""
706 else
707     LIB_PREFIX=64
708 fi
709 vtkldir=${vtkpath}/lib${LIB_PREFIX}
710 vtkdir=${vtkldir}/vtk-5.0
711 # hdf dir
712 hdfdir=`printenv HDF5HOME`/lib
713 # med dir
714 meddir=`printenv MED3HOME`/lib
715 # qwt dir
716 qwtdir=`find_in_path libqwt.so ${LD_LIBRARY_PATH}`
717 # python dir
718 where_python=`which python`                 # e.g. /usr/bin/python
719 if [ -n "$where_python" ] ; then
720     where_python=`dirname $where_python`    # --> /usr/bin
721     where_python=`dirname $where_python`    # --> /usr
722     python_version=`python -c "import sys; print sys.version[:3]"`
723     pythondir=${where_python}/lib/python${python_version}
724 fi
725 # sip dir
726 sipdir=`find_in_path sip.so ${LD_LIBRARY_PATH}`
727 # pyqt dir
728 pyqtdir=`find_in_path Qt.so ${LD_LIBRARY_PATH}`
729 # tcl/tk dir
730 tcldir=`printenv TCLHOME`/lib
731 # boost dir
732 boostdir=`printenv BOOSTDIR`/lib
733 # blsurf dir
734 blsurfdir=`printenv BLSURFHOME`/lib
735 # libxml2 dir
736 libxmldir=`printenv LIBXML_DIR`/lib
737 # metis dir
738 metisdir=`printenv METISDIR`
739 # scotch dir
740 scotchbindir=`printenv SCOTCHDIR`/bin
741 scotchlibdir=`printenv SCOTCHDIR`/lib
742 # gl dir
743 if test `uname -m` = "x86_64" ; then
744     libGLpath=/usr/lib64/libGL.la
745 else
746     libGLpath=/usr/lib/libGL.la
747 fi
748 # graphviz dir
749 graphvizdir=`printenv GRAPHVIZHOME`/lib
750 # qscintilla dir
751 qscintilladir=`printenv QSCINTILLA_DIR`/lib
752 # expat dir
753 expatdir=${EXPAT_ROOT}/lib
754 # paraview dir
755 paraviewdir=`printenv PVHOME`/lib
756 # qt dir
757 qtdir=`printenv QTDIR`/lib
758
759 for l in X ${la_files}; do
760
761 if [ "$l" != "X" ] ; then
762     d=`dirname $l`
763     l=`basename $l`
764     cd $ldir; cd $d
765
766     # . process salome modules dependencies
767     for mod in $SALOME_MODULES; do
768         moddir=`printenv ${mod}_ROOT_DIR`
769         if [ -n "${moddir}" ] ; then
770             sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}[1]\?/lib% \1${moddir}/lib%g" \
771                 -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}WOGUI[1]\?/lib% \1${moddir}/lib%g" \
772                 -e "s%^libdir='[^[:space:]]*${mod}[1]\?/\(lib.*\)'%libdir='${moddir}/\1'%g" \
773                 -e "s%^libdir='[^[:space:]]*${mod}WOGUI[1]\?/\(lib.*\)'%libdir='${moddir}/\1'%g" $l > $l"_"
774             mv -f $l"_" $l
775         fi
776     done
777
778     # . process netgen dependencies
779     if [ -n "${netgendir}" ] && [ -d "${netgendir}" ] ; then
780         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*netgen-[0-9.]\+/lib% \1${netgendir}/lib%g" $l
781     fi
782
783     # . process freetype dependencies
784     if [ -n "${freetypedir}" ] && [ -d "${freetypedir}" ] ; then
785         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*freetype-[0-9.]\+/lib% \1${freetypedir}/lib%g" $l
786     fi
787
788     # . process ftgl dependencies
789     if [ -n "${ftgldir}" ] && [ -d "${ftgldir}" ] ; then
790         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*ftgl-[0-9.]\+/lib% \1${ftgldir}/lib%g" $l
791     fi
792
793     # . process gl2ps dependencies
794     if [ -n "${gl2psdir}" ] && [ -d "${gl2psdir}" ] ; then
795         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*gl2ps-[0-9.]\+/lib% \1${gl2psdir}/lib%g" $l
796     fi
797     
798     # . process freeimage dependencies
799     if [ -n "${freeimagedir}" ] && [ -d "${freeimagedir}" ] ; then
800         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*freeimage-[0-9.]\+/lib% \1${freeimagedir}/lib%g" $l
801     fi
802
803     # . process tbb dependencies
804     if [ -n "${tbbdir}" ] && [ -d "${tbbdir}" ] ; then
805         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*tbb[^[:space:]]*/lib[^[:space:]]*% \1${tbbdir}%g" $l
806     fi
807     
808     # . process cgns dependencies
809     if [ -n "${cgnslibdir}" ] && [ -d "${cgnslibdir}" ] ; then
810         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*cgnslib-[0-9.]\+/lib% \1${cgnslibdir}/lib%g" $l
811     fi
812
813     # . process CAS.CADE dependencies
814     if [ -n "${CASROOT}" ] && [ -d "${casdir}" ] ; then
815         sed -e "s%-L[^[:space:]]*OCCT[^[:space:]]*/install/lib%-L${casdir}%g" \
816             -e "s%[^[:space:]]*OCCT[^[:space:]]*/install/lib/%${casdir}/%g"   \
817             -e "s%[[:space:]]-L[^[:space:]]*\(OCCT\|CAS\)[^[:space:]]*/lib\?% -L${CASROOT}/lib%g" \
818             -e "s%[[:space:]][^[:space:]]*\(OCCT\|CAS\)[^[:space:]]*/lib/lib\?% ${CASROOT}/lib/lib%g" $l > $l"_"
819         mv -f $l"_" $l
820     fi
821
822     # . process omniORB dependencies
823     if [ -n "${OMNIORBDIR}" ] && [ -d "${omnidir}" ] ; then
824         sed -i "s%-L[^[:space:]]*omni[^[:space:]]*%-L${omnidir}%g;s%-R[^[:space:]]*omni[^[:space:]]*%-R${omnidir}%g" $l
825     fi
826
827     # . process VTK dependencies
828     if [ -n "${VTKHOME}" ] && [ -d "${vtkdir}" ] && [ -d "${vtkldir}" ] ; then
829         sed -i "s%-L[^[:space:]]*VTK[^[:space:]]*/\(lib\|lib64\)/vtk\-5\.0%-L${vtkdir}%g;s%-L[^[:space:]]*VTK[^[:space:]]*/\(lib\|lib64\)%-L${vtkldir}%g" $l
830     fi
831
832     # . process HDF dependencies
833     if [ -n "${HDF5HOME}" ] && [ -d "${hdfdir}" ] ; then
834         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*hdf[^[:space:]/]*/lib% \1${hdfdir}%g" $l
835     fi
836
837     # . process MED dependencies
838     if [ -n "${MED3HOME}" ] && [ -d "${meddir}" ] ; then
839         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*med[^[:space:]/]*/lib% \1${meddir}%g" $l
840     fi
841
842     # . process qwt dependencies
843     if [ -n "${qwtdir}" ] && [ -d "${qwtdir}" ] ; then
844         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*qwt[^[:space:]/]*/lib% \1${qwtdir}%g" $l
845     fi
846
847     # . process qt dependencies
848     if [ -n "${QTDIR}" ] && [ -d "${qtdir}" ] ; then
849         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*qt[^[:space:]/]*/lib% \1${qtdir}%g" $l
850     fi
851
852     # . process python dependencies
853     if [ -n "${pythondir}" ] && [ -d "${pythondir}" ] ; then
854         sed -i "s%-L[^[:space:]]*python[0-9]\.[0-9]\([^[:space:]]*\)%-L${pythondir}\1%g" $l
855     fi
856
857     # . process sip dependencies
858     if [ -n "${sipdir}" ] && [ -d "${sipdir}" ] ; then
859         sed -i "s%-L[^[:space:]]*sip[^[:space:]]*%-L${sipdir}%g" $l
860     fi
861
862     # . process PyQt dependencies
863     if [ -n "${pyqtdir}" ] && [ -d "${pyqtdir}" ] ; then
864         sed -i "s%-L[^[:space:]]*PyQt[^[:space:]]*%-L${pyqtdir}%g" $l
865     fi
866
867     # . process tcl/tk dependencies
868     if [ -n "${tcldir}" ] && [ -d "${tcldir}" ] ; then
869         sed -i "s%-L[^[:space:]]*tcltk[^[:space:]]*/lib%-L${tcldir}%g" $l
870     fi
871
872     # . process boost dependencies
873     if [ -n "${boostdir}" ] && [ -d "${boostdir}" ] ; then
874         sed -i "s%-L[^[:space:]]*boost[^[:space:]]*/lib%-L${boostdir}%g" $l
875     fi
876
877     # . process blsurf dependencies
878     if [ -n "${blsurfdir}" ] && [ -d "${blsurfdir}" ] ; then
879         sed -i "s%-L[^[:space:]]*BLSurf[^[:space:]]*/lib%-L${blsurfdir}%g" $l
880     fi
881
882     # . process libxml dependencies
883     if [ -n "${libxmldir}" ] && [ -d "${libxmldir}" ] ; then
884         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*libxml2-[0-9]\.[0-9]\.[0-9]/lib% \1${libxmldir}%g;s%[[:space:]]\(-L\)\?[^[:space:]]*libxml2/lib% \1${libxmldir}%g" $l
885     fi
886
887     # . process metis dependencies
888     if [ -n "${metisdir}" ] && [ -d "${metisdir}" ] ; then
889         sed -i "s%-L[^[:space:]]*metis[^[:space:]]*%-L${metisdir}%g" $l
890     fi
891
892     # . process scotch dependencies
893     if [ -n "${scotchbindir}" ] && [ -d "${scotchbindir}" ] ; then
894         sed -i "s%-L[^[:space:]]*scotch[^[:space:]]*/bin%-L${scotchbindir}%g" $l
895     fi
896     if [ -n "${scotchlibdir}" ] && [ -d "${scotchlibdir}" ] ; then
897         sed -i "s%-L[^[:space:]]*scotch[^[:space:]]*/lib%-L${scotchlibdir}%g" $l
898     fi
899
900     # . process libGL.la dependencies
901     sed -i "s%$libGLpath%""%g" $l
902
903     # . process graphviz dependencies
904     if [ -n "${graphvizdir}" ] && [ -d "${graphvizdir}" ] ; then
905         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*graphviz-[0-9]\.[0-9]\+\.[0-9]/lib% \1${graphvizdir}%g;s%[[:space:]]\(-L\)\?[^[:space:]]*graphviz/lib% \1${graphvizdir}%g" $l
906     fi
907
908     # . process QScintilla dependencies
909     if [ -n "${qscintilladir}" ] && [ -d "${qscintilladir}" ] ; then
910         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*QScintilla-[0-9]\.[0-9]\(\.[0-9]\)\?/lib% \1${qscintilladir}%g" $l
911     fi
912
913     # . process expat-2.0.1 dependencies
914     if [ -n "${expatdir}" ] && [ -d "${expatdir}" ] ; then
915         sed -i "s%-L[^[:space:]]*expat[^[:space:]]*/lib%-L${expatdir}%g;s%[^[:space:]]*expat[^[:space:]]*/lib/libexpat.la%-lexpat%g" $l
916     fi
917
918     # . process ParaView dependencies
919     if [ -n "${paraviewdir}" ] && [ -d "${paraviewdir}" ] ; then
920         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*ParaView-[0-9]\.[0-9]\+\.[0-9]/lib% \1${paraviewdir}%g" $l
921     fi
922     
923 fi
924 done
925
926 cd $srcdir
927 return 0
928 }