]> SALOME platform Git repositories - tools/install.git/blob - config_files/common.sh
Salome HOME
Prepare SALOME 7.3.0
[tools/install.git] / config_files / common.sh
1 #!/bin/bash -noprofile
2
3 ####################################################################################
4 #  File      : common.sh
5 #  Created   : Thu Dec 18 12:01:00 2002
6 #  Author    : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
7 #  Project   : SALOME
8 #  Module    : Installation Wizard
9 #  Copyright : 2002-2013 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.2.0"
23 export YACSGEN_VERSION="7.2.0"
24 export JOBMANAGER_VERSION="7.2.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=${!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=\${!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=\${!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 ] && [ ! -e ${install_root}/build.csh ]; then
427     cp -f ./build.csh ${install_root}
428 fi
429 if [ -e ./build.sh ] && [ ! -e ${install_root}/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 d in `echo ${whereIs} | sed -e"s%:% %g"` ;  do
481     ret=`find ${d} -name $1 2>/dev/null`
482     if [ -n "${ret}" ] ; then
483         #echo "The $1 exists on yours system in a ${d} 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 local d
631 local libdir
632 # search libGL.so* file and correct libGL.la in the same directory
633 for d in /usr/X11R6/lib64 /usr/lib64 /usr/X11R6/lib /usr/lib ; do
634     if [ "`ls ${d}/libGL.so* 2>/dev/null`" ] && [ -f ${d}/libGL.la ]; then
635         libdir=`grep "libdir=" ${d}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%" -e "s%/*$%%g"`
636         if [ "${libdir}" = "${d}" ] ; then
637             echo "${d}"
638             return 0
639         fi
640     fi
641 done
642 # search libGL.la file and check if this file is correct
643 for d in /usr/X11R6/lib64 /usr/lib64 /usr/X11R6/lib /usr/lib ; do
644     if [ -f ${d}/libGL.la ] ; then
645         libdir=`grep "libdir=" ${d}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%"`
646         if [ "`ls ${libdir}/libGL.so* 2>/dev/null`" ] ; then
647             echo "${d}"
648             return 0
649         fi
650     fi
651 done
652 # then search libGL.so* file
653 for d in /usr/X11R6/lib64 /usr/lib64 /usr/X11R6/lib /usr/lib ; do
654     if [ "`ls ${d}/libGL.so* 2>/dev/null`" ] ; then
655         echo "${d}"
656         return 0
657     fi
658 done
659 echo ""
660 return 1
661 }
662
663 fix_gl_libs(){
664     local gllibdir="`where_gl_libs`"
665     if [ "${gllibdir}" != "" ] ; then
666 #VSR: 02/04/2013 - next block is commented as it seems to be wrong :( libGL.la should not be ever mentioned
667 #       if [ -f ${gllibdir}/libGL.la ] ; then
668 #           libdir=`grep "libdir=" ${gllibdir}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%"`
669 #           if [ "`ls ${libdir}/libGL.so* 2>/dev/null`" ] ; then
670 #               str_to_replace="${gllibdir}/libGL.la"
671 #           fi
672 #       fi
673         if [ "${str_to_replace}" = "" ] ; then
674             str_to_replace="-L${gllibdir} -lGL"
675         fi
676         
677         la_files=`find . -name "*.la"`
678         for la_file in ${la_files} XXX ; do
679             if [ "${la_file}" = "XXX" ] ; then continue; fi
680             grep -e "libGL.la" ${la_file} >& /dev/null || grep -e "-lGL\b" ${la_file} >& /dev/null && \
681             sed -e "s%-lGL\b%%g"                                                       \
682                 -e "s%[^[:space:]']*libGL.la[[:space:]]%%g"                            \
683                 -e "s%^dependency_libs='\(.*\)%dependency_libs='${str_to_replace} \1%" \
684                 ${la_file} > ${la_file}.new && \
685                 mv -f ${la_file}.new ${la_file}
686         done
687     fi
688 }
689
690 modif_la_files(){
691 ldir=$1
692 if [ -z "${ldir}" ] || [ ! -d "${ldir}" ]; then return 1; fi
693
694 srcdir=`pwd`
695
696 SALOME_MODULES="`env | awk -F_ '/[a-zA-Z0-9]*_ROOT_DIR/ { print $1 }'`"
697
698 cd ${ldir}
699 ldir=`pwd`
700 la_files=`find . -name "*.la"`
701
702 # netgen dir
703 netgendir=${NETGEN_ROOT_DIR}
704 # freetype dir
705 freetypedir=${FREETYPE_ROOT_DIR}
706 # ftgl dir
707 ftgldir=${FTGL_ROOT_DIR}
708 # gl2ps dir
709 gl2psdir=${GL2PS_ROOT_DIR}
710 # freeimage dir
711 freeimagedir=${FREEIMAGE_ROOT_DIR}
712 # tbb dir
713 tbbbasedir=${TBB_ROOT_DIR}
714 TBBKERNEL='cc4.1.0_libc2.4_kernel2.6.16.21'
715 if test `uname -m` = "x86_64" ; then
716     export TBBMODE="intel64/${TBBKERNEL}"
717 else
718     export TBBMODE="ia32/${TBBKERNEL}"
719 fi
720 tbbdir=${tbbbasedir}/lib/${TBBMODE}
721 # cgns dir
722 cgnslibdir=${CGNS_ROOT_DIR}
723 # occt dir
724 casdir=${CAS_ROOT_DIR}/lib
725 if [ ! -d ${casdir} ] ; then casdir=${CAS_ROOT_DIR}/Linux/lib ; fi
726 if [ ! -d ${casdir} ] ; then casdir=${CAS_ROOT_DIR}/lin/lib ; fi
727 # omniorb dir
728 omnidir=${OMNIORB_ROOT_DIR}/lib
729 # vtk dir
730 vtkpath=${VTK_DIR}
731 if [ `uname -m` = "x86_64" ] && [ -d ${vtkpath}/lib64 ] ; then
732     LIB_PREFIX=64
733 elif [ -d ${vtkpath}/lib ] ; then
734     LIB_PREFIX=""
735 else
736     LIB_PREFIX=64
737 fi
738 vtkldir=${vtkpath}/lib${LIB_PREFIX}
739 vtkdir=${vtkldir}/vtk-5.0
740 # hdf dir
741 hdfdir=${HDF5_ROOT_DIR}/lib
742 # med dir
743 meddir=${MEDFILE_ROOT_DIR}/lib
744 # qwt dir
745 qwtdir=`find_in_path libqwt.so ${LD_LIBRARY_PATH}`
746 # python dir
747 where_python=`which python`                 # e.g. /usr/bin/python
748 if [ -n "${where_python}" ] ; then
749     where_python=`dirname ${where_python}`    # --> /usr/bin
750     where_python=`dirname ${where_python}`    # --> /usr
751     python_version=`python -c "import sys; print sys.version[:3]"`
752     pythondir=${where_python}/lib/python${python_version}
753 fi
754 # sip dir
755 sipdir=`find_in_path sip.so ${LD_LIBRARY_PATH}`
756 # pyqt dir
757 pyqtdir=`find_in_path Qt.so ${LD_LIBRARY_PATH}`
758 # tcl/tk dir
759 tcldir=${TCLHOME}/lib
760 # boost dir
761 boostdir=${BOOST_ROOT_DIR}/lib
762 # blsurf dir
763 blsurfdir=${BLSURFHOME}/lib
764 # libxml2 dir
765 libxmldir=${LIBXML2_ROOT_DIR}/lib
766 # metis dir
767 metisdir=${METIS_ROOT_DIR}
768 # scotch dir
769 scotchbindir=${SCOTCH_ROOT_DIR}/bin
770 scotchlibdir=${SCOTCH_ROOT_DIR}/lib
771 # gl dir
772 if test `uname -m` = "x86_64" ; then
773     libGLpath=/usr/lib64/libGL.la
774 else
775     libGLpath=/usr/lib/libGL.la
776 fi
777 # graphviz dir
778 graphvizdir=${GRAPHVIZ_ROOT_DIR}/lib
779 # qscintilla dir
780 qscintilladir=${QSCINTILLA_ROOT_DIR}/lib
781 # expat dir
782 expatdir=${EXPAT_ROOT_DIR}/lib
783 # paraview dir
784 paraviewdir=${PARAVIEW_ROOT_DIR}/lib
785 # qt dir
786 qtdir=${QT4_ROOT_DIR}/lib
787 # distene meshgems dir
788 if test `uname -m` = "x86_64" ; then
789     mgemsdir=${MESHGEMS_ROOT_DIR}/lib/Linux_64
790 else
791     mgemsdir=${MESHGEMS_ROOT_DIR}/lib/Linux
792 fi
793
794 for l in X ${la_files}; do
795
796 if [ "${l}" != "X" ] ; then
797     d=`dirname ${l}`
798     l=`basename ${l}`
799     cd ${ldir}; cd ${d}
800
801     # . process salome modules dependencies
802     for mod in ${SALOME_MODULES} ; do
803         moddir=${mod}_ROOT_DIR
804         moddir=${!moddir}
805         if [ -n "${moddir}" ] ; then
806             sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}[1]\?/lib% \1${moddir}/lib%g" \
807                 -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}WOGUI[1]\?/lib% \1${moddir}/lib%g" \
808                 -e "s%^libdir='[^[:space:]]*${mod}[1]\?/\(lib.*\)'%libdir='${moddir}/\1'%g" \
809                 -e "s%^libdir='[^[:space:]]*${mod}WOGUI[1]\?/\(lib.*\)'%libdir='${moddir}/\1'%g" ${l} > ${l}"_"
810             mv -f ${l}"_" ${l}
811         fi
812     done
813
814     # . process netgen dependencies
815     if [ -n "${netgendir}" ] && [ -d "${netgendir}" ] ; then
816         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*netgen-[0-9.]\+/lib% \1${netgendir}/lib%g" ${l}
817     fi
818
819     # . process freetype dependencies
820     if [ -n "${freetypedir}" ] && [ -d "${freetypedir}" ] ; then
821         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*freetype-[0-9.]\+/lib% \1${freetypedir}/lib%g" ${l}
822     fi
823
824     # . process ftgl dependencies
825     if [ -n "${ftgldir}" ] && [ -d "${ftgldir}" ] ; then
826         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*ftgl-[0-9.]\+/lib% \1${ftgldir}/lib%g" ${l}
827     fi
828
829     # . process gl2ps dependencies
830     if [ -n "${gl2psdir}" ] && [ -d "${gl2psdir}" ] ; then
831         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*gl2ps-[0-9.]\+/lib% \1${gl2psdir}/lib%g" ${l}
832     fi
833     
834     # . process freeimage dependencies
835     if [ -n "${freeimagedir}" ] && [ -d "${freeimagedir}" ] ; then
836         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*freeimage-[0-9.]\+/lib% \1${freeimagedir}/lib%g" ${l}
837     fi
838
839     # . process tbb dependencies
840     if [ -n "${tbbdir}" ] && [ -d "${tbbdir}" ] ; then
841         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*tbb[^[:space:]]*/lib[^[:space:]]*% \1${tbbdir}%g" ${l}
842     fi
843     
844     # . process cgns dependencies
845     if [ -n "${cgnslibdir}" ] && [ -d "${cgnslibdir}" ] ; then
846         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*cgnslib-[0-9.]\+/lib% \1${cgnslibdir}/lib%g" ${l}
847     fi
848
849     # . process CAS.CADE dependencies
850     if [ -n "${CAS_ROOT_DIR}" ] && [ -d "${casdir}" ] ; then
851         sed -e "s%-L[^[:space:]]*OCCT[^[:space:]]*/install/lib%-L${casdir}%g" \
852             -e "s%[^[:space:]]*OCCT[^[:space:]]*/install/lib/%${casdir}/%g"   \
853             -e "s%[[:space:]]-L[^[:space:]]*\(OCCT\|CAS\)[^[:space:]]*/lib\?% -L${CAS_ROOT_DIR}/lib%g" \
854             -e "s%[[:space:]][^[:space:]]*\(OCCT\|CAS\)[^[:space:]]*/lib/lib\?% ${CAS_ROOT_DIR}/lib/lib%g" ${l} > ${l}"_"
855         mv -f ${l}"_" ${l}
856     fi
857
858     # . process omniORB dependencies
859     if [ -n "${OMNIORB_ROOT_DIR}" ] && [ -d "${omnidir}" ] ; then
860         sed -i "s%-L[^[:space:]]*omni[^[:space:]]*%-L${omnidir}%g;s%-R[^[:space:]]*omni[^[:space:]]*%-R${omnidir}%g" ${l}
861     fi
862
863     # . process VTK dependencies
864     if [ -n "${VTK_DIR}" ] && [ -d "${vtkdir}" ] && [ -d "${vtkldir}" ] ; then
865         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}
866     fi
867
868     # . process HDF dependencies
869     if [ -n "${HDF5_ROOT_DIR}" ] && [ -d "${hdfdir}" ] ; then
870         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*hdf[^[:space:]/]*/lib% \1${hdfdir}%g" ${l}
871     fi
872
873     # . process MED dependencies
874     if [ -n "${MEDFILE_ROOT_DIR}" ] && [ -d "${meddir}" ] ; then
875         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*med[^[:space:]/]*/lib% \1${meddir}%g" ${l}
876     fi
877
878     # . process qwt dependencies
879     if [ -n "${qwtdir}" ] && [ -d "${qwtdir}" ] ; then
880         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*qwt[^[:space:]/]*/lib% \1${qwtdir}%g" ${l}
881     fi
882
883     # . process qt dependencies
884     if [ -n "${QT4_ROOT_DIR}" ] && [ -d "${qtdir}" ] ; then
885         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*qt[^[:space:]/]*/lib% \1${qtdir}%g" ${l}
886     fi
887
888     # . process python dependencies
889     if [ -n "${pythondir}" ] && [ -d "${pythondir}" ] ; then
890         sed -i "s%-L[^[:space:]]*python[0-9]\.[0-9]\([^[:space:]]*\)%-L${pythondir}\1%g" ${l}
891     fi
892
893     # . process sip dependencies
894     if [ -n "${sipdir}" ] && [ -d "${sipdir}" ] ; then
895         sed -i "s%-L[^[:space:]]*sip[^[:space:]]*%-L${sipdir}%g" ${l}
896     fi
897
898     # . process PyQt dependencies
899     if [ -n "${pyqtdir}" ] && [ -d "${pyqtdir}" ] ; then
900         sed -i "s%-L[^[:space:]]*PyQt[^[:space:]]*%-L${pyqtdir}%g" ${l}
901     fi
902
903     # . process tcl/tk dependencies
904     if [ -n "${tcldir}" ] && [ -d "${tcldir}" ] ; then
905         sed -i "s%-L[^[:space:]]*tcltk[^[:space:]]*/lib%-L${tcldir}%g" ${l}
906     fi
907
908     # . process boost dependencies
909     if [ -n "${boostdir}" ] && [ -d "${boostdir}" ] ; then
910         sed -i "s%-L[^[:space:]]*boost[^[:space:]]*/lib%-L${boostdir}%g" ${l}
911     fi
912
913     # . process blsurf dependencies
914     if [ -n "${blsurfdir}" ] && [ -d "${blsurfdir}" ] ; then
915         sed -i "s%-L[^[:space:]]*BLSurf[^[:space:]]*/lib%-L${blsurfdir}%g" ${l}
916     fi
917
918     # . process libxml dependencies
919     if [ -n "${libxmldir}" ] && [ -d "${libxmldir}" ] ; then
920         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}
921     fi
922
923     # . process metis dependencies
924     if [ -n "${metisdir}" ] && [ -d "${metisdir}" ] ; then
925         sed -i "s%-L[^[:space:]]*metis[^[:space:]]*%-L${metisdir}%g" ${l}
926     fi
927
928     # . process scotch dependencies
929     if [ -n "${scotchbindir}" ] && [ -d "${scotchbindir}" ] ; then
930         sed -i "s%-L[^[:space:]]*scotch[^[:space:]]*/bin%-L${scotchbindir}%g" ${l}
931     fi
932     if [ -n "${scotchlibdir}" ] && [ -d "${scotchlibdir}" ] ; then
933         sed -i "s%-L[^[:space:]]*scotch[^[:space:]]*/lib%-L${scotchlibdir}%g" ${l}
934     fi
935
936     # . process libGL.la dependencies
937     sed -i "s%${libGLpath}%""%g" ${l}
938
939     # . process graphviz dependencies
940     if [ -n "${graphvizdir}" ] && [ -d "${graphvizdir}" ] ; then
941         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}
942     fi
943
944     # . process QScintilla dependencies
945     if [ -n "${qscintilladir}" ] && [ -d "${qscintilladir}" ] ; then
946         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*QScintilla-[0-9]\.[0-9]\(\.[0-9]\)\?/lib% \1${qscintilladir}%g" ${l}
947     fi
948
949     # . process expat-2.0.1 dependencies
950     if [ -n "${expatdir}" ] && [ -d "${expatdir}" ] ; then
951         sed -i "s%-L[^[:space:]]*expat[^[:space:]]*/lib%-L${expatdir}%g;s%[^[:space:]]*expat[^[:space:]]*/lib/libexpat.la%-lexpat%g" ${l}
952     fi
953
954     # . process ParaView dependencies
955     if [ -n "${paraviewdir}" ] && [ -d "${paraviewdir}" ] ; then
956         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*ParaView-[0-9]\.[0-9]\+\.[0-9]/lib% \1${paraviewdir}%g" ${l}
957     fi
958     
959     # . process DISTENE MeshGems dependencies
960     if [ -n "${mgemsdir}" ] && [ -d "${mgemsdir}" ] ; then
961         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*MeshGems-[0-9.]\+/Products/lib/Linux\(_64\)\?% \1${mgemsdir}%g" ${l}
962     fi
963
964 fi
965 done
966
967 cd ${srcdir}
968 return 0
969 }