root/other-projects/cascade-make/trunk/lib/cascade-lib.bash @ 26627

Revision 26627, 6.1 KB (checked in by davidb, 6 years ago)

Support for cross-compiling added

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" ] ; then
60    tar_args="xvf"
61  else
62    echo "Warning: Unrecognized extension: $ext"
63    echo "Assuming tarred, gzipped file"
64    tar_args="xvjf"
65  fi
66
67
68  echo tar $tar_args $package$version$ext
69  tar $tar_args $package$version$ext
70
71  if [ $? != 0 ] ; then
72    echo "      Error encountered running *untar* stage of $progname"
73    exit 1
74  fi
75}
76
77opt_run_tarclean()
78{
79  local type=$1
80  local package=$2
81  local version=$3
82
83  if [ $type = "1" ] ; then
84
85    local dir=$package$version
86    if [ -d $dir ] ; then
87      echo /bin/rm -rf $dir
88      /bin/rm -rf $dir
89
90      if [ $? != 0 ] ; then
91        echo "      Error encountered running *tarclean* stage of $progname"
92        exit 1
93      fi
94    else
95      echo "Unable to find directory $dir"
96    fi
97  fi
98}
99
100toplevel_make_dist()
101{
102  local distos=$1 ; shift
103  local dirname=`basename $exthome`
104
105  local checklist="$*"
106  local distlist=""
107
108  for d in $checklist ; do
109    if [ -e $d ] ; then
110      distlist="$distlist $dirname/$d"
111    fi
112  done
113
114  pushd ..
115   
116  tar cvzf $dirname-$distos.tar.gz $distlist
117  mv $dirname-$distos.tar.gz $dirname/.
118
119  popd
120}
121
122default_toplevel_make_dist()
123{
124  local distos=$1 ; shift
125  local dirname=`basename $exthome`
126
127  local checklist="setup.bash setup.bat perllib $GSDLOS lib $*"
128  toplevel_make_dist $distos $checklist
129}
130
131opt_run_untar()
132{
133  local force_untar=$1
134  local auto_untar=$2
135  local package=$3
136  local version=$4
137
138  local ext="";
139
140  if [ ! -z "$5" ] ; then
141    ext=$5
142  else
143    ext=".tar.gz"
144  fi
145
146  if [ $force_untar = "1" ] ; then
147    run_untar $package $version $ext
148  elif [ $auto_config = "1" ] ; then
149    if [ -d $package$version ] ; then
150      echo "Found untarred version of $package$version$ext => no need to untar"
151    else
152      run_untar $package $version $ext
153    fi
154  fi
155}
156
157
158opt_run_configure()
159{
160  local force_config=$1; shift
161  local auto_config=$1; shift
162  local package=$1; shift
163  local version=$1; shift
164  local prefix=$1; shift
165
166  if [ $force_config = "1" ] ; then
167    echo "[pushd $package$version]"
168    ( cd $package$version ; \
169      echo $CROSSCONFIGURE_VARS ./configure --prefix="$prefix" $CROSSCONFIGURE_ARGS $@ ;
170      eval $CROSSCONFIGURE_VARS ./configure --prefix="$prefix" $CROSSCONFIGURE_ARGS $@ )
171    if [ $? != 0 ] ; then
172        echo "      Error encountered running *configure* stage of $progname"
173        exit 1
174    fi
175    echo "[popd]"
176  else
177    if [ $auto_config = "1" ] ; then
178      echo "Found top-level for ${progname%.*} => no need to run ./configure"
179    fi
180  fi
181}
182
183
184opt_run_perl_configure()
185{
186  local force_config=$1; shift
187  local auto_config=$1; shift
188  local package=$1; shift
189  local version=$1; shift
190  local prefix=$1; shift
191
192  if [ $force_config = "1" ] ; then
193    echo "[pushd $package$version]"
194    ( cd $package$version ; \
195      echo perl Makefile.PL PREFIX="$prefix" $CROSSCOMPILE $@ ;
196      perl Makefile.PL PREFIX="$prefix" $CROSSCOMPILE $@)
197    if [ $? != 0 ] ; then
198        echo "      Error encountered running *configure* stage of $progname"
199        exit 1
200    fi
201    echo "[popd]"
202  else
203    if [ $auto_config = "1" ] ; then
204      echo "Found top-level for ${progname%.*} => no need to run perl configure"
205    fi
206  fi
207}
208
209
210opt_run_make()
211{
212  local type=$1
213  local package=$2
214  local version=$3
215  local opt_target=""
216
217  if [ ! -z "$4" ] ; then
218    opt_target=$4
219  fi
220
221  if [ $type = "1" ] ; then
222    ( cd $package$version ; \
223      make $opt_target)
224
225    if [ $? != 0 ] ; then
226        echo "      Error encountered running *make $target* stage of $progname"
227        exit 1
228    fi
229  fi
230}
231
232
233run_installclean()
234{
235  local fulldir="$exthome/$GSDLOS"
236  echo ""
237  read -p "Delete $fulldir [y/n]?" ans
238  if [ $ans = "y" ] ; then
239    /bin/rm -rf "$fulldir"
240  fi
241
242  exit 0
243}
244
245
246print_usage()
247{
248  echo "$0 [untar|configure|comiple|install|clean|distclean|tarclean|makedist]+"
249  echo "  or"
250  echo "$0 [installclean|help]"
251  exit 0
252}
253
254force_untar=0
255auto_untar=0
256
257force_config=0
258auto_config=0
259
260compile=0
261install=0
262clean=0
263distclean=0
264tarclean=0
265makedist=0
266
267if [ $# -gt 0 ] ; then
268  for cmd in $* ; do
269    echo $cmd
270    if   [ $cmd = "untar" ]        ; then force_untar=1
271    elif [ $cmd = "configure" ]    ; then force_config=1
272    elif [ $cmd = "compile" ]      ; then compile=1
273    elif [ $cmd = "install" ]      ; then install=1 
274    elif [ $cmd = "clean" ]        ; then clean=1 
275    elif [ $cmd = "distclean" ]    ; then distclean=1
276    elif [ $cmd = "tarclean" ]     ; then tarclean=1
277    elif [ $cmd = "makedist" ]     ; then makedist=1
278
279    elif [ $cmd = "installclean" ] ; then run_installclean
280    elif [ $cmd = "help" ]         ; then print_usage
281    fi
282  done
283else
284  # defaults
285  auto_untar=1
286  auto_config=1
287  compile=1
288  install=1
289  clean=0
290  distclean=0
291  tarclean=0
292  makedist=0
293fi
294
295if [ $auto_config = "1" ] ; then
296  if [ ! -e $package$version/Makefile ] &&  [ ! -e $package$version/config.h ] ; then
297    force_config=1
298  fi
299fi
Note: See TracBrowser for help on using the browser.