Assembly.cs: LoadWithPartialName
[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
64     echo "Installing $name..."
65     if [ ! -f $here/$tarfile ]; then
66         wget http://www.go-mono.org/archive/$tarfile
67     fi
68
69     # Assume that the package built correctly if the dir is there
70     if [ ! -d $here/$dirname ]; then
71         # Build and install package
72         tar xzf $here/$tarfile || exit -1
73         (cd $here/$dirname; ./configure --prefix=$here/install || exit -1; make || exit -1; make install || exit -1)
74         success=$?
75         if [ $success -ne 0 ]; then
76             echo "***** $name build failure. Run rm -rf $here/$dirname to have this script attempt to build $name again next time"
77             exit -1
78         fi
79     fi
80 }
81
82 if aclocal_scan pkg.m4 ; then
83     install_pkgconfig=no
84 else
85     install_pkgconfig=yes
86 fi
87
88 if aclocal_scan glib-2.0.m4 ; then
89     install_glib=no
90     if [ $install_pkgconfig = "yes" ]; then
91         # We have to tell the newly-installed pkgconfig about the
92         # system-installed glib
93         PKG_CONFIG_PATH=`pkgconfig_scan glib-2.0`:$PKG_CONFIG_PATH
94     fi
95 else
96     install_glib=yes
97     PKG_CONFIG_PATH="$here/install/lib/pkgconfig:$PKG_CONFIG_PATH"
98 fi
99
100 if [ -f /usr/include/gc/gc.h ]; then
101     install_libgc=no
102 else
103     install_libgc=yes
104 fi
105
106 if [ $install_pkgconfig = "yes" -o $install_glib = "yes" ]; then
107     ACLOCAL_FLAGS="-I $here/install/share/aclocal $ACLOCAL_FLAGS"
108 fi
109
110 export PATH
111 export LD_LIBRARY_PATH
112 export ACLOCAL_FLAGS
113 export PKG_CONFIG_PATH
114
115 CPPFLAGS="$CPPFLAGS -I$here/install/include"
116 LDFLAGS="$LDFLAGS -L$here/install/lib"
117 export CPPFLAGS
118 export LDFLAGS
119
120 # Grab pkg-config-0.8, glib-1.3.12 if necessary
121
122 if [ $install_pkgconfig = "yes" ]; then
123     install_package pkgconfig-0.8.0.tar.gz pkgconfig-0.8.0 pkgconfig
124 else
125     echo "Not installing pkgconfig, you already seem to have it installed"
126 fi
127
128 if [ $install_glib = "yes" ]; then
129     install_package glib-1.3.13.tar.gz glib-1.3.13 glib
130 else
131     echo "Not installing glib, you already seem to have it installed"
132 fi
133
134 if [ $install_libgc = "yes" ]; then
135     install_package gc6.0.tar.gz gc6.0 libgc
136     # make install didnt do the headers!
137     mkdir -p $here/install/include/gc
138     cp -r $here/gc6.0/include/* $here/install/include/gc
139 else
140     echo "Not installing libgc, you already seem to have it installed"
141 fi
142
143 # End of build dependencies, now get the latest mono checkout and build that
144
145 test -z "$CVSROOT" && CVSROOT=:pserver:anonymous@anoncvs.go-mono.com:/mono
146 export CVSROOT
147
148 echo "Updating mono"
149
150 # cvs checkout does the same as cvs update, except that it copes with
151 # new modules being added
152
153 # Older versions of cvs insist on a cvs login for :pserver: methods
154 # Make sure cvs is using ssh for :ext: methods
155
156 if [ ${CVSROOT:0:5} = ":ext:" ]; then
157     CVS_RSH=ssh
158     export CVS_RSH
159 elif [ ${CVSROOT:0:9} = ":pserver:" ]; then
160     # Chop off the trailing /mono because cvs 1.11 adds the port number
161     # into the .cvspass line
162     if ! grep ${CVSROOT%:/mono} ~/.cvspass > /dev/null 2>&1 ; then
163         echo "Logging into CVS server.  Anonymous CVS password is probably empty"
164         cvs login
165     fi
166 fi
167
168 cvs checkout mono || exit -1
169
170 # Build and install mono
171 echo "Building and installing mono"
172
173 (cd $here/mono; ./autogen.sh --prefix=$here/install || exit -1; make || exit -1; make install || exit -1) || exit -1
174
175
176 echo ""
177 echo ""
178 echo "All done."
179 echo "Add $here/install/bin to \$PATH"
180 echo "Add $here/install/lib to \$LD_LIBRARY_PATH"
181 echo "Don't forget to copy the class libraries to $here/install/lib"
182