1 | #!/bin/bash |
---|
2 | # |
---|
3 | # How to use: |
---|
4 | # |
---|
5 | # A. SETUP |
---|
6 | # -------- |
---|
7 | # |
---|
8 | # 1. create a new directory, e.g. |
---|
9 | # mkdir my_arb_compile; cd my_arb_compile |
---|
10 | # |
---|
11 | # 2. checkout arb, e.g. (the last argument is the name of the target directory) |
---|
12 | # svn co svn+ssh://USERNAME@svn.arb-home.de/svn/ARB/trunk myARB |
---|
13 | # # or |
---|
14 | # svn co http://vc.arb-home.de/readonly/trunk myARB |
---|
15 | # |
---|
16 | # 3. link the included compile script, e.g. |
---|
17 | # ln -s myARB/util/arb_compile.sh compile_myARB.sh |
---|
18 | # |
---|
19 | # 4. call the script |
---|
20 | # ./compile_myARB.sh |
---|
21 | # |
---|
22 | # 5. review the generated config |
---|
23 | # vi compile_myARB.config |
---|
24 | # |
---|
25 | # 6. call the script again (this will generate config.makefile and fail) |
---|
26 | # ./compile_myARB.sh |
---|
27 | # |
---|
28 | # 7. edit the generated config.makefile (default builds a openGL/64bit/linux-ARB) |
---|
29 | # vi myARB/config.makefile |
---|
30 | # |
---|
31 | # 8. call the script again (this shall succeed) |
---|
32 | # ./compile_myARB.sh |
---|
33 | # |
---|
34 | # |
---|
35 | # B. UPGRADE |
---|
36 | # ----------- |
---|
37 | # |
---|
38 | # 1. simply call the script to upgrade ARB to newest revision |
---|
39 | # ./compile_myARB.sh |
---|
40 | # |
---|
41 | # |
---|
42 | # C. Multiple versions (in one 'my_arb_compile' directory) |
---|
43 | # -------------------- |
---|
44 | # |
---|
45 | # When you use a different name for the link target in step A.3. it |
---|
46 | # is possible to work with multiple checkouts and multiple configs |
---|
47 | # inside the same 'my_arb_compile' directory. |
---|
48 | # The name used as checkout directory has to be changed for subsequent |
---|
49 | # versions. Change 'myARB' to a different name in steps A.2., A.3. and A.7 |
---|
50 | # |
---|
51 | |
---|
52 | # ------------------------------------------- |
---|
53 | # default values for optional config entries: |
---|
54 | |
---|
55 | REVERT=1 |
---|
56 | CLEAN=1 |
---|
57 | |
---|
58 | # ------------------------------------------- |
---|
59 | |
---|
60 | default_config() { |
---|
61 | echo "# config to compile ARB via $BASENAME.sh" |
---|
62 | echo "" |
---|
63 | echo "# Subdirectory in which ARB is located:" |
---|
64 | echo "SUBDIR=myARB" |
---|
65 | echo "" |
---|
66 | echo "# Real CPU cores" |
---|
67 | echo "CORES=2" |
---|
68 | echo "" |
---|
69 | echo "# SVN revision to use (empty=newest)" |
---|
70 | echo "REVISION=" |
---|
71 | echo "" |
---|
72 | echo "# normally this script reverts all local changes (uncomment the next line to avoid that)" |
---|
73 | echo "#REVERT=0" |
---|
74 | echo "" |
---|
75 | echo "# normally this script always does a complete rebuild (uncomment the next line to avoid that)" |
---|
76 | echo "#CLEAN=0" |
---|
77 | } |
---|
78 | |
---|
79 | clean() { |
---|
80 | if [ "$CLEAN" = "1" ]; then |
---|
81 | make clean |
---|
82 | else |
---|
83 | echo "No cleanup done before update" |
---|
84 | true |
---|
85 | fi |
---|
86 | } |
---|
87 | |
---|
88 | revert() { |
---|
89 | if [ "$REVERT" = "1" ]; then |
---|
90 | svn revert -R . |
---|
91 | else |
---|
92 | echo "Did not revert local changes" |
---|
93 | echo "Current local changes are:" |
---|
94 | echo "-----------------------------" |
---|
95 | svn diff |
---|
96 | echo "-----------------------------" |
---|
97 | true |
---|
98 | fi |
---|
99 | } |
---|
100 | |
---|
101 | update() { |
---|
102 | set -x |
---|
103 | clean && \ |
---|
104 | revert && \ |
---|
105 | svn up --force $UPDATE_ARGS |
---|
106 | } |
---|
107 | build() { |
---|
108 | if [ "$CLEAN" = "1" ]; then |
---|
109 | make -j$CORES clean |
---|
110 | make -j$CORES tarfile_quick |
---|
111 | else |
---|
112 | echo "No cleanup done before compilation" |
---|
113 | make -j$CORES tarfile_quick |
---|
114 | fi |
---|
115 | } |
---|
116 | |
---|
117 | upgrade() { |
---|
118 | echo "Upgrading ARB checkout in '$ARBHOME'" |
---|
119 | echo "" |
---|
120 | echo "Starting build process" |
---|
121 | echo "(you may watch the output using" |
---|
122 | echo " less +F $LOG" |
---|
123 | echo "in another terminal)" |
---|
124 | echo "" |
---|
125 | (update && build) >& $LOG |
---|
126 | } |
---|
127 | |
---|
128 | arbshell() { |
---|
129 | echo "ARBHOME now is '$ARBHOME'" |
---|
130 | $ARBHOME/bin/arb_ntree --help 2>&1 | grep version |
---|
131 | echo "Opening a new shell ('$SHELL'). Run arb here. Press ctrl-d to close this shell." |
---|
132 | $SHELL |
---|
133 | ARBHOME=$OLDARBHOME |
---|
134 | echo "ARBHOME now is again '$ARBHOME'" |
---|
135 | } |
---|
136 | |
---|
137 | # ---------------------------------------- |
---|
138 | |
---|
139 | if [ !$?ARBHOME ]; then |
---|
140 | ARBHOME='' |
---|
141 | fi |
---|
142 | OLDARBHOME=$ARBHOME |
---|
143 | |
---|
144 | BASEDIR=`pwd` |
---|
145 | BASENAME=`basename $0 | perl -pne 's/.sh//'` |
---|
146 | |
---|
147 | echo "BASENAME='$BASENAME'" |
---|
148 | |
---|
149 | CONFIG=$BASENAME.config |
---|
150 | LOG=$BASEDIR/$BASENAME.log |
---|
151 | |
---|
152 | if [ -f $CONFIG ]; then |
---|
153 | source $CONFIG |
---|
154 | else |
---|
155 | default_config > $CONFIG |
---|
156 | echo "$CONFIG has been generated" |
---|
157 | SUBDIR= |
---|
158 | fi |
---|
159 | |
---|
160 | if [ "$SUBDIR" = "" ]; then |
---|
161 | echo "Review config, then rerun this script" |
---|
162 | else |
---|
163 | ARBHOME=$BASEDIR/$SUBDIR |
---|
164 | |
---|
165 | if [ ! -d $ARBHOME ]; then |
---|
166 | echo "ARBHOME='$ARBHOME' (no such directory)" |
---|
167 | else |
---|
168 | PATH=$ARBHOME/bin:$PATH |
---|
169 | if [ !$?LD_LIBRARY_PATH ]; then |
---|
170 | LD_LIBRARY_PATH=$ARBHOME/lib |
---|
171 | fi |
---|
172 | LD_LIBRARY_PATH=$ARBHOME/lib:$LD_LIBRARY_PATH |
---|
173 | |
---|
174 | export ARBHOME PATH LD_LIBRARY_PATH |
---|
175 | |
---|
176 | cd $ARBHOME |
---|
177 | |
---|
178 | if [ "$REVISION" = "" ]; then |
---|
179 | UPDATE_ARGS= |
---|
180 | else |
---|
181 | UPDATE_ARGS="-r $REVISION" |
---|
182 | fi |
---|
183 | |
---|
184 | (upgrade && echo "ARB upgrade succeeded" && arbshell) || ( echo "Error: Something failed (see $LOG)" && false) |
---|
185 | fi |
---|
186 | fi |
---|
187 | |
---|