Salome HOME
PAL14048: Fix linking problem on Mandriva 64-bit?
[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-2006 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 3 ] ; then
88     product_name=$3;
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 # 1. first dump all environment files into the $SHRC file
129 product_sequence="$2"
130 for i in $product_sequence ; do
131     env_file=${install_work}/env_${i}.sh
132     ( test -e $env_file && cat $env_file >> ${install_work}/$SHRC 2>/dev/null )
133 done
134
135 # 2. writing global functions to _salome.sh file
136 cat >> ${install_work}/_$SHRC <<EOF
137 ##########################################################################
138 # Functions exporta and exportp are used to append/prepend correspondingly 
139 # one directory or a set of directories separated by semicolon symbol (':')
140 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
141 # LD_RUN_PATH etc. 
142 # The main purpose is to replace default setenv command behavior:
143 # exporta, exportp also remove duplicated entries, shortening in that way
144 # the environment variables.
145 # If some directory being added is already included into the variable
146 # nothing is done for it.
147 # Note, that these functions work some slower that setenv command itself.
148 #
149 #### cleandup ###
150 # appends/prepends set of directories (second parameter) 
151 # to the another set of directories (first parameter) and
152 # removes duplicated entries;
153 # the third parameter defines the mode: 0 - append, 1 - prepend
154 cleandup() {
155 out_var=\`echo \$1 \$2 | awk -v dir=\$3 '{                   \\
156      na = split(\$2,a,":");                               \\
157      k1=0;                                               \\
158      bbb[k1++]="";                                       \\
159      ccc[""];                                            \\
160      if(\$1 != "<empty>") {                               \\
161        nb = split(\$1,b,":");                             \\
162        for(i=1;i<=nb;i++) {                              \\
163          if(!(b[i] in ccc) ) {                           \\
164            ccc[b[i]];                                    \\
165            bbb[k1++]=b[i];                               \\
166          };                                              \\
167        };                                                \\
168      };                                                  \\
169      k2=0;                                               \\
170      aaa[k2++]="";                                       \\
171      for(i=1;i<=na;i++) {                                \\
172        if(!(a[i] in ccc)) {                              \\
173          ccc[a[i]];                                      \\
174          aaa[k2++]=a[i];                                 \\
175        };                                                \\
176      };                                                  \\
177      ORS=":";                                            \\
178      if(dir) {                                           \\
179        for(i=1;i<k2;i++) {                               \\
180          print aaa[i];                                   \\
181        }                                                 \\
182        for(i=1;i<k1;i++) {                               \\
183          print bbb[i];                                   \\
184        }                                                 \\
185      }                                                   \\
186      else {                                              \\
187        for(i=1;i<k1;i++) {                               \\
188          print bbb[i];                                   \\
189        }                                                 \\
190        for(i=1;i<k2;i++) {                               \\
191          print aaa[i];                                   \\
192        }                                                 \\
193      }                                                   \\
194    }' | sed -e 's/\(.*\):/\1/g'\`
195 echo \$out_var
196 }
197 ### exporta ###
198 # appends directory or set of directories, separated by ':' (second parameter)
199 # to the variable (first parameter)
200 exporta () { 
201 xenv=\`printenv \$1\`
202 if [ -z "\$xenv" ]; then xenv="<empty>"; fi
203 out_var=\`cleandup \$xenv \$2 0\`
204 export \$1=\$out_var
205 }
206 ### exportp ###
207 # prepends directory or set of directories, separated by ':' (second parameter)
208 # to the variable (first parameter)
209 exportp () { 
210 xenv=\`printenv \$1\`
211 if [ -z "\$xenv" ]; then xenv="<empty>"; fi
212 out_var=\`cleandup \$xenv \$2 1\`
213 export \$1=\$out_var
214 }
215 ###########################################################################
216
217 EOF
218
219 # 3. writing global functions to _salome.csh file
220 cat >> ${install_work}/_$CSHRC <<EOF
221
222 ###########################################################################
223 # Aliases setenva and setenvp are used to append/prepend correspondingly 
224 # one directory or a set of directories separated by semicolon symbol (':')
225 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
226 # LD_RUN_PATH etc. 
227 # The main purpose is to replace default setenv command behavior:
228 # setenva, setenvp also remove duplicated entries, shortening in that way
229 # the environment variables.
230 # If some directory being added is already included into the variable
231 # nothing is done for it.
232 # Note, that these aliases work some slower that setenv command itself.
233 #
234 #### cleandup ###
235 # appends/prepends set of directories (second parameter) 
236 # to the another set of directories (first parameter) and
237 # removes duplicated entries;
238 # the third parameter defines the mode: 0 - append, 1 - prepend
239 alias cleandup "echo \!:1 \!:2 | awk -v dir=\!:3         \\\\
240 '"'{ na = split(\$2,a,":");                               \\\\
241      k1=0;                                               \\\\
242      bbb[k1++]="";                                       \\\\
243      ccc[""];                                            \\\\
244      if(\$1 != "<empty>") {                               \\\\
245        nb = split(\$1,b,":");                             \\\\
246        for(i=1;i<=nb;i++) {                              \\\\
247          if(!(b[i] in ccc) ) {                           \\\\
248            ccc[b[i]];                                    \\\\
249            bbb[k1++]=b[i];                               \\\\
250          };                                              \\\\
251        };                                                \\\\
252      };                                                  \\\\
253      k2=0;                                               \\\\
254      aaa[k2++]="";                                       \\\\
255      for(i=1;i<=na;i++) {                                \\\\
256        if(!(a[i] in ccc)) {                              \\\\
257          ccc[a[i]];                                      \\\\
258          aaa[k2++]=a[i];                                 \\\\
259        };                                                \\\\
260      };                                                  \\\\
261      ORS=":";                                            \\\\
262      if(dir) {                                           \\\\
263        for(i=1;i<k2;i++) {                               \\\\
264          print aaa[i];                                   \\\\
265        }                                                 \\\\
266        for(i=1;i<k1;i++) {                               \\\\
267          print bbb[i];                                   \\\\
268        }                                                 \\\\
269      }                                                   \\\\
270      else {                                              \\\\
271        for(i=1;i<k1;i++) {                               \\\\
272          print bbb[i];                                   \\\\
273        }                                                 \\\\
274        for(i=1;i<k2;i++) {                               \\\\
275          print aaa[i];                                   \\\\
276        }                                                 \\\\
277      }                                                   \\\\
278   }'"' | sed -e 's/\(.*\):/\1/g'"
279 ### setenva ###
280 # appends directory or set of directories, separated by ':' (second parameter)
281 # to the variable (first parameter)
282 alias setenva 'set a=\!:1 ; set b=\!:2 ;  \\
283                set c=\`printenv \$a\` ;      \\
284                set b=\`cleandup \$c \$b 0\` ; \\
285                setenv \$a \$b ;             \\
286                unset a, b, c'
287
288 ### setenvp ###
289 # prepends directory or set of directories, separated by ':' (second parameter)
290 # to the variable (first parameter)
291 alias setenvp 'set a=\!:1 ; set b=\!:2 ;  \\
292                set c=\`printenv \$a\` ;      \\
293                set b=\`cleandup \$c \$b 1\` ; \\
294                setenv \$a \$b ;             \\
295                unset a, b, c'
296 ###########################################################################
297
298 EOF
299 cat ${install_work}/$CSHRC >> ${install_work}/_$CSHRC
300
301 # 4. put the contents of salome.sh to _salome.sh replacing export by export(a|p) aliases where necessary
302 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
303 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
304 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
305 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
306
307 # Setting "/usr/X11R6/lib" path in LD_LIBRARY_PATH for the libGL.so.1 file
308 if test `uname -m` = "x86_64" ; then
309 echo '# Setting /usr/X11R6/lib64 path in LD_LIBRARY_PATH for the libGL.so.1 file' >> ${INSTALL_WORK}/_tmp2
310 echo 'export LD_LIBRARY_PATH=/usr/X11R6/lib64:/usr/lib64:${LD_LIBRARY_PATH}' >> ${INSTALL_WORK}/_tmp2
311 else
312 echo '# Setting /usr/X11R6/lib path in LD_LIBRARY_PATH for the libGL.so.1 file' >> ${INSTALL_WORK}/_tmp2
313 echo 'export LD_LIBRARY_PATH=/usr/X11R6/lib:${LD_LIBRARY_PATH}' >> ${INSTALL_WORK}/_tmp2
314 fi
315
316 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$SHRC
317
318 # 5. Create a salome.csh file from salome.sh by replacing export by setenv, etc.
319 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${install_work}/$SHRC > ${INSTALL_WORK}/_tmp1 2>/dev/null
320 cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/$CSHRC
321
322 # 6. Create a _salome.csh file from _salome.sh by replacing export by setenv, exporta by setenva, etc.
323 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
324 sed -e 's%exporta \([[:alnum:]_[:blank:]]*\)%setenva \1%g'  ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
325 sed -e 's%exportp \([[:alnum:]_[:blank:]]*\)%setenvp \1%g'  ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
326 sed -e 's%if \[ -n "\${ENV_FOR_LAUNCH}" \] ; then%if ( ${?ENV_FOR_LAUNCH} ) then%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
327 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
328 sed -e 's%^\([[:blank:]]*\)fi\([[:blank:]]*\)$%\1endif\2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
329 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$CSHRC 2>/dev/null
330
331 rm -f ${INSTALL_WORK}/_tmp1 ${INSTALL_WORK}/_tmp2
332
333 if [ $# -eq 4 ] ; then
334     product_dir=$4
335     if [ -e ${product_dir} ] ; then
336         cp -f ${install_work}/_$SHRC  ${product_dir}/$SHRC
337         cp -f ${install_work}/_$CSHRC ${product_dir}/$CSHRC
338     fi
339 fi
340 sed -e 's%setenv ENV_FOR_LAUNCH 1%setenv ENV_FOR_LAUNCH 0%' ${install_work}/_$CSHRC > ${install_root}/env_build.csh
341 sed -e 's%export ENV_FOR_LAUNCH=1%export ENV_FOR_LAUNCH=0%' ${install_work}/_$SHRC  > ${install_root}/env_build.sh
342
343 cp -f ${install_work}/_$CSHRC ${install_root}/env_products.csh
344 cp -f ${install_work}/_$SHRC  ${install_root}/env_products.sh
345
346 rm -f ${install_work}/_$SHRC ${install_work}/_$CSHRC
347 ### !!! copying build.csh and build.sh scripts
348 if [ -e ./build.csh ]; then
349     cp -f ./build.csh ${install_root}
350 fi
351 if [ -e ./build.sh ]; then
352     cp -f ./build.sh ${install_root}
353 fi
354 ### !!! copying release notes
355 for p in `ls ../` ; do
356     export pdf=`echo ${p} | sed s/[.]/" "/g | awk '{print $2}'`
357     if [ "${pdf}" = "pdf" ]; then
358         export RN=$p
359         if [ ! -e ${install_root}/${RN} ]; then
360             cp -f ../${RN} ${install_root}
361         fi
362     fi
363 done
364
365 }
366
367 #try use already existing product
368 try_existing()
369 {
370 product_dir=$1;  install_root=$2;  install_work=$3;  product_sequence="$4";  product_type=$5
371 env_file=${product_dir}/env_${product_type}.sh
372 if [ -f ${env_file} ] ; then
373     cp -f ${env_file} ${install_work}
374     make_env ${install_root} ${install_work} "${product_sequence}"
375     source ${install_work}/$SHRC
376     check_version
377     if [ $? -eq 0 ] ; then
378         if [ -d ${product_dir} ] && [ -w ${product_dir} ] ; then
379             #makedir ${product_dir}
380             print_env
381             return 0    
382         fi
383     else
384         rm -f ${install_work}/env_${product_type}.sh
385         make_env ${install_root} ${install_work} "${product_sequence}"
386     fi
387 fi
388 return 1;
389 }
390
391 #check existance of lib passed as first parameter
392 #return 0 if lib exists
393 #if you pass second parameter search will be done in it 
394 #otherwise search will be done in $LD_LIBRARY_PATH
395 #you should use : as dilimeter if you are going to pass second parameter
396 check_lib_version(){
397 if [ -n "$2" ]; then
398    whereIs=$2
399 else
400    whereIs=$LD_LIBRARY_PATH
401 fi
402 for L in `echo ${whereIs} | sed -e"s%:% %g"` ;  do
403     ret=`find $L -name $1 2>/dev/null`
404     if [ -n "$ret" ] ; then
405         #echo "The $1 exists on yours system in a $L folder"
406         return 0
407     fi
408 done
409 return 1
410 }
411
412 find_in_path(){
413 file=$1;  shift; 
414 path=$*
415 for i in `echo ${path} | sed -e"s%:% %g"` ; do 
416     ret=`find $i -name $file -maxdepth 1 2>/dev/null`
417     if [ -n "$ret" ] ; then
418         ret=`echo $ret | sed -e"s%/\$file$%%g"`
419         echo $ret
420         return 0
421     fi
422 done
423 return 1
424 }
425
426 sort_path(){
427 arg1=$1;  val1=$2;  arg2=$3;  val2=$4
428 tmp="^$val1$|^$val1:|:$val1$|:$val1:"
429 #echo $val2 | grep -E "$tmp" >/dev/null 2>&1
430 #if [ $? -eq 0 ] ; then 
431 #    echo "$arg2"
432 #    return
433 #fi
434 to_tail=1
435 exclude_list="usr lib bin sbin etc"
436 for i in ${exclude_list} ; do
437     tmp="^/$i/|^/$i\$"
438     echo ${val1} | grep -E "$tmp" >/dev/null 2>&1
439     if [ $? == 0 ] ; then to_tail=0; break; fi
440 done
441 if [ $to_tail -eq 0 ] ; then
442     echo $arg2:$arg1
443 else
444     echo $arg1:$arg2
445 fi
446 return $to_tail
447 }
448
449 where_gcc(){
450 maj_ver=`echo $1 | awk -F. '{if(NF>0) print $1; else print 0}'`
451 min_ver=`echo $1 | awk -F. '{if(NF>1) print $2; else print 0}'`
452 rel_ver=`echo $1 | awk -F. '{if(NF>2) print $3; else print 0}'`
453 let ver=$maj_ver*10000+$min_ver*100+$rel_ver
454 newer=""
455 newerver=0
456 for i in `echo ${PATH}:/usr/bin:/usr/local/bin | sed -e"s%:% %g"` ; do 
457     ret=`find $i -name gcc -maxdepth 1 2>/dev/null`
458     if [ -n "$ret" ] ; then
459         maj_ver=`$ret -dumpversion | awk -F. '{if(NF>0) print $1; else print 0}'`
460         min_ver=`$ret -dumpversion | awk -F. '{if(NF>1) print $2; else print 0}'`
461         rel_ver=`$ret -dumpversion | awk -F. '{if(NF>2) print $3; else print 0}'`
462         let ver1=$maj_ver*10000+$min_ver*100+$rel_ver
463         if [ $ver1 -eq $ver ] ; then
464             ret=`echo $ret | sed -e"s%/gcc$%%g"`
465             echo $ret
466             return 0
467         fi
468         if [ $ver1 -gt $ver ] && [ $ver1 -gt $newerver ] ; then
469             let newerver=$ver1
470             newer=`echo $ret | sed -e"s%/gcc$%%g"`
471         fi
472     fi
473 done
474 if [ -n "$newer" ] ; then
475     echo $newer
476     return 0
477 fi
478 return 1
479 }
480
481 where_tcl(){
482 if test -z "${TCLHOME}"; then
483     TCLHOME=/usr
484 fi
485 tclcfg=`find ${TCLHOME}/lib -name "tclConfig.sh" 2> /dev/null`
486 file=""
487 maxver=0
488 for f in $tclcfg; do
489     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;}'`
490     if [ $maxver -lt $ver ]; then
491         maxver=$ver
492         file=$f
493     fi
494 done
495 if test -n "$file"; then
496     echo `dirname $file`
497     return 0
498 else
499     echo ""
500     return 1
501 fi
502 }
503
504 where_tk(){
505 if test -z "${TCLHOME}"; then
506     TCLHOME=/usr
507 fi
508 tclcfg=`find ${TCLHOME}/lib -name "tkConfig.sh" 2> /dev/null`
509 file=""
510 maxver=0
511 for f in $tclcfg; do
512     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;}'`
513     if [ $maxver -lt $ver ]; then
514         maxver=$ver
515         file=$f
516     fi
517 done
518 if test -n "$file"; then
519     echo `dirname $file`
520     return 0
521 else
522     echo ""
523     return 1
524 fi
525 }
526
527 where_dps(){
528 if test -f /usr/X11R6/include/DPS/dpsconfig.h ; then
529     echo "/usr/X11R6"
530     return 0
531 fi
532 if test -f /usr/include/DPS/dpsconfig.h ; then
533     echo "/usr"
534     return 0
535 fi
536 echo ""
537 return 1
538 }
539
540 where_gl_includes(){
541 for d in /usr/X11R6/include /usr/include ; do
542     if [ -d ${d}/GL ] && [ -f ${d}/GL/gl.h ] ; then
543         echo "$d"
544         return 0
545     fi
546 done
547 echo ""
548 return 1
549 }
550
551 where_gl_libs(){
552 # first search libGL.la file and check if this file is correct
553 for d in /usr/X11R6/lib64 /usr/lib64 /usr/X11R6/lib /usr/lib ; do
554     if [ -f ${d}/libGL.la ] ; then
555         libdir=`grep "libdir=" ${d}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%"`
556         if [ "`ls $libdir/libGL.so* 2>/dev/null`" ] ; then
557             echo "$d"
558             return 0
559         fi
560     fi
561 done
562 # then search libGL.so* file
563 for d in /usr/X11R6/lib64 /usr/lib64 /usr/X11R6/lib /usr/lib ; do
564     if [ "`ls ${d}/libGL.so* 2>/dev/null`" ] ; then
565         echo "$d"
566         return 0
567     fi
568 done
569 echo ""
570 return 1
571 }
572
573 modif_la_files(){
574 ldir=$1
575 if [ -z "$ldir" ] || [ ! -d "$ldir" ]; then return 1; fi
576
577 srcdir=`pwd`
578
579 SALOME_MODULES="`env | awk -F_ '/[[:alnum:]]*_ROOT_DIR/ { print $1 }'`"
580
581 cd $ldir
582 ldir=`pwd`
583 la_files=`find . -name "*.la"`
584
585 for l in X ${la_files}; do
586 if [ "$l" != "X" ] ; then
587     d=`dirname $l`
588     l=`basename $l`
589     cd $ldir; cd $d
590     # 1. process salome modules dependencies
591     for mod in $SALOME_MODULES; do
592         moddir=`printenv ${mod}_ROOT_DIR`
593         if [ -n "${moddir}" ] ; then
594             #echo $l $mod $moddir
595             sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}[^[:space:]/]*/lib% \1${moddir}/lib%g" $l > $l"_"
596             mv -f $l"_" $l
597         fi
598     done
599     # 2. process CAS.CADE dependencies
600     casdir=`printenv CASROOT`/lib
601     if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/Linux/lib ; fi
602     if [ ! -d ${casdir} ] ; then casdir=`printenv CASROOT`/lin/lib ; fi
603     if [ -n "${CASROOT}" ] && [ -d "${casdir}" ] ; then
604         # echo $l $CASROOT $casdir
605         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*\(OCT\|CAS\)[^[:space:]/]*/Linux/lib% \1${casdir}%g" \
606             -e "s%[[:space:]]\(-L\)\?[^[:space:]]*\(OCT\|CAS\)[^[:space:]/]*/lin/lib% \1${casdir}%g"   \
607             -e "s%[[:space:]]\(-L\)\?[^[:space:]]*\(OCT\|CAS\)[^[:space:]/]*/lib% \1${casdir}%g" $l > $l"_"
608         mv -f $l"_" $l
609     fi
610     # 3. process omniORB dependencies
611     omnidir=`printenv OMNIORBDIR`/lib/i586_linux_2.0_glibc2.1
612     if [ ! -d ${omnidir} ] ; then omnidir=`printenv OMNIORBDIR`/lib ; fi
613     if [ -n "${OMNIORBDIR}" ] && [ -d "${omnidir}" ] ; then
614         # echo $l $OMNIORBDIR $omnidir
615         sed -e "s%-L[^[:space:]]*omni[^[:space:]]*%-L${omnidir}%g" $l > $l"_"
616         mv -f $l"_" $l
617     fi
618     # 4. process VTK dependencies
619     vtkdir=`printenv VTKHOME`/lib/vtk
620     if [ -n "${VTKHOME}" ] && [ -d "${vtkdir}" ] ; then
621         # echo $l $VTKHOME $vtkdir
622         sed -e "s%-L[^[:space:]]*VTK[^[:space:]]*/lib/vtk%-L${vtkdir}%g" $l > $l"_"
623         mv -f $l"_" $l
624     fi
625     # 5. process HDF dependencies
626     hdfdir=`printenv HDF5HOME`/lib
627     if [ -n "${HDF5HOME}" ] && [ -d "${hdfdir}" ] ; then
628         # echo $l $HDF5HOME $hdfdir
629         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*hdf[^[:space:]/]*/lib% \1${hdfdir}%g" $l > $l"_"
630         mv -f $l"_" $l
631     fi
632     # 6. process MED dependencies
633     meddir=`printenv MED2HOME`/lib
634     if [ -n "${MED2HOME}" ] && [ -d "${meddir}" ] ; then
635         # echo $l $MED2HOME $meddir
636         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*med[^[:space:]/]*/lib% \1${meddir}%g" $l > $l"_"
637         mv -f $l"_" $l
638     fi
639     # 7. process qwt dependencies
640     qwtdir=`find_in_path libqwt.so ${LD_LIBRARY_PATH}`
641     if [ -n "${qwtdir}" ] && [ -d "${qwtdir}" ] ; then
642         # echo $l $qwtdir
643         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*qwt[^[:space:]/]*/lib% \1${qwtdir}%g" $l > $l"_"
644         mv -f $l"_" $l
645     fi
646     # 8. process qt dependencies
647     qtdir=`printenv QTDIR`/lib
648     if [ -n "${QTDIR}" ] && [ -d "${qtdir}" ] ; then
649         # echo $l $QTDIR $qtdir
650         sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*qt[^[:space:]/]*/lib% \1${qtdir}%g" $l > $l"_"
651         mv -f $l"_" $l
652     fi
653     # 9. process python dependencies
654     where_python=`which python`                 # e.g. /usr/bin/python
655     if [ -n "$where_python" ] ; then
656         where_python=`dirname $where_python`    # --> /usr/bin
657         where_python=`dirname $where_python`    # --> /usr
658         python_version=`python -c "import sys; print sys.version[:3]"`
659         # echo $l $where_python $python_version
660         sed -e "s%-L[^[:space:]]*python[0-9]\.[0-9]\([^[:space:]]*\)%-L${where_python}/lib/python${python_version}\1%g" $l > $l"_"
661         mv -f $l"_" $l
662     fi
663     # 10. process sip dependencies
664     sipdir=`find_in_path sip.so ${LD_LIBRARY_PATH}`
665     if [ -n "${sipdir}" ] && [ -d "${sipdir}" ] ; then
666         # echo $l $sipdir
667         sed -e "s%-L[^[:space:]]*sip[^[:space:]]*%-L${sipdir}%g" $l > $l"_"
668         mv -f $l"_" $l
669     fi
670     # 11. process PyQt dependencies
671     pyqtdir=`find_in_path qt.so ${LD_LIBRARY_PATH}`
672     if [ -n "${pyqtdir}" ] && [ -d "${pyqtdir}" ] ; then
673         # echo $l $pyqtdir
674         sed -e "s%-L[^[:space:]]*PyQt[^[:space:]]*%-L${pyqtdir}%g" $l > $l"_"
675         mv -f $l"_" $l
676     fi
677     # 12. process tcl/tk dependencies
678     tcldir=`printenv TCLHOME`/lib
679     if [ -n "${tcldir}" ] && [ -d "${tcldir}" ] ; then
680         # echo $l $TCLHOME $tcldir
681         sed -e "s%-L[^[:space:]]*tcltk[^[:space:]]*/lib%-L${tcldir}%g" $l > $l"_"
682         mv -f $l"_" $l
683     fi
684     # 13. process boost dependencies
685     boostdir=`printenv BOOSTDIR`/lib
686     if [ -n "${boostdir}" ] && [ -d "${boostdir}" ] ; then
687         # echo $l $BOOSTDIR $boostdir
688         sed -e "s%-L[^[:space:]]*boost[^[:space:]]*/lib%-L${boostdir}%g" $l > $l"_"
689         mv -f $l"_" $l
690     fi
691     # 14. modify libdir
692     #sed -e "s%^libdir='\(.*\)'%libdir='${PRODUCT_DIR}/lib/salome'%g" $l > $l"_"
693     mod=`basename $ldir | awk -F_ '{print $1}'`
694     moddir=`printenv ${mod}_ROOT_DIR`
695     sed -e "s%^libdir='[^[:space:]]*${mod}[^[:space:]]*/\(lib.*\)'%libdir='${moddir}/\1'%g" $l > $l"_"
696     mv -f $l"_" $l
697 fi
698 done
699
700 cd $srcdir
701 return 0
702 }