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

Last change on this file since 24689 was 24689, checked in by jmt12, 13 years ago

Add new function for Perl CPAN module configuration (which calls 'perl Makefile.PL PREFIX=' rather than configure)

File size: 5.8 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 echo "GSDLOS was not set. Setting it to '$GSDLOS'"
14 export GSDLOS
15fi
16
17if test $# -gt "0" ; then
18 if test -z ${1##GEXT*} ; then
19
20 ext=$1 ; shift
21 reldir=$1 ; shift
22
23 eval exthome=`echo \\$$ext`
24 if test -z "$exthome" ; then
25 echo "Environment variable $ext for Greenstone extension not set"
26 echo "Sourcing $reldir/setup.bash"
27 source $reldir/setup.bash
28
29 eval exthome=`echo \\$$ext`
30 fi
31 fi
32fi
33
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
91toplevel_make_dist()
92{
93 local distos=$1 ; shift
94 local dirname=`basename $exthome`
95
96 local checklist="$*"
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-$distos.tar.gz $distlist
108 mv $dirname-$distos.tar.gz $dirname/.
109
110 popd
111}
112
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
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{
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
156
157 if [ $force_config = "1" ] ; then
158 echo "[pushd $package$version]"
159 ( cd $package$version ; \
160 echo ./configure --prefix="$prefix" $CROSSCOMPILE $@ ; \
161 ./configure --prefix="$prefix" $CROSSCOMPILE $@ )
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_perl_configure()
176{
177 local force_config=$1; shift
178 local auto_config=$1; shift
179 local package=$1; shift
180 local version=$1; shift
181 local prefix=$1; shift
182
183 if [ $force_config = "1" ] ; then
184 echo "[pushd $package$version]"
185 ( cd $package$version ; \
186 echo perl Makefile.PL PREFIX="$prefix" $CROSSCOMPILE $@ ;
187 perl Makefile.PL PREFIX="$prefix" $CROSSCOMPILE $@)
188 if [ $? != 0 ] ; then
189 echo " Error encountered running *configure* stage of $progname"
190 exit 1
191 fi
192 echo "[popd]"
193 else
194 if [ $auto_config = "1" ] ; then
195 echo "Found top-level for ${progname%.*} => no need to run perl configure"
196 fi
197 fi
198}
199
200
201opt_run_make()
202{
203 local type=$1
204 local package=$2
205 local version=$3
206 local opt_target=""
207
208 if [ ! -z "$4" ] ; then
209 opt_target=$4
210 fi
211
212 if [ $type = "1" ] ; then
213 ( cd $package$version ; \
214 make $opt_target)
215
216 if [ $? != 0 ] ; then
217 echo " Error encountered running *make $target* stage of $progname"
218 exit 1
219 fi
220 fi
221}
222
223
224run_installclean()
225{
226 local fulldir="$exthome/$GSDLOS"
227 echo ""
228 read -p "Delete $fulldir [y/n]?" ans
229 if [ $ans = "y" ] ; then
230 /bin/rm -rf "$fulldir"
231 fi
232
233 exit 0
234}
235
236
237print_usage()
238{
239 echo "$0 [untar|configure|comiple|install|clean|distclean|tarclean|makedist]+"
240 echo " or"
241 echo "$0 [installclean|help]"
242 exit 0
243}
244
245force_untar=0
246auto_untar=0
247
248force_config=0
249auto_config=0
250
251compile=0
252install=0
253clean=0
254distclean=0
255tarclean=0
256makedist=0
257
258if [ $# -gt 0 ] ; then
259 for cmd in $* ; do
260 echo $cmd
261 if [ $cmd = "untar" ] ; then force_untar=1
262 elif [ $cmd = "configure" ] ; then force_config=1
263 elif [ $cmd = "compile" ] ; then compile=1
264 elif [ $cmd = "install" ] ; then install=1
265 elif [ $cmd = "clean" ] ; then clean=1
266 elif [ $cmd = "distclean" ] ; then distclean=1
267 elif [ $cmd = "tarclean" ] ; then tarclean=1
268 elif [ $cmd = "makedist" ] ; then makedist=1
269
270 elif [ $cmd = "installclean" ] ; then run_installclean
271 elif [ $cmd = "help" ] ; then print_usage
272 fi
273 done
274else
275 # defaults
276 auto_untar=1
277 auto_config=1
278 compile=1
279 install=1
280 clean=0
281 distclean=0
282 tarclean=0
283 makedist=0
284fi
285
286if [ $auto_config = "1" ] ; then
287 if [ ! -e $package$version/Makefile ] && [ ! -e $package$version/config.h ] ; then
288 force_config=1
289 fi
290
291fi
Note: See TracBrowser for help on using the repository browser.