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

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

Added the ability to change the dist name (e.g. linux, windows, java etc.)

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