Salome HOME
1) getSize() just returns required size that read from XML now;
[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-2007 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 (optionally)"
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-ihm key to build_configure and configure"
42     echo "            commands for MED module to build its sources without GUI."
43     echo "            By default MED sources are built with GUI."
44     echo ""
45     echo "-d          Delete build directories before calling configure, to enforce full"
46     echo "            rebuild (and reinstall if -i or -p option is used) of 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 "-i          Performs make install step. Default is off that means only make"
60     echo "            step."
61     echo ""
62     echo "-p <prefix> Define the directory where to install modules after compilation."
63     echo "            By default the directory where compilation is performed is used."
64     echo ""
65     echo "-v <level>  Verbose level (0-2, default 2): print information on build status:"
66     echo "            0: only 'make' errors"
67     echo "            1: 0 + compiler and other errors (build_configure, configure)"
68     echo "            2: 1 + compiler and other warnings "
69     echo ""
70     echo "-h          Prints this help information."
71     echo ""
72     echo "Note:       If no keys are given script just performs make step."
73     echo ""
74     echo "Example:"
75     echo "            ./build.csh -o -i -b KERNEL MED GEOM"
76     echo ""
77     echo "            This will make KERNEL, GEOM and MED modules: build_configure,"
78     echo "            configure, make and install procedures will be performed for all"
79     echo "            specified modules. The modules will be built in the optimized mode."
80     echo ""
81     exit 1
82 }
83
84 is_build_configure=0
85 is_configure=0
86 med_with_gui=1
87 is_delete=0
88 verbose_level=2
89 params=""
90 b_params=""
91 modules="KERNEL GUI GEOM MED SMESH VISU SUPERV NETGENPLUGIN GHS3DPLUGIN COMPONENT PYCALCULATOR CALCULATOR HELLO PYHELLO LIGHT RANDOMIZER SIERPINSKY"
92 optim=""
93 is_install=0
94 is_tui=0
95 prefix=""
96
97 #########################################################
98 # parse parameters
99 #########################################################
100 while getopts ":hbcwdoitv:p:" option ; do
101     case $option in
102         h ) usage ;;
103         b ) is_build_configure=1 ; is_configure=1 ;;
104         c ) is_configure=1 ;;
105         w ) med_with_gui=0 ;;
106         d ) is_delete=1 ;;
107         o ) optim="--enable-production=yes --disable-debug" ;;
108         i ) is_install=1 ;;
109         t ) is_tui=1 ;;
110         v ) verbose_level=$OPTARG ;;
111         p ) is_install=1 ; prefix=$OPTARG ;;
112         ? ) usage ;;
113     esac
114 done
115 # shift to have the good number of other args
116 shift $((OPTIND - 1))
117
118 for arg in $@ ; do
119     known=0
120     for m in $modules ; do
121         if [ "$m" == "$arg" ] ; then known=1 ; break ; fi
122     done
123     if [ $known -eq 1 ] ; then
124         params="$params $arg"
125     else
126         b_params="$b_params $arg"
127         echo
128         echo '!!! Warning !!! Unknown module: '$arg'. Skipping.'
129     fi
130 done
131
132 #########################################################
133 # sort modules in proper order according to the dependancies
134 #########################################################
135 if [ "${params}" != "" ] ; then
136     xparams=""
137     for module in ${modules} ; do
138         found=0
139         for p in $params ; do
140             if [ "$p" == "$module" ] ; then found=1 ; break ; fi
141         done
142         if [ $found -eq 1 ] ; then xparams="$xparams $module" ; fi
143     done
144     modules="$xparams"
145 elif [ "${b_params}" != "" ] ; then
146     echo
147     echo "Nothing to be built. Exiting."
148     echo
149     exit 1
150 fi
151
152 echo
153 echo ">>> The following SALOME packages will be built:"
154 echo $modules
155
156 #########################################################
157 # set environment
158 #########################################################
159 env_script=`dirname $0`/env_build.sh
160 if [ ! -e $env_script ] ; then
161     env_script=`dirname $0`/env_products.sh
162 fi
163 if [ -e $env_script ] ; then
164     echo
165     echo ">>> Setting environment"
166     source $env_script
167 else
168     echo
169     echo '!!! Warning !!! Environment is not set.'
170     echo 'Neither env_build.sh nor env_products.sh file is found.'
171     echo 'Proceed with the current environment.'
172 fi
173
174 BUILD_DIR=${PWD}
175 LOG_DIR=${BUILD_DIR}/LOGS
176
177 #########################################################
178 # define installation prefix
179 #########################################################
180 if [ "$prefix" == "" ] ; then
181     prefix=${BUILD_DIR}/INSTALL
182     if [ $is_install -eq 1 ] ; then
183         echo
184         echo '!!! Warning !!! Installation directory is not set.'
185         echo "All the modules will be installed to the $prefix"
186     elif [ "`echo ${modules} | grep KERNEL`" != "" ] ; then
187         echo
188         echo '!!! Warning !!! KERNEL module requires install step to be performed.'
189         echo "For this module -i option will be forced."
190         echo "The module(s) will be installed to the $prefix"
191     fi
192 else
193     if [ "`echo $prefix | grep -E '^/'`" == "" ] ; then
194         prefix=${BUILD_DIR}/$prefix
195         echo
196         echo '!!! Warning !!! Relative prefix is used.'
197         echo "All the modules will be installed to the $prefix."
198     fi
199 fi
200
201 #########################################################
202 # create log directory
203 #########################################################
204 if [ ! -e ${LOG_DIR} ] ; then
205     mkdir -p ${LOG_DIR}
206 fi
207
208 echo
209 echo "==========================================================================="
210 echo "Starting SALOME build at `date`"
211 echo "==========================================================================="
212 echo
213
214 #########################################################
215 # loop for all given modules
216 #########################################################
217 for module in ${modules}; do
218     echo ">>> Processing ${module} module"
219
220     module_src=`printenv ${module}_SRC_DIR`
221     module_build=${BUILD_DIR}/${module}_BUILD
222     
223     if [ "${module_src}" != "" ] ; then
224         add_keys=""
225         cd ${BUILD_DIR}
226         #########################################################
227         # check if sources directory exists
228         #########################################################
229         if [ ! -e ${module_src} ] ; then
230             echo
231             echo '!!! Error !!! Cannot find module sources directory:'
232             echo "${module_src} does not exist."
233             echo
234             continue
235         fi
236         #########################################################
237         # check if configure script exists
238         #########################################################
239         cfg_exist=0
240         if [ -e ${module_src}/configure ] ; then
241             cfg_exist=1
242         fi
243         #########################################################
244         # perform build_configure if -b flag is given or if 
245         # configure script does not exist (first compilation?)
246         #########################################################
247         if [ $is_build_configure -eq 1 ] || [ $cfg_exist -eq 0 ] ; then
248             echo "... Performing build_configure"
249             #########################################################
250             # check if build_configure script exists
251             #########################################################
252             if [ ! -e ${module_src}/build_configure ] ; then
253                 echo '!!! Warning !!! Cannot find build_configure script in '${module_src}'.'
254             else
255                 #########################################################
256                 # call build_configure
257                 #########################################################
258                 if [ $med_with_gui -eq 0 ] && [ ${module} == "MED" ] ; then
259                     add_keys="--without-ihm"
260                 fi
261                 cd ${module_src}
262                 ./build_configure ${add_keys} >& ${LOG_DIR}/build_configure_${module}.log
263                 #########################################################
264                 # echo possible errors
265                 #########################################################
266                 if [ $verbose_level -gt 0 ] ; then
267                     cat ${LOG_DIR}/build_configure_${module}.log | grep -E "(failed|: error:)" >&2
268                 fi
269             fi
270         fi
271         #########################################################
272         # deleting build directory if -d flag is given
273         #########################################################
274         if [ -e ${module_build} ] && [ $is_delete -eq 1 ] ; then
275             echo "... Removing ${module_build}"
276             rm -rf ${module_build}
277         fi
278         #########################################################
279         # creating build directory if it does not exist
280         #########################################################
281         if [ ! -e ${module_build} ] ; then
282             mkdir -p ${module_build}
283         fi
284         cd ${module_build}
285         #########################################################
286         # check if top Makefile exists in build directory, i.e. 
287         # is it necessary to run configure script
288         #########################################################
289         mkfile_exist=0
290         if [ -e ${module_build}/Makefile ] ; then
291             mkfile_exist=1
292         fi
293         #########################################################
294         # check if configure options are changed from the 
295         # previous launch
296         #########################################################
297         opts_changed=0
298 ##      if [ -f ${module_build}/config.log ] ; then
299 ##          old_prefix=`grep -e '^prefix=' ${module_build}/config.log | sed -e "s%^prefix='\(.*\)'%\1%"`
300 ##          if [ "$old_prefix" != "$prefix" ] ; then
301 ##              opts_changed=1
302 ##          fi
303 ##      fi
304         #########################################################
305         # define installation directory (by using module's version
306         # number); default is a build directory
307         #########################################################
308         vx=""
309         cfg_file=configure.ac
310         if [ ! -e ${module_src}/${cfg_file} ] ; then
311             cfg_file=configure.in.base
312         fi
313         if [ -e ${module_src}/${cfg_file} ] ; then
314             vx=`grep -e "^VERSION=" ${module_src}/${cfg_file} | awk -F= '{ if (NF>1) print $NF; }' | tr -d '[:space:]'`
315         fi
316         px=${BUILD_DIR}/${module}
317         if [ "$prefix" != "" ] ; then
318             px=$prefix/${module}
319         fi
320         if [ "$vx" != "" ] ; then
321             px="$px"_"$vx"
322         fi
323         #########################################################
324         # perform configure if -c flag is given or if 
325         # Makefile does not exist (first compilation?)
326         #########################################################
327         if [ $is_configure -eq 1 ] || [ $mkfile_exist -eq 0 ] || [ $opts_changed -eq 1 ] ; then
328             echo "... Performing configure"
329             #########################################################
330             # check if configure script exists
331             #########################################################
332             if [ ! -e ${module_src}/configure ] ; then
333                 echo
334                 echo '!!! Warning !!! Can not find configure script in '${module_src}'.'
335                 echo
336             else
337                 if [ $med_with_gui -eq 0 ] && [ "${module}" == "MED" ] ; then
338                     add_keys="--without-ihm"
339                 fi
340                 if [ "${module}" == "NETGENPLUGIN" ] && [ "$NETGENHOME" != "" ] ; then
341                     add_keys="--with-netgen=${NETGENHOME}"
342                 fi
343                 ${module_src}/configure --prefix=$px ${optim} ${add_keys} >& ${LOG_DIR}/configure_${module}.log
344                 #########################################################
345                 # echo possible errors
346                 #########################################################
347                 if [ $verbose_level -gt 0 ] ; then
348                     cat ${LOG_DIR}/configure_${module}.log | grep ": error:" >&2
349                 fi
350                 if [ $verbose_level -gt 1 ] ; then
351                     cat ${LOG_DIR}/configure_${module}.log | grep ": WARNING:" >&2
352                 fi
353             fi
354         fi
355         #########################################################
356         # perform make
357         #########################################################
358         echo "... Performing make"
359         #########################################################
360         # first clear dependencies
361         #########################################################
362         find . -name ".dep*" -type f -exec rm -f {} \; >& /dev/null
363         make >& ${LOG_DIR}/make_${module}.log
364         sts=$?
365         #########################################################
366         # if make step is successful set the ${module}_ROOT_DIR
367         # environment variable
368         #########################################################
369         if [ $sts -eq 0 ] ; then
370             export ${module}_ROOT_DIR=${module_build}
371         fi
372         #########################################################
373         # print make errors
374         #########################################################
375         cat ${LOG_DIR}/make_${module}.log | grep '[*][*][*]' >&2
376         #########################################################
377         # print compiler errors and warnings
378         # Note: here awk is used to concatenate together several lines of single
379         #       error or warning message produced by stupid gnu compiler
380         # Actually, instead of that we could use 'fmessage length=n' option of g++...
381         #########################################################
382         if [ $verbose_level -gt 0 ] ; then
383             ###cat ${LOG_DIR}/make_${module}.log | grep ": error"
384             cat ${LOG_DIR}/make_${module}.log | awk 'substr($0,0,1)!=" " {print ""} {printf $0} END {print ""}' | grep "${module_src}/[A-Za-z_0-9./]*:" | sed s@"^${module_src}/src/"@@ >&2
385         fi
386         if [ $verbose_level -gt 1 ] ; then
387             cat ${LOG_DIR}/make_${module}.log | awk 'substr($0,0,1)!=" " {print ""} {printf $0} END {print ""}' | grep ": warning" | sed s@"^${module_src}/src/"@@ >&2
388         fi
389         #########################################################
390         # perform make dev_docs step if -t flag is given
391         #########################################################
392         if [ $is_tui -eq 1 ] && [ $sts -eq 0 ] && [ -d ${module_build}/doc ] ; then
393             cd ${module_build}/doc
394             dd=`cat Makefile | grep -E "dev_docs[[:space:]]*:"`
395             if [ "$dd" != "" ] ; then
396                 echo "... Performing make dev_docs"
397                 make dev_docs >& ${LOG_DIR}/make_dev_docs_${module}.log
398                 cat ${LOG_DIR}/make_dev_docs_${module}.log | grep '[*][*][*]' >&2
399             fi
400         fi
401         cd ${module_build}
402         #########################################################
403         # perform make if -i or -p flags are given
404         #########################################################
405         if [ $is_install -eq 1 ] && [ $sts -eq 0 ] || [ "${module}" == "KERNEL" ] ; then
406             #########################################################
407             # deleting build directory if -d flag is given
408             #########################################################
409             if [ -e $px ] && [ $is_delete -eq 1 ] ; then
410                 echo "... Removing $px"
411                 rm -rf $px
412             fi
413             echo "... Performing make install"
414             make install >& ${LOG_DIR}/make_install_${module}.log
415             sts=$?
416             #########################################################
417             # if make install step is successful set the 
418             # ${module}_ROOT_DIR environment variable
419             #########################################################
420             if [ $sts -eq 0 ] ; then
421                 export ${module}_ROOT_DIR=$px
422             fi
423         fi
424         echo ">>> Finished ${module} module"
425     else
426         echo
427         echo '!!! Error !!! Cannot find module sources. '${module}'_SRC_DIR environment variable is not set.'
428         echo
429     fi
430 done
431 #########################################################
432 # finalize
433 #########################################################
434 cd ${BUILD_DIR}
435
436 echo
437 echo "==========================================================================="
438 echo "SALOME build finished at `date`"
439 echo "==========================================================================="
440 echo