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

Last change on this file since 23077 was 23077, checked in by sjm84, 13 years ago

Added makedist, installclean and help functionality to cascade-lib.bash. installclean still needs a minor fix

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