]> SALOME platform Git repositories - tools/install.git/blob - config_files/build.sh
Salome HOME
Process PV_PLUGIN_PATH envvar properly in the generated context file
[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-2014 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 #  Last update: 13/12/2013: porting SALOME build procedure to CMake
17 #
18 ####################################################################################
19
20 # set to 1 to print debug information for script
21 if [ "${DEBUG_SCRIPT}" = "" ] ; then
22     DEBUG_SCRIPT=0
23 fi
24
25 # default installation directory
26 def_install_dir="$(pwd)/INSTALL"
27 # default modules list
28 def_modules=""
29 def_modules="${def_modules} KERNEL GUI GEOM MED SMESH PARAVIS YACS HOMARD HEXABLOCK JOBMANAGER"
30 def_modules="${def_modules} NETGENPLUGIN GHS3DPLUGIN BLSURFPLUGIN HexoticPLUGIN GHS3DPRLPLUGIN HEXABLOCKPLUGIN"
31 def_modules="${def_modules} COMPONENT CALCULATOR PYCALCULATOR HELLO PYHELLO LIGHT PYLIGHT"
32 def_modules="${def_modules} RANDOMIZER SIERPINSKY ATOMIC ATOMGEN ATOMSOLV DOCUMENTATION"
33
34 ###############################################################
35 # Function: Print usage information and exit
36 ###############################################################
37 usage(){
38     echo ""
39     echo "Build specified SALOME module(s)"
40     echo ""
41     echo "Usage:"
42     echo "             $(basename $0) [ <option> ] ... [ <module> [ <module> ... ] ]"
43     echo ""
44     echo "<module>       Modules to build, separated by space(s)."
45     echo "               By default, all modules are built."
46     echo "               Note, that modules given in the command lines are automatically"
47     echo "               sorted according to the inter-dependencies."
48     echo ""
49     echo "Options:"
50     echo ""
51     echo "-h             Print help on the information."
52     echo ""
53     echo "-d             Delete build (and install) directories before calling CMake,"
54     echo "               to force full rebuild of each specified module."
55     echo "               Default: off."
56     echo ""
57     echo "-t             Perform make dev_docs step to build developer documentation,"
58     echo "               for those modules which support this feature."
59     echo "               Default: off."
60     echo ""
61     echo "-j <JOBS>      Specify number of jobs (commands) to run simultaneously,"
62     echo "               this option, when specified, passed directly to make."
63     echo ""
64     echo "-p <PREFIX>    Specify installation directory."
65     echo "               Default: ${def_install_dir}."
66     echo ""
67     echo "-D<OPT>=<VAL>  Specify additional options to be passed to CMake command."
68     echo ""
69     echo "Examples:"
70     echo ""
71     echo "  $(basename $0) -p /home/user/salome KERNEL MED GEOM"
72     echo ""
73     echo "  This will make KERNEL, GEOM and MED modules and install them to the "
74     echo "  /home/user/salome directory."
75     echo "  The modules will be built in the Release mode."
76     echo ""
77     echo "  $(basename $0) -DCMAKE_BUILD_TYPE=Debug -DSALOME_BUILD_GUI=OFF"
78     echo ""
79     echo "  This will build all modules without GUI support. Those modules, that do not"
80     echo "  support compilation without GUI, won't be affected."
81     echo "  The modules will be built in the Debug mode and installed to the default"
82     echo "  location."
83     echo ""
84     exit 0
85 }
86
87 ###############################################################
88 # Function: Show error, print usage information and exit
89 ###############################################################
90 error_exit()
91 {
92     echo
93     echo "$(basename $0): $*"
94     echo
95     exit 1
96 }
97
98 ###############################################################
99 # Function: Get CMake options for the specified module
100 ###############################################################
101 get_cmake_options()
102 {
103     local def_options="-DCMAKE_BUILD_TYPE=Release"
104     case $1 in
105         KERNEL ) def_options="${def_options} -DSALOME_USE_LIBBATCH=ON -DSALOME_USE_SIMAN=ON" ;;
106         SMESH  ) def_options="${def_options} -DSALOME_SMESH_USE_CGNS=ON -DSALOME_SMESH_USE_TBB=ON" ;;
107     esac
108     echo ${def_options}
109 }
110
111 ###############################################################
112 # Function: Check if module supports compilation without gui
113 ###############################################################
114 supports_wogui()
115 {
116     local res
117     case $1 in
118         KERNEL | GEOM | MED | SMESH | NETGENPLUGIN | GHS3DPLUGIN | GHS3DPRLPLUGIN | BLSURFPLUGIN | HexoticPLUGIN ) res=0 ;;
119         YACS | HEXABLOCK | HEXABLOCKPLUGIN ) res=0 ;;
120         * ) res=1 ;;
121     esac
122     return $res
123 }
124
125 ###############################################################
126 # Function: Check if module supports make dev_docs step
127 ###############################################################
128 supports_build_tui()
129 {
130     local res
131     case $1 in
132         KERNEL | GUI | GEOM | MED | SMESH | YACS | BLSURFPLUGIN | PYCALCULATOR ) res=0 ;;
133         * ) res=1 ;;
134     esac
135     return $res
136 }
137
138 ###
139 # set initial values for options
140 ###
141
142 is_delete=0
143 build_devdocs=0
144 prefix=
145 nbjobs=
146 cmake_options=
147
148 ###
149 # parse command line
150 ###
151
152 for o in "$@" ; do
153     case ${o} in
154         -* )
155             if [ "${wait_arg}" = "1" ] ; then
156                 error_exit "option requires an argument -- ${wait_opt}"
157             fi
158             o=${o:1}
159             while [ "${o}" != "" ] ; do
160                 oo=${o:0:1}
161                 ov=${o:1}
162                 case ${oo} in 
163                     h ) usage ;;
164                     D ) cmake_option=${ov}
165                         if [ "${cmake_option}" = "" ] ; then
166                             error_exit "specify cmake option in -D<OPT>=<VAL> format"
167                         fi
168                         cmake_options="${cmake_options} -${o}"
169                         break
170                         ;;
171                     p ) prefix=${ov}
172                         if [ "${prefix}" = "" ] ; then
173                             wait_arg=1
174                             wait_opt=p
175                         fi
176                         break
177                         ;;
178                     j ) nbjobs=${ov}
179                         if [ "${nbjobs}" = "" ] ; then
180                             wait_arg=1
181                             wait_opt=j
182                         fi
183                         break
184                         ;;
185                     d ) is_delete=1 ;;
186                     t ) build_devdocs=1 ;;
187                     * ) error_exit "unknown option -- ${oo}" ;;
188                 esac
189                 o=${o:1}
190             done
191             ;;
192         * )
193             echo ${def_modules} | grep -e "\<${o}\>" > /dev/null
194             if [ "$?" = "0" ] ; then
195                 if [ "${wait_arg}" = "1" ] ; then
196                     error_exit "option requires an argument -- ${wait_opt}"
197                 fi
198                 modules="${modules} ${o}"
199             elif [ "${wait_opt}" != "" ] ; then
200                 case ${wait_opt} in
201                     p ) prefix=${o} ;;
202                     j ) nbjobs=${o} ;;
203                     * ) error_exit "unknown option -- ${wait_opt}" ;;
204                 esac
205                 wait_arg=0
206                 wait_opt=
207             else
208                 error_exit "unknown module -- ${o}"
209             fi
210             ;;
211     esac
212 done
213 if [ "${wait_arg}" = "1" ] ; then
214     error_exit "option requires an argument -- ${wait_opt}"
215 fi
216
217 ###
218 # check installation directory
219 ###
220
221 if [ "${prefix}" = "" ] ; then
222     echo
223     echo "Warning: installation directory is not set."
224     echo "All modules will be installed to ${def_install_dir}."
225     echo
226     prefix=${def_install_dir}
227 elif [ "`echo ${prefix} | grep -E '^/'`" = "" ] ; then
228     prefix="$(pwd)/${prefix}"
229     echo
230     echo 'Warning: relative prefix is used.'
231     echo "All the modules will be installed to ${prefix}."
232     echo
233 fi
234
235 ###
236 # sort modules in proper order according to the dependancies
237 ###
238
239 if [ "${modules}" != "" ] ; then
240     xmodules=""
241     for module in ${def_modules} ; do
242         found=0
243         echo ${modules} | grep -e "\<${module}\>" > /dev/null
244         if [ "$?" = "0" ] ; then
245             xmodules="${xmodules} ${module}"
246         fi
247     done
248     modules="${xmodules}"
249 else
250     modules="${def_modules}"
251 fi
252
253 ###
254 # print status information (for script debugging purposes)
255 ###
256
257 if [ "${DEBUG_SCRIPT}" = "1" ] ; then
258     echo
259     echo "====== debug script: options: begin ====="
260     echo "prefix=$prefix"
261     echo "nbjobs=$nbjobs"
262     echo "cmake_options=$cmake_options"
263     echo "modules=$modules"
264     echo "is_delete=$is_delete"
265     echo "build_devdocs=$build_devdocs"
266     echo "====== debug script: options: end ======="
267     echo
268 fi
269
270 ###
271 # start build
272 ###
273
274 echo "==========================================================================="
275 echo "SALOME build started at `date`"
276 echo "==========================================================================="
277
278 ###
279 # set environment
280 ###
281
282 # try env.sh
283 env_script=`dirname $0`/env.sh
284 if [ ! -e ${env_script} ] ; then
285     # ... if not found, try env_build.sh
286     env_script=`dirname $0`/env_build.sh
287 fi
288 if [ ! -e ${env_script} ] ; then
289     # ... if not found, try env_products.sh
290     env_script=`dirname $0`/env_products.sh
291 fi
292 # source env file, if found
293 if [ -e ${env_script} ] ; then
294     echo ". Source environment script ${env_script}"
295     source ${env_script}
296 else
297     echo
298     echo "Warning: environment is not set."
299     echo "No environment file ($(dirname $0)/env.sh, $(dirname $0)/env_build.sh, $(dirname $0)/env_products.sh) is found."
300     echo "Proceed with the current environment."
301     echo
302 fi
303
304 BUILD_DIR=$(pwd)
305 LOG_DIR=${BUILD_DIR}/LOGS
306 if [ "${nbjobs}" != "" ] ; then
307     nbjobs="-j${nbjobs}"
308 fi
309
310 ###
311 # create log directory
312 ###
313
314 if [ ! -e ${LOG_DIR} ] ; then
315     mkdir -p ${LOG_DIR}
316 fi
317
318 ###
319 # loop through all specified modules
320 ###
321
322 for module in ${modules} ; do
323     echo "......................"
324     echo ".. ${module} module..."
325
326     module_src=${module}_SRC_DIR
327     module_src=${!module_src}
328     module_build=${BUILD_DIR}/${module}_BUILD
329     without_gui=0
330
331     cd ${BUILD_DIR}
332
333     ###
334     # get CMake options to be applied to the module
335     ###
336
337     # get default CMake options
338     def_cmake_options=`get_cmake_options ${module}`
339
340     # process cmake options specified via command line
341     module_cmake_options=
342     for option in ${def_cmake_options} ; do
343         option_name=`echo $option | sed -e "s%^-D%%g;s%=.*$%%g"`
344         if [ "`echo ${cmake_options} | grep -e '-D${option_name}='`" = "" ] ; then
345             module_cmake_options="${module_cmake_options} ${option}"
346         fi
347     done
348     for option in ${cmake_options} ; do
349         option_name=`echo $option | sed -e "s%^-D%%g;s%=.*$%%g"`
350         if [ "${option_name}" != "CMAKE_INSTALL_PREFIX" ] ; then
351             module_cmake_options="${module_cmake_options} ${option}"
352         fi
353         if [ "${option}" = "-DSALOME_BUILD_GUI=OFF" ] ; then
354             without_gui=1
355         fi
356     done
357
358     ###
359     # check source directory
360     ###
361
362     if [ "${module_src}" = "" ] ; then
363         echo "Error: cannot find module sources. ${module}_SRC_DIR environment variable is not set."
364         continue
365     fi
366
367     if [ ! -d ${module_src} ] ; then
368         echo "Error: cannot find module sources directory: ${module_src} does not exist."
369         continue
370     fi
371
372     ###
373     # remove build directory (if -d option is given)
374     ###
375
376     if [ "${is_delete}" = "1" ] && [ -d ${module_build} ] ; then
377         echo ".... Removing ${module_build}"
378         chmod -R +w ${module_build} >& /dev/null && rm -rf ${module_build} >& /dev/null
379         if [ "$?" != "0" ] ; then
380             echo "Warning: cannot remove build directory ${module_build}: permission denied."
381         fi
382     fi
383     
384     ###
385     # create build directory (if it does not exist)
386     ###
387
388     if [ ! -d ${module_build} ] ; then
389         echo ".... Creating ${module_build}"
390         mkdir -p ${module_build} >& /dev/null
391         if [ "$?" != "0" ] ; then
392             echo "Error: cannot create build directory ${module_build}: permission denied."
393             continue
394         fi
395     fi
396     
397     ###
398     # get installation directory for the module
399     ###
400
401     # get version id
402     vx=""
403     if [ -e ${module_src}/CMakeLists.txt ] ; then
404         ver_major=$(grep "SET(\${PROJECT_NAME_UC}_MAJOR_VERSION" ${module_src}/CMakeLists.txt | sed -e "s%.*\([0-9]\+\).*%\1%g")
405         ver_minor=$(grep "SET(\${PROJECT_NAME_UC}_MINOR_VERSION" ${module_src}/CMakeLists.txt | sed -e "s%.*\([0-9]\+\).*%\1%g")
406         ver_patch=$(grep "SET(\${PROJECT_NAME_UC}_PATCH_VERSION" ${module_src}/CMakeLists.txt | sed -e "s%.*\([0-9]\+\).*%\1%g")
407         vx="${ver_major}.${ver_minor}.${ver_patch}"
408     fi
409     if [ "${vx}" != "" ] ; then
410         vx="_${vx}"
411     fi
412
413     # set prefix
414     px="${prefix}/${module}${vx}"
415
416     ###
417     # run cmake
418     ###
419
420     echo ".... Running cmake"
421
422     # check presence of CMakeLists.txt
423     if [ ! -e ${module_src}/CMakeLists.txt ] ; then
424         echo "Error: ${module_src}/CMakeLists.txt does not exist."
425         continue
426     fi
427
428     # when building without gui support, check that module supports this option
429     if [ "${without_gui}" = "1" ] ; then
430         supports_wogui ${module}
431         if [ "$?" != "0" ] ; then
432             echo "Error: build without gui is not supported."
433             continue
434         fi
435     fi
436         
437     # run cmake
438     
439     echo "========================================================================" >  ${LOG_DIR}/${module}_cmake.log
440     echo "cmake ${module_src} -DCMAKE_INSTALL_PREFIX=${px} ${module_cmake_options}" >> ${LOG_DIR}/${module}_cmake.log
441     echo "========================================================================" >> ${LOG_DIR}/${module}_cmake.log
442     ( cd ${module_build} && cmake ${module_src} -DCMAKE_INSTALL_PREFIX=${px} ${module_cmake_options} >> ${LOG_DIR}/${module}_cmake.log 2>&1 )
443     sts=$?
444
445     # stop if there were any errors
446     if [ "${sts}" != "0" ] ; then
447         echo "Error: cmake failed; see ${LOG_DIR}/${module}_cmake.log for more details."
448         continue
449     fi
450
451     ###
452     # run make
453     ###
454     
455     echo ".... Running make"
456
457     # run make
458     echo "========================================================================" >  ${LOG_DIR}/${module}_make.log
459     echo "make ${nbjobs}"                                                           >> ${LOG_DIR}/${module}_make.log
460     echo "========================================================================" >> ${LOG_DIR}/${module}_make.log
461     ( cd ${module_build} && make ${nbjobs} >> ${LOG_DIR}/${module}_make.log 2>&1 )
462     sts=$?
463
464     # stop if there were any errors
465     if [ "${sts}" != "0" ] ; then
466         echo "Error: make failed; see ${LOG_DIR}/${module}_make.log for more details."
467         continue
468     fi
469
470     ###
471     # run make dev_docs step (if -t option is given)
472     ###
473
474     if [ "${build_devdocs}" = "1" ] ; then
475         supports_build_tui ${module}
476         if [ "$?" = "0" ] ; then
477             echo ".... Running make dev_docs"
478             echo "========================================================================" >  ${LOG_DIR}/${module}_make_devdocs.log
479             echo "make dev_docs"                                                            >> ${LOG_DIR}/${module}_make_devdocs.log
480             echo "========================================================================" >> ${LOG_DIR}/${module}_make_devdocs.log
481             ( cd ${module_build} && make dev_docs >> ${LOG_DIR}/${module}_make_devdocs.log 2>&1 )
482             sts=$?
483             
484             if [ "${sts}" != "0" ] ; then
485                 echo "Warning: make dev_docs failed; see ${LOG_DIR}/${module}_make_devdocs.log for more details."
486             fi
487         fi
488     fi
489
490     ###
491     # remove install directory (if -d option is given)
492     ###
493
494     if [ "${is_delete}" = "1" ] && [ -d ${px} ] ; then
495         echo ".... Removing ${px}"
496         chmod -R +w ${px} >& /dev/null && rm -rf ${px} >& /dev/null
497         if [ "$?" != "0" ] ; then
498             echo "Warning: cannot remove install directory ${px}: permission denied."
499         fi
500     fi
501
502     ###
503     # run make install
504     ###
505
506     echo ".... Running make install"
507     echo "========================================================================" >  ${LOG_DIR}/${module}_make_install.log
508     echo "make install"                                                             >> ${LOG_DIR}/${module}_make_install.log
509     echo "========================================================================" >> ${LOG_DIR}/${module}_make_install.log
510     ( cd ${module_build} && make install >> ${LOG_DIR}/${module}_make_install.log 2>&1 )
511     sts=$?
512           
513     if [ "${sts}" != "0" ] ; then
514         echo "Error: make install failed; see ${LOG_DIR}/${module}_make_install.log for more details."
515         continue
516     fi
517
518     ###
519     # set ${module}_ROOT_DIR environment variable
520     ###
521
522     export ${module}_ROOT_DIR=${px}
523
524     echo ".. Finished ${module} module"
525 done
526
527 ###
528 # finalize
529 ###
530
531 cd ${BUILD_DIR}
532
533 echo "==========================================================================="
534 echo "SALOME build finished at `date`"
535 echo "==========================================================================="