Salome HOME
43d80bc3c69c71be550a42427e3d03a15f6107dd
[tools/install.git] / config_files / build.csh
1 #!/bin/csh -f
2 ##################################################################################################
3 # Name       : build.csh
4 # Description: Build and install SALOME 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 GUI GEOM MED SMESH VISU SUPERV NETGENPLUGIN GHS3DPLUGIN COMPONENT PYCALCULATOR CALCULATOR HELLO PYHELLO LIGHT)
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_build.csh
139 if ( ! -e $env_script ) then
140     set env_script=`dirname $0`/env_products.csh
141 endif
142 if ( -e $env_script ) then
143     echo ">>> Setting environment"
144     source $env_script
145 else
146     echo "\!\!\! Warning \!\!\! Environment is not set: file env_products.csh is not found."
147 endif
148
149 set BUILD_DIR=${PWD}
150 set LOG_DIR=${BUILD_DIR}/LOGS
151
152 #########################################################
153 # define installation prefix
154 #########################################################
155 if ( "$prefix" == "" ) then
156     set prefix=${BUILD_DIR}/INSTALL
157     if ( $is_install == 1 ) then
158         echo "\!\!\! Warning \!\!\! Installation directory is not set."
159         echo "All the modules will be installed to the $prefix"
160     else
161         set is_kernel=`echo ${modules} | grep KERNEL`
162         if ( "$is_kernel" != "" ) then
163             echo "\!\!\! Warning \!\!\! KERNEL module requires install step to be performed."
164             echo "For this module -i option will be forced."
165             echo "The module(s) will be installed to the $prefix"
166         endif
167     endif
168 else
169     set is_absolute=`echo $prefix | grep -e "^/"`
170     if ( "$is_absolute" == "" ) then
171         set prefix=${BUILD_DIR}/$prefix
172         echo "\!\!\! Warning \!\!\! Relative prefix is used."
173         echo "All the modules will be installed to the $prefix"
174     endif
175 endif
176
177 #########################################################
178 # create log directory
179 #########################################################
180 if ( ! -e ${LOG_DIR} ) then
181     mkdir -p ${LOG_DIR}
182 endif
183
184 echo "==========================================================================="
185 echo "Starting SALOME build at `date`"
186 echo "==========================================================================="
187
188 #########################################################
189 # loop for all given modules
190 #########################################################
191 foreach module (${modules})
192   echo ">>> Processing ${module} module"
193
194   set module_src=`printenv ${module}_SRC_DIR`
195   set module_build=${BUILD_DIR}/${module}_BUILD
196
197   if ( ${module_src} != "" ) then
198     set add_keys=""
199     cd ${BUILD_DIR}
200     #########################################################
201     # check if sources directory exists
202     #########################################################
203     if ( ! -e ${module_src} ) then
204         echo "\!\!\! Error \!\!\! Can't find sources directory: ${module_src} does not exist."
205         continue
206     endif
207     #########################################################
208     # check if configure script exists
209     #########################################################
210     set cfg_exist=0
211     if ( -e ${module_src}/configure ) then
212         set cfg_exist=1
213     endif
214     #########################################################
215     # perform build_configure if -b flag is given or if 
216     # configure script does not exist (first compilation?)
217     #########################################################
218     if ( $is_build_configure == 1 || $cfg_exist == 0 ) then
219         echo "... Performing build_configure"
220         #########################################################
221         # check if build_configure script exists
222         #########################################################
223         if ( ! -e ${module_src}/build_configure ) then
224             echo "\!\!\! Warning \!\!\! Can not find build_configure script in ${module_src}."
225         else
226             #########################################################
227             # call build_configure
228             #########################################################
229             cd ${module_src}
230             ./build_configure >& ${LOG_DIR}/build_configure_${module}.log
231             #########################################################
232             # echo possible errors
233             #########################################################
234             if ( $verbose_level > 0 ) then
235                 cat ${LOG_DIR}/build_configure_${module}.log | grep ": error:"
236             endif
237         endif
238     endif
239     #########################################################
240     # deleting build directory if -d flag is given
241     #########################################################
242     if ( -e ${module_build} && $is_delete == 1 ) then
243         echo "... Removing ${module_build}"
244         rm -rf ${module_build}
245     endif
246     #########################################################
247     # creating build directory if it does not exist
248     #########################################################
249     if ( ! -e ${module_build} ) then
250         mkdir -p ${module_build}
251     endif
252     cd ${module_build}
253     #########################################################
254     # check if top Makefile exists in build directory, i.e. 
255     # is it necessary to run configure script
256     #########################################################
257     set mkfile_exist=0
258     if ( -e ${module_build}/Makefile ) then
259         set mkfile_exist=1
260     endif
261     #########################################################
262     # check if configure options are changed from the 
263     # previous launch
264     #########################################################
265     set opts_changed=0
266 ##    if ( -f ${module_build}/config.log ) then
267 ##      set old_prefix=`grep -e '^prefix=' ${module_build}/config.log | sed -e "s%^prefix='\(.*\)'%\1%"`
268 ##      if ( "$old_prefix" != "$prefix" ) then
269 ##          set opts_changed=1
270 ##      endif
271 ##    endif
272     #########################################################
273     # define installation directory (by using module's version
274     # number); default is a build directory
275     #########################################################
276     set vx=""
277     set cfg_file=configure.ac
278     if ( ! -e ${module_src}/${cfg_file} ) then
279         set cfg_file=configure.in.base
280     endif
281     if ( -e ${module_src}/${cfg_file} ) then
282         set vx=`grep -e "^VERSION=" ${module_src}/${cfg_file} | awk -F= '{ if (NF>1) print $NF; }' | tr -d '[:space:]'`
283     endif
284     set px=${BUILD_DIR}/${module}
285     if ( "$prefix" != "" ) then
286         set px=$prefix/${module}
287     endif
288     if ( "$vx" != "" ) then
289         set px="$px"_"$vx"
290     endif
291     #########################################################
292     # perform configure if -c flag is given or if 
293     # Makefile does not exist (first compilation?)
294     #########################################################
295     if ( $is_configure == 1 || $mkfile_exist == 0 || $opts_changed == 1 ) then
296         echo "... Performing configure"
297         #########################################################
298         # check if configure script exists
299         #########################################################
300         if ( ! -e ${module_src}/configure ) then
301             echo "\!\!\! Warning \!\!\! Can not find configure script in ${module_src}."
302         else
303             if (  "${module}" == "NETGENPLUGIN" && ($?NETGENHOME) ) then
304                 set add_keys="--with-netgen=${NETGENHOME}"
305             endif
306             ${module_src}/configure --prefix=$px ${optim} ${add_keys} >& ${LOG_DIR}/configure_${module}.log
307             #########################################################
308             # echo possible errors
309             #########################################################
310             if ( $verbose_level > 0 ) then
311                 cat ${LOG_DIR}/configure_${module}.log | grep ": error:"
312             endif
313             if ( $verbose_level > 1 ) then
314                 cat ${LOG_DIR}/configure_${module}.log | grep ": WARNING:"
315             endif
316         endif
317     endif
318     #########################################################
319     # perform make
320     #########################################################
321     echo "... Performing make"
322     #########################################################
323     # first clear dependencies
324     #########################################################
325     find . -name ".dep*" -type f -exec rm -f {} \; >& /dev/null
326     make >& ${LOG_DIR}/make_${module}.log
327     set sts=$status
328     #########################################################
329     # if make step is successful set the ${module}_ROOT_DIR
330     # environment variable
331     #########################################################
332     if ( $sts == 0 ) then
333         setenv ${module}_ROOT_DIR ${module_build}
334     endif
335     #########################################################
336     # print make errors
337     #########################################################
338     cat ${LOG_DIR}/make_${module}.log | grep '[*][*][*]'
339     #########################################################
340     # print compiler errors and warnings
341     # Note: here awk is used to concatenate together several lines of single
342     #       error or warning message produced by stupid gnu compiler
343     # Actually, instead of that we could use 'fmessage length=n' option of g++...
344     #########################################################
345     if ( $verbose_level > 0 ) then
346         ###cat ${LOG_DIR}/make_${module}.log | grep ": error"
347         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/"@@
348     endif
349     if ( $verbose_level > 1 ) then
350         cat ${LOG_DIR}/make_${module}.log | awk 'substr($0,0,1)!=" " {print ""} {printf $0} END {print ""}' | grep ": warning" | sed s@"^${module_src}/src/"@@
351     endif
352     #########################################################
353     # perform make if -i or -p flags are given
354     #########################################################
355     if ( $is_install == 1 && $sts == 0 || "${module}" == "KERNEL" ) then
356         echo "... Performing make install"
357         #########################################################
358         # deleting build directory if -d flag is given
359         #########################################################
360         if ( -e $px && $is_delete == 1 ) then
361             echo "... Removing $px"
362             rm -rf $px
363         endif
364         make install >& ${LOG_DIR}/make_install_${module}.log
365         set sts=$status
366         #########################################################
367         # if make install step is successful set the 
368         # ${module}_ROOT_DIR environment variable
369         #########################################################
370         if ( $sts == 0 ) then
371             setenv ${module}_ROOT_DIR $px
372         endif
373     endif
374     echo ">>> Finished ${module} module"
375   else
376     echo "\!\!\! Error \!\!\! Can't find module sources. ${module}_SRC_DIR environment variable is not set."
377   endif
378 end
379 #########################################################
380 # finalize
381 #########################################################
382 cd ${BUILD_DIR}
383
384 echo "==========================================================================="
385 echo "SALOME build finished at `date`"
386 echo "==========================================================================="