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