Salome HOME
5f16e513716dd545b14d45510bda45fbd77e8ecd
[tools/install.git] / config_files / build.sh
1 #!/bin/bash -noprofile
2
3 ####################################################################################
4 #  File      : build.sh
5 #  Created   : Thu Jan 27 09:50:55 2005
6 #  Author    : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
7 #  Project   : SALOME
8 #  Module    : Installation Wizard
9 #  Copyright : 2002-2012 CEA
10 #
11 #  This script is the part of the SALOME installation procedure.
12 #
13 #  This script can be used to build and install SALOME modules from sources.
14 #  Try build.sh -h for more details about usage.
15 #
16 ####################################################################################
17
18 ###############################################################
19 # Prints usage information and exits
20 ###############################################################
21 usage(){
22     echo ""
23     echo "Description:"
24     echo "            Builds given SALOME modules by performing make and "
25     echo "            make install commands"
26     echo ""
27     echo "Usage:"
28     echo "            build.sh [ <option> ] ... [ <module> [ <module> ... ] ]"
29     echo ""
30     echo "<module>    Modules to build, separated by space(s)."
31     echo "            If no modules are given - all SALOME modules are assumed."
32     echo "            Note, that modules given in command lines are automatically"
33     echo "            sorted in such order to support correct modules dependencies."
34     echo ""
35     echo "Options:"
36     echo "-b          Perform build_configure command for all given modules."
37     echo "            This option forces configure (-c) key to be set. Default is off."
38     echo ""
39     echo "-c          Perform configure command for all given modules. Default is off."
40     echo ""
41     echo "-w          Add --without-gui key to build_configure and configure commands"
42     echo "            to build SALOME module sources without GUI."
43     echo "            By default sources are built with GUI."
44     echo ""
45     echo "-d          Delete build directories before calling configure, to force full"
46     echo "            rebuild and reinstall of the module."
47     echo "            Use this option carefully."
48     echo ""
49     echo "-o          Build sources in optimized mode. Default is off that means"
50     echo "            debug mode."
51     echo "            Use this option together with -c or -b."
52     echo "            This option can require -d option to be set (to ensure that"
53     echo "            previously created build directories are removed to enforce"
54     echo "            rebuild in optimized mode)."
55     echo ""
56     echo "-t          Performs make dev_docs step to build TUI documentation for those"
57     echo "            modules which support this. Default is off."
58     echo ""
59     echo "-p <prefix> Define the directory where to install modules after compilation."
60     echo "            By default the directory where compilation is performed is used."
61     echo ""
62     echo "-v <level>  Verbose level (0-2, default 2): print information on build status:"
63     echo "            0: only 'make' errors"
64     echo "            1: 0 + compiler and other errors (build_configure, configure)"
65     echo "            2: 1 + compiler and other warnings "
66     echo ""
67     echo "-h          Prints this help information."
68     echo ""
69     echo "Note:       If no keys are given script just performs make step."
70     echo ""
71     echo "Example:"
72     echo "            ./build.csh -o -p /home/user/salome -b KERNEL MED GEOM"
73     echo ""
74     echo "            This will make KERNEL, GEOM and MED modules: build_configure,"
75     echo "            configure, make and install procedures will be performed for all"
76     echo "            specified modules. The modules will be built in the optimized mode."
77     echo ""
78     exit 1
79 }
80
81 is_build_configure=0
82 is_configure=0
83 inst_with_gui=1
84 is_delete=0
85 verbose_level=2
86 params=""
87 modules="KERNEL GUI GEOM MED SMESH VISU PARAVIS YACS NETGENPLUGIN GHS3DPLUGIN BLSURFPLUGIN HexoticPLUGIN GHS3DPRLPLUGIN COMPONENT PYCALCULATOR CALCULATOR HELLO PYHELLO LIGHT PYLIGHT SIERPINSKY RANDOMIZER HEXABLOCK HEXABLOCKPLUGIN ATOMIC ATOMGEN ATOMSOLV HOMARD JOBMANAGER"
88 optim=""
89 is_install=1
90 is_tui=0
91 prefix=""
92 def_install_dir="/INSTALL"
93
94 #########################################################
95 # parse parameters
96 #########################################################
97 while getopts ":hbcwdotv:p:" option ; do
98     case $option in
99         h ) usage ;;
100         b ) is_build_configure=1 ; is_configure=1 ;;
101         c ) is_configure=1 ;;
102         w ) inst_with_gui=0 ;;
103         d ) is_delete=1 ;;
104         o ) optim="--enable-production=yes --disable-debug" ;;
105         t ) is_tui=1 ;;
106         v ) verbose_level=$OPTARG ;;
107         p ) is_install=1 ; prefix=$OPTARG ;;
108         ? ) usage ;;
109     esac
110 done
111 # shift to have the good number of other args
112 shift $((OPTIND - 1))
113
114 b_params=""
115
116 for arg in $@ ; do
117     known=0
118     for m in $modules ; do
119         if [ "$m" == "$arg" ] ; then known=1 ; break ; fi
120     done
121     if [ $known -eq 0 ] ; then
122         echo
123         echo '!!! Warning !!! Unknown module: '$arg'.'
124         b_params="$b_params $arg"
125     else
126         params="$params $arg"
127     fi
128 done
129
130 #########################################################
131 # sort modules in proper order according to the dependancies
132 #########################################################
133 if [ "${params}" != "" ] ; then
134     xparams=""
135     for module in ${modules} ; do
136         found=0
137         for p in $params ; do
138             if [ "$p" == "$module" ] ; then found=1 ; break ; fi
139         done
140         if [ $found -eq 1 ] ; then 
141             xparams="$xparams $module"
142         fi
143     done
144     modules="$xparams $b_params"
145 elif [ "${b_params}" != "" ] ; then
146     modules="$b_params"
147 fi
148
149 echo
150 echo ">>> The following modules will be built:"
151 echo $modules
152 echo
153
154 #########################################################
155 # set environment
156 #########################################################
157 env_script=`dirname $0`/env_build.sh
158 if [ ! -e $env_script ] ; then
159     env_script=`dirname $0`/env_products.sh
160 fi
161 if [ ! -e $env_script ] ; then
162     env_script=`dirname $0`/env.sh
163 fi
164 if [ -e $env_script ] ; then
165     echo
166     echo ">>> Setting environment"
167     source $env_script
168 else
169     echo
170     echo '!!! Warning !!! Environment is not set.'
171     echo 'No environment file (env_build.sh, env_products.sh, env.sh) is found.'
172     echo 'Proceed with the current environment.'
173 fi
174
175 BUILD_DIR=${PWD}
176 LOG_DIR=${BUILD_DIR}/LOGS
177
178 #########################################################
179 # define installation prefix
180 #########################################################
181 if [ "$prefix" == "" ] ; then
182     echo
183     echo '!!! Warning !!! Installation directory is not set.'
184     echo "All the modules will be installed to the ${BUILD_DIR}${def_install_dir}"
185 else
186     if [ "`echo $prefix | grep -E '^/'`" == "" ] ; then
187         prefix=${BUILD_DIR}/$prefix
188         echo
189         echo '!!! Warning !!! Relative prefix is used.'
190         echo "All the modules will be installed to the $prefix."
191     fi
192 fi
193
194 #########################################################
195 # create log directory
196 #########################################################
197 if [ ! -e ${LOG_DIR} ] ; then
198     mkdir -p ${LOG_DIR}
199 fi
200
201 echo
202 echo "==========================================================================="
203 echo "Starting SALOME build at `date`"
204 echo "==========================================================================="
205 echo
206
207 #########################################################
208 # loop for all given modules
209 #########################################################
210 for module in ${modules}; do
211     echo ">>> Processing ${module} module"
212
213     module_src=`printenv ${module}_SRC_DIR`
214     module_build=${BUILD_DIR}/${module}_BUILD
215     
216     if [ "${module_src}" != "" ] ; then
217         cd ${BUILD_DIR}
218         #########################################################
219         # check if sources directory exists
220         #########################################################
221         if [ ! -e ${module_src} ] ; then
222             echo
223             echo '!!! Error !!! Cannot find module sources directory:'
224             echo "${module_src} does not exist."
225             echo
226             continue
227         fi
228         #########################################################
229         # check if configure script exists
230         #########################################################
231         cfg_exist=0
232         if [ -e ${module_src}/configure ] || [ -e ${module_src}/CMakeLists.txt ] ; then
233             cfg_exist=1
234         fi
235         #########################################################
236         # perform build_configure if -b flag is given or if 
237         # configure script does not exist (first compilation?)
238         #########################################################
239         if [ $is_build_configure -eq 1 ] || [ $cfg_exist -eq 0 ] ; then
240             echo "... Performing build_configure"
241             #########################################################
242             # check if build_configure script exists
243             #########################################################
244             if [ ! -e ${module_src}/build_configure ] && [ "${module}" != "PARAVIS" ] ; then
245                 echo '!!! Warning !!! Cannot find build_configure script in '${module_src}'.'
246             else
247                 if [ "${module}" == "PARAVIS" ]; then
248                     echo '!!! Warning !!! build_configure step is not executed for '${module}'.'                    
249                 else
250                     #########################################################
251                     # call build_configure
252                     #########################################################
253                     mybuildconf_keys="${BUILDCONF_OPTS}"
254                     if [ $inst_with_gui -eq 0 ] ; then
255                         mybuildconf_keys="${mybuildconf_keys} --without-gui"
256                     fi
257                     cd ${module_src}
258                     ./build_configure ${mybuildconf_keys} >& ${LOG_DIR}/build_configure_${module}.log
259                     #########################################################
260                     # echo possible errors
261                     #########################################################
262                     if [ $verbose_level -gt 0 ] ; then
263                         cat ${LOG_DIR}/build_configure_${module}.log | grep -E "(failed|: error:)" >&2
264                     fi
265                 fi
266             fi
267         fi
268         #########################################################
269         # deleting build directory if -d flag is given
270         #########################################################
271         if [ -e ${module_build} ] && [ $is_delete -eq 1 ] ; then
272             echo "... Removing ${module_build}"
273             chmod -R +w ${module_build} && rm -rf ${module_build} >& /dev/null
274             if [ "$?" != "0" ] ; then
275                 echo
276                 echo '!!! Warning !!! Cannot remove build directory ${module_build}. Permission denied.'
277                 echo
278             fi
279         fi
280         #########################################################
281         # creating build directory if it does not exist
282         #########################################################
283         if [ ! -e ${module_build} ] ; then
284             mkdir -p ${module_build} >& /dev/null
285             if [ "$?" != "0" ] ; then
286                 echo
287                 echo '!!! Error !!! Cannot create build directory ${module_build}. Permission denied.'
288                 echo
289                 continue
290             fi
291         fi
292         cd ${module_build}
293         #########################################################
294         # check if top Makefile exists in build directory, i.e. 
295         # is it necessary to run configure script
296         #########################################################
297         mkfile_exist=0
298         if [ -e ${module_build}/Makefile ] ; then
299             mkfile_exist=1
300         fi
301         #########################################################
302         # check if configure options are changed from the 
303         # previous launch
304         #########################################################
305         opts_changed=0
306         #########################################################
307         # define installation directory (by using module's version
308         # number); default is a build directory
309         #########################################################
310         vx=""
311         if [ -e ${module_src}/configure.ac ] ; then
312             vx=`grep -e "^AC_INIT" ${module_src}/configure.ac | sed -e "s%.*\[\([[:digit:].]*\)\].*%\1%g"`
313         elif [ -e ${module_src}/configure.in.base ] ; then
314             vx=`grep -e "^VERSION=" ${module_src}/configure.in.base | awk -F= '{ if (NF>1) print $NF; }' | tr -d '[:space:]'`
315             if [ "$vx" == "" ] ; then
316                 vx=`grep -e "^AC_INIT" ${module_src}/configure.in.base | sed -e "s%.*\[\([[:digit:].]*\)\].*%\1%g"`
317             fi
318         elif [ -e ${module_src}/CMakeLists.txt ] ; then
319             ver_maj=`cat ${module_src}/CMakeLists.txt | grep SET\(VERSION_MAJOR | sed -e "s%[A-Z_() ]%%g"`
320             ver_min=`cat ${module_src}/CMakeLists.txt | grep SET\(VERSION_MINOR | sed -e "s%[A-Z_() ]%%g"`
321             ver_maintenance=`cat ${module_src}/CMakeLists.txt | grep SET\(VERSION_MAINTENANCE | sed -e "s%[A-Z_() ]%%g"`
322             vx="${ver_maj}.${ver_min}.${ver_maintenance}"
323         fi
324         if [ "$vx" != "" ] ; then
325             vx="_$vx"
326         fi
327         if [ "$prefix" == "" ] ; then
328             px=${BUILD_DIR}${def_install_dir}/${module}${vx}
329         else
330             px=$prefix/${module}${vx}
331         fi
332         #########################################################
333         # perform configure if -c flag is given or if 
334         # Makefile does not exist (first compilation?)
335         #########################################################
336         if [ $is_configure -eq 1 ] || [ $mkfile_exist -eq 0 ] || [ $opts_changed -eq 1 ] ; then
337             echo "... Performing configure"
338             #########################################################
339             # check if configure script exists
340             #########################################################
341             if [ ! -e ${module_src}/configure ] && [ "${module}" != "PARAVIS" ] ; then
342                 echo
343                 echo '!!! Warning !!! Can not find configure script in '${module_src}'.'
344                 echo
345             else
346                 myconf_keys="${CONF_OPTS}"
347                 if [ $inst_with_gui -eq 0 ] ; then
348                     myconf_keys="${myconf_keys} --without-gui"
349                 fi
350                 if [ "${module}" == "MED" ] && [ "${METISDIR}" != "" ] && [ "${SCOTCHDIR}" != "" ] ; then
351                     myconf_keys="${myconf_keys} --enable-splitter=yes --with-metis=${METISDIR} --with-scotch=${SCOTCHDIR}"
352                 fi
353                 if [ "${module}" == "NETGENPLUGIN" ] && [ "$NETGENHOME" != "" ] ; then
354                     myconf_keys="${myconf_keys} --with-netgen=${NETGENHOME}"
355                 fi
356
357                 if [ "${module}" == "PARAVIS" ] ; then
358                     cd ${module_build}; cmake ${module_src} -DCMAKE_INSTALL_PREFIX=$px >& ${LOG_DIR}/configure_${module}.log
359                 else
360                     ${module_src}/configure --prefix=$px ${optim} ${myconf_keys} >& ${LOG_DIR}/configure_${module}.log
361                 fi
362
363                 #########################################################
364                 # echo possible errors
365                 #########################################################
366                 if [ $verbose_level -gt 0 ] ; then
367                     cat ${LOG_DIR}/configure_${module}.log | grep ": error:" >&2
368                 fi
369                 if [ $verbose_level -gt 1 ] ; then
370                     cat ${LOG_DIR}/configure_${module}.log | grep ": WARNING:" >&2
371                 fi
372             fi
373         fi
374         #########################################################
375         # perform make
376         #########################################################
377         echo "... Performing make"
378         #########################################################
379         # first clear dependencies
380         #########################################################
381         find . -name ".dep*" -type f -exec rm -f {} \; >& /dev/null
382         #########################################################
383         # then make
384         #########################################################
385         if [ "${module}" == "PARAVIS" ] ; then
386             VTK_AUTOLOAD_PATH_BACKUP=${VTK_AUTOLOAD_PATH}
387             test "${VTK_AUTOLOAD_PATH}" != "" && unset VTK_AUTOLOAD_PATH
388         fi
389         make >& ${LOG_DIR}/make_${module}.log
390         sts=$?
391         if [ "${module}" == "PARAVIS" ] ; then
392             test "${VTK_AUTOLOAD_PATH_BACKUP}" != "" && export VTK_AUTOLOAD_PATH=${VTK_AUTOLOAD_PATH_BACKUP}
393         fi
394         #########################################################
395         # if make step is successful set the ${module}_ROOT_DIR
396         # environment variable
397         #########################################################
398         #if [ $sts -eq 0 ] ; then
399         #    export ${module}_ROOT_DIR=${module_build}
400         #fi
401         #########################################################
402         # print make errors
403         #########################################################
404         cat ${LOG_DIR}/make_${module}.log | grep -Ei '[*][*][*].*error' >&2
405         #########################################################
406         # print compiler errors and warnings
407         # Note: here awk is used to concatenate together several lines of single
408         #       error or warning message produced by stupid gnu compiler
409         # Actually, instead of that we could use 'fmessage length=n' option of g++...
410         #########################################################
411         if [ $verbose_level -gt 0 ] ; then
412             ###cat ${LOG_DIR}/make_${module}.log | grep ": error"
413             cat ${LOG_DIR}/make_${module}.log | awk 'substr($0,0,1)!=" " {print ""} {print $0} END {print ""}' | grep "${module_src}/[A-Za-z_0-9./]*:" | sed s@"^${module_src}/src/"@@ >&2
414         fi
415         if [ $verbose_level -gt 1 ] ; then
416             cat ${LOG_DIR}/make_${module}.log | awk 'substr($0,0,1)!=" " {print ""} {print $0} END {print ""}' | grep -E ": warning|* Warning" | sed s@"^${module_src}/src/"@@ >&2
417         fi
418         #########################################################
419         # perform make dev_docs step if -t flag is given
420         #########################################################
421         if [ $is_tui -eq 1 ] && [ $sts -eq 0 ] && [ -d ${module_build}/doc ] ; then
422             cd ${module_build}/doc
423             dd=`cat Makefile | grep -E "dev_docs[[:space:]]*:"`
424             if [ "$dd" != "" ] ; then
425                 echo "... Performing make dev_docs"
426                 make dev_docs >& ${LOG_DIR}/make_dev_docs_${module}.log
427                 cat ${LOG_DIR}/make_dev_docs_${module}.log | grep '[*][*][*]' >&2
428             fi
429         fi
430         cd ${module_build}
431         #########################################################
432         # perform make if -i or -p flags are given
433         #########################################################
434         if [ $is_install -eq 1 ] && [ $sts -eq 0 ] || [ "${module}" == "KERNEL" ] ; then
435             #########################################################
436             # deleting build directory if -d flag is given
437             #########################################################
438             if [ -e $px ] && [ $is_delete -eq 1 ] ; then
439                 echo "... Removing $px"
440                 rm -rf $px >& /dev/null
441                 if [ "$?" != "0" ] ; then
442                     echo
443                     echo '!!! Warning !!! Cannot remove install directory ${px}. Permission denied.'
444                     echo
445                 fi
446             fi
447             echo "... Performing make install"
448             make install >& ${LOG_DIR}/make_install_${module}.log
449             sts=$?
450             #########################################################
451             # if make install step is successful set the 
452             # ${module}_ROOT_DIR environment variable
453             #########################################################
454             if [ $sts -eq 0 ] ; then
455                 export ${module}_ROOT_DIR=$px
456             fi
457         fi
458         echo ">>> Finished ${module} module"
459     else
460         echo
461         echo '!!! Error !!! Cannot find module sources. '${module}'_SRC_DIR environment variable is not set.'
462         echo
463     fi
464 done
465 #########################################################
466 # finalize
467 #########################################################
468 cd ${BUILD_DIR}
469
470 echo
471 echo "==========================================================================="
472 echo "SALOME build finished at `date`"
473 echo "==========================================================================="
474 echo