Flush
[mono.git] / web / mono-build-w32.sh
1 #!/bin/bash
2
3 # Script to automate the building of mono and its dependencies on
4 # cygwin.  Relies on wget being installed (could make it fall back to
5 # using lynx, links, w3, curl etc), assumes that gcc, make, tar,
6 # automake, etc are already installed too (may be worth testing for
7 # all that right at the top and bailing out if missing/too old/too new
8 # etc).
9
10
11 # See where we are.  This will become the top level directory for the
12 # installation, unless we are given an alternative location
13 here=$1
14 test -z "$here" && here=`pwd`
15
16 echo "Building Mono and dependencies in $here, installing to $here/install"
17
18 PATH=$here/install/bin:$here/install/lib:$PATH
19
20 # Make sure cygwin's libiconv is installed, or libtool blows its tiny mind
21 if [ ! -f /usr/lib/libiconv.la ]; then
22     echo "You need to install the cygwin \"libiconv\" package!"
23     exit -1
24 fi
25
26 # Check mono out first, so we can run aclocal from inside the mono dir (it
27 # needs to see which version of the real aclocal to run)
28 test -z "$CVSROOT" && CVSROOT=:pserver:anonymous@anoncvs.go-mono.com:/mono
29 export CVSROOT
30
31 echo "Updating mono"
32
33 # cvs checkout does the same as cvs update, except that it copes with
34 # new modules being added
35
36 # Older versions of cvs insist on a cvs login for :pserver: methods
37 # Make sure cvs is using ssh for :ext: methods
38
39 if [ ${CVSROOT:0:5} = ":ext:" ]; then
40     CVS_RSH=ssh
41     export CVS_RSH
42 elif [ ${CVSROOT:0:9} = ":pserver:" ]; then
43     if ! grep $CVSROOT ~/.cvspass > /dev/null 2>&1 ; then
44         echo "Logging into CVS server.  Anonymous CVS password is probably empty"
45         cvs login || exit -1
46     fi
47 fi
48
49 cvs checkout mono || exit -1
50
51 echo "Checking automake version"
52 automake_required="1.6.2"
53 automake_version=`automake --version | head -1 | awk '{print $4}' | tr -d '[a-zA-Z]' | sed 's/-.*$//g'`
54 echo "Found automake version $automake_version"
55 if expr $automake_version \< $automake_required > /dev/null; then
56         echo "Your automake is too old!  You need version $automake_required or newer."
57         exit -1
58 else
59         echo "Automake version new enough."
60 fi
61
62 # This causes libgc-not-found problem
63 #
64 ## Select the stable version anyway...
65 #if [ ! -z "${AUTO_STABLE}" -o -e /usr/autotool/stable ]; then
66 #    export AUTO_STABLE=${AUTO_STABLE:-/usr/autotool/stable}
67 #    export AUTO_DEVEL=${AUTO_STABLE}
68 #fi
69
70 # Need to install pkgconfig and set ACLOCAL_FLAGS if there is not a
71 # pkgconfig installed already.  Otherwise set PKG_CONFIG_PATH to the
72 # glib we're about to install in $here/install.
73
74
75 # --print-ac-dir was added in 1.2h according to the ChangeLog.  This
76 # should mean that any automake new enough for us has it.
77
78 # This sets ACLOCAL_FLAGS to point to the freshly installed pkgconfig
79 # if it doesnt already exist on the system (otherwise auto* breaks if
80 # it finds two copies of the m4 macros).  The GIMP for Windows
81 # pkgconfig sets its prefix based on the location of its binary, so we
82 # dont need PKG_CONFIG_PATH (the internal pkgconfig config file
83 # $prefix is handled similarly). For the cygwin pkgconfig we do need to
84 # set it, and we need to edit the mingw pc files too.
85
86 function aclocal_scan () {
87     # Quietly ignore the rogue '-I' and other aclocal flags that
88     # aren't actually directories...
89     #
90     # cd into mono/ so that the aclocal wrapper can work out which version
91     # of aclocal to run, and add /usr/share/aclocal too cos aclocal looks there
92     # too.
93     for i in `(cd mono && aclocal --print-ac-dir)` /usr/share/aclocal $ACLOCAL_FLAGS
94     do
95         if [ -f $i/$1 ]; then
96             return 0
97         fi
98     done
99
100     return 1
101 }
102
103 function install_icuconfig() {
104     if [ ! -f $here/install/bin/icu-config ]; then
105         wget http://www.go-mono.com/archive/icu-config
106         mv icu-config $here/install/bin
107         chmod 755 $here/install/bin/icu-config
108     fi
109 }
110
111
112 function install_package() {
113     zipfile=$1
114     markerfile=$2
115     name=$3
116
117     echo "Installing $name..."
118     if [ ! -f $here/$zipfile ]; then
119         wget http://www.go-mono.com/archive/$zipfile
120     fi
121
122     # Assume that the package is installed correctly if the marker
123     # file is there
124     if [ ! -f $here/install/$markerfile ]; then
125         (cd $here/install || exit -1; unzip -o $here/$zipfile || exit -1) || exit -1
126     fi
127 }
128
129 # pkgconfig is only used during the build, so we can use the cygwin version
130 # if it exists
131 if aclocal_scan pkg.m4 ; then
132     install_pkgconfig=no
133 else
134     install_pkgconfig=yes
135 fi
136
137 # This causes libgc-not-found problem
138 #
139 ## But we still need to use the mingw libs for glib & co
140 #ACLOCAL_FLAGS="-I $here/install/share/aclocal $ACLOCAL_FLAGS"
141
142 #export PATH
143 #export ACLOCAL_FLAGS
144
145 # Grab pkg-config, glib etc
146 if [ ! -d $here/install ]; then
147     mkdir $here/install || exit -1
148 fi
149
150 # Fetch and install pkg-config, glib, iconv, intl
151
152 if [ $install_pkgconfig = "yes" ]; then
153     install_package pkgconfig-0.11-20020310.zip bin/pkg-config.exe pkgconfig
154 else
155     echo "Not installing pkgconfig, you already seem to have it installed"
156 fi
157 install_package glib-2.0.4-20020703.zip lib/libglib-2.0-0.dll glib
158 install_package glib-dev-2.0.4-20020703.zip lib/glib-2.0.lib glib-dev
159 install_package libiconv-1.7.zip lib/iconv.dll iconv
160 install_package libintl-0.10.40-20020101.zip lib/libintl-1.dll intl
161 install_package libgc-dev.zip lib/gc.dll gc-dev
162 install_package icu-2.6.1-Win32_msvc7.zip icu/bin/icuuc26.dll icu
163
164 install_icuconfig
165
166 if [ $install_pkgconfig = "no" ]; then
167     echo "Fixing up the pkgconfig paths"
168     for i in $here/install/lib/pkgconfig/*.pc
169     do
170         mv $i $i.orig
171         sed -e "s@^prefix=/target\$@prefix=$here/install@" < $i.orig > $i
172     done
173     export PKG_CONFIG_PATH=$here/install/lib/pkgconfig
174 fi
175
176 # Needed to find the libgc bits
177 export CFLAGS="-I $here/install/include -I $here/install/icu/include"
178 export LDFLAGS="-L$here/install/lib -L$here/install/icu/lib"
179 export PATH="$here/install/icu/bin:$PATH"
180
181 # Make sure we build native w32, not cygwin
182 #CC="gcc -mno-cygwin"
183 #export CC
184
185 # --prefix is used to set the class library dir in mono, and it needs
186 # to be in windows-native form.  It also needs to have '\' turned into
187 # '/' to avoid quoting issues during the build.
188 prefix=`cygpath -w $here/install | sed -e 's@\\\\@/@g'`
189
190 # Build and install mono
191 echo "Building and installing mono"
192
193 (cd $here/mono; ./autogen.sh --prefix=$prefix || exit -1; make || exit -1; make install || exit -1) || exit -1
194
195
196 echo ""
197 echo ""
198 echo "All done."
199 echo "Add $here/install/bin and $here/install/lib to \$PATH"
200 echo "Don't forget to copy the class libraries to $here/install/lib"
201