Merge pull request #1356 from martinjt/ReadEntityV2
[mono-project.git] / build-mingw32.sh
blob4c8ed8c1dc4f6e04ae258737d01c76442172c609
1 #!/bin/bash -e
2 CURDIR="`pwd`"
3 MINGW=i386-mingw32msvc
4 CROSS_DIR=/opt/cross/$MINGW
5 EXTRA_CROSS_DIR=
6 INSTALL_DESTDIR="$CURDIR/mono-win32"
7 PROFILES="default net_2_0 net_3_5 net_4_0 net_4_5 moonlight"
8 TEMPORARY_PKG_CONFIG_DIR=/tmp/$RANDOM-pkg-config-$RANDOM
9 ORIGINAL_PATH="$PATH"
11 export CPPFLAGS_FOR_EGLIB CFLAGS_FOR_EGLIB CPPFLAGS_FOR_LIBGC CFLAGS_FOR_LIBGC
13 function cleanup ()
15 if [ -d "$TEMPORARY_PKG_CONFIG_DIR" ]; then
16 rm -rf "$TEMPORARY_PKG_CONFIG_DIR"
20 function check_pkg_config_dir ()
22 local DIR="$1"
23 local DIR_PREFIX="$2"
25 if [ ! -d "$DIR" ]; then
26 return
29 install -d -m 755 "$TEMPORARY_PKG_CONFIG_DIR"
30 for pc in "$DIR"/*.pc; do
31 if [ -f $pc ]; then
32 pcname="`basename $pc`"
33 sed -e "s;^prefix=.*;prefix=$DIR_PREFIX;g" < $pc > "$TEMPORARY_PKG_CONFIG_DIR"/$pcname
34 fi;
35 done
37 if [ -z "$CROSS_PKG_CONFIG_DIR" ]; then
38 CROSS_PKG_CONFIG_DIR="$TEMPORARY_PKG_CONFIG_DIR"
42 function show_build_info ()
44 cat <<EOF
45 Installation prefix: $MONO_PREFIX
46 CPPFLAGS: ${CPPFLAGS:=not set}
47 LDFLAGS: ${LDFLAGS:=not set}
48 MONO_PATH: ${MONO_PATH:=not set}
49 EOF
52 function setup ()
54 local pcname
56 CROSS_BIN_DIR="$CROSS_DIR/bin"
57 CROSS_DLL_DIR="$CROSS_DIR/bin"
58 PATH=$CROSS_BIN_DIR:$PATH
60 MONO_VERSION=`grep AC_INIT configure.ac | cut -d ',' -f 2|tr -d '\[ \]'`
62 if [ -d ./.git ]; then
63 MONO_GIT_COMMIT="`git log -1 --format=format:%t`"
64 MONO_GIT_BRANCH="`git branch|grep '\*'|cut -d ' ' -f 2|tr -d '\)'|tr -d '\('`"
65 MONO_RELEASE="$MONO_VERSION-$MONO_GIT_BRANCH-$MONO_GIT_COMMIT"
66 else
67 MONO_RELEASE="$MONO_VERSION"
70 MONO_PREFIX="$MONO_PREFIX/mono-$MONO_RELEASE"
72 NOCONFIGURE=yes
73 export NOCONFIGURE
75 check_pkg_config_dir "$CROSS_DIR/lib/pkgconfig" "$CROSS_DIR"
77 if [ -n "$EXTRA_CROSS_DIR" -a -d "$EXTRA_CROSS_DIR" ]; then
78 if [ -d "$EXTRA_CROSS_DIR/bin" ]; then
79 PATH="$EXTRA_CROSS_DIR/bin":$PATH
82 check_pkg_config_dir "$EXTRA_CROSS_DIR/lib/pkgconfig" "$EXTRA_CROSS_DIR"
84 if [ -d "$EXTRA_CROSS_DIR/include" ]; then
85 if [ -z "$CPPFLAGS" ]; then
86 CPPFLAGS="-I \"$EXTRA_CROSS_DIR/include\""
87 else
88 CPPFLAGS="-I \"$EXTRA_CROSS_DIR/include\" $CFLAGS"
92 if [ -d "$EXTRA_CROSS_DIR/lib" ]; then
93 if [ -z "$LDFLAGS" ]; then
94 LDFLAGS="-I \"$EXTRA_CROSS_DIR/lib\""
95 else
96 LDFLAGS="-I \"$EXTRA_CROSS_DIR/lib\" $LDFLAGS"
100 if [ -d "$EXTRA_CROSS_DIR/share/aclocal" ]; then
101 if [ -z "$MONO_PATH" ]; then
102 MONO_PATH="\"$EXTRA_CROSS_DIR\""
103 else
104 MONO_PATH="\"$EXTRA_CROSS_DIR\":$MONO_PATH"
109 export PATH MONO_PATH CPPFLAGS
110 show_build_info
113 function build ()
115 if [ -f ./Makefile ]; then
116 make distclean
119 if [ -d ./autom4te.cache ]; then
120 rm -rf ./autom4te.cache
123 if [ -f ./config.status ]; then
124 for f in `find -name config.status -type f`; do
125 rm $f
126 done
129 ./autogen.sh
131 BUILD="`./config.guess`"
133 if [ ! -d "$CURDIR/build-cross-windows" ]; then
134 mkdir "$CURDIR/build-cross-windows"
137 cd "$CURDIR/build-cross-windows"
138 rm -rf *
139 ../configure --prefix=$MONO_PREFIX --with-crosspkgdir=$CROSS_PKG_CONFIG_DIR --build=$BUILD --target=$MINGW --host=$MINGW --enable-parallel-mark --program-transform-name="" --with-tls=none --disable-mcs-build --disable-embed-check --enable-win32-dllmain=yes --with-libgc-threads=win32 --with-profile4=yes
140 make
141 cd "$CURDIR"
143 if [ ! -d "$CURDIR/build-cross-windows-mcs" ]; then
144 mkdir "$CURDIR/build-cross-windows-mcs"
147 rm -rf autom4te.cache
148 unset PATH
149 PATH="$ORIGINAL_PATH"
150 export PATH
151 cd "$CURDIR/build-cross-windows-mcs"
152 rm -rf *
153 ../configure --prefix=$MONO_PREFIX --enable-parallel-mark
154 make
157 function doinstall ()
159 if [ -d "$INSTALL_DIR" ]; then
160 rm -rf "$INSTALL_DIR"
162 cd "$CURDIR/build-cross-windows"
163 make DESTDIR="$INSTALL_DESTDIR" USE_BATCH_FILES=yes install
165 if test -d $CURDIR/mcs; then
166 mcsdir=$CURDIR/mcs
167 else
168 mcsdir=$CURDIR/../mcs
171 cd "$mcsdir/mcs"
172 for p in $PROFILES; do
173 make DESTDIR="$INSTALL_DESTDIR" PROFILE=$p install || echo "mcs profile $p installation failed"
174 done
176 cd "$mcsdir/class"
177 for p in $PROFILES; do
178 make DESTDIR="$INSTALL_DESTDIR" PROFILE=$p install || echo "class library profile $p installation failed"
179 done
181 cd "$mcsdir/tools"
182 for p in $PROFILES; do
183 make DESTDIR="$INSTALL_DESTDIR" PROFILE=$p install || echo "tools profile $p installation failed"
184 done
186 cd "$CURDIR/mono-win32"
187 rm -f "$CURDIR/mono-win32-$MONO_RELEASE".zip
188 zip -9r "$CURDIR/mono-win32-$MONO_RELEASE".zip .
192 function usage ()
194 cat <<EOF
195 Usage: build-mingw32.sh [OPTIONS]
197 where OPTIONS are:
199 -d DIR Sets the location of directory where MINGW is installed [$CROSS_DIR]
200 -e DIR Sets the location of directory where additional cross develoment packages are installed [${EXTRA_CROSS_DIR:=none}]
201 -m MINGW Sets the MINGW target name to be passed to configure [$MINGW]
202 -p PREFIX Prefix at which Mono is to be installed. Build will append the 'mono-X.Y' string to that path
205 exit 1
208 trap cleanup 0
210 pushd . > /dev/null
212 while getopts "d:m:e:p:" opt; do
213 case "$opt" in
214 d) CROSS_DIR="$OPTARG" ;;
215 m) MINGW="$OPTARG" ;;
216 e) EXTRA_CROSS_DIR="$OPTARG" ;;
217 p) MONO_PREFIX="$OPTARG" ;;
218 *) usage ;;
219 esac
220 done
222 setup
223 build
224 doinstall
225 show_build_info
227 popd > /dev/null