source: trunk/util/arb_compile.sh

Last change on this file was 19245, checked in by westram, 2 years ago
  • Property svn:executable set to *
File size: 5.0 KB
Line 
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
55REVERT=1
56CLEAN=1
57
58# -------------------------------------------
59
60default_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
79log() {
80    echo "############################################################ [ $1 $2 ]"
81}
82log_start() {
83    log $1 start
84}
85log_result() {
86    local TAG=$1
87    local STATUS=$2
88    if [ $STATUS = 0 ]; then
89        log $TAG succeeded
90    else
91        log $TAG failed
92    fi
93    return $STATUS
94}
95
96clean() {
97    log_start clean
98    if [ "$CLEAN" = "1" ]; then
99        make clean
100    else
101        echo "No cleanup done before update"
102        true
103    fi
104    log_result clean $?
105}
106
107revert() {
108    log_start revert
109    if [ "$REVERT" = "1" ]; then
110        svn revert -R .
111    else
112        echo "Did not revert local changes"
113        echo "Current local changes are:"
114        echo "-----------------------------"
115        svn diff
116        echo "-----------------------------"
117        true
118    fi
119    log_result revert $?
120}
121svnup() {
122    log_start svnup
123    svn up --force $UPDATE_ARGS
124    log_result svnup $?
125}
126dumpcfg() {
127    ARB_CONFIG=config.makefile
128
129    log current "$CONFIG"
130    cat ../$CONFIG
131
132    log current "$ARB_CONFIG"
133    if [ -e $ARB_CONFIG ]; then
134        cat $ARB_CONFIG
135    else
136        echo "$ARB_CONFIG does not exist (yet)"
137    fi
138}
139update() {
140    clean && \
141        revert && \
142        svnup
143}
144build() {
145    log_start build
146    if [ "$CLEAN" = "1" ]; then
147        make -j$CORES TARFILE
148    else
149        echo "No cleanup done before compilation"
150        make -j$CORES TARFILE_QUICK
151    fi
152    log_result build $?
153}
154
155upgrade() {
156    echo "Upgrading ARB checkout in '$ARBHOME'"
157    echo ""
158    echo "Starting build process"
159    echo "(you may watch the output using"
160    echo "     less +F $LOG"
161    echo "in another terminal)"
162    echo ""
163    (dumpcfg && update && build) >& $LOG
164}
165
166arbshell() {
167    echo "ARBHOME now is '$ARBHOME'"
168    $ARBHOME/bin/arb_ntree --help 2>&1 | grep version
169    echo "Opening a new shell ('$SHELL'). Run arb here. Press ctrl-d to close this shell."
170    $SHELL
171    ARBHOME=$OLDARBHOME
172    echo "ARBHOME now is again '$ARBHOME'"
173}
174
175# ----------------------------------------
176
177if [ !$?ARBHOME ]; then
178    ARBHOME=''
179fi
180OLDARBHOME=$ARBHOME
181
182BASEDIR=`pwd`
183BASENAME=`basename $0 | perl -pne 's/.sh//'`
184
185echo "BASENAME='$BASENAME'"
186
187CONFIG=$BASENAME.config
188LOG=$BASEDIR/$BASENAME.log
189
190if [ -f $CONFIG ]; then
191    source $CONFIG
192else
193    default_config > $CONFIG
194    echo "$CONFIG has been generated"
195    SUBDIR=
196fi
197
198if [ "$SUBDIR" = "" ]; then
199    echo "Review config, then rerun this script"
200else
201    ARBHOME=$BASEDIR/$SUBDIR
202
203    if [ ! -d $ARBHOME ]; then
204        echo "ARBHOME='$ARBHOME' (no such directory)"
205    else
206        PATH=$ARBHOME/bin:$PATH
207        if [ !$?LD_LIBRARY_PATH ]; then
208            LD_LIBRARY_PATH=$ARBHOME/lib
209        else
210            LD_LIBRARY_PATH=$ARBHOME/lib:$LD_LIBRARY_PATH
211        fi
212
213        export ARBHOME PATH LD_LIBRARY_PATH
214
215        cd $ARBHOME
216
217        if [ "$REVISION" = "" ]; then
218            UPDATE_ARGS=
219        else
220            UPDATE_ARGS="-r $REVISION"
221        fi
222
223        (upgrade && echo "ARB upgrade succeeded" && arbshell) || ( echo "Error: Something failed (see $LOG)" && false)
224    fi
225fi
226
Note: See TracBrowser for help on using the repository browser.