kick off
[mono.git] / doc / mono-build.sh
1 #!/bin/bash
2
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).
8
9
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`
14
15 echo "Building Mono and dependencies in $here, installing to $here/install"
16
17 PATH=$here/install/bin:$PATH
18 LD_LIBRARY_PATH=$here/install/lib:$LD_LIBRARY_PATH
19
20 # Need to install pkgconfig and set ACLOCAL_FLAGS if there is not a
21 # pkgconfig installed already.  Otherwise set PKG_CONFIG_PATH to the
22 # glib we're about to install in $here/install.  This script could
23 # attempt to be clever and see if glib 2 is already installed, too.
24
25
26 # --print-ac-dir was added in 1.2h according to the ChangeLog.  This
27 # should mean that any automake new enough for us has it.
28
29 function aclocal_scan () {
30     # Quietly ignore the rogue '-I' and other aclocal flags that
31     # aren't actually directories...
32     for i in `aclocal --print-ac-dir` $ACLOCAL_FLAGS
33     do
34         if [ -f $i/$1 ]; then
35             return 0
36         fi
37     done
38
39     return 1
40 }
41
42 function pkgconfig_scan () {
43     module=$1
44
45     echo "Finding pkgconfig files for $module..."
46
47     # Should we use locate? or just a list of well-known directories?
48     # locate has the problem of false positives in src dirs
49     for i in /usr/lib/pkgconfig /usr/local/lib/pkgconfig
50     do
51         echo "Looking in $i..."
52         if [ -f $i/${module}.pc ]; then
53             echo $i
54             return
55         fi
56     done
57 }
58
59 function install_package() {
60     tarfile=$1
61     dirname=$2
62     name=$3
63     configure_options=$4
64
65     echo "Installing $name..."
66     if [ ! -f $here/$tarfile ]; then
67         wget http://www.go-mono.org/archive/$tarfile
68     fi
69
70     # Assume that the package built correctly if the dir is there
71     if [ ! -d $here/$dirname ]; then
72         # Build and install package
73         tar xzf $here/$tarfile || exit -1
74         (cd $here/$dirname; ./configure --prefix=$here/install $configure_options || exit -1; make || exit -1; make install || exit -1)
75         success=$?
76         if [ $success -ne 0 ]; then
77             echo "***** $name build failure. Run rm -rf $here/$dirname to have this script attempt to build $name again next time"
78             exit -1
79         fi
80     fi
81 }
82
83 if aclocal_scan pkg.m4 ; then
84     install_pkgconfig=no
85 else
86     install_pkgconfig=yes
87 fi
88
89 if aclocal_scan glib-2.0.m4 ; then
90     install_glib=no
91     if [ $install_pkgconfig = "yes" ]; then
92         # We have to tell the newly-installed pkgconfig about the
93         # system-installed glib
94         PKG_CONFIG_PATH=`pkgconfig_scan glib-2.0`:$PKG_CONFIG_PATH
95     fi
96 else
97     install_glib=yes
98     PKG_CONFIG_PATH="$here/install/lib/pkgconfig:$PKG_CONFIG_PATH"
99 fi
100
101 if [ -f /usr/include/gc/gc.h ]; then
102     install_libgc=no
103 else
104     install_libgc=yes
105 fi
106
107 if [ $install_pkgconfig = "yes" -o $install_glib = "yes" ]; then
108     ACLOCAL_FLAGS="-I $here/install/share/aclocal $ACLOCAL_FLAGS"
109 fi
110
111 export PATH
112 export LD_LIBRARY_PATH
113 export ACLOCAL_FLAGS
114 export PKG_CONFIG_PATH
115
116 CPPFLAGS="$CPPFLAGS -I$here/install/include"
117 LDFLAGS="$LDFLAGS -L$here/install/lib"
118 export CPPFLAGS
119 export LDFLAGS
120
121 # Grab pkg-config-0.8, glib-1.3.12 if necessary
122
123 if [ $install_pkgconfig = "yes" ]; then
124     install_package pkgconfig-0.8.0.tar.gz pkgconfig-0.8.0 pkgconfig ""
125 else
126     echo "Not installing pkgconfig, you already seem to have it installed"
127 fi
128
129 if [ $install_glib = "yes" ]; then
130     install_package glib-1.3.13.tar.gz glib-1.3.13 glib ""
131 else
132     echo "Not installing glib, you already seem to have it installed"
133 fi
134
135 if [ $install_libgc = "yes" ]; then
136     LIBS="-ldl" install_package gc6.0.tar.gz gc6.0 libgc "--enable-threads=pthreads"
137     # make install didnt do the headers!
138     mkdir -p $here/install/include/gc
139     cp -r $here/gc6.0/include/* $here/install/include/gc
140 else
141     echo "Not installing libgc, you already seem to have it installed"
142 fi
143
144 # End of build dependencies, now get the latest mono checkout and build that
145
146 test -z "$CVSROOT" && CVSROOT=:pserver:anonymous@anoncvs.go-mono.com:/mono
147 export CVSROOT
148
149 echo "Updating mono"
150
151 # cvs checkout does the same as cvs update, except that it copes with
152 # new modules being added
153
154 # Older versions of cvs insist on a cvs login for :pserver: methods
155 # Make sure cvs is using ssh for :ext: methods
156
157 if [ ${CVSROOT:0:5} = ":ext:" ]; then
158     CVS_RSH=ssh
159     export CVS_RSH
160 elif [ ${CVSROOT:0:9} = ":pserver:" ]; then
161     # Chop off the trailing /mono because cvs 1.11 adds the port number
162     # into the .cvspass line
163     if ! grep ${CVSROOT%:/mono} ~/.cvspass > /dev/null 2>&1 ; then
164         echo "Logging into CVS server.  Anonymous CVS password is probably empty"
165         cvs login
166     fi
167 fi
168
169 cvs checkout mono || exit -1
170
171 # Build and install mono
172 echo "Building and installing mono"
173
174 (cd $here/mono; ./autogen.sh --prefix=$here/install || exit -1; make || exit -1; make install || exit -1) || exit -1
175
176
177 echo ""
178 echo ""
179 echo "All done."
180 echo "Add $here/install/bin to \$PATH"
181 echo "Add $here/install/lib to \$LD_LIBRARY_PATH"
182 echo "Don't forget to copy the class libraries to $here/install/lib"
183