2010-05-05 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / web / mono-build.sh
blob17b604cc27386ef0a37525f9f8adf3d2d174b9e9
1 #! /usr/bin/env bash
3 # Script to automate the building of mono and its dependencies.
4 # Relies on wget being installed (could make it fall back to using
5 # lynx, links, w3, curl etc), assumes that gcc, make, tar, automake,
6 # etc are already installed too (may be worth testing for all that
7 # right at the top and bailing out if missing/too old/too new etc).
10 # See where we are. This will become the top level directory for the
11 # installation, unless we are given an alternative location
12 here=$1
13 test -z "$here" && here=`pwd`
15 echo "Building Mono and dependencies in $here, installing to $here/install"
17 PATH=$here/install/bin:$PATH
18 LD_LIBRARY_PATH=$here/install/lib:$LD_LIBRARY_PATH
20 # Find a tool to fetch files. It must take an HTTP URL on the command line and
21 # save the file in the current directory. (It must also talk HTTP/1.1, which
22 # rules out BSD's ftp(1), at least on FreeBSD 4.4.)
23 viable_downloaders="wget fetch"
24 for i in $viable_downloaders
26 if which $i > /dev/null; then
27 downloader=`which $i`
28 break
30 done
32 if [ -z "$downloader" ]; then
33 echo "Can't find a commandline download tool (tried: $viable_downloaders)"
34 exit -1
35 else
36 echo "Using $downloader to fetch files"
37 fi
39 # We need to prefer GNU make if there's a choice. BSD make falls over in
40 # the glib build if gtk-doc is disabled.
41 viable_makers="gmake make"
42 for i in $viable_makers
44 if which $i > /dev/null; then
45 MAKE=$i
46 break
48 done
50 if [ -z "$MAKE" ]; then
51 echo "Can't find a make tool (tried: $viable_makers)"
52 exit -1
53 else
54 echo "Using $MAKE"
55 export MAKE
58 # Need to install pkgconfig and set ACLOCAL_FLAGS if there is not a
59 # pkgconfig installed already. Otherwise set PKG_CONFIG_PATH to the
60 # glib we're about to install in $here/install. This script could
61 # attempt to be clever and see if glib 2 is already installed, too.
64 # --print-ac-dir was added in 1.2h according to the ChangeLog. This
65 # should mean that any automake new enough for us has it.
67 function aclocal_scan () {
68 # Quietly ignore the rogue '-I' and other aclocal flags that
69 # aren't actually directories...
70 for i in `aclocal --print-ac-dir` $ACLOCAL_FLAGS
72 if [ -f $i/$1 ]; then
73 return 0
75 done
77 return 1
80 function pkgconfig_scan () {
81 module=$1
83 echo "Finding pkgconfig files for $module..."
85 # Should we use locate? or just a list of well-known directories?
86 # locate has the problem of false positives in src dirs
87 for i in /usr/lib/pkgconfig /usr/local/lib/pkgconfig
89 echo "Looking in $i..."
90 if [ -f $i/${module}.pc ]; then
91 echo $i
92 return
94 done
97 function install_package() {
98 tarfile=$1
99 dirname=$2
100 name=$3
101 configure_options=$4
103 echo "Installing $name..."
104 if [ ! -f $here/$tarfile ]; then
105 (cd $here && $downloader http://www.go-mono.com/archive/$tarfile)
108 # Assume that the package built correctly if the dir is there
109 if [ ! -d $here/$dirname ]; then
110 # Build and install package
111 (cd $here && tar xzf $tarfile) || exit -1
112 (cd $here/$dirname; ./configure --prefix=$here/install $configure_options || exit -1; $MAKE || exit -1; $MAKE install || exit -1)
113 success=$?
114 if [ $success -ne 0 ]; then
115 echo "***** $name build failure. Run rm -rf $here/$dirname to have this script attempt to build $name again next time"
116 exit -1
121 if aclocal_scan pkg.m4 ; then
122 install_pkgconfig=no
123 else
124 install_pkgconfig=yes
127 if aclocal_scan glib-2.0.m4 ; then
128 install_glib=no
129 if [ $install_pkgconfig = "yes" ]; then
130 # We have to tell the newly-installed pkgconfig about the
131 # system-installed glib
132 PKG_CONFIG_PATH=`pkgconfig_scan glib-2.0`:$PKG_CONFIG_PATH
134 else
135 install_glib=yes
136 PKG_CONFIG_PATH="$here/install/lib/pkgconfig:$PKG_CONFIG_PATH"
139 if [ -f /usr/include/gc/gc.h ]; then
140 install_libgc=no
141 else
142 install_libgc=yes
145 if [ $install_pkgconfig = "yes" -o $install_glib = "yes" ]; then
146 ACLOCAL_FLAGS="-I $here/install/share/aclocal $ACLOCAL_FLAGS"
149 export PATH
150 export LD_LIBRARY_PATH
151 export ACLOCAL_FLAGS
152 export PKG_CONFIG_PATH
154 # Freebsd puts iconv in /usr/local, so see if we need to add
155 # /usr/local/include and /usr/local/lib to CPPFLAGS and LDFLAGS. We could
156 # skip this if it would add /usr/include and /usr/lib, but leaving it
157 # shouldnt break anything.
159 # Actually, it does break stuff :-( gcc 3.2 prints gratuitous warnings
160 # and configure fails to find header files because of this cpp output.
162 if [ ! -f /usr/include/iconv.h ]; then
163 iconvdirs="/usr/local/include"
164 for i in $iconvdirs
166 if [ -f $i/iconv.h ]; then
167 iconvh_dir=$i
168 break
170 done
172 if [ -z "$iconvh_dir" ]; then
173 echo "Can't find iconv headers (looked in $iconvdirs)"
174 exit -1
177 iconvlib_dir=`echo $iconvh_dir | sed -e 's/include/lib/'`
179 echo "Adding $iconvh_dir to CPPFLAGS"
180 echo "Adding $iconvlib_dir to LDFLAGS"
182 CPPFLAGS="$CPPFLAGS -I$here/install/include -I$iconvh_dir"
183 LDFLAGS="$LDFLAGS -L$here/install/lib -L$iconvlib_dir"
184 else
185 CPPFLAGS="$CPPFLAGS -I$here/install/include"
186 LDFLAGS="$LDFLAGS -L$here/install/lib"
189 export CPPFLAGS
190 export LDFLAGS
192 # Grab pkg-config, glib and libgc if necessary
194 if [ $install_pkgconfig = "yes" ]; then
195 install_package pkgconfig-0.8.0.tar.gz pkgconfig-0.8.0 pkgconfig ""
196 else
197 echo "Not installing pkgconfig, you already seem to have it installed"
200 if [ $install_glib = "yes" ]; then
201 install_package glib-2.0.6.tar.gz glib-2.0.6 glib ""
202 else
203 echo "Not installing glib, you already seem to have it installed"
206 if [ $install_libgc = "yes" ]; then
207 install_package gc6.1alpha5.tar.gz gc6.1alpha5 libgc "--enable-threads=pthreads"
208 # make install didnt do the headers!
209 mkdir -p $here/install/include/gc
210 cp -r $here/gc6.1alpha5/include/* $here/install/include/gc
211 else
212 echo "Not installing libgc, you already seem to have it installed"
215 # End of build dependencies, now get the latest mono checkout and build that
217 test -z "$CVSROOT" && CVSROOT=:pserver:anonymous@anoncvs.go-mono.com:/mono
218 export CVSROOT
220 echo "Updating mono"
222 # cvs checkout does the same as cvs update, except that it copes with
223 # new modules being added
225 # Older versions of cvs insist on a cvs login for :pserver: methods
226 # Make sure cvs is using ssh for :ext: methods
228 if [ ${CVSROOT:0:5} = ":ext:" ]; then
229 CVS_RSH=ssh
230 export CVS_RSH
231 elif [ ${CVSROOT:0:9} = ":pserver:" ]; then
232 # Chop off the trailing /mono because cvs 1.11 adds the port number
233 # into the .cvspass line
234 if ! grep ${CVSROOT%:/mono} ~/.cvspass > /dev/null 2>&1 ; then
235 echo "Logging into CVS server. Anonymous CVS password is probably empty"
236 cvs login
240 (cd $here && cvs checkout mono) || exit -1
242 # Build and install mono
243 echo "Building and installing mono"
245 (cd $here/mono; ./autogen.sh --prefix=$here/install || exit -1; $MAKE || exit -1; $MAKE install || exit -1) || exit -1
248 echo ""
249 echo ""
250 echo "All done."
251 echo "Add $here/install/bin to \$PATH"
252 echo "Add $here/install/lib to \$LD_LIBRARY_PATH"
253 echo "Don't forget to copy the class libraries to $here/install/lib"