Salome HOME
Fix problems with paths to Python and Qt
[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-2008 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-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 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 inst_with_gui=1
87 is_delete=0
88 verbose_level=2
89 params=""
90 b_params=""
91 modules="KERNEL GUI GEOM MED SMESH VISU NETGENPLUGIN GHS3DPLUGIN BLSURFPLUGIN HexoticPLUGIN GHS3DPRLPLUGIN COMPONENT PYCALCULATOR CALCULATOR HELLO PYHELLO LIGHT SIERPINSKY RANDOMIZER YACS"
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 ) inst_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 [ $inst_with_gui -eq 0 ] ; then
259                     add_keys="--without-gui"
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             if [ "$vx" == "" ] ; then
316                 vx=`grep -e "^AC_INIT" ${module_src}/${cfg_file} | sed -e "s%.*\[\([[:digit:].]*\)\].*%\1%g"`
317             fi
318         fi
319         px=${BUILD_DIR}/${module}
320         if [ "$prefix" != "" ] ; then
321             px=$prefix/${module}
322         fi
323         if [ "$vx" != "" ] ; then
324             px="$px"_"$vx"
325         fi
326         #########################################################
327         # perform configure if -c flag is given or if 
328         # Makefile does not exist (first compilation?)
329         #########################################################
330         if [ $is_configure -eq 1 ] || [ $mkfile_exist -eq 0 ] || [ $opts_changed -eq 1 ] ; then
331             echo "... Performing configure"
332             #########################################################
333             # check if configure script exists
334             #########################################################
335             if [ ! -e ${module_src}/configure ] ; then
336                 echo
337                 echo '!!! Warning !!! Can not find configure script in '${module_src}'.'
338                 echo
339             else
340                 if [ $inst_with_gui -eq 0 ] ; then
341                     add_keys="--without-gui"
342                 fi
343                 if [  "${module}" == "MED" ] && [ "${METISDIR}" != "" ] && [ "${SCOTCHDIR}" != "" ] ; then
344                     add_keys="--enable-splitter=yes --with-metis=${METISDIR} --with-scotch=${SCOTCHDIR}"
345                 fi
346                 if [ "${module}" == "NETGENPLUGIN" ] && [ "$NETGENHOME" != "" ] ; then
347                     add_keys="--with-netgen=${NETGENHOME}"
348                 fi
349                 ${module_src}/configure --prefix=$px ${optim} ${add_keys} >& ${LOG_DIR}/configure_${module}.log
350                 #########################################################
351                 # echo possible errors
352                 #########################################################
353                 if [ $verbose_level -gt 0 ] ; then
354                     cat ${LOG_DIR}/configure_${module}.log | grep ": error:" >&2
355                 fi
356                 if [ $verbose_level -gt 1 ] ; then
357                     cat ${LOG_DIR}/configure_${module}.log | grep ": WARNING:" >&2
358                 fi
359             fi
360         fi
361         #########################################################
362         # perform make
363         #########################################################
364         echo "... Performing make"
365         #########################################################
366         # first clear dependencies
367         #########################################################
368         find . -name ".dep*" -type f -exec rm -f {} \; >& /dev/null
369         make >& ${LOG_DIR}/make_${module}.log
370         sts=$?
371         #########################################################
372         # if make step is successful set the ${module}_ROOT_DIR
373         # environment variable
374         #########################################################
375         if [ $sts -eq 0 ] ; then
376             export ${module}_ROOT_DIR=${module_build}
377         fi
378         #########################################################
379         # print make errors
380         #########################################################
381         cat ${LOG_DIR}/make_${module}.log | grep '[*][*][*]' >&2
382         #########################################################
383         # print compiler errors and warnings
384         # Note: here awk is used to concatenate together several lines of single
385         #       error or warning message produced by stupid gnu compiler
386         # Actually, instead of that we could use 'fmessage length=n' option of g++...
387         #########################################################
388         if [ $verbose_level -gt 0 ] ; then
389             ###cat ${LOG_DIR}/make_${module}.log | grep ": error"
390             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
391         fi
392         if [ $verbose_level -gt 1 ] ; then
393             cat ${LOG_DIR}/make_${module}.log | awk 'substr($0,0,1)!=" " {print ""} {printf $0} END {print ""}' | grep ": warning" | sed s@"^${module_src}/src/"@@ >&2
394         fi
395         #########################################################
396         # perform make dev_docs step if -t flag is given
397         #########################################################
398         if [ $is_tui -eq 1 ] && [ $sts -eq 0 ] && [ -d ${module_build}/doc ] ; then
399             cd ${module_build}/doc
400             dd=`cat Makefile | grep -E "dev_docs[[:space:]]*:"`
401             if [ "$dd" != "" ] ; then
402                 echo "... Performing make dev_docs"
403                 make dev_docs >& ${LOG_DIR}/make_dev_docs_${module}.log
404                 cat ${LOG_DIR}/make_dev_docs_${module}.log | grep '[*][*][*]' >&2
405             fi
406         fi
407         cd ${module_build}
408         #########################################################
409         # perform make if -i or -p flags are given
410         #########################################################
411         if [ $is_install -eq 1 ] && [ $sts -eq 0 ] || [ "${module}" == "KERNEL" ] ; then
412             #########################################################
413             # deleting build directory if -d flag is given
414             #########################################################
415             if [ -e $px ] && [ $is_delete -eq 1 ] ; then
416                 echo "... Removing $px"
417                 rm -rf $px
418             fi
419             echo "... Performing make install"
420             make install >& ${LOG_DIR}/make_install_${module}.log
421             sts=$?
422             #########################################################
423             # if make install step is successful set the 
424             # ${module}_ROOT_DIR environment variable
425             #########################################################
426             if [ $sts -eq 0 ] ; then
427                 export ${module}_ROOT_DIR=$px
428             fi
429         fi
430         echo ">>> Finished ${module} module"
431     else
432         echo
433         echo '!!! Error !!! Cannot find module sources. '${module}'_SRC_DIR environment variable is not set.'
434         echo
435     fi
436 done
437 #########################################################
438 # finalize
439 #########################################################
440 cd ${BUILD_DIR}
441
442 echo
443 echo "==========================================================================="
444 echo "SALOME build finished at `date`"
445 echo "==========================================================================="
446 echo