source: trunk/environments/g4py/tools/g4autobuild/g4autobuild @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

  • Property svn:executable set to *
File size: 9.4 KB
Line 
1#! /bin/bash -
2# ======================================================================
3#  A script for Geant4 autobuild
4#
5#  Version 2.4.2 Apr. 2010
6#
7#  [usage]
8#    g4autobuild [<options>]
9#
10#    [options]
11#      --help, -h       print this message
12#      --prefix=PREFIX  base directory of Geant4 builds [$(cwd)/]
13#      --config=CONFIG  configure file [PREFIX/g4auto.cfg]
14#      --jobs=N         allow N jobs at once
15#      --with-fpic      default -fPIC option
16# ======================================================================
17export LANG=C
18
19PATH=/bin:/usr/bin
20export PATH
21
22# ======================================================================
23# help message
24# ======================================================================
25show_help() {
26cat <<EOF
27 [usage]
28   g4autobuild [<options>]
29
30   [options]
31     --help, -h       print this message
32     --prefix=PREFIX  root directory of autobuild [\$(PWD)/]
33     --config=CONFIG  configure file [PREFIX/g4auto.cfg]
34     --jobs=N         allow N jobs at once
35     --with-fpic      default -fPIC option
36
37EOF
38}
39
40# ======================================================================
41# external environment
42# ======================================================================
43add_ext_env() {
44aext=$1
45aval=$2
46
47# for bash
48cat >> g4rc.sh <<EOF
49export $aext=$aval
50EOF
51
52# for csh
53cat >> g4rc.csh <<EOF
54setenv $aext $aval
55EOF
56
57}
58
59# ======================================================================
60# vis. environment
61# ======================================================================
62add_vis_envs() {
63avis=$1
64
65# for bash
66cat >> g4rc.sh <<EOF
67export G4VIS_BUILD_${avis}_DRIVER=1
68export G4VIS_USE_${avis}=1
69
70EOF
71
72# for csh
73cat >> g4rc.csh <<EOF
74setenv G4VIS_BUILD_${avis}_DRIVER 1
75setenv G4VIS_USE_${avis} 1
76
77EOF
78
79}
80
81# ======================================================================
82# ui environment
83# ======================================================================
84add_ui_envs() {
85aui=$1
86
87if [ $aui = TCSH -o $aui = GAG ]; then
88# for bash
89cat >> g4rc.sh <<EOF
90export G4UI_USE_${aui}=1
91EOF
92
93# for csh
94cat >> g4rc.csh <<EOF
95setenv G4UI_USE_${aui} 1
96EOF
97else
98# for bash
99cat >> g4rc.sh <<EOF
100export G4UI_BUILD_${aui}_SESSION=1
101export G4UI_USE_${aui}=1
102EOF
103
104# for csh
105cat >> g4rc.csh <<EOF
106setenv G4UI_BUILD_${aui}_SESSION 1
107setenv G4UI_USE_${aui} 1
108EOF
109fi
110
111}
112
113# ======================================================================
114# options
115# ======================================================================
116add_options() {
117aopt=$1
118
119# for bash
120cat >> g4rc.sh <<EOF
121export G4LIB_BUILD_${aopt}=1
122export G4LIB_USE_${aopt}=1
123EOF
124
125# for csh
126cat >> g4rc.csh <<EOF
127setenv G4LIB_BUILD_${aopt} 1
128setenv G4LIB_USE_${aopt} 1
129EOF
130
131}
132
133# ======================================================================
134# main
135# ======================================================================
136# default values
137prefix=`pwd`
138config=$prefix/g4auto.cfg
139status_dir=$prefix/status
140njobs=1
141qfpic=0
142
143# parsing options
144while test $# -gt 0
145do
146  case $1 in
147    -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
148    *) optarg= ;;
149  esac
150
151  case $1 in
152    --help|-h) show_help;  exit 0 ;;
153    # ---------------------------------------------------------------
154    --prefix=*)                prefix=$optarg                    ;;
155    --config=*)                config=$optarg                    ;;
156    --jobs=*)                  njobs=$optarg                     ;;
157    --with-fpic )              qfpic=1                           ;;
158    # ---------------------------------------------------------------
159    -*)
160      echo "Unrecognized option: $1"
161      exit -1
162      ;;
163    *)
164      echo "Invalid argument: $1"
165      exit -1
166      ;;
167  esac
168  shift
169done
170
171# check something
172if [ ! -d $prefix ]; then
173  echo "*** abort :$prefix does not exist."
174  exit -1
175fi
176
177if [ ! -e $config ]; then
178  echo "*** abort :$config does not exist."
179  exit -1
180fi
181
182if [ ! -d $status_dir ]; then
183  echo "$status_dir does not exist. It is created."
184  mkdir $status_dir
185fi
186
187if [ ! `echo "$njobs" | egrep "^[0-9]+$"` ];  then
188  echo "*** abort : #jobs must be a number."
189  exit -1
190fi
191
192# ======================================================================
193# parsing a config file...
194# ======================================================================
195g4sys=`grep '^G4SYS'  $config | awk '{print $2}'`
196g4base=`grep '^G4BASE' $config | awk '{print $2}'`
197clhepbase=`grep '^CLHEPBASE' $config | awk '{print $2}'`
198geant4_set=`grep '^-' $config | awk '{print $2}'`
199clhep_set=`grep '^-' $config | awk '{print $3}'`
200xercescroot=`grep '^XERCESCROOT' $config | awk '{print $2}'`
201qthome=`grep '^QTHOME' $config | awk '{print $2}'`
202vis_set=`grep '^v' $config | awk '{print $2}'`
203ui_set=`grep '^u' $config | awk '{print $2}'`
204opt_set=`grep '^o' $config | awk '{print $2}'`
205
206if [ $g4sys == Darwin-g++ ]; then
207  qfpic=1
208fi
209
210if [ ! -d $g4base ]; then
211  echo "*** abort :$g4base does not exist."
212  exit -1
213fi
214
215if [ ! -d $clhepbase ]; then
216  echo "*** abort :$clhepbase does not exist."
217  exit -1
218fi
219
220if [ $xercescroot ]; then
221  if [ ! -d $xercescroot ]; then
222    echo "*** abort :$xercescroot does not exist."
223    exit -1
224  fi
225fi
226
227if [ $qthome ]; then
228  if [ ! -d $qthome ]; then
229    echo "*** abort :$qthome does not exist."
230    exit -1
231  fi
232fi
233
234# ======================================================================
235# building Geant4
236
237idx=1
238for g4 in $geant4_set
239do
240  echo "@@@ building Geant4 ($g4) ..."
241 
242  g4dir=$g4base/$g4
243
244  if [ ! -d $g4dir ]; then
245    echo "*** (error) target directory does not exist."
246    exit -1
247  fi
248
249  set $clhep_set
250  clhep="clhep=\${$idx}"
251  eval $clhep
252
253  pushd $g4dir > /dev/null 2>&1
254
255  cat > g4rc.sh << EOF
256# ========================================================================
257#    Geant4 development environment
258# ========================================================================
259export LANG=C
260
261# ========================================================================
262# System
263# ========================================================================
264export G4SYSTEM=$g4sys
265export G4INSTALL=$g4base/$g4
266export CLHEP_BASE_DIR=$clhepbase/$clhep
267EOF
268
269  cat > g4rc.csh << EOF
270# ========================================================================
271#    Geant4 development environment
272# ========================================================================
273setenv LANG C
274
275# ========================================================================
276# System
277# ========================================================================
278setenv G4SYSTEM $g4sys
279setenv G4INSTALL $g4base/$g4
280setenv CLHEP_BASE_DIR $clhepbase/$clhep
281EOF
282
283if [ $xercescroot ]; then
284  envval=XERCESCROOT
285  add_ext_env XERCESCROOT $xercescroot
286fi
287
288if [ $qthome ]; then
289  envval=QTHOME
290  add_ext_env QTHOME $qthome
291fi
292
293  cat >> g4rc.sh <<EOF
294
295# ========================================================================
296# Visualization
297# ========================================================================
298EOF
299
300  cat >> g4rc.csh << EOF
301
302# ========================================================================
303# Visualization
304# ========================================================================
305EOF
306
307  # vis. envs
308  for vis in $vis_set
309  do
310    add_vis_envs $vis
311  done
312
313  cat >> g4rc.sh <<EOF
314# ========================================================================
315# UI
316# ========================================================================
317EOF
318
319  cat >> g4rc.csh <<EOF
320# ========================================================================
321# UI
322# ========================================================================
323EOF
324
325  # ui envs
326  for ui in $ui_set
327  do
328    add_ui_envs $ui
329  done
330
331  cat >> g4rc.sh <<EOF
332
333# ========================================================================
334# Options
335# ========================================================================
336EOF
337
338  cat >> g4rc.csh <<EOF
339
340# ========================================================================
341# Options
342# ========================================================================
343EOF
344
345  # options
346  for aopt in $opt_set
347  do
348    add_options $aopt
349  done
350
351  # ======================================================================
352  # ok, Lets' build...
353  . g4rc.sh
354
355  # ======================================================================
356  # normal lib
357  if [ ! -e $status_dir/$g4.lib ]; then
358    echo "@@@ building normal lib ..."
359    pushd source > /dev/null 2>&1
360    make --jobs=$njobs > make.log 2>&1
361    make includes > /dev/null 2>&1
362    popd > /dev/null 2>&1
363
364    touch $status_dir/$g4.lib
365  fi
366
367  # ======================================================================
368  # global lib
369  if [ ! -e $status_dir/$g4.glib ]; then
370    echo "@@@ buinding global lib ..."
371    export G4LIB=$G4INSTALL/glib
372
373    pushd source > /dev/null 2>&1
374    make global > make-global.log 2>&1
375    popd > /dev/null 2>&1
376
377    touch $status_dir/$g4.glib
378  fi
379
380  # ======================================================================
381  # shared lib 
382  if [ ! -e $status_dir/$g4.slib ]; then
383    echo "@@@ buinding shared lib ..."
384    export G4LIB=$G4INSTALL/slib
385    if [ $qfpic == 1 ]; then
386      export G4TMP=$G4INSTALL/tmp
387    else
388      export G4TMP=$G4INSTALL/tmp-slib
389    fi
390    export G4LIB_BUILD_SHARED=1
391
392    pushd source > /dev/null 2>&1
393    make --jobs=$njobs > make-slib.log 2>&1 
394    make global >> make-slib.log 2>&1
395    popd > /dev/null 2>&1
396
397    touch $status_dir/$g4.slib
398  fi
399
400  # ======================================================================
401  # done
402  unset G4LIB
403  unset G4TMP
404  unset G4LIB_BUILD_SHARED
405
406  popd > /dev/null 2>&1
407
408  echo $((idx++)) > /dev/null 2>&1
409done
410
411exit 0
412
Note: See TracBrowser for help on using the repository browser.