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