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