Salome HOME
Update for version 2.2.3
[tools/install.git] / config_files / build.csh
1 #! /bin/csh -f
2 ##################################################################################################
3 # Name       : build.csh
4 # Description: Build and install SALOME2 modules from sources
5 # Author     : Vadim SANDLER (VSR), Open CASCADE S.A.
6 # Created    : 27.01.2005
7 ##################################################################################################
8
9 set is_build_configure=0
10 set is_configure=0
11 set is_delete=0
12 set verbose_level=2
13 set params=""
14 set b_params=""
15 set modules=(KERNEL GEOM MED SMESH VISU SUPERV NETGENPLUGIN GHS3DPLUGIN COMPONENT PYCALCULATOR HELLO PYHELLO)
16 set optim=""
17 set is_install=0
18 set is_help=0
19 set prefix=""
20
21 #########################################################
22 # parse parameters
23 #########################################################
24 while ( ${%1} > 0 )
25     if ( "$1" == "-b" ) then
26         set is_build_configure=1
27         set is_configure=1
28     else if ( "$1" == "-c" ) then
29         set is_configure=1
30     else if ( "$1" == "-d" ) then
31         set is_delete=1
32     else if ( "$1" == "-o" ) then
33         set optim="--enable-production=yes --disable-debug"
34     else if ( "$1" == "-i" ) then
35         set is_install=1
36     else if ( "$1" == "-v" ) then
37         shift
38         set verbose_level=$1
39     else if ( "$1" == "-p" ) then
40         shift
41         set is_install=1
42         set prefix=$1
43     else if ( "$1" == "-h" ) then
44         set is_help=1
45     else
46         set ckt=`echo ${modules} | grep $1`
47         if ( "$ckt" != "" ) then
48             set params="$params $1"
49         else
50             set b_params="$b_params $1"
51             echo "Warning: Unknown module: $1. Skipping."
52         endif
53     endif
54     shift
55 end
56
57 #########################################################
58 # if -h option is given - print help info and exit 
59 #########################################################
60 if ( $is_help == 1 ) then
61 echo ""
62 echo ""
63 echo "Description:"
64 echo "            Builds given SALOME2 modules by performing make and (optionally) make install commands"
65 echo ""
66 echo "Usage:"
67 echo "            build.csh [ <option> ] ... [ <module> [ <module> ... ] ]"
68 echo ""
69 echo "<module>    Modules to build, separated by space(s)."
70 echo "            If no modules are given - all SALOME2 modules are assumed."
71 echo "            Note, that modules given in command lines are automatically sorted in such order"
72 echo "            to support correct modules dependencies."
73 echo ""
74 echo "Options:"
75 echo "-b          Perform build_configure command for all given modules."
76 echo "            This option forces configure (-c) key to be set. Default is off."
77 echo ""
78 echo "-c          Perform configure command for all given modules. Default is off."
79 echo ""
80 echo "-d          Delete build directories before calling configure, to enforce full rebuild"
81 echo "            (and reinstall if -i or -p option is used) of module."
82 echo "            Use this option carefully."
83 echo ""
84 echo "-o          Build sources in optimized mode. Default is off that means debug mode."
85 echo "            Use this option together with -c or -b."
86 echo "            This option can require -d option to be set (to ensure that previously"
87 echo "            created build directories are removed to enforce rebuild in optimized mode)."
88 echo ""
89 echo "-i          Performs make install step. Default is off that means only make step."
90 echo ""
91 echo "-p <prefix> Define the directory where to install modules after compilation."
92 echo "            By default the directory where compilation is performed is used."
93 echo ""
94 echo "-v <level>  Verbose level (0-2, default 2): print information on build status:"
95 echo "            0: only 'make' errors"
96 echo "            1: 0 + compiler and other errors (including build_configure, configure)"
97 echo "            2: 1 + compiler and other warnings "
98 echo ""
99 echo "-h          Prints this help information."
100 echo ""
101 echo "Note:       If no keys are given script just performs make step."
102 echo ""
103 echo "Example:"
104 echo "            ./build.csh -o -i -b KERNEL MED GEOM"
105 echo ""
106 echo "            This will make KERNEL, GEOM and MED modules: build_configure, configure, make"
107 echo "            and install procedures will be performed for all specified modules."
108 echo "            The modules will be built in the optimized mode"
109 echo ""
110 exit
111 endif
112
113 #########################################################
114 # sort modules in proper order according to the dependancies
115 #########################################################
116 if ( "${params}" != "" ) then
117     set xparams=""
118     foreach module (${modules})
119         set ckt=`echo ${params} | grep ${module}`
120         if ( "$ckt" != "" ) then
121             set xparams="$xparams $module"
122         endif
123     end
124     set modules=($xparams)
125 else
126     if ( "${b_params}" != "" ) then
127         echo "Nothing to be built. Exiting."
128         exit
129     endif
130 endif
131
132 echo "The following SALOME packages will be built:"
133 echo $modules
134
135 #########################################################
136 # set environment
137 #########################################################
138 set env_script=`dirname $0`/env_products.csh
139 if ( -e $env_script ) then
140     echo "Setting environment"
141     source $env_script
142 else
143     echo "Warning! Environment is not set: file env_products.csh is not found."
144 endif
145
146 set BUILD_DIR=${PWD}
147 set LOG_DIR=${BUILD_DIR}/LOGS
148
149 #########################################################
150 # create log directory
151 #########################################################
152 if ( ! -e ${LOG_DIR} ) then
153     mkdir -p ${LOG_DIR}
154 endif
155
156 echo "==========================================================================="
157 echo "Starting SALOME build at `date`"
158
159 #########################################################
160 # loop for all given modules
161 #########################################################
162 foreach module (${modules})
163   echo "==========================================================================="
164   echo "Processing ${module} module"
165
166   set module_src=`printenv ${module}_SRC_DIR`
167   set module_build=${BUILD_DIR}/${module}_BUILD
168
169   if ( ${module_src} != "" ) then
170     set add_keys=""
171     cd ${BUILD_DIR}
172     #########################################################
173     # check if sources directory exists
174     #########################################################
175     if ( ! -e ${module_src} ) then
176         echo "Error! Can't find sources directory: ${module_src} does not exist."
177         continue
178     endif
179     #########################################################
180     # check if configure script exists
181     #########################################################
182     set cfg_exist=0
183     if ( -e ${module_src}/configure ) then
184         set cfg_exist=1
185     endif
186     #########################################################
187     # perform build_configure if -b flag is given or if 
188     # configure script does not exist (first compilation?)
189     #########################################################
190     if ( $is_build_configure == 1 || $cfg_exist == 0 ) then
191         echo "------- Build configure ---------"
192         #########################################################
193         # if build_configure script is not found, omit the module
194         #########################################################
195         if ( ! -e ${module_src}/build_configure ) then
196             echo "Error! Nothing to build in ${module_src}. Skipping module."
197             continue
198         endif
199         #########################################################
200         # call build_configure
201         #########################################################
202         cd ${module_src}
203         ./build_configure >& ${LOG_DIR}/build_configure_${module}.log
204         #########################################################
205         # echo possible errors
206         #########################################################
207         if ( $verbose_level > 0 ) then
208             cat ${LOG_DIR}/build_configure_${module}.log | grep ": error:"
209         endif
210     endif
211     #########################################################
212     # deleting build directory if -d flag is given
213     #########################################################
214     if ( -e ${module_build} && $is_delete == 1 ) then
215         echo "Deleting ${module_build}"
216         rm -rf ${module_build}
217     endif
218     #########################################################
219     # creating build directory if it does not exist
220     #########################################################
221     if ( ! -e ${module_build} ) then
222         mkdir -p ${module_build}
223     endif
224     cd ${module_build}
225     #########################################################
226     # check if top Makefile exists in build directory, i.e. 
227     # is it necessary to run configure script
228     #########################################################
229     set mkfile_exist=0
230     if ( -e ${module_build}/Makefile ) then
231         set mkfile_exist=1
232     endif
233     #########################################################
234     # define installation directory (by using module's version
235     # number); default is a build directory
236     #########################################################
237     set vx=""
238     if ( -e ${module_src}/bin/VERSION ) then
239         set vx=`awk -F: '{split ( $2,x," " ) ; print x[1];}' ${module_src}/bin/VERSION`
240     endif
241     set px=${BUILD_DIR}/${module}
242     if ( "$prefix" != "" ) then
243         set px=$prefix/${module}
244     endif
245     if ( "$vx" != "" ) then
246         set px="$px"_"$vx"
247     endif
248     #########################################################
249     # perform configure if -c flag is given or if 
250     # Makefile does not exist (first compilation?)
251     #########################################################
252     if ( $is_configure == 1 || $mkfile_exist == 0) then
253         echo "------- Configure ---------------"
254         if (  "${module}" == "NETGENPLUGIN" && ($?NETGENHOME) ) then
255             set add_keys="--with-netgen=${NETGENHOME}"
256         endif
257         ${module_src}/configure --prefix=$px ${optim} ${add_keys} >& ${LOG_DIR}/configure_${module}.log
258         #########################################################
259         # echo possible errors
260         #########################################################
261         if ( $verbose_level > 0 ) then
262             cat ${LOG_DIR}/configure_${module}.log | grep ": error:"
263         endif
264         if ( $verbose_level > 1 ) then
265             cat ${LOG_DIR}/configure_${module}.log | grep ": WARNING:"
266         endif
267     endif
268     #########################################################
269     # perform make
270     #########################################################
271     echo "------- Make --------------------"
272     #########################################################
273     # first clear dependencies
274     #########################################################
275     find . -name ".dep*" -exec rm -rf {} \; >& /dev/null
276     make >& ${LOG_DIR}/make_${module}.log
277     set sts=$status
278     #########################################################
279     # if make step is successful set the ${module}_ROOT_DIR
280     # environment variable
281     #########################################################
282     if ( $sts == 0 ) then
283         setenv ${module}_ROOT_DIR ${module_build}
284     endif
285     #########################################################
286     # print make errors
287     #########################################################
288     cat ${LOG_DIR}/make_${module}.log | grep '[*][*][*]'
289     #########################################################
290     # print compiler errors and warnings
291     # Note: here awk is used to concatenate together several lines of single
292     #       error or warning message produced by stupid gnu compiler
293     # Actually, instead of that we could use 'fmessage length=n' option of g++...
294     #########################################################
295     if ( $verbose_level > 0 ) then
296         ###cat ${LOG_DIR}/make_${module}.log | grep ": error"
297         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/"@@
298     endif
299     if ( $verbose_level > 1 ) then
300         cat ${LOG_DIR}/make_${module}.log | awk 'substr($0,0,1)!=" " {print ""} {printf $0} END {print ""}' | grep ": warning" | sed s@"^${module_src}/src/"@@
301     endif
302     #########################################################
303     # perform make if -i or -p flags are given
304     #########################################################
305     if ( $is_install == 1 && $sts == 0 ) then
306         echo "------- Make install ------------"
307         #########################################################
308         # deleting build directory if -d flag is given
309         #########################################################
310         if ( -e $px && $is_delete == 1 ) then
311             echo "Deleting $px"
312             rm -rf $px
313         endif
314         make install >& ${LOG_DIR}/make_install_${module}.log
315         set sts=$status
316         #########################################################
317         # if make install step is successful set the 
318         # ${module}_ROOT_DIR environment variable
319         #########################################################
320         if ( $sts == 0 ) then
321             setenv ${module}_ROOT_DIR $px
322         endif
323     endif
324     echo ""
325   else
326     echo "Error! Can't find module sources. ${module}_SRC_DIR environment variable is not set."
327   endif
328 end
329 #########################################################
330 # finalize
331 #########################################################
332 cd ${BUILD_DIR}
333
334 echo "==========================================================================="
335 echo "SALOME build finished at `date`"
336 echo "==========================================================================="