3 ####################################################################################
5 # Created : Thu Jan 27 09:50:55 2005
6 # Author : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
8 # Module : Installation Wizard
9 # Copyright : 2002-2008 CEA
11 # This script is the part of the SALOME installation procedure.
13 # This script can be used to build and install SALOME modules from sources.
14 # Try build.sh -h for more details about usage.
16 ####################################################################################
18 ###############################################################
19 # Prints usage information and exits
20 ###############################################################
24 echo " Builds given SALOME modules by performing make and "
25 echo " make install commands"
28 echo " build.sh [ <option> ] ... [ <module> [ <module> ... ] ]"
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."
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."
39 echo "-c Perform configure command for all given modules. Default is off."
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."
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."
49 echo "-o Build sources in optimized mode. Default is off that means"
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)."
56 echo "-t Performs make dev_docs step to build TUI documentation for those"
57 echo " modules which support this. Default is off."
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."
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 "
67 echo "-h Prints this help information."
69 echo "Note: If no keys are given script just performs make step."
72 echo " ./build.csh -o -p /home/user/salome -b KERNEL MED GEOM"
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."
87 modules="KERNEL GUI GEOM MED SMESH VISU YACS NETGENPLUGIN GHS3DPLUGIN BLSURFPLUGIN HexoticPLUGIN GHS3DPRLPLUGIN COMPONENT PYCALCULATOR CALCULATOR HELLO PYHELLO LIGHT PYLIGHT SIERPINSKY RANDOMIZER"
92 def_install_dir="/INSTALL"
94 #########################################################
96 #########################################################
97 while getopts ":hbcwdotv:p:" option ; do
100 b ) is_build_configure=1 ; is_configure=1 ;;
101 c ) is_configure=1 ;;
102 w ) inst_with_gui=0 ;;
104 o ) optim="--enable-production=yes --disable-debug" ;;
106 v ) verbose_level=$OPTARG ;;
107 p ) is_install=1 ; prefix=$OPTARG ;;
111 # shift to have the good number of other args
112 shift $((OPTIND - 1))
118 for m in $modules ; do
119 if [ "$m" == "$arg" ] ; then known=1 ; break ; fi
121 if [ $known -eq 0 ] ; then
123 echo '!!! Warning !!! Unknown module: '$arg'.'
124 b_params="$b_params $arg"
126 params="$params $arg"
130 #########################################################
131 # sort modules in proper order according to the dependancies
132 #########################################################
133 if [ "${params}" != "" ] ; then
135 for module in ${modules} ; do
137 for p in $params ; do
138 if [ "$p" == "$module" ] ; then found=1 ; break ; fi
140 if [ $found -eq 1 ] ; then
141 xparams="$xparams $module"
144 modules="$xparams $b_params"
145 elif [ "${b_params}" != "" ] ; then
150 echo ">>> The following modules will be built:"
154 #########################################################
156 #########################################################
157 env_script=`dirname $0`/env_build.sh
158 if [ ! -e $env_script ] ; then
159 env_script=`dirname $0`/env_products.sh
161 if [ ! -e $env_script ] ; then
162 env_script=`dirname $0`/env.sh
164 if [ -e $env_script ] ; then
166 echo ">>> Setting environment"
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.'
176 LOG_DIR=${BUILD_DIR}/LOGS
178 #########################################################
179 # define installation prefix
180 #########################################################
181 if [ "$prefix" == "" ] ; then
183 echo '!!! Warning !!! Installation directory is not set.'
184 echo "All the modules will be installed to the ${BUILD_DIR}${def_install_dir}"
186 if [ "`echo $prefix | grep -E '^/'`" == "" ] ; then
187 prefix=${BUILD_DIR}/$prefix
189 echo '!!! Warning !!! Relative prefix is used.'
190 echo "All the modules will be installed to the $prefix."
194 #########################################################
195 # create log directory
196 #########################################################
197 if [ ! -e ${LOG_DIR} ] ; then
202 echo "==========================================================================="
203 echo "Starting SALOME build at `date`"
204 echo "==========================================================================="
207 #########################################################
208 # loop for all given modules
209 #########################################################
210 for module in ${modules}; do
211 echo ">>> Processing ${module} module"
213 module_src=`printenv ${module}_SRC_DIR`
214 module_build=${BUILD_DIR}/${module}_BUILD
216 if [ "${module_src}" != "" ] ; then
218 #########################################################
219 # check if sources directory exists
220 #########################################################
221 if [ ! -e ${module_src} ] ; then
223 echo '!!! Error !!! Cannot find module sources directory:'
224 echo "${module_src} does not exist."
228 #########################################################
229 # check if configure script exists
230 #########################################################
232 if [ -e ${module_src}/configure ] ; then
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 ] ; then
245 echo '!!! Warning !!! Cannot find build_configure script in '${module_src}'.'
247 #########################################################
248 # call build_configure
249 #########################################################
250 mybuildconf_keys="${BUILDCONF_OPTS}"
251 if [ $inst_with_gui -eq 0 ] ; then
252 mybuildconf_keys="${mybuildconf_keys} --without-gui"
255 ./build_configure ${mybuildconf_keys} >& ${LOG_DIR}/build_configure_${module}.log
256 #########################################################
257 # echo possible errors
258 #########################################################
259 if [ $verbose_level -gt 0 ] ; then
260 cat ${LOG_DIR}/build_configure_${module}.log | grep -E "(failed|: error:)" >&2
264 #########################################################
265 # deleting build directory if -d flag is given
266 #########################################################
267 if [ -e ${module_build} ] && [ $is_delete -eq 1 ] ; then
268 echo "... Removing ${module_build}"
269 chmod -R +w ${module_build} && rm -rf ${module_build} >& /dev/null
270 if [ "$?" != "0" ] ; then
272 echo '!!! Warning !!! Cannot remove build directory ${module_build}. Permission denied.'
276 #########################################################
277 # creating build directory if it does not exist
278 #########################################################
279 if [ ! -e ${module_build} ] ; then
280 mkdir -p ${module_build} >& /dev/null
281 if [ "$?" != "0" ] ; then
283 echo '!!! Error !!! Cannot create build directory ${module_build}. Permission denied.'
289 #########################################################
290 # check if top Makefile exists in build directory, i.e.
291 # is it necessary to run configure script
292 #########################################################
294 if [ -e ${module_build}/Makefile ] ; then
297 #########################################################
298 # check if configure options are changed from the
300 #########################################################
302 ## if [ -f ${module_build}/config.log ] ; then
303 ## old_prefix=`grep -e '^prefix=' ${module_build}/config.log | sed -e "s%^prefix='\(.*\)'%\1%"`
304 ## if [ "$old_prefix" != "$prefix" ] ; then
308 #########################################################
309 # define installation directory (by using module's version
310 # number); default is a build directory
311 #########################################################
313 if [ -e ${module_src}/configure.ac ] ; then
314 vx=`grep -e "^AC_INIT" ${module_src}/configure.ac | sed -e "s%.*\[\([[:digit:].]*\)\].*%\1%g"`
315 elif [ -e ${module_src}/configure.in.base ] ; then
316 vx=`grep -e "^VERSION=" ${module_src}/configure.in.base | awk -F= '{ if (NF>1) print $NF; }' | tr -d '[:space:]'`
317 if [ "$vx" == "" ] ; then
318 vx=`grep -e "^AC_INIT" ${module_src}/configure.in.base | sed -e "s%.*\[\([[:digit:].]*\)\].*%\1%g"`
321 if [ "$vx" != "" ] ; then
324 if [ "$prefix" == "" ] ; then
325 #module_root_dir=`printenv ${module}_ROOT_DIR`
326 #if [ "$module_root_dir" != "" ] ; then
327 # px=$module_root_dir
329 px=${BUILD_DIR}${def_install_dir}/${module}${vx}
332 px=$prefix/${module}${vx}
334 #########################################################
335 # perform configure if -c flag is given or if
336 # Makefile does not exist (first compilation?)
337 #########################################################
338 if [ $is_configure -eq 1 ] || [ $mkfile_exist -eq 0 ] || [ $opts_changed -eq 1 ] ; then
339 echo "... Performing configure"
340 #########################################################
341 # check if configure script exists
342 #########################################################
343 if [ ! -e ${module_src}/configure ] ; then
345 echo '!!! Warning !!! Can not find configure script in '${module_src}'.'
348 myconf_keys="${CONF_OPTS}"
349 if [ $inst_with_gui -eq 0 ] ; then
350 myconf_keys="${myconf_keys} --without-gui"
352 if [ "${module}" == "MED" ] && [ "${METISDIR}" != "" ] && [ "${SCOTCHDIR}" != "" ] ; then
353 myconf_keys="${myconf_keys} --enable-splitter=yes --with-metis=${METISDIR} --with-scotch=${SCOTCHDIR}"
355 if [ "${module}" == "NETGENPLUGIN" ] && [ "$NETGENHOME" != "" ] ; then
356 myconf_keys="${myconf_keys} --with-netgen=${NETGENHOME}"
358 ${module_src}/configure --prefix=$px ${optim} ${myconf_keys} >& ${LOG_DIR}/configure_${module}.log
359 #########################################################
360 # echo possible errors
361 #########################################################
362 if [ $verbose_level -gt 0 ] ; then
363 cat ${LOG_DIR}/configure_${module}.log | grep ": error:" >&2
365 if [ $verbose_level -gt 1 ] ; then
366 cat ${LOG_DIR}/configure_${module}.log | grep ": WARNING:" >&2
370 #########################################################
372 #########################################################
373 echo "... Performing make"
374 #########################################################
375 # first clear dependencies
376 #########################################################
377 find . -name ".dep*" -type f -exec rm -f {} \; >& /dev/null
378 make >& ${LOG_DIR}/make_${module}.log
380 #########################################################
381 # if make step is successful set the ${module}_ROOT_DIR
382 # environment variable
383 #########################################################
384 #if [ $sts -eq 0 ] ; then
385 # export ${module}_ROOT_DIR=${module_build}
387 #########################################################
389 #########################################################
390 cat ${LOG_DIR}/make_${module}.log | grep -Ei '[*][*][*].*error' >&2
391 #########################################################
392 # print compiler errors and warnings
393 # Note: here awk is used to concatenate together several lines of single
394 # error or warning message produced by stupid gnu compiler
395 # Actually, instead of that we could use 'fmessage length=n' option of g++...
396 #########################################################
397 if [ $verbose_level -gt 0 ] ; then
398 ###cat ${LOG_DIR}/make_${module}.log | grep ": error"
399 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
401 if [ $verbose_level -gt 1 ] ; then
402 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
404 #########################################################
405 # perform make dev_docs step if -t flag is given
406 #########################################################
407 if [ $is_tui -eq 1 ] && [ $sts -eq 0 ] && [ -d ${module_build}/doc ] ; then
408 cd ${module_build}/doc
409 dd=`cat Makefile | grep -E "dev_docs[[:space:]]*:"`
410 if [ "$dd" != "" ] ; then
411 echo "... Performing make dev_docs"
412 make dev_docs >& ${LOG_DIR}/make_dev_docs_${module}.log
413 cat ${LOG_DIR}/make_dev_docs_${module}.log | grep '[*][*][*]' >&2
417 #########################################################
418 # perform make if -i or -p flags are given
419 #########################################################
420 if [ $is_install -eq 1 ] && [ $sts -eq 0 ] || [ "${module}" == "KERNEL" ] ; then
421 #########################################################
422 # deleting build directory if -d flag is given
423 #########################################################
424 if [ -e $px ] && [ $is_delete -eq 1 ] ; then
425 echo "... Removing $px"
426 rm -rf $px >& /dev/null
427 if [ "$?" != "0" ] ; then
429 echo '!!! Warning !!! Cannot remove install directory ${px}. Permission denied.'
433 echo "... Performing make install"
434 make install >& ${LOG_DIR}/make_install_${module}.log
436 #########################################################
437 # if make install step is successful set the
438 # ${module}_ROOT_DIR environment variable
439 #########################################################
440 if [ $sts -eq 0 ] ; then
441 export ${module}_ROOT_DIR=$px
444 echo ">>> Finished ${module} module"
447 echo '!!! Error !!! Cannot find module sources. '${module}'_SRC_DIR environment variable is not set.'
451 #########################################################
453 #########################################################
457 echo "==========================================================================="
458 echo "SALOME build finished at `date`"
459 echo "==========================================================================="