Salome HOME
9334e9a1d46ed53a7c9c813058f52dccca890cb0
[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 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 # create log directory
154 #########################################################
155 if ( ! -e ${LOG_DIR} ) then
156     mkdir -p ${LOG_DIR}
157 endif
158
159 echo "==========================================================================="
160 echo "Starting SALOME build at `date`"
161
162 #########################################################
163 # loop for all given modules
164 #########################################################
165 foreach module (${modules})
166   echo "==========================================================================="
167   echo "Processing ${module} module"
168
169   set module_src=`printenv ${module}_SRC_DIR`
170   set module_build=${BUILD_DIR}/${module}_BUILD
171
172   if ( ${module_src} != "" ) then
173     set add_keys=""
174     cd ${BUILD_DIR}
175     #########################################################
176     # check if sources directory exists
177     #########################################################
178     if ( ! -e ${module_src} ) then
179         echo "Error! Can't find sources directory: ${module_src} does not exist."
180         continue
181     endif
182     #########################################################
183     # check if configure script exists
184     #########################################################
185     set cfg_exist=0
186     if ( -e ${module_src}/configure ) then
187         set cfg_exist=1
188     endif
189     #########################################################
190     # perform build_configure if -b flag is given or if 
191     # configure script does not exist (first compilation?)
192     #########################################################
193     if ( $is_build_configure == 1 || $cfg_exist == 0 ) then
194         echo "------- Build configure ---------"
195         #########################################################
196         # if build_configure script is not found, omit the module
197         #########################################################
198         if ( ! -e ${module_src}/build_configure ) then
199             echo "Error! Nothing to build in ${module_src}. Skipping module."
200             continue
201         endif
202         #########################################################
203         # call build_configure
204         #########################################################
205         cd ${module_src}
206         ./build_configure >& ${LOG_DIR}/build_configure_${module}.log
207         #########################################################
208         # echo possible errors
209         #########################################################
210         if ( $verbose_level > 0 ) then
211             cat ${LOG_DIR}/build_configure_${module}.log | grep ": error:"
212         endif
213     endif
214     #########################################################
215     # deleting build directory if -d flag is given
216     #########################################################
217     if ( -e ${module_build} && $is_delete == 1 ) then
218         echo "Deleting ${module_build}"
219         rm -rf ${module_build}
220     endif
221     #########################################################
222     # creating build directory if it does not exist
223     #########################################################
224     if ( ! -e ${module_build} ) then
225         mkdir -p ${module_build}
226     endif
227     cd ${module_build}
228     #########################################################
229     # check if top Makefile exists in build directory, i.e. 
230     # is it necessary to run configure script
231     #########################################################
232     set mkfile_exist=0
233     if ( -e ${module_build}/Makefile ) then
234         set mkfile_exist=1
235     endif
236     #########################################################
237     # define installation directory (by using module's version
238     # number); default is a build directory
239     #########################################################
240     set vx=""
241     if ( -e ${module_src}/bin/VERSION ) then
242         set vx=`awk -F: '{ if (NF > 1) print $NF; }' ${module_src}/bin/VERSION | tr -d '[:space:]'`
243     endif
244     set px=${BUILD_DIR}/${module}
245     if ( "$prefix" != "" ) then
246         set px=$prefix/${module}
247     endif
248     if ( "$vx" != "" ) then
249         set px="$px"_"$vx"
250     endif
251     #########################################################
252     # perform configure if -c flag is given or if 
253     # Makefile does not exist (first compilation?)
254     #########################################################
255     if ( $is_configure == 1 || $mkfile_exist == 0) then
256         echo "------- Configure ---------------"
257         if (  "${module}" == "NETGENPLUGIN" && ($?NETGENHOME) ) then
258             set add_keys="--with-netgen=${NETGENHOME}"
259         endif
260         ${module_src}/configure --prefix=$px ${optim} ${add_keys} >& ${LOG_DIR}/configure_${module}.log
261         #########################################################
262         # echo possible errors
263         #########################################################
264         if ( $verbose_level > 0 ) then
265             cat ${LOG_DIR}/configure_${module}.log | grep ": error:"
266         endif
267         if ( $verbose_level > 1 ) then
268             cat ${LOG_DIR}/configure_${module}.log | grep ": WARNING:"
269         endif
270     endif
271     #########################################################
272     # perform make
273     #########################################################
274     echo "------- Make --------------------"
275     #########################################################
276     # first clear dependencies
277     #########################################################
278     find . -name ".dep*" -exec rm -rf {} \; >& /dev/null
279     make >& ${LOG_DIR}/make_${module}.log
280     set sts=$status
281     #########################################################
282     # if make step is successful set the ${module}_ROOT_DIR
283     # environment variable
284     #########################################################
285     if ( $sts == 0 ) then
286         setenv ${module}_ROOT_DIR ${module_build}
287     endif
288     #########################################################
289     # print make errors
290     #########################################################
291     cat ${LOG_DIR}/make_${module}.log | grep '[*][*][*]'
292     #########################################################
293     # print compiler errors and warnings
294     # Note: here awk is used to concatenate together several lines of single
295     #       error or warning message produced by stupid gnu compiler
296     # Actually, instead of that we could use 'fmessage length=n' option of g++...
297     #########################################################
298     if ( $verbose_level > 0 ) then
299         ###cat ${LOG_DIR}/make_${module}.log | grep ": error"
300         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/"@@
301     endif
302     if ( $verbose_level > 1 ) then
303         cat ${LOG_DIR}/make_${module}.log | awk 'substr($0,0,1)!=" " {print ""} {printf $0} END {print ""}' | grep ": warning" | sed s@"^${module_src}/src/"@@
304     endif
305     #########################################################
306     # perform make if -i or -p flags are given
307     #########################################################
308     if ( $is_install == 1 && $sts == 0 ) then
309         echo "------- Make install ------------"
310         #########################################################
311         # deleting build directory if -d flag is given
312         #########################################################
313         if ( -e $px && $is_delete == 1 ) then
314             echo "Deleting $px"
315             rm -rf $px
316         endif
317         make install >& ${LOG_DIR}/make_install_${module}.log
318         set sts=$status
319         #########################################################
320         # if make install step is successful set the 
321         # ${module}_ROOT_DIR environment variable
322         #########################################################
323         if ( $sts == 0 ) then
324             setenv ${module}_ROOT_DIR $px
325         endif
326     endif
327     echo ""
328   else
329     echo "Error! Can't find module sources. ${module}_SRC_DIR environment variable is not set."
330   endif
331 end
332 #########################################################
333 # finalize
334 #########################################################
335 cd ${BUILD_DIR}
336
337 echo "==========================================================================="
338 echo "SALOME build finished at `date`"
339 echo "==========================================================================="