]> SALOME platform Git repositories - tools/install.git/blob - config_files/common.sh
Salome HOME
Merge branch 'SALOME_7' of salome:tools/install into SALOME_7
[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-2014 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 export CFGRC="salome.cfg"
19
20 #####################################################
21 # !WARNING! This is current SALOME version number
22 ####################################################
23 export SALOME_VERSION="7.4.0"
24 export YACSGEN_VERSION=${SALOME_VERSION}
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} ${CFGRC} ; 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
132 ### !!! writing salome.sh file !!!  -> define INST_ROOT
133 cat >> ${install_work}/${SHRC} <<EOF
134 #${DELIM} Setting products installation directory ${DELIM}
135 export INST_ROOT=${install_root}
136
137 #${DELIM} Environment switch: 0 for SALOME building, 1 for SALOME launching ${DELIM}
138 export ENV_FOR_LAUNCH=1
139
140 #${DELIM} Setting numeric locale ${DELIM}
141 export LC_NUMERIC=C
142
143 EOF
144
145 ### !!! writing salome.csh file !!! -> set inital variables
146 pre_vars="PATH LD_LIBRARY_PATH LD_RUN_PATH PYTHONPATH TCLLIBPATH"
147 for i in ${pre_vars} ; do
148 cat >> ${install_work}/${CSHRC} <<EOF
149 #${DELIM} setting initial ${i} ${DELIM}
150 if (! (\$?${i}) ) then
151   setenv ${i}
152 endif
153
154 EOF
155 done
156
157 ### !!! writing salome.cfs file !!! -> set inital variables
158 cat >> ${install_work}/${CFGRC} <<EOF
159 [SALOME Configuration]
160
161 EOF
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 # 1. first dump all environment files into the ${SHRC} file
177 product_sequence="$2"
178 install_products="$3"
179 for i in ${product_sequence} ; do
180     env_file=${install_work}/env_${i}.sh
181     _env_file=${install_work}/_env_${i}.sh
182     if [ -e ${_env_file} ] ; then
183         cat ${_env_file} >> ${install_work}/${SHRC} 2>/dev/null
184     elif [ -e ${env_file} ] ; then
185         echo ${install_products} | grep -q "\b${i}\b"
186         if [ $? -eq 1 ] ; then
187             cat ${env_file} | sed 's/^/## /' >> ${install_work}/${SHRC} 2>/dev/null
188         else
189             cat ${env_file} >> ${install_work}/${SHRC} 2>/dev/null
190         fi
191     fi
192 done
193
194 # 2. writing global functions to _salome.sh file
195 cat >> ${install_work}/_${SHRC} <<EOF
196 ##########################################################################
197 # Functions exporta and exportp are used to append/prepend correspondingly
198 # one directory or a set of directories separated by semicolon symbol (':')
199 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
200 # LD_RUN_PATH etc.
201 # The main purpose is to replace default setenv command behavior:
202 # exporta, exportp also remove duplicated entries, shortening in that way
203 # the environment variables.
204 # If some directory being added is already included into the variable
205 # nothing is done for it.
206 # Note, that these functions work some slower that setenv command itself.
207 #
208 #### cleandup ###
209 # appends/prepends set of directories (second parameter)
210 # to the another set of directories (first parameter) and
211 # removes duplicated entries;
212 # the third parameter defines the mode: 0 - append, 1 - prepend
213 cleandup() {
214 out_var=\`echo \$1 \$2 | awk -v dir=\$3 '{                   \\
215      na = split(\$2,a,":");                               \\
216      k1=0;                                               \\
217      bbb[k1++]="";                                       \\
218      ccc[""];                                            \\
219      if(\$1 != "<empty>") {                               \\
220        nb = split(\$1,b,":");                             \\
221        for(i=1;i<=nb;i++) {                              \\
222          if(!(b[i] in ccc) ) {                           \\
223            ccc[b[i]];                                    \\
224            bbb[k1++]=b[i];                               \\
225          };                                              \\
226        };                                                \\
227      };                                                  \\
228      k2=0;                                               \\
229      aaa[k2++]="";                                       \\
230      for(i=1;i<=na;i++) {                                \\
231        if(!(a[i] in ccc)) {                              \\
232          ccc[a[i]];                                      \\
233          aaa[k2++]=a[i];                                 \\
234        };                                                \\
235      };                                                  \\
236      ORS=":";                                            \\
237      if(dir) {                                           \\
238        for(i=1;i<k2;i++) {                               \\
239          print aaa[i];                                   \\
240        }                                                 \\
241        for(i=1;i<k1;i++) {                               \\
242          print bbb[i];                                   \\
243        }                                                 \\
244      }                                                   \\
245      else {                                              \\
246        for(i=1;i<k1;i++) {                               \\
247          print bbb[i];                                   \\
248        }                                                 \\
249        for(i=1;i<k2;i++) {                               \\
250          print aaa[i];                                   \\
251        }                                                 \\
252      }                                                   \\
253    }' | sed -e 's/\(.*\):/\1/g'\`
254 echo \${out_var}
255 }
256 ### exporta ###
257 # appends directory or set of directories, separated by ':' (second parameter)
258 # to the variable (first parameter)
259 exporta () {
260 xenv=\${!1}
261 if [ -z "\${xenv}" ]; then xenv="<empty>"; fi
262 out_var=\`cleandup \${xenv} \$2 0\`
263 export \$1=\${out_var}
264 }
265 ### exportp ###
266 # prepends directory or set of directories, separated by ':' (second parameter)
267 # to the variable (first parameter)
268 exportp () {
269 xenv=\${!1}
270 if [ -z "\${xenv}" ]; then xenv="<empty>"; fi
271 out_var=\`cleandup \${xenv} \$2 1\`
272 export \$1=\${out_var}
273 }
274 ###########################################################################
275
276 EOF
277
278 # 3. writing global functions to _salome.csh file
279 cat >> ${install_work}/_${CSHRC} <<EOF
280
281 ###########################################################################
282 # Aliases setenva and setenvp are used to append/prepend correspondingly
283 # one directory or a set of directories separated by semicolon symbol (':')
284 # to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
285 # LD_RUN_PATH etc.
286 # The main purpose is to replace default setenv command behavior:
287 # setenva, setenvp also remove duplicated entries, shortening in that way
288 # the environment variables.
289 # If some directory being added is already included into the variable
290 # nothing is done for it.
291 # Note, that these aliases work some slower that setenv command itself.
292 #
293 #### cleandup ###
294 # appends/prepends set of directories (second parameter)
295 # to the another set of directories (first parameter) and
296 # removes duplicated entries;
297 # the third parameter defines the mode: 0 - append, 1 - prepend
298 alias cleandup "echo \!:1 \!:2 | awk -v dir=\!:3         \\\\
299 '"'{ na = split(\$2,a,":");                               \\\\
300      k1=0;                                               \\\\
301      bbb[k1++]="";                                       \\\\
302      ccc[""];                                            \\\\
303      if(\$1 != "<empty>") {                               \\\\
304        nb = split(\$1,b,":");                             \\\\
305        for(i=1;i<=nb;i++) {                              \\\\
306          if(!(b[i] in ccc) ) {                           \\\\
307            ccc[b[i]];                                    \\\\
308            bbb[k1++]=b[i];                               \\\\
309          };                                              \\\\
310        };                                                \\\\
311      };                                                  \\\\
312      k2=0;                                               \\\\
313      aaa[k2++]="";                                       \\\\
314      for(i=1;i<=na;i++) {                                \\\\
315        if(!(a[i] in ccc)) {                              \\\\
316          ccc[a[i]];                                      \\\\
317          aaa[k2++]=a[i];                                 \\\\
318        };                                                \\\\
319      };                                                  \\\\
320      ORS=":";                                            \\\\
321      if(dir) {                                           \\\\
322        for(i=1;i<k2;i++) {                               \\\\
323          print aaa[i];                                   \\\\
324        }                                                 \\\\
325        for(i=1;i<k1;i++) {                               \\\\
326          print bbb[i];                                   \\\\
327        }                                                 \\\\
328      }                                                   \\\\
329      else {                                              \\\\
330        for(i=1;i<k1;i++) {                               \\\\
331          print bbb[i];                                   \\\\
332        }                                                 \\\\
333        for(i=1;i<k2;i++) {                               \\\\
334          print aaa[i];                                   \\\\
335        }                                                 \\\\
336      }                                                   \\\\
337   }'"' | sed -e 's/\(.*\):/\1/g'"
338 ### setenva ###
339 # appends directory or set of directories, separated by ':' (second parameter)
340 # to the variable (first parameter)
341 alias setenva 'set a=\!:1 ; set b=\!:2 ;      \\
342                set c=\`printenv \${a}\` ;        \\
343                set b=\`cleandup \${c} \${b} 0\` ; \\
344                setenv \${a} \${b} ;             \\
345                unset a, b, c'
346
347 ### setenvp ###
348 # prepends directory or set of directories, separated by ':' (second parameter)
349 # to the variable (first parameter)
350 alias setenvp 'set a=\!:1 ; set b=\!:2 ;      \\
351                set c=\`printenv \${a}\` ;        \\
352                set b=\`cleandup \${c} \${b} 1\` ; \\
353                setenv \${a} \${b} ;             \\
354                unset a, b, c'
355 ###########################################################################
356
357 EOF
358 cat ${install_work}/${CSHRC} >> ${install_work}/_${CSHRC}
359
360 # 4. put the contents of salome.sh to _salome.sh replacing export by export(a|p) aliases where necessary
361 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
362 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
363 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
364 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
365
366 cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_${SHRC}
367
368 # 5. Create a salome.csh file from salome.sh by replacing export by setenv, etc.
369 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${install_work}/${SHRC} > ${INSTALL_WORK}/_tmp1 2>/dev/null
370 cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/${CSHRC}
371
372 # 6. Create a _salome.csh file from _salome.sh by replacing export by setenv, exporta by setenva, etc.
373 sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
374 sed -e 's%exporta \([[:alnum:]_[:blank:]]*\)%setenva \1%g'  ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
375 sed -e 's%exportp \([[:alnum:]_[:blank:]]*\)%setenvp \1%g'  ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
376 sed -e 's%if \[ -n "\${PYTHONPATH}" \] ; then%if ( ${?PYTHONPATH} ) then%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
377 sed -e 's%if \[ -n "\${ENV_FOR_LAUNCH}" \] ; then%if ( ${?ENV_FOR_LAUNCH} ) then%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
378 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
379 sed -e 's%^\([[:blank:]]*\)fi\([[:blank:]]*\)$%\1endif\2%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
380 sed -e 's%var.sh%var.csh%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
381 sed -e 's%if \[ -e "\${LICENSE_FILE}" \] ; then%if ( -e ${LICENSE_FILE} ) then%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
382
383 cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/_${CSHRC} 2>/dev/null
384
385 rm -f ${INSTALL_WORK}/_tmp1 ${INSTALL_WORK}/_tmp2
386
387 # 7. Create a salome.cfg file from salome.sh
388 cat ${install_work}/${SHRC} | grep -v -e "^## " | grep -v "PV_PLUGIN_PATH" | awk 'BEGIN {v=1} /if / {v=0;} /fi/ {v=1;} {if (match($0, "KERNEL")) exit 0; else if(v==1 && match($0, "^ *fi *$")==0) print $0;}' >> ${install_work}/${CFGRC}
389 sed -i "s%export PATH=\(.*\):\${\?PATH}\?%ADD_TO_PATH: \1%g" ${install_work}/${CFGRC}
390 sed -i "s%export LD_LIBRARY_PATH=\(.*\):\${\?LD_LIBRARY_PATH}\?%ADD_TO_LD_LIBRARY_PATH: \1%g" ${install_work}/${CFGRC}
391 sed -i "s%export PYTHONPATH=\(.*\):\${\?PYTHONPATH}\?%ADD_TO_PYTHONPATH: \1%g" ${install_work}/${CFGRC}
392 sed -i "s%export %%g" ${install_work}/${CFGRC}
393 sed -i "s%INST_ROOT%ROOT_SALOME%g" ${install_work}/${CFGRC}
394 sed -i "s%\${\?\([A-Za-z0-9_]\+\)}\?%\%(\1)s%g" ${install_work}/${CFGRC}
395
396 if [ $# -eq 5 ] ; then
397     product_dir=$5
398     if [ -d ${product_dir} ] ; then
399         test -e ${product_dir}/${SHRC} && mv ${product_dir}/${SHRC} ${product_dir}/${SHRC}_`date +%F_%T`
400         cp ${install_work}/_${SHRC}  ${product_dir}/${SHRC}
401         test -e ${product_dir}/${CSHRC} && mv ${product_dir}/${CSHRC} ${product_dir}/${CSHRC}_`date +%F_%T`
402         cp ${install_work}/_${CSHRC} ${product_dir}/${CSHRC}
403         test -e ${product_dir}/${CFGRC} && mv ${product_dir}/${CFGRC} ${product_dir}/${CFGRC}_`date +%F_%T`
404         cp ${install_work}/${CFGRC} ${product_dir}/${CFGRC}
405     fi
406 fi
407 sed -e 's%setenv ENV_FOR_LAUNCH 1%setenv ENV_FOR_LAUNCH 0%' ${install_work}/_${CSHRC} > ${install_root}/env_build.csh
408 sed -e 's%export ENV_FOR_LAUNCH=1%export ENV_FOR_LAUNCH=0%' ${install_work}/_${SHRC}  > ${install_root}/env_build.sh
409
410 cp -f ${install_work}/_${CSHRC} ${install_root}/env_products.csh
411 cp -f ${install_work}/_${SHRC}  ${install_root}/env_products.sh
412
413 rm -f ${install_work}/_${SHRC} ${install_work}/_${CSHRC}
414
415 ### !!! copying build.csh and build.sh scripts
416 if [ -e ./build.csh ] && [ ! -e ${install_root}/build.csh ]; then
417     cp -f ./build.csh ${install_root}
418 fi
419 if [ -e ./build.sh ] && [ ! -e ${install_root}/build.sh ]; then
420     cp -f ./build.sh ${install_root}
421 fi
422
423 ### !!! copying release notes
424 for p in `ls ../` ; do
425     export pdf=`echo ${p} | sed s/[.]/" "/g | awk '{print $2}'`
426     if [ "${pdf}" = "pdf" ]; then
427         export RN=${p}
428         if [ ! -e ${install_root}/${RN} ]; then
429             cp -f ../${RN} ${install_root}
430         fi
431     fi
432 done
433
434 }
435
436 #try use already existing product
437 try_existing()
438 {
439 product_dir=$1;  install_root=$2;  install_work=$3;
440 product_sequence="$4"; installed_products="$5";  product_type=$6
441 env_file=${product_dir}/env_${product_type}.sh
442 if [ -f ${env_file} ] ; then
443     cp -f ${env_file} ${install_work}/_env_${product_type}.sh
444     make_env ${install_root} ${install_work} "${product_sequence}" "${installed_products}"
445     source ${install_work}/${SHRC}
446     check_version
447     if [ $? -eq 0 ] ; then
448         return 0
449     fi
450 fi
451 echo ${product_type} | grep -q '_src$'
452 if [ $? -eq 1 ] ; then
453     print_env_bin
454 else
455     print_env_src
456 fi
457 return 0
458 }
459
460 #check existance of lib passed as first parameter
461 #return 0 if lib exists
462 #if you pass second parameter search will be done in it
463 #otherwise search will be done in ${LD_LIBRARY_PATH}
464 #you should use : as dilimeter if you are going to pass second parameter
465 check_lib_version(){
466 if [ -n "$2" ]; then
467    whereIs=$2
468 else
469    whereIs=${LD_LIBRARY_PATH}
470 fi
471 for d in `echo ${whereIs} | sed -e"s%:% %g"` ;  do
472     ret=`find ${d} -name $1 2>/dev/null`
473     if [ -n "${ret}" ] ; then
474         #echo "The $1 exists on yours system in a ${d} folder"
475         return 0
476     fi
477 done
478 return 1
479 }
480
481 find_in_path(){
482 file=$1;  shift;
483 path=$*
484 for i in `echo ${path} | sed -e"s%:% %g"` ; do
485     ret=`find ${i} -name ${file} -maxdepth 1 2>/dev/null`
486     if [ -n "${ret}" ] ; then
487         ret=`echo ${ret} | sed -e"s%/\${file}$%%g"`
488         echo ${ret}
489         return 0
490     fi
491 done
492 return 1
493 }
494
495 sort_path(){
496 arg1=$1;  val1=$2;  arg2=$3;  val2=$4
497 tmp="^${val1}$|^${val1}:|:${val1}$|:${val1}:"
498 #echo ${val2} | grep -E "${tmp}" >/dev/null 2>&1
499 #if [ $? -eq 0 ] ; then
500 #    echo "${arg2}"
501 #    return
502 #fi
503 to_tail=1
504 exclude_list="usr lib bin sbin etc"
505 for i in ${exclude_list} ; do
506     tmp="^/${i}/|^/${i}\$"
507     echo ${val1} | grep -E "${tmp}" >/dev/null 2>&1
508     if [ "$?" = "0" ] ; then to_tail=0; break; fi
509 done
510 if [ ${to_tail} -eq 0 ] ; then
511     echo ${arg2}:${arg1}
512 else
513     echo ${arg1}:${arg2}
514 fi
515 return ${to_tail}
516 }
517
518 where_gcc(){
519 maj_ver=`echo $1 | awk -F. '{if(NF>0) print $1; else print 0}'`
520 min_ver=`echo $1 | awk -F. '{if(NF>1) print $2; else print 0}'`
521 rel_ver=`echo $1 | awk -F. '{if(NF>2) print $3; else print 0}'`
522 let ver=${maj_ver}*10000+${min_ver}*100+${rel_ver}
523 newer=""
524 newerver=0
525 for i in `echo ${PATH}:/usr/bin:/usr/local/bin | sed -e"s%:% %g"` ; do
526     ret=`find ${i} -name gcc -maxdepth 1 2>/dev/null`
527     if [ -n "${ret}" ] ; then
528         maj_ver=`${ret} -dumpversion | awk -F. '{if(NF>0) print $1; else print 0}'`
529         min_ver=`${ret} -dumpversion | awk -F. '{if(NF>1) print $2; else print 0}'`
530         rel_ver=`${ret} -dumpversion | awk -F. '{if(NF>2) print $3; else print 0}'`
531         let ver1=${maj_ver}*10000+${min_ver}*100+${rel_ver}
532         if [ ${ver1} -eq ${ver} ] ; then
533             ret=`echo ${ret} | sed -e"s%/gcc$%%g"`
534             echo ${ret}
535             return 0
536         fi
537         if [ ${ver1} -gt ${ver} ] && [ ${ver1} -gt ${newerver} ] ; then
538             let newerver=${ver1}
539             newer=`echo ${ret} | sed -e"s%/gcc$%%g"`
540         fi
541     fi
542 done
543 if [ -n "${newer}" ] ; then
544     echo ${newer}
545     return 0
546 fi
547 return 1
548 }
549
550 where_tcl(){
551 if test -z "${TCLHOME}"; then
552     TCLHOME=/usr
553 fi
554 tclcfg=`find ${TCLHOME}/lib -name "tclConfig.sh" 2> /dev/null`
555 file=""
556 maxver=0
557 for f in ${tclcfg} ; do
558     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;}'`
559     if [ ${maxver} -lt ${ver} ]; then
560         maxver=${ver}
561         file=${f}
562     fi
563 done
564 if test -n "${file}"; then
565     echo `dirname ${file}`
566     return 0
567 else
568     echo ""
569     return 1
570 fi
571 }
572
573 where_tk(){
574 if test -z "${TCLHOME}"; then
575     TCLHOME=/usr
576 fi
577 tclcfg=`find ${TCLHOME}/lib -name "tkConfig.sh" 2> /dev/null`
578 file=""
579 maxver=0
580 for f in ${tclcfg} ; do
581     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;}'`
582     if [ ${maxver} -lt ${ver} ]; then
583         maxver=${ver}
584         file=${f}
585     fi
586 done
587 if test -n "${file}"; then
588     echo `dirname ${file}`
589     return 0
590 else
591     echo ""
592     return 1
593 fi
594 }
595
596 where_dps(){
597 if test -f /usr/X11R6/include/DPS/dpsconfig.h ; then
598     echo "/usr/X11R6"
599     return 0
600 fi
601 if test -f /usr/include/DPS/dpsconfig.h ; then
602     echo "/usr"
603     return 0
604 fi
605 echo ""
606 return 1
607 }
608
609 where_gl_includes(){
610 for d in /usr/X11R6/include /usr/include ; do
611     if [ -d ${d}/GL ] && [ -f ${d}/GL/gl.h ] ; then
612         echo "${d}"
613         return 0
614     fi
615 done
616 echo ""
617 return 1
618 }
619
620 where_gl_libs(){
621 local d
622 local libdir
623 local libdirs="/usr/X11R6/lib64 /usr/lib64 /usr/lib/`uname -m`-linux-gnu /usr/X11R6/lib /usr/lib"
624
625 # search libGL.so* file and correct libGL.la in the same directory
626 for d in ${libdirs} ; do
627     if [ "`ls ${d}/libGL.so* 2>/dev/null`" ] && [ -f ${d}/libGL.la ]; then
628         libdir=`grep "libdir=" ${d}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%" -e "s%/*$%%g"`
629         if [ "${libdir}" = "${d}" ] ; then
630             echo "${d}"
631             return 0
632         fi
633     fi
634 done
635 # search libGL.la file and check if this file is correct
636 for d in ${libdirs} ; do
637     if [ -f ${d}/libGL.la ] ; then
638         libdir=`grep "libdir=" ${d}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%"`
639         if [ "`ls ${libdir}/libGL.so* 2>/dev/null`" ] ; then
640             echo "${d}"
641             return 0
642         fi
643     fi
644 done
645 # then search libGL.so* file
646 for d in ${libdirs} ; do
647     if [ "`ls ${d}/libGL.so* 2>/dev/null`" ] ; then
648         echo "${d}"
649         return 0
650     fi
651 done
652 echo ""
653 return 1
654 }
655
656 where_libgl_so(){
657 local libdirs="/usr/X11R6/lib64 /usr/lib64 /usr/lib/`uname -m`-linux-gnu /usr/X11R6/lib /usr/lib"
658 local d
659 for d in ${libdirs} ; do
660     if [ -f ${d}/libGL.so ] ; then
661         echo ${d}/libGL.so
662         return 0
663     fi
664 done
665 echo ""
666 return 1
667 }
668
669 fix_gl_libs(){
670     local gllibdir="`where_gl_libs`"
671     if [ "${gllibdir}" != "" ] ; then
672 #VSR: 02/04/2013 - next block is commented as it seems to be wrong :( libGL.la should not be ever mentioned
673 #       if [ -f ${gllibdir}/libGL.la ] ; then
674 #           libdir=`grep "libdir=" ${gllibdir}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%"`
675 #           if [ "`ls ${libdir}/libGL.so* 2>/dev/null`" ] ; then
676 #               str_to_replace="${gllibdir}/libGL.la"
677 #           fi
678 #       fi
679         if [ "${str_to_replace}" = "" ] ; then
680             str_to_replace="-L${gllibdir} -lGL"
681         fi
682
683         la_files=`find . -name "*.la"`
684         for la_file in ${la_files} XXX ; do
685             if [ "${la_file}" = "XXX" ] ; then continue; fi
686             grep -e "libGL.la" ${la_file} >& /dev/null || grep -e "-lGL\b" ${la_file} >& /dev/null && \
687             sed -e "s%-lGL\b%%g"                                                       \
688                 -e "s%[^[:space:]']*libGL.la[[:space:]]%%g"                            \
689                 -e "s%^dependency_libs='\(.*\)%dependency_libs='${str_to_replace} \1%" \
690                 ${la_file} > ${la_file}.new && \
691                 mv -f ${la_file}.new ${la_file}
692         done
693     fi
694 }
695
696 ##
697 # function: workaround on some platforms to use latest available version of gcc (e.g. gcc44 on CentOS 5.5)
698 ##
699 use_latest_gcc(){
700     local gcc_min=$1
701     local gcc_ver=`gcc -dumpversion | awk -F. '{a1=0;a2=0;a3=0;if(NF>0)a1=$1;if(NF>1)a2=$2;if(NF>2)a3=$3;printf("%02d%02d%02d",a1,a2,a3);}'`
702     local gcc_found
703     local gxx_found
704     if [ ${gcc_ver} -le ${gcc_min} ] ; then
705         local wheregcc=$(dirname `which gcc`)
706         local all_gcc=$(find ${wheregcc}/gcc*)
707         local gcc_alt
708         local gcc_max=0
709         for gcc_alt in ${all_gcc} XXX ; do
710             if [ ${gcc_alt} = "XXX" ] ; then continue ; fi
711             gcc_ver=`${gcc_alt} -dumpversion 2>/dev/null | awk -F. '{a1=0;a2=0;a3=0;if(NF>0)a1=$1;if(NF>1)a2=$2;if(NF>2)a3=$3;printf("%02d%02d%02d",a1,a2,a3);}'`
712             if [ "${gcc_ver}" = "" ] ; then continue ; fi
713             if [ ${gcc_ver} -gt ${gcc_min} ] && [ ${gcc_ver} -gt ${gcc_max} ] ; then
714                 gcc_max=${gcc_ver}
715                 gcc_found=${gcc_alt}
716                 gxx_found=`echo ${gcc_found} | sed -e "s%gcc%g++%"`
717             fi
718         done
719         if [ "${gcc_found}" != "" ] ; then
720             echo "CC=${gcc_found} CXX=${gxx_found}"
721         fi
722     fi
723 }
724
725 modif_la_files(){
726 return 0
727 # obsolete
728 ldir=$1
729 if [ -z "${ldir}" ] || [ ! -d "${ldir}" ]; then return 1; fi
730
731 srcdir=`pwd`
732
733 SALOME_MODULES="`env | awk -F_ '/[a-zA-Z0-9]*_ROOT_DIR/ { print $1 }'`"
734
735 cd ${ldir}
736 ldir=`pwd`
737 la_files=`find . -name "*.la"`
738
739 # netgen dir
740 netgendir=${NETGEN_ROOT_DIR}
741 # freetype dir
742 freetypedir=${FREETYPE_ROOT_DIR}
743 # ftgl dir
744 ftgldir=${FTGL_ROOT_DIR}
745 # gl2ps dir
746 gl2psdir=${GL2PS_ROOT_DIR}
747 # freeimage dir
748 freeimagedir=${FREEIMAGE_ROOT_DIR}
749 # tbb dir
750 tbbbasedir=${TBB_ROOT_DIR}
751 TBBKERNEL='cc4.1.0_libc2.4_kernel2.6.16.21'
752 if test `uname -m` = "x86_64" ; then
753     export TBBMODE="intel64/${TBBKERNEL}"
754 else
755     export TBBMODE="ia32/${TBBKERNEL}"
756 fi
757 tbbdir=${tbbbasedir}/lib/${TBBMODE}
758 # cgns dir
759 cgnslibdir=${CGNS_ROOT_DIR}
760 # occt dir
761 casdir=${CAS_ROOT_DIR}/lib
762 if [ ! -d ${casdir} ] ; then casdir=${CAS_ROOT_DIR}/Linux/lib ; fi
763 if [ ! -d ${casdir} ] ; then casdir=${CAS_ROOT_DIR}/lin/lib ; fi
764 # omniorb dir
765 omnidir=${OMNIORB_ROOT_DIR}/lib
766 # vtk dir
767 vtkpath=${VTK_DIR}
768 if [ `uname -m` = "x86_64" ] && [ -d ${vtkpath}/lib64 ] ; then
769     LIB_PREFIX=64
770 elif [ -d ${vtkpath}/lib ] ; then
771     LIB_PREFIX=""
772 else
773     LIB_PREFIX=64
774 fi
775 vtkldir=${vtkpath}/lib${LIB_PREFIX}
776 vtkdir=${vtkldir}/vtk-5.0
777 # hdf dir
778 hdfdir=${HDF5_ROOT_DIR}/lib
779 # med dir
780 meddir=${MEDFILE_ROOT_DIR}/lib
781 # qwt dir
782 qwtdir=`find_in_path libqwt.so ${LD_LIBRARY_PATH}`
783 # python dir
784 where_python=`which python`                 # e.g. /usr/bin/python
785 if [ -n "${where_python}" ] ; then
786     where_python=`dirname ${where_python}`    # --> /usr/bin
787     where_python=`dirname ${where_python}`    # --> /usr
788     python_version=`python -c "import sys; print sys.version[:3]"`
789     pythondir=${where_python}/lib/python${python_version}
790 fi
791 # sip dir
792 sipdir=`find_in_path sip.so ${LD_LIBRARY_PATH}`
793 # pyqt dir
794 pyqtdir=`find_in_path Qt.so ${LD_LIBRARY_PATH}`
795 # tcl/tk dir
796 tcldir=${TCLHOME}/lib
797 # boost dir
798 boostdir=${BOOST_ROOT_DIR}/lib
799 # blsurf dir
800 blsurfdir=${BLSURFHOME}/lib
801 # libxml2 dir
802 libxmldir=${LIBXML2_ROOT_DIR}/lib
803 # metis dir
804 metisdir=${METIS_ROOT_DIR}
805 # scotch dir
806 scotchbindir=${SCOTCH_ROOT_DIR}/bin
807 scotchlibdir=${SCOTCH_ROOT_DIR}/lib
808 # gl dir
809 if test `uname -m` = "x86_64" ; then
810     libGLpath=/usr/lib64/libGL.la
811 else
812     libGLpath=/usr/lib/libGL.la
813 fi
814 # graphviz dir
815 graphvizdir=${GRAPHVIZ_ROOT_DIR}/lib
816 # qscintilla dir
817 qscintilladir=${QSCINTILLA_ROOT_DIR}/lib
818 # expat dir
819 expatdir=${EXPAT_ROOT_DIR}/lib
820 # paraview dir
821 paraviewdir=${PARAVIEW_ROOT_DIR}/lib
822 # qt dir
823 qtdir=${QT4_ROOT_DIR}/lib
824 # distene meshgems dir
825 if test `uname -m` = "x86_64" ; then
826     mgemsdir=${MESHGEMS_ROOT_DIR}/lib/Linux_64
827 else
828     mgemsdir=${MESHGEMS_ROOT_DIR}/lib/Linux
829 fi
830
831 for l in X ${la_files}; do
832
833 if [ "${l}" != "X" ] ; then
834     d=`dirname ${l}`
835     l=`basename ${l}`
836     cd ${ldir}; cd ${d}
837
838     # . process salome modules dependencies
839     for mod in ${SALOME_MODULES} ; do
840         moddir=${mod}_ROOT_DIR
841         moddir=${!moddir}
842         if [ -n "${moddir}" ] ; then
843             sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}[1]\?/lib% \1${moddir}/lib%g" \
844                 -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}WOGUI[1]\?/lib% \1${moddir}/lib%g" \
845                 -e "s%^libdir='[^[:space:]]*${mod}[1]\?/\(lib.*\)'%libdir='${moddir}/\1'%g" \
846                 -e "s%^libdir='[^[:space:]]*${mod}WOGUI[1]\?/\(lib.*\)'%libdir='${moddir}/\1'%g" ${l} > ${l}"_"
847             mv -f ${l}"_" ${l}
848         fi
849     done
850
851     # . process netgen dependencies
852     if [ -n "${netgendir}" ] && [ -d "${netgendir}" ] ; then
853         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*netgen-[0-9.]\+/lib% \1${netgendir}/lib%g" ${l}
854     fi
855
856     # . process freetype dependencies
857     if [ -n "${freetypedir}" ] && [ -d "${freetypedir}" ] ; then
858         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*freetype-[0-9.]\+/lib% \1${freetypedir}/lib%g" ${l}
859     fi
860
861     # . process ftgl dependencies
862     if [ -n "${ftgldir}" ] && [ -d "${ftgldir}" ] ; then
863         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*ftgl-[0-9.]\+/lib% \1${ftgldir}/lib%g" ${l}
864     fi
865
866     # . process gl2ps dependencies
867     if [ -n "${gl2psdir}" ] && [ -d "${gl2psdir}" ] ; then
868         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*gl2ps-[0-9.]\+/lib% \1${gl2psdir}/lib%g" ${l}
869     fi
870
871     # . process freeimage dependencies
872     if [ -n "${freeimagedir}" ] && [ -d "${freeimagedir}" ] ; then
873         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*freeimage-[0-9.]\+/lib% \1${freeimagedir}/lib%g" ${l}
874     fi
875
876     # . process tbb dependencies
877     if [ -n "${tbbdir}" ] && [ -d "${tbbdir}" ] ; then
878         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*tbb[^[:space:]]*/lib[^[:space:]]*% \1${tbbdir}%g" ${l}
879     fi
880
881     # . process cgns dependencies
882     if [ -n "${cgnslibdir}" ] && [ -d "${cgnslibdir}" ] ; then
883         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*cgnslib-[0-9.]\+/lib% \1${cgnslibdir}/lib%g" ${l}
884     fi
885
886     # . process CAS.CADE dependencies
887     if [ -n "${CAS_ROOT_DIR}" ] && [ -d "${casdir}" ] ; then
888         sed -e "s%-L[^[:space:]]*OCCT[^[:space:]]*/install/lib%-L${casdir}%g" \
889             -e "s%[^[:space:]]*OCCT[^[:space:]]*/install/lib/%${casdir}/%g"   \
890             -e "s%[[:space:]]-L[^[:space:]]*\(OCCT\|CAS\)[^[:space:]]*/lib\?% -L${CAS_ROOT_DIR}/lib%g" \
891             -e "s%[[:space:]][^[:space:]]*\(OCCT\|CAS\)[^[:space:]]*/lib/lib\?% ${CAS_ROOT_DIR}/lib/lib%g" ${l} > ${l}"_"
892         mv -f ${l}"_" ${l}
893     fi
894
895     # . process omniORB dependencies
896     if [ -n "${OMNIORB_ROOT_DIR}" ] && [ -d "${omnidir}" ] ; then
897         sed -i "s%-L[^[:space:]]*omni[^[:space:]]*%-L${omnidir}%g;s%-R[^[:space:]]*omni[^[:space:]]*%-R${omnidir}%g" ${l}
898     fi
899
900     # . process VTK dependencies
901     if [ -n "${VTK_DIR}" ] && [ -d "${vtkdir}" ] && [ -d "${vtkldir}" ] ; then
902         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}
903     fi
904
905     # . process HDF dependencies
906     if [ -n "${HDF5_ROOT_DIR}" ] && [ -d "${hdfdir}" ] ; then
907         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*hdf[^[:space:]/]*/lib% \1${hdfdir}%g" ${l}
908     fi
909
910     # . process MED dependencies
911     if [ -n "${MEDFILE_ROOT_DIR}" ] && [ -d "${meddir}" ] ; then
912         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*med[^[:space:]/]*/lib% \1${meddir}%g" ${l}
913     fi
914
915     # . process qwt dependencies
916     if [ -n "${qwtdir}" ] && [ -d "${qwtdir}" ] ; then
917         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*qwt[^[:space:]/]*/lib% \1${qwtdir}%g" ${l}
918     fi
919
920     # . process qt dependencies
921     if [ -n "${QT4_ROOT_DIR}" ] && [ -d "${qtdir}" ] ; then
922         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*qt[^[:space:]/]*/lib% \1${qtdir}%g" ${l}
923     fi
924
925     # . process python dependencies
926     if [ -n "${pythondir}" ] && [ -d "${pythondir}" ] ; then
927         sed -i "s%-L[^[:space:]]*python[0-9]\.[0-9]\([^[:space:]]*\)%-L${pythondir}\1%g" ${l}
928     fi
929
930     # . process sip dependencies
931     if [ -n "${sipdir}" ] && [ -d "${sipdir}" ] ; then
932         sed -i "s%-L[^[:space:]]*sip[^[:space:]]*%-L${sipdir}%g" ${l}
933     fi
934
935     # . process PyQt dependencies
936     if [ -n "${pyqtdir}" ] && [ -d "${pyqtdir}" ] ; then
937         sed -i "s%-L[^[:space:]]*PyQt[^[:space:]]*%-L${pyqtdir}%g" ${l}
938     fi
939
940     # . process tcl/tk dependencies
941     if [ -n "${tcldir}" ] && [ -d "${tcldir}" ] ; then
942         sed -i "s%-L[^[:space:]]*tcltk[^[:space:]]*/lib%-L${tcldir}%g" ${l}
943     fi
944
945     # . process boost dependencies
946     if [ -n "${boostdir}" ] && [ -d "${boostdir}" ] ; then
947         sed -i "s%-L[^[:space:]]*boost[^[:space:]]*/lib%-L${boostdir}%g" ${l}
948     fi
949
950     # . process blsurf dependencies
951     if [ -n "${blsurfdir}" ] && [ -d "${blsurfdir}" ] ; then
952         sed -i "s%-L[^[:space:]]*BLSurf[^[:space:]]*/lib%-L${blsurfdir}%g" ${l}
953     fi
954
955     # . process libxml dependencies
956     if [ -n "${libxmldir}" ] && [ -d "${libxmldir}" ] ; then
957         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}
958     fi
959
960     # . process metis dependencies
961     if [ -n "${metisdir}" ] && [ -d "${metisdir}" ] ; then
962         sed -i "s%-L[^[:space:]]*metis[^[:space:]]*%-L${metisdir}%g" ${l}
963     fi
964
965     # . process scotch dependencies
966     if [ -n "${scotchbindir}" ] && [ -d "${scotchbindir}" ] ; then
967         sed -i "s%-L[^[:space:]]*scotch[^[:space:]]*/bin%-L${scotchbindir}%g" ${l}
968     fi
969     if [ -n "${scotchlibdir}" ] && [ -d "${scotchlibdir}" ] ; then
970         sed -i "s%-L[^[:space:]]*scotch[^[:space:]]*/lib%-L${scotchlibdir}%g" ${l}
971     fi
972
973     # . process libGL.la dependencies
974     sed -i "s%${libGLpath}%""%g" ${l}
975
976     # . process graphviz dependencies
977     if [ -n "${graphvizdir}" ] && [ -d "${graphvizdir}" ] ; then
978         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}
979     fi
980
981     # . process QScintilla dependencies
982     if [ -n "${qscintilladir}" ] && [ -d "${qscintilladir}" ] ; then
983         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*QScintilla-[0-9]\.[0-9]\(\.[0-9]\)\?/lib% \1${qscintilladir}%g" ${l}
984     fi
985
986     # . process expat-2.0.1 dependencies
987     if [ -n "${expatdir}" ] && [ -d "${expatdir}" ] ; then
988         sed -i "s%-L[^[:space:]]*expat[^[:space:]]*/lib%-L${expatdir}%g;s%[^[:space:]]*expat[^[:space:]]*/lib/libexpat.la%-lexpat%g" ${l}
989     fi
990
991     # . process ParaView dependencies
992     if [ -n "${paraviewdir}" ] && [ -d "${paraviewdir}" ] ; then
993         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*ParaView-[0-9]\.[0-9]\+\.[0-9]/lib% \1${paraviewdir}%g" ${l}
994     fi
995
996     # . process DISTENE MeshGems dependencies
997     if [ -n "${mgemsdir}" ] && [ -d "${mgemsdir}" ] ; then
998         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*MeshGems-[0-9.]\+/Products/lib/Linux\(_64\)\?% \1${mgemsdir}%g" ${l}
999     fi
1000
1001 fi
1002 done
1003
1004 cd ${srcdir}
1005 return 0
1006 }
1007
1008 modif_cfg_file(){
1009     local nf=$1
1010     if [ "${nf}" = "" ] || [ ! -e ${nf} ] ; then
1011         return
1012     fi
1013     if [ "${PYTHON_ROOT_DIR}" != "" ] ; then
1014         sed -i "s%\([^/]*\)[^; ]*/Python-[0-9.]\+%\1${PYTHON_ROOT_DIR}%g" $1
1015     fi
1016     if [ "${SWIG_ROOT_DIR}" != "" ] ; then
1017         sed -i "s%\([^/]*\)[^; ]*/swig-[0-9.]\+%\1${SWIG_ROOT_DIR}%g" $1
1018     fi
1019     if [ "${OMNIORB_ROOT_DIR}" != "" ] ; then
1020         sed -i "s%\([^/]*\)[^; ]*/omniORB-[0-9.]\+%\1${OMNIORB_ROOT_DIR}%g" $1
1021     fi
1022     if [ "${HDF5_ROOT_DIR}" != "" ] ; then
1023         sed -i "s%\([^/]*\)[^; ]*/hdf5-[0-9.]\+%\1${HDF5_ROOT_DIR}%g" $1
1024     fi
1025     if [ "${BOOST_ROOT_DIR}" != "" ] ; then
1026         sed -i "s%\([^/]*\)[^; ]*/boost-[0-9.]\+%\1${BOOST_ROOT_DIR}%g" $1
1027     fi
1028     if [ "${MEDFILE_ROOT_DIR}" != "" ] ; then
1029         sed -i "s%\([^/]*\)[^; ]*/med-[0-9.]\+%\1${MEDFILE_ROOT_DIR}%g" $1
1030     fi
1031     if [ "${QT4_ROOT_DIR}" != "" ] ; then
1032         sed -i "s%\([^/]*\)[^; ]*/qt-[0-9.]\+%\1${QT4_ROOT_DIR}%g" $1
1033     fi
1034     if [ "${QWT_ROOT_DIR}" != "" ] ; then
1035         sed -i "s%\([^/]*\)[^; ]*/qwt-[0-9.]\+%\1${QWT_ROOT_DIR}%g" $1
1036     fi
1037     if [ "${SIP_ROOT_DIR}" != "" ] ; then
1038         sed -i "s%\([^/]*\)[^; ]*/sip-[0-9.]\+%\1${SIP_ROOT_DIR}%g" $1
1039     fi
1040     if [ "${PYQT4_ROOT_DIR}" != "" ] ; then
1041         sed -i "s%\([^/]*\)[^; ]*/PyQt-[0-9.]\+%\1${PYQT4_ROOT_DIR}%g" $1
1042     fi
1043     if [ "${QSCINTILLA_ROOT_DIR}" != "" ] ; then
1044         sed -i "s%\([^/]*\)[^; ]*/QScintilla-[0-9.]\+%\1${QSCINTILLA_ROOT_DIR}%g" $1
1045     fi
1046     if [ "${PARAVIEW_ROOT_DIR}" != "" ] ; then
1047         sed -i "s%\([^/]*\)[^; ]*/ParaView-[0-9.]\+%\1${PARAVIEW_ROOT_DIR}%g" $1
1048     fi
1049     if [ "${LIBXML2_ROOT_DIR}" != "" ] ; then
1050         sed -i "s%\([^/]*\)[^; ]*/libxml2-[0-9.]\+%\1${LIBXML2_ROOT_DIR}%g" $1
1051     fi
1052     if [ "${EXPAT_ROOT_DIR}" != "" ] ; then
1053         sed -i "s%\([^/]*\)[^; ]*/expat-[0-9.]\+%\1${EXPAT_ROOT_DIR}%g" $1
1054     fi
1055     if [ "${FREETYPE_ROOT_DIR}" != "" ] ; then
1056         sed -i "s%\([^/]*\)[^; ]*/freetype-[0-9.]\+%\1${FREETYPE_ROOT_DIR}%g" $1
1057     fi
1058     if [ "${FREEIMAGE_ROOT_DIR}" != "" ] ; then
1059         sed -i "s%\([^/]*\)[^; ]*/freeimage-[0-9.]\+%\1${FREEIMAGE_ROOT_DIR}%g" $1
1060     fi
1061     if [ "${GL2PS_ROOT_DIR}" != "" ] ; then
1062         sed -i "s%\([^/]*\)[^; ]*/gl2ps-[0-9.]\+%\1${GL2PS_ROOT_DIR}%g" $1
1063     fi
1064     if [ "${TBB_ROOT_DIR}" != "" ] ; then
1065         sed -i "s%\([^/]*\)[^; ]*/tbb[^/; \"]\+%\1${TBB_ROOT_DIR}%g" $1
1066     fi
1067     if [ "${CAS_ROOT_DIR}" != "" ] ; then
1068         sed -i "s%\([^/]*\)[^; ]*/OCCT[^/]*\(/[^ /;\"]*\)\?\(\"\|/inc\|/lib\)%\1${CAS_ROOT_DIR}\3%g" $1
1069     fi
1070     if [ "${NETGEN_ROOT_DIR}" != "" ] ; then
1071         sed -i "s%\([^/]*\)[^; ]*/netgen-[0-9.]\+%\1${NETGEN_ROOT_DIR}%g" $1
1072     fi
1073     if [ "${CGNS_ROOT_DIR}" != "" ] ; then
1074         sed -i "s%\([^/]*\)[^; ]*/cgnslib-[0-9.]\+%\1${CGNS_ROOT_DIR}%g" $1
1075     fi
1076     if [ "${NUMPY_ROOT_DIR}" != "" ] ; then
1077         sed -i "s%\([^/]*\)[^; ]*/numpy-[0-9.]\+%\1${NUMPY_ROOT_DIR}%g" $1
1078     fi
1079     if [ "${GRAPHVIZ_ROOT_DIR}" != "" ] ; then
1080         sed -i "s%\([^/]*\)[^; ]*/graphviz-[0-9.]\+%\1${GRAPHVIZ_ROOT_DIR}%g" $1
1081     fi
1082     if [ "${DOXYGEN_ROOT_DIR}" != "" ] ; then
1083         sed -i "s%\([^/]*\)[^; ]*/doxygen-[0-9.]\+%\1${DOXYGEN_ROOT_DIR}%g" $1
1084     fi
1085     if [ "${SPHINX_ROOT_DIR}" != "" ] ; then
1086         sed -i "s%\([^/]*\)[^; ]*/Sphinx-[0-9.]\+%\1${SPHINX_ROOT_DIR}%g" $1
1087     fi
1088     if [ "${WSO2_ROOT_DIR}" != "" ] ; then
1089         sed -i "s%\([^/]*\)[^; ]*/wso2-wsf-cpp-[0-9.]\+%\1${WSO2_ROOT_DIR}%g" $1
1090     fi
1091     if [ "${MESHGEMS_ROOT_DIR}" != "" ] ; then
1092         sed -i "s%\([^/]*\)[^; ]*/MeshGems-[0-9.]\+%\1${MESHGEMS_ROOT_DIR}%g" $1
1093     fi
1094     if [ "${METIS_ROOT_DIR}" != "" ] ; then
1095         sed -i "s%\([^/]*\)[^; ]*/metis-[0-9.]\+%\1${METIS_ROOT_DIR}%g" $1
1096     fi
1097     if [ "${SCOTCH_ROOT_DIR}" != "" ] ; then
1098         sed -i "s%\([^/]*\)[^; ]*/scotch-[0-9.]\+%\1${SCOTCH_ROOT_DIR}%g" $1
1099     fi
1100     local libglso=`where_libgl_so`
1101     local sm
1102     local smvar
1103     for sm in LIBBATCH SIMANIO KERNEL GUI GEOM MED SMESH PARAVIS YACS HEXABLOCK HOMARD JOBMANAGER \
1104         NETGENPLUGIN BLSURFPLUGIN GHS3DPLUGIN GHS3DPRLPLUGIN HexoticPLUGIN HEXABLOCKPLUGIN \
1105         CALCULATOR PYCALCULATOR COMPONENT HELLO PYHELLO LIGHT PYLIGHT ATOMIC ATOMGEN ATOMSOLV RANDOMIZER SIERPINSKY ; do
1106         smvar=${sm}_ROOT_DIR
1107         if [ "${!smvar}" != "" ] ; then
1108             sed -i "s%\([; \"]\)/[^; \"]\+/${sm}\([; \"/]\)%\1${!smvar}\2%g" $1
1109         fi
1110         grep libGL.so $1 > /dev/null && sed -i "s%\([; \"]\)/[^; \"]\+/libGL.so[0-9.]*%\1${libglso}%g" $1
1111     done
1112 }