#!/bin/bash ########################################################################### ## Copyright (C) Wizardry and Steamworks 2012 - License: GNU GPLv3 ## ## Please see: http://www.gnu.org/licenses/gpl.html for legal details, ## ## rights of fair usage, the disclaimer and warranty conditions. ## ########################################################################### # ### # Builds mono 3.0.1 on an iOS device provided that the # device has a build-environment set-up. The final stage # signs the resulting binaries and bundles mono. ## # This script requires the CoreFoundation headers to be # transferred to the device before compiling. ### # versions MONO_VERSION=3.0.1 LIBICONV_VERSION=1.7 # check build programs. BUILD_PROGS=( "/usr/bin/awk" \ "/usr/bin/ldid" \ "/usr/bin/gcc" \ "/usr/bin/tar" \ "/usr/bin/curl" \ "/usr/bin/autoconf" \ "/usr/bin/automake" \ "/usr/bin/make" \ "/bin/cat" \ "/usr/bin/file" \ "/usr/local/bin/perl" ) for BF in "${BUILD_PROGS[@]}"; do if [ ! -x "$BF" ]; then echo "Required build dependency not found: $BF" echo "Please install the relevant files and run this script again." exit 1 fi done unset BUILD_PROGS # check headers. BUILD_HEADERS=( "/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h" \ "/usr/include/crt_externs.h" ) for BF in "${BUILD_HEADERS[@]}"; do if [ ! -f "$BF" ]; then echo "Required build dependency not found: $BF" echo "Please check that you have transfered CoreFoundation to the device and that you have a valid build environment on your device." exit 1 fi done unset BUILD_HEADERS # check for patch if [ ! -f mono_ios.patch ]; then echo "Patch file mono_ios.patch not found. The patch should be placed in the same directory as this script." exit 1 fi # grab current directory CWD=`pwd` # grab libiconv compile and install to temporary path echo "Downloading libiconv..." if [ ! -f "libiconv-$LIBICONV_VERSION.tar.gz" ]; then curl -OkL "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-$LIBICONV_VERSION.tar.gz" fi if [ ! -f "libiconv-$LIBICONV_VERSION.tar.gz" ]; then echo "Downloading libiconv failed..." fi echo "Extracting libiconv..." tar -xf "libiconv-$LIBICONV_VERSION.tar.gz" rm -rf "libiconv-$LIBICONV_VERSION.tar.gz" cd "libiconv-$LIBICONV_VERSION" echo "Compiling libiconv..." CFLAGS="-Os" CXXFLAGS="-Os" CPPFLAGS="-Os" ./configure --prefix=/usr \ --sysconfdir=/etc \ --localstatedir=/var if [ $? -ne 0 ]; then echo "Configuring libiconv failed..." exit 1 fi make -j1 if [ $? -ne 0 ]; then echo "Compiling libiconv failed..." exit 1 fi make install DESTDIR=/tmp/libiconv cd $CWD echo "Cleaning up..." rm -rf "libiconv-$LIBICONV_VERSION" # grab mono, compile and install to temporary path echo "Downloading mono..." if [ ! -f "mono-$MONO_VERSION.tar.bz2" ]; then curl -OkL "http://download.mono-project.com/sources/mono/mono-$MONO_VERSION.tar.bz2" fi if [ ! -f "mono-$MONO_VERSION.tar.bz2" ]; then echo "Downloading mono failed..." fi echo "Extracting mono..." tar -jxf "mono-$MONO_VERSION.tar.bz2" rm -rf "mono-$MONO_VERSION.tar.bz2" cd "mono-$MONO_VERSION" echo "Patching mono..." if [ ! -f ../mono_ios.patch ]; then echo "Patch file mono_ios.patch not found. The patch should be placed in the same directory as this script." exit 1 fi cat ../mono_ios.patch | patch -p1 --dry-run if [ $? -ne 0 ]; then echo "Failed to patch mono..." exit 1 fi cat ../mono_ios.patch | patch -p1 echo "Compiling mono..." # BUG: build fails with --with-shared_mono=no so we build shared CFLAGS="-Os" CXXFLAGS="-Os" CPPFLAGS="-Os" ./configure --prefix=/usr \ --sysconfdir=/etc \ --localstatedir=/var \ --enable-nls=no \ --enable-small-config \ --with-tls=pthread \ --disable-mono-debugger \ --with-sigaltstack=no \ --with-sgen=no \ --with-glib=embedded \ --disable-system-aot \ --enable-minimal=aot \ --with-static_mono=no \ --enable-static=no \ --with-libiconv-prefix=/tmp/libiconv if [ $? -ne 0 ]; then echo "Configuring mono failed..." exit 1 fi make -j1 if [ $? -ne 0 ]; then echo "Compiling mono failed..." exit 1 fi make install DESTDIR=/tmp/mono cd $CWD echo "Cleaning up..." rm -rf "mono-$MONO_VERSION" # bundle the result echo "Making bundle..." mkdir -p /tmp/mono/DEBIAN cat > /tmp/mono/DEBIAN/control << EOF Package: org.grimore.mono Name: mono Version: $MONO_VERSION Architecture: iphoneos-arm Description: the mono C# compiler Mono is an open source, cross-platform, implementation of C# and the CLR that is binary compatible with Microsoft.NET, designed to allow developers to easily create cross platform applications. No icons are added to the home screen. No Screenshots for this item. Homepage: http://grimore.org/ios:mono Maintainer: Wizardry and Steamworks Author: Wizardry and Steamworks (WaS) Sponsor: Wizardry and Steamworks Section: Development EOF # sign binaries echo "Signing binaries..." for i in `find /tmp/mono -type f`; do FT=`file -b $i | awk '{ print $1 }'` case $FT in Mach-O ) EXE=`file -b $i | awk '{ print $2 }'` if [[ $EXE == "executable" ]]; then ldid -S $i fi ;; Bourne ) chmod +x $i ;; * ) ;; esac done echo "Packaging..." dpkg-deb -Zlzma -b /tmp/mono /tmp/mono.deb # clean-up echo "Cleaning temporary files..." rm -rf /tmp/libiconv rm -rf /tmp/mono echo "Mono package ready at /tmp/mono.deb."