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