# $Id: Portfile 68024 2010-05-25 00:18:35Z ryandesign@macports.org $

PortSystem              1.0
PortGroup               archcheck 1.0
PortGroup               xcodeversion 1.0

name                    wine
conflicts               wine-devel wine-crossover-games
set my_name             wine
version                 1.0.1
revision                7
license                 LGPL-2.1+
categories              x11
maintainers             ryandesign jwa openmaintainer
homepage                http://www.winehq.org/
platforms               darwin
use_bzip2               yes
distname                ${my_name}-${version}
dist_subdir             ${my_name}
set wine_distfile       [suffix ${distname}]
set wine_gecko_distfile wine_gecko-0.1.0.cab
distfiles               ${wine_distfile} ${wine_gecko_distfile}
extract.only            ${wine_distfile}
build.target            depend all
use_parallel_build      yes
universal_variant       no

minimum_xcodeversions   {8 2.5}

description \
    Wine Is Not an Emulator

long_description \
    Wine is an implementation of the Windows APIs on top of X11.

master_sites \
    sourceforge:wine \
    http://ibiblio.org/pub/linux/system/emulators/wine/

checksums \
    ${wine_distfile} \
    md5     b49540f4ed194c7e8da4cdc4b5bd3404 \
    sha1    0550b03bf7b314514a87b6abb2198da96ef83b22 \
    rmd160  fecd2bf970c51c80fc02ca39631034f066da145e \
    ${wine_gecko_distfile} \
    md5     b188c296f045d20abdb11e9c0564894b \
    sha1    c16f1072dc6b0ced20935662138dcf019a38cd56 \
    rmd160  61f85ee39e96f88783541460d2fce31db7cc0183

# Note: Most of the X11 libs are dlopen()'d
depends_lib \
    port:expat \
    port:fontconfig \
    port:freetype \
    port:jpeg \
    port:lcms \
    port:libiconv \
    port:libpng \
    port:libxml2 \
    port:libxslt \
    port:ncurses \
    port:openssl \
    port:zlib \
    port:xorg-libsm \
    port:xorg-libXcomposite \
    port:xorg-libXcursor \
    port:xorg-libXi \
    port:xorg-libXinerama \
    port:xorg-libXrandr \
    port:xorg-libXxf86vm \
    port:mesa

archcheck.files         lib/libexpat.dylib \
                        lib/libfontconfig.dylib \
                        lib/libfreetype.dylib \
                        lib/libjpeg.dylib \
                        lib/liblcms.dylib \
                        lib/libiconv.dylib \
                        lib/libpng.dylib \
                        lib/libxml2.dylib \
                        lib/libxslt.dylib \
                        lib/libncurses.dylib \
                        lib/libssl.dylib \
                        lib/libz.dylib \
                        lib/libSM.dylib \
                        lib/libXcomposite.dylib \
                        lib/libXcursor.dylib \
                        lib/libXi.dylib \
                        lib/libXinerama.dylib \
                        lib/libXrandr.dylib \
                        lib/libXxf86vm.dylib \
                        lib/libGL.dylib

depends_build \
    port:pkgconfig

# patch-freetype.c-pFT_MulFix.diff should no longer be needed with wine 1.2
patchfiles \
    patch-freetype.c-pFT_MulFix.diff

use_autoreconf yes
autoreconf.args -fvi

configure.ldflags-append \
    -framework CoreServices \
    -lz

configure.args          --without-alsa \
                        --without-audioio \
                        --without-capi \
                        --with-cms \
                        --with-coreaudio \
                        --without-cups \
                        --with-curses \
                        --without-esd \
                        --with-fontconfig \
                        --with-freetype \
                        --without-gphoto \
                        --with-glu \
                        --without-hal \
                        --without-jack \
                        --with-jpeg \
                        --without-ldap \
                        --without-nas \
                        --with-opengl \
                        --with-openssl \
                        --without-oss \
                        --with-png \
                        --without-sane \
                        --with-xcomposite \
                        --with-xcursor \
                        --with-xinerama \
                        --with-xinput \
                        --with-xml \
                        --with-xrandr \
                        --with-xrender \
                        --with-xshape \
                        --with-xshm \
                        --with-xslt \
                        --with-xvidmode \
                        --with-x \
                        --x-include=${prefix}/include \
                        --x-lib=${prefix}/lib

# This is not 64-bit friendly yet
if {[info exists supported_archs]} {
    supported_archs i386
}
configure.build_arch i386

platform darwin 10 {
    # _getdirentries_is_not_available_when_64_bit_inodes_are_in_effect dlls/ntdll/directory.o
    configure.cppflags-append -D_DARWIN_NO_64_BIT_INODE
}

pre-fetch {
    if {"big" == ${os.endian}} {
        ui_error "${name} can only be used on an Intel Mac or other computer with a little-endian processor."
        return -code error "incompatible processor"
    }
    if {"darwin" == ${os.platform} && ${os.major} > 9} {
        ui_error "${name} ${version} is not compatible with Mac OS X 10.6 or later. Until ${name} 1.2 is released, please install wine-devel instead."
        return -code error "incompatible Mac OS X version"
    }
}

pre-configure {
    foreach badfile {/usr/local/include/dispatch/dispatch.h} {
        if {[file exists ${badfile}]} {
            ui_error "You have a copy of [file tail ${badfile}] in [file dirname ${badfile}] that will prevent"
            ui_error "${name} from building properly. Please remove it before trying again."
            return -code error "incompatible file"
        }
    }
}

post-destroot {
    xinstall -d ${destroot}${prefix}/libexec/wine
    file rename ${destroot}${prefix}/bin/wine ${destroot}${prefix}/libexec/wine/wine
    xinstall ${filespath}/wine.in ${destroot}${prefix}/bin/wine
    reinplace s|@PREFIX@|${prefix}|g ${destroot}${prefix}/bin/wine
    
    xinstall -d ${destroot}${prefix}/share/wine/gecko
    xinstall -m 644 ${distpath}/${wine_gecko_distfile} ${destroot}${prefix}/share/wine/gecko
    
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} \
        ANNOUNCE \
        AUTHORS \
        COPYING.LIB \
        LICENSE \
        README \
        ${destroot}${prefix}/share/doc/${name}
}

livecheck.type          regex
livecheck.regex         {"/announce/([0-9]+\.[0-9]*[02468](\.[0-9]+)*)"}
