# $Id: PKGBUILD 140778 2011-10-19 07:11:57Z daniel $
# Maintainer: Daniel Isenmann <daniel@archlinux.org>
# Contributor: Brice Carpentier <brice@dlfp.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - Added alarm.patch for armv7h to fix detection of VFP capability
#    and using autogen.sh to rebuild for configure.in changes.

pkgname=mono
pkgver=3.4.0
pkgrel=1
pkgdesc="Free implementation of the .NET platform including runtime and compiler"
arch=(i686 x86_64)
license=('GPL' 'LGPL2.1' 'MPL' 'custom:MITX11')
url="http://www.mono-project.com/"
depends=('zlib' 'libgdiplus>=2.10' 'sh' 'python')
options=('!libtool' '!makeflags')
provides=('monodoc')
conflicts=('monodoc')
source=(http://download.mono-project.com/sources/mono/${pkgname}-${pkgver}.tar.bz2
        mono.binfmt.d
	sgen_fix.patch
	build_fix.patch
	Microsoft.Portable.Common.targets)
md5sums=('698024a40ee0721c2a24c45be2e39f28'
         'b9ef8a65fea497acf176cca16c1e2402'
         '8a700b94bff7a913f920e95890d2fb4c'
         '30a5af1a4ff50b98f9e73cc2ae554115'
         'acbffadb0ac233c494b40dd5e79209a5')

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  patch -p1 < ../build_fix.patch  
  cp ../Microsoft.Portable.Common.targets mcs/tools/xbuild/targets/

  # build mono
  if [ "$CARCH" = "armv7h" -o "$CARCH" = "armv6h" ]; then
    #Disabling alarm patch, arm support might be in now.
    #patch -Np1 -i ${srcdir}/alarm.patch
    sed -i 's/^AM_CONFIG_HEADER/AC_CONFIG_HEADERS/' configure.in
    sed -i 's/^AM_CONFIG_HEADER/AC_CONFIG_HEADERS/' eglib/configure.ac
    sed -i 's/AM_PROG_CC_STDC/AC_PROG_CC/' configure.in
    sed -i 's/AUTOMAKE_OPTIONS = cygnus//' runtime/Makefile.am
    ./autogen.sh --prefix=/usr --sysconfdir=/etc \
                 --with-fpu=VFP --bindir=/usr/bin --sbindir=/usr/bin --disable-static --disable-quiet-build  --disable-system-aot --with-mcs-docs=no
  else
    sed -i 's/armv6=yes/armv6=no/' configure
    ./configure --prefix=/usr --sysconfdir=/etc --bindir=/usr/bin --sbindir=/usr/bin --with-fpu=NONE --disable-static --disable-quiet-build --disable-system-aot --with-mcs-docs=no
  fi
  make

  # build jay
  cd ${srcdir}/${pkgname}-${pkgver}/mcs/jay
  make
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install

  # install jay
  pushd "${srcdir}"/${pkgname}-${pkgver}/mcs/jay
  make DESTDIR=${pkgdir} prefix=/usr INSTALL=../../install-sh install
  popd

  # install binfmt conf file and pathes
  install -D -m644 ${srcdir}/mono.binfmt.d ${pkgdir}/usr/lib/binfmt.d/mono.conf

  #install license
  mkdir -p ${pkgdir}/usr/share/licenses/${pkgname}
  install -m644 mcs/MIT.X11 ${pkgdir}/usr/share/licenses/${pkgname}/
  
  #fix .pc file to be able to request mono on what it depends, fixes #go-oo build
  sed -i -e "s:#Requires:Requires:" ${pkgdir}/usr/lib/pkgconfig/mono.pc
}