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