source: other-projects/cascade-make/trunk/lib/cascade-lib.bash@ 23111

Last change on this file since 23111 was 23111, checked in by sjm84, 14 years ago

Swapping 2 sections of code

File size: 5.1 KB
RevLine 
[23111]1if test -z $GSDLOS ; then
2 GSDLOS=`uname -s | tr '[A-Z]' '[a-z]'`
3 # check for running bash under Cygwin
4 if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ;
5 then
6 GSDLOS=windows
7 fi
8 # check for running bash under MinGW/MSys
9 if test "`echo $GSDLOS | sed 's/mingw//'`" != "$GSDLOS" ;
10 then
11 GSDLOS=windows
12 fi
13 echo "GSDLOS was not set. Setting it to '$GSDLOS'"
14 export GSDLOS
15fi
[22122]16
[22245]17if test $# -gt "0" ; then
18 if test -z ${1##GEXT*} ; then
19
20 ext=$1 ; shift
21 reldir=$1 ; shift
[23095]22
[22245]23 eval exthome=`echo \\$$ext`
24 if test -z "$exthome" ; then
[23095]25 echo "Environment variable $ext for Greenstone extension not set"
[22245]26 echo "Sourcing $reldir/setup.bash"
27 source $reldir/setup.bash
[23095]28
29 eval exthome=`echo \\$$ext`
[22245]30 fi
31 fi
32fi
33
[22122]34run_untar()
35{
36 local package=$1
37 local version=$2
38 local ext=$3
39
40 tar_args="";
41
42 if [ $ext = ".tar.gz" ] ; then
43 tar_args="xvzf"
44 elif [ $ext = ".tgz" ] ; then
45 tar_args="xvzf"
46 elif [ $ext = ".tar.bz2" ] ; then
47 tar_args="xvjf"
48 elif [ $ext = ".tar.bz" ] ; then
49 tar_args="xvjf"
50 elif [ $ext = ".tar" ] ; then
51 tar_args="xvf"
52 else
53 echo "Warning: Unrecognized extension: $ext"
54 echo "Assuming tarred, gzipped file"
55 tar_args="xvjf"
56 fi
57
58
59 echo tar $tar_args $package$version$ext
60 tar $tar_args $package$version$ext
61
62 if [ $? != 0 ] ; then
63 echo " Error encountered running *untar* stage of $progname"
64 exit 1
65 fi
66}
67
68opt_run_tarclean()
69{
70 local type=$1
71 local package=$2
72 local version=$3
73
74 if [ $type = "1" ] ; then
75
76 local dir=$package$version
77 if [ -d $dir ] ; then
78 echo /bin/rm -rf $dir
79 /bin/rm -rf $dir
80
81 if [ $? != 0 ] ; then
82 echo " Error encountered running *tarclean* stage of $progname"
83 exit 1
84 fi
85 else
86 echo "Unable to find directory $dir"
87 fi
88 fi
89}
90
[23077]91toplevel_make_dist()
92{
[23104]93 local distos=$1 ; shift
[23095]94 local dirname=`basename $exthome`
[23077]95
[23104]96 local checklist="$*"
[23077]97 local distlist=""
98
99 for d in $checklist ; do
100 if [ -e $d ] ; then
101 distlist="$distlist $dirname/$d"
102 fi
103 done
104
105 pushd ..
106
[23104]107 tar cvzf $dirname-$distos.tar.gz $distlist
108 mv $dirname-$distos.tar.gz $dirname/.
[23077]109
110 popd
111}
112
[23104]113default_toplevel_make_dist()
114{
115 local distos=$1 ; shift
116 local dirname=`basename $exthome`
117
118 local checklist="setup.bash setup.bat perllib $GSDLOS lib $*"
119 toplevel_make_dist $distos $checklist
120}
121
[22122]122opt_run_untar()
123{
124 local force_untar=$1
125 local auto_untar=$2
126 local package=$3
127 local version=$4
128
129 local ext="";
130
131 if [ ! -z "$5" ] ; then
132 ext=$5
133 else
134 ext=".tar.gz"
135 fi
136
137 if [ $force_untar = "1" ] ; then
138 run_untar $package $version $ext
139 elif [ $auto_config = "1" ] ; then
140 if [ -d $package$version ] ; then
141 echo "Found untarred version of $package$version$ext => no need to untar"
142 else
143 run_untar $package $version $ext
144 fi
145 fi
146}
147
148
149opt_run_configure()
150{
[22130]151 local force_config=$1; shift
152 local auto_config=$1; shift
153 local package=$1; shift
154 local version=$1; shift
155 local prefix=$1; shift
[22122]156
157 if [ $force_config = "1" ] ; then
158 echo "[pushd $package$version]"
159 ( cd $package$version ; \
[22130]160 echo ./configure --prefix="$prefix" $CROSSCOMPILE $@ ; \
161 ./configure --prefix="$prefix" $CROSSCOMPILE $@ )
[22122]162 if [ $? != 0 ] ; then
163 echo " Error encountered running *configure* stage of $progname"
164 exit 1
165 fi
166 echo "[popd]"
167 else
168 if [ $auto_config = "1" ] ; then
169 echo "Found top-level for ${progname%.*} => no need to run ./configure"
170 fi
171 fi
172}
173
174
175opt_run_make()
176{
177 local type=$1
178 local package=$2
179 local version=$3
180 local opt_target=""
181
182 if [ ! -z "$4" ] ; then
183 opt_target=$4
184 fi
185
186 if [ $type = "1" ] ; then
187 ( cd $package$version ; \
188 make $opt_target)
189
190 if [ $? != 0 ] ; then
191 echo " Error encountered running *make $target* stage of $progname"
192 exit 1
193 fi
194 fi
195}
196
197
[23077]198run_installclean()
199{
[23095]200 local fulldir="$exthome/$GSDLOS"
201 echo ""
[23077]202 read -p "Delete $fulldir [y/n]?" ans
203 if [ $ans = "y" ] ; then
204 /bin/rm -rf "$fulldir"
205 fi
206
207 exit 0
208}
209
210
211print_usage()
212{
213 echo "$0 [untar|configure|comiple|install|clean|distclean|tarclean|makedist]+"
214 echo " or"
215 echo "$0 [installclean|help]"
216 exit 0
217}
218
[22122]219force_untar=0
220auto_untar=0
221
222force_config=0
223auto_config=0
224
225compile=0
226install=0
227clean=0
228distclean=0
229tarclean=0
[23077]230makedist=0
[22122]231
232if [ $# -gt 0 ] ; then
233 for cmd in $* ; do
234 echo $cmd
[23077]235 if [ $cmd = "untar" ] ; then force_untar=1
236 elif [ $cmd = "configure" ] ; then force_config=1
237 elif [ $cmd = "compile" ] ; then compile=1
238 elif [ $cmd = "install" ] ; then install=1
239 elif [ $cmd = "clean" ] ; then clean=1
240 elif [ $cmd = "distclean" ] ; then distclean=1
241 elif [ $cmd = "tarclean" ] ; then tarclean=1
242 elif [ $cmd = "makedist" ] ; then makedist=1
243
244 elif [ $cmd = "installclean" ] ; then run_installclean
245 elif [ $cmd = "help" ] ; then print_usage
[22122]246 fi
247 done
248else
249 # defaults
250 auto_untar=1
251 auto_config=1
252 compile=1
253 install=1
254 clean=0
255 distclean=0
256 tarclean=0
[23077]257 makedist=0
[22122]258fi
259
260if [ $auto_config = "1" ] ; then
261 if [ ! -e $package$version/Makefile ] && [ ! -e $package$version/config.h ] ; then
262 force_config=1
263 fi
264
[23077]265fi
Note: See TracBrowser for help on using the repository browser.