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