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

Last change on this file since 27273 was 27273, checked in by davidb, 11 years ago

function for calling 'make' extended to allow passing of variable number of additional arguments. Allows for usage such as 'make install DESTDIR=/foo/bar

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
121 popd
122}
123
124default_toplevel_make_dist()
125{
126 local distos=$1 ; shift
127 local dirname=`basename $exthome`
128
129 local checklist="setup.bash setup.bat perllib $GSDLOS lib $*"
130 toplevel_make_dist $distos $checklist
131}
132
133opt_run_untar()
134{
135 local force_untar=$1
136 local auto_untar=$2
137 local package=$3
138 local version=$4
139
140 local ext="";
141
142 if [ ! -z "$5" ] ; then
143 ext=$5
144 else
145 ext=".tar.gz"
146 fi
147
148 if [ $force_untar = "1" ] ; then
149 run_untar $package $version $ext
150 elif [ $auto_config = "1" ] ; then
151 if [ -d $package$version ] ; then
152 echo "Found untarred version of $package$version$ext => no need to untar"
153 else
154 run_untar $package $version $ext
155 fi
156 fi
157}
158
159
160opt_run_configure()
161{
162 local force_config=$1; shift
163 local auto_config=$1; shift
164 local package=$1; shift
165 local version=$1; shift
166 local prefix=$1; shift
167
168 if [ $force_config = "1" ] ; then
169 echo "[pushd $package$version]"
170 ( cd $package$version ; \
171 echo $CROSSCONFIGURE_VARS ./configure --prefix="$prefix" $CROSSCONFIGURE_ARGS $@ ;
172 eval $CROSSCONFIGURE_VARS ./configure --prefix="$prefix" $CROSSCONFIGURE_ARGS $@ )
173 if [ $? != 0 ] ; then
174 echo " Error encountered running *configure* stage of $progname"
175 exit 1
176 fi
177 echo "[popd]"
178 else
179 if [ $auto_config = "1" ] ; then
180 echo "Found top-level for ${progname%.*} => no need to run ./configure"
181 fi
182 fi
183}
184
185
186opt_run_perl_configure()
187{
188 local force_config=$1; shift
189 local auto_config=$1; shift
190 local package=$1; shift
191 local version=$1; shift
192 local prefix=$1; shift
193
194 if [ $force_config = "1" ] ; then
195 echo "[pushd $package$version]"
196 ( cd $package$version ; \
197 echo perl Makefile.PL PREFIX="$prefix" $CROSSCOMPILE $@ ;
198 perl Makefile.PL PREFIX="$prefix" $CROSSCOMPILE $@)
199 if [ $? != 0 ] ; then
200 echo " Error encountered running *configure* stage of $progname"
201 exit 1
202 fi
203 echo "[popd]"
204 else
205 if [ $auto_config = "1" ] ; then
206 echo "Found top-level for ${progname%.*} => no need to run perl configure"
207 fi
208 fi
209}
210
211
212opt_run_make()
213{
214 local type=$1; shift
215 local package=$1; shift
216 local version=$1; shift
217 local opt_target=""
218
219 if [ ! -z "$1" ] ; then
220 opt_target=$1; shift
221 fi
222
223 if [ $type = "1" ] ; then
224 ( cd $package$version ; \
225 make $opt_target $@)
226
227 if [ $? != 0 ] ; then
228 echo " Error encountered running *make $target* stage of $progname"
229 exit 1
230 fi
231 fi
232}
233
234
235opt_run_cmake()
236{
237 local type=$1
238 local package=$2
239 local version=$3
240 local subdir=$4
241 local opt_target=""
242
243 if [ ! -z "$5" ] ; then
244 opt_target=$5
245 fi
246
247 if [ $type = "1" ] ; then
248 ( cd $package$version/$subdir ; \
249 make $opt_target)
250
251 if [ $? != 0 ] ; then
252 echo " Error encountered running *make $target* stage of $progname"
253 exit 1
254 fi
255 fi
256}
257
258
259run_installclean()
260{
261 local fulldir="$exthome/$GSDLOS"
262 echo ""
263 read -p "Delete $fulldir [y/n]?" ans
264 if [ $ans = "y" ] ; then
265 /bin/rm -rf "$fulldir"
266 fi
267
268 exit 0
269}
270
271
272print_usage()
273{
274 echo "$0 [untar|configure|comiple|install|clean|distclean|tarclean|makedist]+"
275 echo " or"
276 echo "$0 [installclean|help]"
277 exit 0
278}
279
280force_untar=0
281auto_untar=0
282
283force_config=0
284auto_config=0
285
286compile=0
287install=0
288clean=0
289distclean=0
290tarclean=0
291makedist=0
292
293if [ $# -gt 0 ] ; then
294 for cmd in $* ; do
295 echo $cmd
296 if [ $cmd = "untar" ] ; then force_untar=1
297 elif [ $cmd = "configure" ] ; then force_config=1
298 elif [ $cmd = "compile" ] ; then compile=1
299 elif [ $cmd = "install" ] ; then install=1
300 elif [ $cmd = "clean" ] ; then clean=1
301 elif [ $cmd = "distclean" ] ; then distclean=1
302 elif [ $cmd = "tarclean" ] ; then tarclean=1
303 elif [ $cmd = "makedist" ] ; then makedist=1
304
305 elif [ $cmd = "installclean" ] ; then run_installclean
306 elif [ $cmd = "help" ] ; then print_usage
307 fi
308 done
309else
310 # defaults
311 auto_untar=1
312 auto_config=1
313 compile=1
314 install=1
315 clean=0
316 distclean=0
317 tarclean=0
318 makedist=0
319fi
320
321if [ $auto_config = "1" ] ; then
322 if [ ! -e $package$version/Makefile ] && [ ! -e $package$version/config.h ] ; then
323 force_config=1
324 fi
325fi
Note: See TracBrowser for help on using the repository browser.