##
##  mono.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_opkg   4.6.2.6
%define       V_dist   4.6.2.6
%define       V_subdir 4.6.2

#   package information
Name:         mono
Summary:      Unix .NET Development Framework
URL:          http://www.mono-project.com/
Vendor:       The Mono Project
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Language
License:      GPL
Version:      %{V_opkg}
Release:      20161103

#   list of sources
Source0:      http://download.mono-project.com/sources/mono/mono-%{V_dist}.tar.bz2
Patch0:       mono.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, pkgconfig, perl, bison, make, gcc
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  glib, glib::with_threads = yes, gc, gc::with_threads = yes
PreReq:       glib, glib::with_threads = yes, gc, gc::with_threads = yes
Conflicts:    pnet

%description
    The Mono project is an open source effort to create a free Unix
    implementation of the .NET Development Framework. This is the base
    package providing a Common Language Runtime (CLR) for the Common
    Language Infrastructure (CLI), a C# Compiler and a set of class
    libraries. The runtime can be embedded into your application. It
    implements both ADO.NET and ASP.NET.

%track
    prog mono = {
        version   = %{V_dist}
        url       = http://download.mono-project.com/sources/mono/
        regex     = mono-(\d+\.\d+(\.\d+)*)\.tar\.bz2
    }

%prep
    %setup -q -n mono-%{V_subdir}
    %patch -p0

%build
    #   configure program
    %{l_shtool} subst \
        -e 's/-lgc/-lgcthread/g' \
        -e 's/isinf (1)/isinf (1.0)/g' \
        configure
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags gc .}" \
    LDFLAGS="%{l_ldflags}" \
    MONO_SHARED_DIR="`pwd`" \
    ./configure \
        --cache-file=./config.cache \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --bindir=%{l_prefix}/libexec/mono \
        --with-gc=boehm \
        --with-jit=yes \
        --without-moonlight \
        --disable-shared \
        --disable-dtrace

    #   build program
    %{l_make} %{l_mflags -O}

%install
    #   use a working install to create subdirs
    %{l_shtool} subst \
        -e 's;\$(mkdir_p);%{l_shtool} mkdir -p;' \
        Makefile */Makefile */*/Makefile

    #   install program
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"

    #   activate executables
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin
    for bin in `cd $RPM_BUILD_ROOT%{l_prefix}/libexec/mono && echo *`; do
        case $bin in
            *.exe ) continue ;;
        esac
        ln  $RPM_BUILD_ROOT%{l_prefix}/libexec/mono/$bin \
            $RPM_BUILD_ROOT%{l_prefix}/bin/$bin
    done

    #   strip down installation
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/libgc-mono
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/locale
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true

    #   fix problematic filenames
    mv  "$RPM_BUILD_ROOT%{l_prefix}/lib/mono/xbuild-frameworks/.NETPortable/v5.0/SupportedFrameworks/Windows Universal 10.0.xml" \
        "$RPM_BUILD_ROOT%{l_prefix}/lib/mono/xbuild-frameworks/.NETPortable/v5.0/SupportedFrameworks/Windows-Universal-10.0.xml"
    mv  "$RPM_BUILD_ROOT%{l_prefix}/lib/mono/xbuild-frameworks/.NETPortable/v5.0/SupportedFrameworks/.NET Framework 4.6.xml" \
        "$RPM_BUILD_ROOT%{l_prefix}/lib/mono/xbuild-frameworks/.NETPortable/v5.0/SupportedFrameworks/.NET-Framework-4.6.xml"
    mv  "$RPM_BUILD_ROOT%{l_prefix}/lib/mono/xbuild-frameworks/.NETPortable/v5.0/SupportedFrameworks/ASP.NET Core 1.0.xml" \
        "$RPM_BUILD_ROOT%{l_prefix}/lib/mono/xbuild-frameworks/.NETPortable/v5.0/SupportedFrameworks/ASP.NET-Core-1.0.xml"

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/mono/*' \
        '%config %{l_prefix}/etc/mono/*/*'

%files -f files

%clean

