# Created by: Yukihiro Nakai <nakai@FreeBSD.org>
# $FreeBSD: head/lang/mono/Makefile 386633 2015-05-17 17:05:41Z romain $

PORTNAME=	mono
PORTVERSION=	4.0.1.28
CATEGORIES=	lang
MASTER_SITES=	http://download.mono-project.com/sources/${PORTNAME}/

PATCHFILES=	#
PATCH_SITES=	https://github.com/mono/mono/commit/
PATCH_DIST_STRIP=-p1

MAINTAINER=	mono@FreeBSD.org
COMMENT=	Open source implementation of .NET Development Framework

BUILD_DEPENDS=	p5-XML-Parser>=0:${PORTSDIR}/textproc/p5-XML-Parser \
		bash:${PORTSDIR}/shells/bash

CC=		cc
CXX=		c++
CPP=		cpp

CFLAGS+=	-O2 -pipe  -fstack-protector -fno-strict-aliasing
CXXFLAGS+=	-O2 -pipe  -fstack-protector -fno-strict-aliasing -lpthread
LDFLAGS+=	-fstack-protector

PREFIX=		/usr/local
LOCALBASE=	/usr/local
LIBDIR=		/usr/lib
#LIBS=

NO_PIE=		yes

XDG_DATA_HOME=	${WRKDIR}
XDG_CONFIG_HOME=${WRKDIR}
HOME=		${WRKDIR}

MAKE_JOBS_UNSAFE= yes

OPTIONS_DEFINE=		NLS
OPTIONS_SUB=		yes

NLS_USES=		gettext
NLS_CONFIGURE_ENABLE=	nls

WRKSRC=		${WRKDIR}/mono-4.0.1
USES=		bison compiler:c11 cpe gettext gmake iconv libtool pathfix perl5 tar:bzip2
USE_GNOME=	glib20
USE_PERL5=	build
GNU_CONFIGURE=	yes
USE_LDCONFIG=	yes

# Moonlight is installed as part of www/moonlight
CONFIGURE_ARGS=	--with-moonlight=no --disable-dtrace

CONFIGURE_ENV=	ac_cv_header_sys_inotify_h=no

# Set location for .wapi creation.
MONO_SHARED_DIR=${WRKDIR}

# LC_ALL is set in order to work around issues people are having when using
# other languages.  This has shown itself in build fails and possibly other
# strange crashes.
MAKE_ENV+=	MONO_SHARED_DIR="${MONO_SHARED_DIR}" \
		INSTALL_STRIP_FLAG="${STRIP}" \
		LC_ALL=C TZ=UTC \
		MONO_EXTERNAL_ENCODINGS=utf8:latin1 \
		CC="${CC}" \
		CXX="${CXX}" \
		CPP="${CPP}" \
		CFLAGS="${CFLAGS}" \
		CXXFLAGS="${CXXFLAGS}" \
		LIBS="" \
		LDFLAGS="${LDFLAGS}" 

ONLY_FOR_ARCHS=	i386 amd64 powerpc

post-patch:
	@${REINPLACE_CMD} -e 's|^#!/bin/bash|#!/usr/bin/env bash|g' \
		${WRKSRC}/scripts/mono-find-provides.in \
		${WRKSRC}/scripts/mono-find-requires.in \
		${WRKSRC}/scripts/mono-test-install
	@${FIND} ${WRKSRC} -name '*.sh' | ${XARGS} ${REINPLACE_CMD} \
		-e 's|^#!/bin/bash|#!/bin/sh|g'
	@${REINPLACE_CMD} 's/isinf (1)/isinf (1.0)/g' ${WRKSRC}/configure

tests: build
	@${ECHO_MSG} "===> Running mono regression tests"
	@(cd ${WRKSRC}/mono/tests && ${SETENV} ${MAKE_ENV} ${MAKE_CMD} \
		${MAKE_FLAGS} Makefile ${MAKE_ARGS} check) && \
#	${MAKE_FLAGS} Makefile CompilerParameters.GenerateInMemory = ${FALSE}

post-configure:
	@${REINPLACE_CMD} -e 's|share\/man|man|g' \
		${WRKSRC}/mcs/jay/Makefile
.include <bsd.port.mk>
