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