Salome HOME
Add dependency of ParaView on freetype and libxml2
[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.5.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 "^## " | awk 'BEGIN {v=1} /if / {if(v!=2)v=0;} /fi/ {if(v!=2)v=1;} /KERNEL/ {v=2;} {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 PV_PLUGIN_PATH=\(.*\)%ADD_TO_PV_PLUGIN_PATH: \1%g" ${install_work}/${CFGRC}
393 sed -i "s%export %%g" ${install_work}/${CFGRC}
394 sed -i "s%INST_ROOT%ROOT_SALOME%g" ${install_work}/${CFGRC}
395 sed -i "s%\${\?\([A-Za-z0-9_]\+\)}\?%\%(\1)s%g" ${install_work}/${CFGRC}
396
397 if [ $# -eq 5 ] ; then
398     product_dir=$5
399     if [ -d ${product_dir} ] ; then
400         test -e ${product_dir}/${SHRC} && mv ${product_dir}/${SHRC} ${product_dir}/${SHRC}_`date +%F_%T`
401         cp ${install_work}/_${SHRC}  ${product_dir}/${SHRC}
402         test -e ${product_dir}/${CSHRC} && mv ${product_dir}/${CSHRC} ${product_dir}/${CSHRC}_`date +%F_%T`
403         cp ${install_work}/_${CSHRC} ${product_dir}/${CSHRC}
404         test -e ${product_dir}/${CFGRC} && mv ${product_dir}/${CFGRC} ${product_dir}/${CFGRC}_`date +%F_%T`
405         cp ${install_work}/${CFGRC} ${product_dir}/${CFGRC}
406     fi
407 fi
408 sed -e 's%setenv ENV_FOR_LAUNCH 1%setenv ENV_FOR_LAUNCH 0%' ${install_work}/_${CSHRC} > ${install_root}/env_build.csh
409 sed -e 's%export ENV_FOR_LAUNCH=1%export ENV_FOR_LAUNCH=0%' ${install_work}/_${SHRC}  > ${install_root}/env_build.sh
410
411 cp -f ${install_work}/_${CSHRC} ${install_root}/env_products.csh
412 cp -f ${install_work}/_${SHRC}  ${install_root}/env_products.sh
413
414 rm -f ${install_work}/_${SHRC} ${install_work}/_${CSHRC}
415
416 ### !!! copying build.csh and build.sh scripts
417 if [ -e ./build.csh ] && [ ! -e ${install_root}/build.csh ]; then
418     cp -f ./build.csh ${install_root}
419 fi
420 if [ -e ./build.sh ] && [ ! -e ${install_root}/build.sh ]; then
421     cp -f ./build.sh ${install_root}
422 fi
423
424 ### !!! copying release notes
425 for p in `ls ../` ; do
426     export pdf=`echo ${p} | sed s/[.]/" "/g | awk '{print $2}'`
427     if [ "${pdf}" = "pdf" ]; then
428         export RN=${p}
429         if [ ! -e ${install_root}/${RN} ]; then
430             cp -f ../${RN} ${install_root}
431         fi
432     fi
433 done
434
435 }
436
437 #try use already existing product
438 try_existing()
439 {
440 product_dir=$1;  install_root=$2;  install_work=$3;
441 product_sequence="$4"; installed_products="$5";  product_type=$6
442 env_file=${product_dir}/env_${product_type}.sh
443 if [ -f ${env_file} ] ; then
444     cp -f ${env_file} ${install_work}/_env_${product_type}.sh
445     make_env ${install_root} ${install_work} "${product_sequence}" "${installed_products}"
446     source ${install_work}/${SHRC}
447     check_version
448     if [ $? -eq 0 ] ; then
449         return 0
450     fi
451 fi
452 echo ${product_type} | grep -q '_src$'
453 if [ $? -eq 1 ] ; then
454     print_env_bin
455 else
456     print_env_src
457 fi
458 return 0
459 }
460
461 #check existance of lib passed as first parameter
462 #return 0 if lib exists
463 #if you pass second parameter search will be done in it
464 #otherwise search will be done in ${LD_LIBRARY_PATH}
465 #you should use : as dilimeter if you are going to pass second parameter
466 check_lib_version(){
467 if [ -n "$2" ]; then
468    whereIs=$2
469 else
470    whereIs=${LD_LIBRARY_PATH}
471 fi
472 for d in `echo ${whereIs} | sed -e"s%:% %g"` ;  do
473     ret=`find ${d} -name $1 2>/dev/null`
474     if [ -n "${ret}" ] ; then
475         #echo "The $1 exists on yours system in a ${d} folder"
476         return 0
477     fi
478 done
479 return 1
480 }
481
482 find_in_path(){
483 file=$1;  shift;
484 path=$*
485 for i in `echo ${path} | sed -e"s%:% %g"` ; do
486     ret=`find ${i} -name ${file} -maxdepth 1 2>/dev/null`
487     if [ -n "${ret}" ] ; then
488         ret=`echo ${ret} | sed -e"s%/\${file}$%%g"`
489         echo ${ret}
490         return 0
491     fi
492 done
493 return 1
494 }
495
496 sort_path(){
497 arg1=$1;  val1=$2;  arg2=$3;  val2=$4
498 tmp="^${val1}$|^${val1}:|:${val1}$|:${val1}:"
499 #echo ${val2} | grep -E "${tmp}" >/dev/null 2>&1
500 #if [ $? -eq 0 ] ; then
501 #    echo "${arg2}"
502 #    return
503 #fi
504 to_tail=1
505 exclude_list="usr lib bin sbin etc"
506 for i in ${exclude_list} ; do
507     tmp="^/${i}/|^/${i}\$"
508     echo ${val1} | grep -E "${tmp}" >/dev/null 2>&1
509     if [ "$?" = "0" ] ; then to_tail=0; break; fi
510 done
511 if [ ${to_tail} -eq 0 ] ; then
512     echo ${arg2}:${arg1}
513 else
514     echo ${arg1}:${arg2}
515 fi
516 return ${to_tail}
517 }
518
519 where_tcl(){
520 if test -z "${TCLHOME}"; then
521     TCLHOME=/usr
522 fi
523 tclcfg=`find ${TCLHOME}/lib -name "tclConfig.sh" 2> /dev/null`
524 file=""
525 maxver=0
526 for f in ${tclcfg} ; do
527     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;}'`
528     if [ ${maxver} -lt ${ver} ]; then
529         maxver=${ver}
530         file=${f}
531     fi
532 done
533 if test -n "${file}"; then
534     echo `dirname ${file}`
535     return 0
536 else
537     echo ""
538     return 1
539 fi
540 }
541
542 where_tk(){
543 if test -z "${TCLHOME}"; then
544     TCLHOME=/usr
545 fi
546 tclcfg=`find ${TCLHOME}/lib -name "tkConfig.sh" 2> /dev/null`
547 file=""
548 maxver=0
549 for f in ${tclcfg} ; do
550     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;}'`
551     if [ ${maxver} -lt ${ver} ]; then
552         maxver=${ver}
553         file=${f}
554     fi
555 done
556 if test -n "${file}"; then
557     echo `dirname ${file}`
558     return 0
559 else
560     echo ""
561     return 1
562 fi
563 }
564
565 where_dps(){
566 if test -f /usr/X11R6/include/DPS/dpsconfig.h ; then
567     echo "/usr/X11R6"
568     return 0
569 fi
570 if test -f /usr/include/DPS/dpsconfig.h ; then
571     echo "/usr"
572     return 0
573 fi
574 echo ""
575 return 1
576 }
577
578 where_gl_includes(){
579 for d in /usr/X11R6/include /usr/include ; do
580     if [ -d ${d}/GL ] && [ -f ${d}/GL/gl.h ] ; then
581         echo "${d}"
582         return 0
583     fi
584 done
585 echo ""
586 return 1
587 }
588
589 where_gl_libs(){
590 local d
591 local libdir
592 local libdirs="/usr/X11R6/lib64 /usr/lib64 /usr/lib/`uname -m`-linux-gnu /usr/X11R6/lib /usr/lib"
593
594 # search libGL.so* file and correct libGL.la in the same directory
595 for d in ${libdirs} ; do
596     if [ "`ls ${d}/libGL.so* 2>/dev/null`" ] && [ -f ${d}/libGL.la ]; then
597         libdir=`grep "libdir=" ${d}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%" -e "s%/*$%%g"`
598         if [ "${libdir}" = "${d}" ] ; then
599             echo "${d}"
600             return 0
601         fi
602     fi
603 done
604 # search libGL.la file and check if this file is correct
605 for d in ${libdirs} ; do
606     if [ -f ${d}/libGL.la ] ; then
607         libdir=`grep "libdir=" ${d}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%"`
608         if [ "`ls ${libdir}/libGL.so* 2>/dev/null`" ] ; then
609             echo "${d}"
610             return 0
611         fi
612     fi
613 done
614 # then search libGL.so* file
615 for d in ${libdirs} ; do
616     if [ "`ls ${d}/libGL.so* 2>/dev/null`" ] ; then
617         echo "${d}"
618         return 0
619     fi
620 done
621 echo ""
622 return 1
623 }
624
625 where_libgl_so(){
626 local libdirs="/usr/X11R6/lib64 /usr/lib64 /usr/lib/`uname -m`-linux-gnu /usr/X11R6/lib /usr/lib"
627 local d
628 for d in ${libdirs} ; do
629     if [ -f ${d}/libGL.so ] ; then
630         echo ${d}/libGL.so
631         return 0
632     fi
633 done
634 echo ""
635 return 1
636 }
637
638 fix_gl_libs(){
639     local gllibdir="`where_gl_libs`"
640     if [ "${gllibdir}" != "" ] ; then
641 #VSR: 02/04/2013 - next block is commented as it seems to be wrong :( libGL.la should not be ever mentioned
642 #       if [ -f ${gllibdir}/libGL.la ] ; then
643 #           libdir=`grep "libdir=" ${gllibdir}/libGL.la | sed -e "s%libdir='\(.*\)'%\1%"`
644 #           if [ "`ls ${libdir}/libGL.so* 2>/dev/null`" ] ; then
645 #               str_to_replace="${gllibdir}/libGL.la"
646 #           fi
647 #       fi
648         if [ "${str_to_replace}" = "" ] ; then
649             str_to_replace="-L${gllibdir} -lGL"
650         fi
651
652         la_files=`find . -name "*.la"`
653         for la_file in ${la_files} XXX ; do
654             if [ "${la_file}" = "XXX" ] ; then continue; fi
655             grep -e "libGL.la" ${la_file} >& /dev/null || grep -e "-lGL\b" ${la_file} >& /dev/null && \
656             sed -e "s%-lGL\b%%g"                                                       \
657                 -e "s%[^[:space:]']*libGL.la[[:space:]]%%g"                            \
658                 -e "s%^dependency_libs='\(.*\)%dependency_libs='${str_to_replace} \1%" \
659                 ${la_file} > ${la_file}.new && \
660                 mv -f ${la_file}.new ${la_file}
661         done
662     fi
663 }
664
665 ##
666 # function: create .qmake.cache file for compilation of custom gcc compiler
667 # usage: gen_qmake_cache <dir>
668 #        <dir> is a directory to put .qmake.cache
669 ##
670
671 gen_qmake_cache()
672 {
673     local d=$1
674     if [ "${d}" != "" ] && [ -d ${d} ] && [ "${CXX}" != "" ] ; then
675         touch ${d}/.qmake.cache >& /dev/null
676         if [ "$?" != "0" ]  ; then
677             return 1
678         fi
679         cat > ${d}/.qmake.cache <<EOF
680 QMAKE_CXX          = ${CXX}
681 QMAKE_LINK         = ${CXX}
682 QMAKE_LINK_SHLIB   = ${CXX}
683 QMAKE_CC           = ${CC}
684 QMAKE_LINK_C       = ${CC}
685 QMAKE_LINK_C_SHLIB = ${CC}
686 EOF
687     fi
688     return 0
689 }
690
691 modif_la_files(){
692 return 0
693 # obsolete
694 ldir=$1
695 if [ -z "${ldir}" ] || [ ! -d "${ldir}" ]; then return 1; fi
696
697 srcdir=`pwd`
698
699 SALOME_MODULES="`env | awk -F_ '/[a-zA-Z0-9]*_ROOT_DIR/ { print $1 }'`"
700
701 cd ${ldir}
702 ldir=`pwd`
703 la_files=`find . -name "*.la"`
704
705 # netgen dir
706 netgendir=${NETGEN_ROOT_DIR}
707 # freetype dir
708 freetypedir=${FREETYPE_ROOT_DIR}
709 # ftgl dir
710 ftgldir=${FTGL_ROOT_DIR}
711 # gl2ps dir
712 gl2psdir=${GL2PS_ROOT_DIR}
713 # freeimage dir
714 freeimagedir=${FREEIMAGE_ROOT_DIR}
715 # tbb dir
716 tbbbasedir=${TBB_ROOT_DIR}
717 TBBKERNEL='cc4.1.0_libc2.4_kernel2.6.16.21'
718 if test `uname -m` = "x86_64" ; then
719     export TBBMODE="intel64/${TBBKERNEL}"
720 else
721     export TBBMODE="ia32/${TBBKERNEL}"
722 fi
723 tbbdir=${tbbbasedir}/lib/${TBBMODE}
724 # cgns dir
725 cgnslibdir=${CGNS_ROOT_DIR}
726 # occt dir
727 casdir=${CAS_ROOT_DIR}/lib
728 if [ ! -d ${casdir} ] ; then casdir=${CAS_ROOT_DIR}/Linux/lib ; fi
729 if [ ! -d ${casdir} ] ; then casdir=${CAS_ROOT_DIR}/lin/lib ; fi
730 # omniorb dir
731 omnidir=${OMNIORB_ROOT_DIR}/lib
732 # vtk dir
733 vtkpath=${VTK_DIR}
734 if [ `uname -m` = "x86_64" ] && [ -d ${vtkpath}/lib64 ] ; then
735     LIB_PREFIX=64
736 elif [ -d ${vtkpath}/lib ] ; then
737     LIB_PREFIX=""
738 else
739     LIB_PREFIX=64
740 fi
741 vtkldir=${vtkpath}/lib${LIB_PREFIX}
742 vtkdir=${vtkldir}/vtk-5.0
743 # hdf dir
744 hdfdir=${HDF5_ROOT_DIR}/lib
745 # med dir
746 meddir=${MEDFILE_ROOT_DIR}/lib
747 # qwt dir
748 qwtdir=`find_in_path libqwt.so ${LD_LIBRARY_PATH}`
749 # python dir
750 where_python=`which python`                 # e.g. /usr/bin/python
751 if [ -n "${where_python}" ] ; then
752     where_python=`dirname ${where_python}`    # --> /usr/bin
753     where_python=`dirname ${where_python}`    # --> /usr
754     python_version=`python -c "import sys; print sys.version[:3]"`
755     pythondir=${where_python}/lib/python${python_version}
756 fi
757 # sip dir
758 sipdir=`find_in_path sip.so ${LD_LIBRARY_PATH}`
759 # pyqt dir
760 pyqtdir=`find_in_path Qt.so ${LD_LIBRARY_PATH}`
761 # tcl/tk dir
762 tcldir=${TCLHOME}/lib
763 # boost dir
764 boostdir=${BOOST_ROOT_DIR}/lib
765 # blsurf dir
766 blsurfdir=${BLSURFHOME}/lib
767 # libxml2 dir
768 libxmldir=${LIBXML2_ROOT_DIR}/lib
769 # metis dir
770 metisdir=${METIS_ROOT_DIR}
771 # scotch dir
772 scotchbindir=${SCOTCH_ROOT_DIR}/bin
773 scotchlibdir=${SCOTCH_ROOT_DIR}/lib
774 # gl dir
775 if test `uname -m` = "x86_64" ; then
776     libGLpath=/usr/lib64/libGL.la
777 else
778     libGLpath=/usr/lib/libGL.la
779 fi
780 # graphviz dir
781 graphvizdir=${GRAPHVIZ_ROOT_DIR}/lib
782 # qscintilla dir
783 qscintilladir=${QSCINTILLA_ROOT_DIR}/lib
784 # paraview dir
785 paraviewdir=${PARAVIEW_ROOT_DIR}/lib
786 # qt dir
787 qtdir=${QT4_ROOT_DIR}/lib
788 # distene meshgems dir
789 if test `uname -m` = "x86_64" ; then
790     mgemsdir=${MESHGEMS_ROOT_DIR}/lib/Linux_64
791 else
792     mgemsdir=${MESHGEMS_ROOT_DIR}/lib/Linux
793 fi
794
795 for l in X ${la_files}; do
796
797 if [ "${l}" != "X" ] ; then
798     d=`dirname ${l}`
799     l=`basename ${l}`
800     cd ${ldir}; cd ${d}
801
802     # . process salome modules dependencies
803     for mod in ${SALOME_MODULES} ; do
804         moddir=${mod}_ROOT_DIR
805         moddir=${!moddir}
806         if [ -n "${moddir}" ] ; then
807             sed -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}[1]\?/lib% \1${moddir}/lib%g" \
808                 -e "s%[[:space:]]\(-L\)\?[^[:space:]]*${mod}WOGUI[1]\?/lib% \1${moddir}/lib%g" \
809                 -e "s%^libdir='[^[:space:]]*${mod}[1]\?/\(lib.*\)'%libdir='${moddir}/\1'%g" \
810                 -e "s%^libdir='[^[:space:]]*${mod}WOGUI[1]\?/\(lib.*\)'%libdir='${moddir}/\1'%g" ${l} > ${l}"_"
811             mv -f ${l}"_" ${l}
812         fi
813     done
814
815     # . process netgen dependencies
816     if [ -n "${netgendir}" ] && [ -d "${netgendir}" ] ; then
817         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*netgen-[0-9.]\+/lib% \1${netgendir}/lib%g" ${l}
818     fi
819
820     # . process freetype dependencies
821     if [ -n "${freetypedir}" ] && [ -d "${freetypedir}" ] ; then
822         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*freetype-[0-9.]\+/lib% \1${freetypedir}/lib%g" ${l}
823     fi
824
825     # . process ftgl dependencies
826     if [ -n "${ftgldir}" ] && [ -d "${ftgldir}" ] ; then
827         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*ftgl-[0-9.]\+/lib% \1${ftgldir}/lib%g" ${l}
828     fi
829
830     # . process gl2ps dependencies
831     if [ -n "${gl2psdir}" ] && [ -d "${gl2psdir}" ] ; then
832         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*gl2ps-[0-9.]\+/lib% \1${gl2psdir}/lib%g" ${l}
833     fi
834
835     # . process freeimage dependencies
836     if [ -n "${freeimagedir}" ] && [ -d "${freeimagedir}" ] ; then
837         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*freeimage-[0-9.]\+/lib% \1${freeimagedir}/lib%g" ${l}
838     fi
839
840     # . process tbb dependencies
841     if [ -n "${tbbdir}" ] && [ -d "${tbbdir}" ] ; then
842         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*tbb[^[:space:]]*/lib[^[:space:]]*% \1${tbbdir}%g" ${l}
843     fi
844
845     # . process cgns dependencies
846     if [ -n "${cgnslibdir}" ] && [ -d "${cgnslibdir}" ] ; then
847         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*cgnslib-[0-9.]\+/lib% \1${cgnslibdir}/lib%g" ${l}
848     fi
849
850     # . process CAS.CADE dependencies
851     if [ -n "${CAS_ROOT_DIR}" ] && [ -d "${casdir}" ] ; then
852         sed -e "s%-L[^[:space:]]*OCCT[^[:space:]]*/install/lib%-L${casdir}%g" \
853             -e "s%[^[:space:]]*OCCT[^[:space:]]*/install/lib/%${casdir}/%g"   \
854             -e "s%[[:space:]]-L[^[:space:]]*\(OCCT\|CAS\)[^[:space:]]*/lib\?% -L${CAS_ROOT_DIR}/lib%g" \
855             -e "s%[[:space:]][^[:space:]]*\(OCCT\|CAS\)[^[:space:]]*/lib/lib\?% ${CAS_ROOT_DIR}/lib/lib%g" ${l} > ${l}"_"
856         mv -f ${l}"_" ${l}
857     fi
858
859     # . process omniORB dependencies
860     if [ -n "${OMNIORB_ROOT_DIR}" ] && [ -d "${omnidir}" ] ; then
861         sed -i "s%-L[^[:space:]]*omni[^[:space:]]*%-L${omnidir}%g;s%-R[^[:space:]]*omni[^[:space:]]*%-R${omnidir}%g" ${l}
862     fi
863
864     # . process VTK dependencies
865     if [ -n "${VTK_DIR}" ] && [ -d "${vtkdir}" ] && [ -d "${vtkldir}" ] ; then
866         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}
867     fi
868
869     # . process HDF dependencies
870     if [ -n "${HDF5_ROOT_DIR}" ] && [ -d "${hdfdir}" ] ; then
871         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*hdf[^[:space:]/]*/lib% \1${hdfdir}%g" ${l}
872     fi
873
874     # . process MED dependencies
875     if [ -n "${MEDFILE_ROOT_DIR}" ] && [ -d "${meddir}" ] ; then
876         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*med[^[:space:]/]*/lib% \1${meddir}%g" ${l}
877     fi
878
879     # . process qwt dependencies
880     if [ -n "${qwtdir}" ] && [ -d "${qwtdir}" ] ; then
881         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*qwt[^[:space:]/]*/lib% \1${qwtdir}%g" ${l}
882     fi
883
884     # . process qt dependencies
885     if [ -n "${QT4_ROOT_DIR}" ] && [ -d "${qtdir}" ] ; then
886         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*qt[^[:space:]/]*/lib% \1${qtdir}%g" ${l}
887     fi
888
889     # . process python dependencies
890     if [ -n "${pythondir}" ] && [ -d "${pythondir}" ] ; then
891         sed -i "s%-L[^[:space:]]*python[0-9]\.[0-9]\([^[:space:]]*\)%-L${pythondir}\1%g" ${l}
892     fi
893
894     # . process sip dependencies
895     if [ -n "${sipdir}" ] && [ -d "${sipdir}" ] ; then
896         sed -i "s%-L[^[:space:]]*sip[^[:space:]]*%-L${sipdir}%g" ${l}
897     fi
898
899     # . process PyQt dependencies
900     if [ -n "${pyqtdir}" ] && [ -d "${pyqtdir}" ] ; then
901         sed -i "s%-L[^[:space:]]*PyQt[^[:space:]]*%-L${pyqtdir}%g" ${l}
902     fi
903
904     # . process tcl/tk dependencies
905     if [ -n "${tcldir}" ] && [ -d "${tcldir}" ] ; then
906         sed -i "s%-L[^[:space:]]*tcltk[^[:space:]]*/lib%-L${tcldir}%g" ${l}
907     fi
908
909     # . process boost dependencies
910     if [ -n "${boostdir}" ] && [ -d "${boostdir}" ] ; then
911         sed -i "s%-L[^[:space:]]*boost[^[:space:]]*/lib%-L${boostdir}%g" ${l}
912     fi
913
914     # . process blsurf dependencies
915     if [ -n "${blsurfdir}" ] && [ -d "${blsurfdir}" ] ; then
916         sed -i "s%-L[^[:space:]]*BLSurf[^[:space:]]*/lib%-L${blsurfdir}%g" ${l}
917     fi
918
919     # . process libxml dependencies
920     if [ -n "${libxmldir}" ] && [ -d "${libxmldir}" ] ; then
921         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}
922     fi
923
924     # . process metis dependencies
925     if [ -n "${metisdir}" ] && [ -d "${metisdir}" ] ; then
926         sed -i "s%-L[^[:space:]]*metis[^[:space:]]*%-L${metisdir}%g" ${l}
927     fi
928
929     # . process scotch dependencies
930     if [ -n "${scotchbindir}" ] && [ -d "${scotchbindir}" ] ; then
931         sed -i "s%-L[^[:space:]]*scotch[^[:space:]]*/bin%-L${scotchbindir}%g" ${l}
932     fi
933     if [ -n "${scotchlibdir}" ] && [ -d "${scotchlibdir}" ] ; then
934         sed -i "s%-L[^[:space:]]*scotch[^[:space:]]*/lib%-L${scotchlibdir}%g" ${l}
935     fi
936
937     # . process libGL.la dependencies
938     sed -i "s%${libGLpath}%""%g" ${l}
939
940     # . process graphviz dependencies
941     if [ -n "${graphvizdir}" ] && [ -d "${graphvizdir}" ] ; then
942         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}
943     fi
944
945     # . process QScintilla dependencies
946     if [ -n "${qscintilladir}" ] && [ -d "${qscintilladir}" ] ; then
947         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*QScintilla-[0-9]\.[0-9]\(\.[0-9]\)\?/lib% \1${qscintilladir}%g" ${l}
948     fi
949
950     # . process ParaView dependencies
951     if [ -n "${paraviewdir}" ] && [ -d "${paraviewdir}" ] ; then
952         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*ParaView-[0-9]\.[0-9]\+\.[0-9]/lib% \1${paraviewdir}%g" ${l}
953     fi
954
955     # . process DISTENE MeshGems dependencies
956     if [ -n "${mgemsdir}" ] && [ -d "${mgemsdir}" ] ; then
957         sed -i "s%[[:space:]]\(-L\)\?[^[:space:]]*MeshGems-[0-9.]\+/Products/lib/Linux\(_64\)\?% \1${mgemsdir}%g" ${l}
958     fi
959
960 fi
961 done
962
963 cd ${srcdir}
964 return 0
965 }
966
967 modif_cfg_file(){
968     local nf=$1
969     if [ "${nf}" = "" ] || [ ! -e ${nf} ] ; then
970         return
971     fi
972     if [ "${PYTHON_ROOT_DIR}" != "" ] ; then
973         sed -i "s%\([^/]*\)[^; ]*/Python-[0-9.]\+%\1${PYTHON_ROOT_DIR}%g" $1
974     fi
975     if [ "${SWIG_ROOT_DIR}" != "" ] ; then
976         sed -i "s%\([^/]*\)[^; ]*/swig-[0-9.]\+%\1${SWIG_ROOT_DIR}%g" $1
977     fi
978     if [ "${OMNIORB_ROOT_DIR}" != "" ] ; then
979         sed -i "s%\([^/]*\)[^; ]*/omniORB-[0-9.]\+%\1${OMNIORB_ROOT_DIR}%g" $1
980     fi
981     if [ "${HDF5_ROOT_DIR}" != "" ] ; then
982         sed -i "s%\([^/]*\)[^; ]*/hdf5-[0-9.]\+%\1${HDF5_ROOT_DIR}%g" $1
983     fi
984     if [ "${BOOST_ROOT_DIR}" != "" ] ; then
985         sed -i "s%\([^/]*\)[^; ]*/boost-[0-9.]\+%\1${BOOST_ROOT_DIR}%g" $1
986     fi
987     if [ "${MEDFILE_ROOT_DIR}" != "" ] ; then
988         sed -i "s%\([^/]*\)[^; ]*/med-[0-9.]\+%\1${MEDFILE_ROOT_DIR}%g" $1
989     fi
990     if [ "${QT4_ROOT_DIR}" != "" ] ; then
991         sed -i "s%\([^/]*\)[^; ]*/qt-[0-9.]\+%\1${QT4_ROOT_DIR}%g" $1
992     fi
993     if [ "${QWT_ROOT_DIR}" != "" ] ; then
994         sed -i "s%\([^/]*\)[^; ]*/qwt-[0-9.]\+%\1${QWT_ROOT_DIR}%g" $1
995     fi
996     if [ "${SIP_ROOT_DIR}" != "" ] ; then
997         sed -i "s%\([^/]*\)[^; ]*/sip-[0-9.]\+%\1${SIP_ROOT_DIR}%g" $1
998     fi
999     if [ "${PYQT4_ROOT_DIR}" != "" ] ; then
1000         sed -i "s%\([^/]*\)[^; ]*/PyQt-[0-9.]\+%\1${PYQT4_ROOT_DIR}%g" $1
1001     fi
1002     if [ "${QSCINTILLA_ROOT_DIR}" != "" ] ; then
1003         sed -i "s%\([^/]*\)[^; ]*/QScintilla-[0-9.]\+%\1${QSCINTILLA_ROOT_DIR}%g" $1
1004     fi
1005     if [ "${PARAVIEW_ROOT_DIR}" != "" ] ; then
1006         sed -i "s%\([^/]*\)[^; ]*/ParaView-[0-9.]\+%\1${PARAVIEW_ROOT_DIR}%g" $1
1007     fi
1008     if [ "${LIBXML2_ROOT_DIR}" != "" ] ; then
1009         sed -i "s%\([^/]*\)[^; ]*/libxml2-[0-9.]\+%\1${LIBXML2_ROOT_DIR}%g" $1
1010     fi
1011     if [ "${FREETYPE_ROOT_DIR}" != "" ] ; then
1012         sed -i "s%\([^/]*\)[^; ]*/freetype-[0-9.]\+%\1${FREETYPE_ROOT_DIR}%g" $1
1013     fi
1014     if [ "${FREEIMAGE_ROOT_DIR}" != "" ] ; then
1015         sed -i "s%\([^/]*\)[^; ]*/freeimage-[0-9.]\+%\1${FREEIMAGE_ROOT_DIR}%g" $1
1016     fi
1017     if [ "${GL2PS_ROOT_DIR}" != "" ] ; then
1018         sed -i "s%\([^/]*\)[^; ]*/gl2ps-[0-9.]\+%\1${GL2PS_ROOT_DIR}%g" $1
1019     fi
1020     if [ "${TBB_ROOT_DIR}" != "" ] ; then
1021         sed -i "s%\([^/]*\)[^; ]*/tbb[^/; \"]\+%\1${TBB_ROOT_DIR}%g" $1
1022     fi
1023     if [ "${CAS_ROOT_DIR}" != "" ] ; then
1024         sed -i "s%\([^/]*\)[^; ]*/OCCT[^/]*\(/[^ /;\"]*\)\?\(\"\|/inc\|/lib\)%\1${CAS_ROOT_DIR}\3%g" $1
1025     fi
1026     if [ "${NETGEN_ROOT_DIR}" != "" ] ; then
1027         sed -i "s%\([^/]*\)[^; ]*/netgen-[0-9.]\+%\1${NETGEN_ROOT_DIR}%g" $1
1028     fi
1029     if [ "${CGNS_ROOT_DIR}" != "" ] ; then
1030         sed -i "s%\([^/]*\)[^; ]*/cgnslib-[0-9.]\+%\1${CGNS_ROOT_DIR}%g" $1
1031     fi
1032     if [ "${NUMPY_ROOT_DIR}" != "" ] ; then
1033         sed -i "s%\([^/]*\)[^; ]*/numpy-[0-9.]\+%\1${NUMPY_ROOT_DIR}%g" $1
1034     fi
1035     if [ "${GRAPHVIZ_ROOT_DIR}" != "" ] ; then
1036         sed -i "s%\([^/]*\)[^; ]*/graphviz-[0-9.]\+%\1${GRAPHVIZ_ROOT_DIR}%g" $1
1037     fi
1038     if [ "${DOXYGEN_ROOT_DIR}" != "" ] ; then
1039         sed -i "s%\([^/]*\)[^; ]*/doxygen-[0-9.]\+%\1${DOXYGEN_ROOT_DIR}%g" $1
1040     fi
1041     if [ "${SPHINX_ROOT_DIR}" != "" ] ; then
1042         sed -i "s%\([^/]*\)[^; ]*/Sphinx-[0-9.]\+%\1${SPHINX_ROOT_DIR}%g" $1
1043     fi
1044     if [ "${WSO2_ROOT_DIR}" != "" ] ; then
1045         sed -i "s%\([^/]*\)[^; ]*/wso2-wsf-cpp-[0-9.]\+%\1${WSO2_ROOT_DIR}%g" $1
1046     fi
1047     if [ "${MESHGEMS_ROOT_DIR}" != "" ] ; then
1048         sed -i "s%\([^/]*\)[^; ]*/MeshGems-[0-9.]\+%\1${MESHGEMS_ROOT_DIR}%g" $1
1049     fi
1050     if [ "${METIS_ROOT_DIR}" != "" ] ; then
1051         sed -i "s%\([^/]*\)[^; ]*/metis-[0-9.]\+%\1${METIS_ROOT_DIR}%g" $1
1052     fi
1053     if [ "${SCOTCH_ROOT_DIR}" != "" ] ; then
1054         sed -i "s%\([^/]*\)[^; ]*/scotch-[0-9.]\+%\1${SCOTCH_ROOT_DIR}%g" $1
1055     fi
1056     local libglso=`where_libgl_so`
1057     local sm
1058     local smvar
1059     for sm in LIBBATCH SIMANIO KERNEL GUI GEOM MED SMESH PARAVIS YACS HEXABLOCK HOMARD JOBMANAGER \
1060         NETGENPLUGIN BLSURFPLUGIN GHS3DPLUGIN GHS3DPRLPLUGIN HexoticPLUGIN HYBRIDPLUGIN HEXABLOCKPLUGIN \
1061         CALCULATOR PYCALCULATOR COMPONENT HELLO PYHELLO LIGHT PYLIGHT ATOMIC ATOMGEN ATOMSOLV RANDOMIZER SIERPINSKY ; do
1062         smvar=${sm}_ROOT_DIR
1063         if [ "${!smvar}" != "" ] ; then
1064             sed -i "s%\([; \"]\)/[^; \"]\+/${sm}\([; \"/]\)%\1${!smvar}\2%g" $1
1065         fi
1066         grep libGL.so $1 > /dev/null && sed -i "s%\([; \"]\)/[^; \"]\+/libGL.so[0-9.]*%\1${libglso}%g" $1
1067     done
1068 }