# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 92577 2012-05-01 18:00:53Z ryandesign@macports.org $

PortSystem          1.0

name                alienarena
version             7.53-20111227
set version_number  [lindex [split ${version} -] 0]
set version_date    [lindex [split ${version} -] 1]
categories          games
platforms           darwin
maintainers         ryandesign
license             GPL-2+

description         retro sci-fi old school deathmatch game similar to Quake \
                    III and Unreal Tournament

long_description    Alien Arena combines some of the very best aspects of \
                    such games as Quake III and Unreal Tournament and wraps \
                    them up with a retro alien theme, while adding tons of \
                    original ideas to make the game quite unique. Alien Arena \
                    is a furious frag fest with arenas ranging from the \
                    small, to the massive. With a large built-in player base, \
                    it's never hard to find a good match going on, at any \
                    hour of the day. The community is friendly, as well as \
                    prolific. Dozens of maps, models, and various accessories \
                    have been created by community members to add on to the \
                    game experience.

homepage            http://red.planetarena.org/
master_sites        http://icculus.org/alienarena/Files/ \
                    gentoo

worksrcdir          alienarena-${version_number}
distname            ${worksrcdir}-linux${version_date}

checksums           rmd160  d0435e7b58bee8743264f042b2e42e0b5020ae43 \
                    sha256  68bb1539c09cc572345ffc64a470dacbc27eb0074c76946694369fdb009c639f

platform darwin {
    pre-fetch {
        # 10.4.11:
        # ld: common symbols not allowed with MH_DYLIB output format with the -multi_module option
        # The usual advice is to use -fno-common (e.g. http://gcc.gnu.org/ml/gcc/2005-06/msg00378.html)
        # but this leads to several "multiple definitions of symbol" errors.
        # 10.5.8:
        # In file included from client/snd_openal.c:37:
        # client/qal.h:108: error: syntax error before 'pqalcCreateContext'
        if {${os.major} < 10} {
            ui_error "Alien Arena requires Mac OS X 10.6 or greater at the moment."
            return -code error "incompatible Mac OS X version"
        }
    }
}

if {${name} == ${subport}} {
    revision                    1
    
    depends_build               port:pkgconfig
    
    depends_lib                 port:curl \
                                port:freetype \
                                port:jpeg \
                                port:libvorbis \
                                port:openal \
                                port:mesa \
                                port:xorg-libX11 \
                                port:xorg-libXext \
                                port:xorg-libXxf86dga \
                                port:xorg-libXxf86vm
    
    depends_run                 port:alienarena-data
    
    # Extract only the specific directories we need, to avoid extracting the huge data1 directory.
    extract.post_args-append    --wildcards \
                                ${worksrcdir}/COPYING \
                                ${worksrcdir}/Makefile.in \
                                ${worksrcdir}/README \
                                ${worksrcdir}/arena \
                                ${worksrcdir}/botinfo \
                                ${worksrcdir}/config \
                                ${worksrcdir}/configure \
                                ${worksrcdir}/data1/*.cfg \
                                ${worksrcdir}/docs \
                                ${worksrcdir}/source
    
    # Needed for autoreconf.
    extract.post_args-append    ${worksrcdir}/Makefile.am \
                                ${worksrcdir}/aclocal.m4 \
                                ${worksrcdir}/configure.ac \
                                ${worksrcdir}/m4
    
    configure.args              --disable-silent-rules \
                                --x-includes=${prefix}/include \
                                --x-libraries=${prefix}/lib \
                                --without-system-libode \
                                --with-xf86dga \
                                --with-xf86vm
    
    patchfiles                  patch-Makefile.am.diff \
                                patch-configure.ac.diff
    
    post-patch {
        reinplace "s|@FRAMEWORKS_DIR@|${frameworks_dir}|g" ${worksrcpath}/configure.ac
    }
    
    use_autoreconf              yes
    
    # On Leopard and presumably Tiger:
    # In file included from client/snd_openal.c:37:
    # client/qal.h:34: error: syntax error before 'pqalEnable'
    #configure.cflags-append -DAL_NO_PROTOTYPES
    
    # Prevent finding an installed version of ode which would cause a build error.
    configure.cppflags-delete   -I${prefix}/include
    configure.cppflags-append   -isystem${prefix}/include
    
    post-destroot {
        xinstall -d ${destroot}${prefix}/share/${name}
        copy ${worksrcpath}/arena ${worksrcpath}/botinfo ${worksrcpath}/data1 ${destroot}${prefix}/share/${name}
    }
    
    variant debug description {Enable debugging symbols} {
        configure.args-append --enable-debugging-symbols
    }
    
    notes "
To play Alien Arena, type:

crx

To run your own dedicated Alien Arena server, use:

crx-ded
"
    
    livecheck.version           ${version_number}
    livecheck.type              regex
    livecheck.url               ${homepage}aquire.html
    livecheck.regex             {Alien Arena ([0-9.]+)}
} else {
    livecheck.type              none
}

subport alienarena-data {
    license                     Restrictive
    supported_archs             noarch
    
    description                 Assets for the Alien Arena game
    
    long_description            ${description}
    
    extract.post_args-append    ${worksrcdir}/data1
    
    post-extract {
        eval delete [glob ${worksrcpath}/data1/*.cfg]
    }
    
    use_configure               no
    
    build {}
    
    destroot {
        xinstall -d ${destroot}${prefix}/share/${name}
        copy ${worksrcpath}/data1 ${destroot}${prefix}/share/${name}
    }
}

