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

Last change on this file since 27619 was 27619, checked in by ak19, 8 years ago

Dr Bainbridge removed the absolute paths in symbolic links to new bz executables into relative paths

File size: 6.6 KB
Line 
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 if test ! -z $crossOS ; then
14 # Override derived value with value explicitly provided in crossOS
15 GSDLOS=$crossOS
16 fi
17
18 echo "GSDLOS was not set. Setting it to '$GSDLOS'"
19 export GSDLOS
20fi
21
22if test $# -gt "0" ; then
23 if test -z ${1##GEXT*} ; then
24
25 ext=$1 ; shift
26 reldir=$1 ; shift
27
28 eval exthome=`echo \\$$ext`
29 if test -z "$exthome" ; then
30 if test -f $reldir/setup.bash ; then
31 echo "Environment variable $ext for Greenstone extension not set"
32 echo "Sourcing $reldir/setup.bash"
33 source $reldir/setup.bash
34
35 eval exthome=`echo \\$$ext`
36 else
37 echo "Did not detect $reldir/setup.bash, Skipping"
38 fi
39 fi
40 fi
41fi
42
43run_untar()
44{
45 local package=$1
46 local version=$2
47 local ext=$3
48
49 tar_args="";
50
51 if [ $ext = ".tar.gz" ] ; then
52 tar_args="xvzf"
53 elif [ $ext = ".tgz" ] ; then
54 tar_args="xvzf"
55 elif [ $ext = ".tar.bz2" ] ; then
56 tar_args="xvjf"
57 elif [ $ext = ".tar.bz" ] ; then
58 tar_args="xvjf"
59 elif [ $ext = ".tar.xz" ] ; then
60 tar_args="xvJf"
61 elif [ $ext = ".tar" ] ; then
62 tar_args="xvf"
63 else
64 echo "Warning: Unrecognized extension: $ext"
65 echo "Assuming tarred, gzipped file"
66 tar_args="xvjf"
67 fi
68
69
70 echo tar $tar_args $package$version$ext
71 tar $tar_args $package$version$ext
72
73 if [ $? != 0 ] ; then
74 echo " Error encountered running *untar* stage of $progname"
75 exit 1
76 fi
77}
78
79opt_run_tarclean()
80{
81 local type=$1
82 local package=$2
83 local version=$3
84
85 if [ $type = "1" ] ; then
86
87 local dir=$package$version
88 if [ -d $dir ] ; then
89 echo /bin/rm -rf $dir
90 /bin/rm -rf $dir
91
92 if [ $? != 0 ] ; then
93 echo " Error encountered running *tarclean* stage of $progname"
94 exit 1
95 fi
96 else
97 echo "Unable to find directory $dir"
98 fi
99 fi
100}
101
102toplevel_make_dist()
103{
104 local distos=$1 ; shift
105 local dirname=`basename $exthome`
106
107 local checklist="$*"
108 local distlist=""
109
110 for d in $checklist ; do
111 if [ -e $d ] ; then
112 distlist="$distlist $dirname/$d"
113 fi
114 done
115
116 pushd ..
117
118 tar cvzf $dirname-$distos.tar.gz $distlist
119 mv $dirname-$distos.tar.gz $dirname/.
120# mv $dirname-$distos.tar.gz $dirname/imagemagick-$distos.tar.gz
121
122 popd
123}
124
125default_toplevel_make_dist()
126{
127 local distos=$1 ; shift
128 local dirname=`basename $exthome`
129
130 local checklist="setup.bash setup.bat perllib $GSDLOS lib $*"
131 toplevel_make_dist $distos $checklist
132}
133
134opt_run_untar()
135{
136 local force_untar=$1
137 local auto_untar=$2
138 local package=$3
139 local version=$4
140
141 local ext="";
142
143 if [ ! -z "$5" ] ; then
144 ext=$5
145 else
146 ext=".tar.gz"
147 fi
148
149 if [ $force_untar = "1" ] ; then
150 run_untar $package $version $ext
151 elif [ $auto_config = "1" ] ; then
152 if [ -d $package$version ] ; then
153 echo "Found untarred version of $package$version$ext => no need to untar"
154 else
155 run_untar $package $version $ext
156 fi
157 fi
158}
159
160
161opt_run_configure()
162{
163 local force_config=$1; shift
164 local auto_config=$1; shift
165 local package=$1; shift
166 local version=$1; shift
167 local prefix=$1; shift
168
169 if [ $force_config = "1" ] ; then
170 echo "[pushd $package$version]"
171 ( cd $package$version ; \
172 echo $CROSSCONFIGURE_VARS ./configure --prefix="$prefix" $CROSSCONFIGURE_ARGS $@ ;
173 eval $CROSSCONFIGURE_VARS ./configure --prefix="$prefix" $CROSSCONFIGURE_ARGS $@ )
174 if [ $? != 0 ] ; then
175 echo " Error encountered running *configure* stage of $progname"
176 exit 1
177 fi
178 echo "[popd]"
179 else
180 if [ $auto_config = "1" ] ; then
181 echo "Found top-level for ${progname%.*} => no need to run ./configure"
182 fi
183 fi
184}
185
186
187opt_run_perl_configure()
188{
189 local force_config=$1; shift
190 local auto_config=$1; shift
191 local package=$1; shift
192 local version=$1; shift
193 local prefix=$1; shift
194
195 if [ $force_config = "1" ] ; then
196 echo "[pushd $package$version]"
197 ( cd $package$version ; \
198 echo perl Makefile.PL PREFIX="$prefix" $CROSSCOMPILE $@ ;
199 perl Makefile.PL PREFIX="$prefix" $CROSSCOMPILE $@)
200 if [ $? != 0 ] ; then
201 echo " Error encountered running *configure* stage of $progname"
202 exit 1
203 fi
204 echo "[popd]"
205 else
206 if [ $auto_config = "1" ] ; then
207 echo "Found top-level for ${progname%.*} => no need to run perl configure"
208 fi
209 fi
210}
211
212
213opt_run_make()
214{
215 local type=$1; shift
216 local package=$1; shift
217 local version=$1; shift
218 local opt_target=""
219
220 if [ ! -z "$1" ] ; then
221 opt_target=$1; shift
222 fi
223
224 if [ $type = "1" ] ; then
225 ( cd $package$version ; \
226 make $opt_target $@)
227
228 if [ $? != 0 ] ; then
229 echo " Error encountered running *make $target* stage of $progname"
230 exit 1
231 fi
232 fi
233}
234
235
236opt_run_cmake()
237{
238 local type=$1
239 local package=$2
240 local version=$3
241 local subdir=$4
242 local opt_target=""
243
244 if [ ! -z "$5" ] ; then
245 opt_target=$5
246 fi
247
248 if [ $type = "1" ] ; then
249 ( cd $package$version/$subdir ; \
250 make $opt_target)
251
252 if [ $? != 0 ] ; then
253 echo " Error encountered running *make $target* stage of $progname"
254 exit 1
255 fi
256 fi
257}
258
259
260run_installclean()
261{
262 local fulldir="$exthome/$GSDLOS"
263 echo ""
264 read -p "Delete $fulldir [y/n]?" ans
265 if [ $ans = "y" ] ; then
266 /bin/rm -rf "$fulldir"
267 fi
268
269 exit 0
270}
271
272
273print_usage()
274{
275 echo "$0 [untar|configure|comiple|install|clean|distclean|tarclean|makedist]+"
276 echo " or"
277 echo "$0 [installclean|help]"
278 exit 0
279}
280
281force_untar=0
282auto_untar=0
283
284force_config=0
285auto_config=0
286
287compile=0
288install=0
289clean=0
290distclean=0
291tarclean=0
292makedist=0
293
294if [ $# -gt 0 ] ; then
295 for cmd in $* ; do
296 echo $cmd
297 if [ $cmd = "untar" ] ; then force_untar=1
298 elif [ $cmd = "configure" ] ; then force_config=1
299 elif [ $cmd = "compile" ] ; then compile=1
300 elif [ $cmd = "install" ] ; then install=1
301 elif [ $cmd = "clean" ] ; then clean=1
302 elif [ $cmd = "distclean" ] ; then distclean=1
303 elif [ $cmd = "tarclean" ] ; then tarclean=1
304 elif [ $cmd = "makedist" ] ; then makedist=1
305
306 elif [ $cmd = "installclean" ] ; then run_installclean
307 elif [ $cmd = "help" ] ; then print_usage
308 fi
309 done
310else
311 # defaults
312 auto_untar=1
313 auto_config=1
314 compile=1
315 install=1
316 clean=0
317 distclean=0
318 tarclean=0
319 makedist=0
320fi
321
322if [ $auto_config = "1" ] ; then
323 if [ ! -e $package$version/Makefile ] && [ ! -e $package$version/config.h ] ; then
324 force_config=1
325 fi
326fi
Note: See TracBrowser for help on using the repository browser.