setup.sh
Go to the documentation of this file.
1 #!/bin/sh
2 #
3 # Setup the edep-sim directory for development (or simply running the
4 # simulation). This makes sure that the ROOT and GEANT4 environment
5 # variables are set (using thisroot.sh and geant4.sh), and then
6 # defines a couple of conveniences commands:
7 #
8 # edep-build == Source ./build/edep-build.sh which will conveniently
9 # run cmake/make/make install from any place so that it's
10 # really easy to recompile.
11 #
12 # edep-setup == Source this file. You probably never have to use
13 # this one.
14 #
15 # This setup script is not needed. You can also do it by hand. It's
16 # a usual cmake build, but you need to make sure root and geant are
17 # "in the path".
18 #
19 # source thisroot.sh
20 # source geant4.sh
21 # cd the-build-directory
22 # cmake -DCMAKE_INSTALL_PREFIX=the-install-directory the-edep-sim-directory
23 # make
24 # make install
25 
26 
27 # Try to setup root. ROOT installs thisroot.sh in the bin directory
28 # to setup the environment. The first "thisroot.sh" in the path will
29 # define the root that is used.
30 . thisroot.sh >& /dev/null
31 if [ $? != 0 ]; then
32  echo ROOT not available.
33 fi
34 
35 # Try to setup geant4. GEANT4 installs geant4.sh in the bin directory
36 # to setup the environment. The first "geant4.sh" in the path will
37 # define the geant that is used.
38 . geant4.sh >& /dev/null
39 if [ $? != 0 ]; then
40  echo GEANT not available.
41 fi
42 
43 # Find the root of the building area.
44 ___edep_root() {
45  COUNT=50
46  while true; do
47  if [ -e ./build -a -d ./build -a -e ./build/edep-build.sh ]; then
48  echo ${PWD}
49  return
50  fi
51  COUNT=$(expr ${COUNT} - 1)
52  if [ ${COUNT} -lt 1 ]; then
53  echo invalid-directory
54  return
55  fi
56  cd ..
57  done
58 }
59 
60 export EDEP_ROOT
61 EDEP_ROOT=$(___edep_root)
62 unset -f ___edep_root
63 
64 if [ ${EDEP_ROOT} = "invalid-directory" ]; then
65  echo EDEP-SIM setup.sh must be sourced in edep-sim directory.
66  return
67 fi
68 
69 ___edep_target () {
70  target="edep"
71  compiler=gcc
72  target="${target}-${compiler}-$(cc -dumpversion)-$(cc -dumpmachine)"
73  echo $target
74 }
75 
76 export EDEP_TARGET
77 EDEP_TARGET=$(___edep_target)
78 unset -f ___edep_target
79 
80 ___path_prepend () {
81  ___path_remove $1 $2
82  eval export $1="$2:\$$1"
83 }
84 ___path_remove () {
85  export $1=$(eval echo -n \$$1 | \
86  awk -v RS=: -v ORS=: '$0 != "'$2'"' | \
87  sed 's/:$//');
88 }
89 
90 ___path_prepend PATH ${EDEP_ROOT}/${EDEP_TARGET}/bin
91 ___path_prepend LD_LIBRARY_PATH ${EDEP_ROOT}/${EDEP_TARGET}/lib
92 
93 unset -f ___path_prepend
94 unset -f ___path_remove
95 
96 
97 alias edep-setup=". ${EDEP_ROOT}/setup.sh"
98 
99 alias edep-build="${EDEP_ROOT}/build/edep-build.sh"
100 
101 echo Defined edep-setup to re-setup the edep-sim package.
102 echo Defined edep-build to build the the edep-sim package.