# -*- 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 108090 2013-07-12 20:02:36Z jwa@macports.org $

PortSystem                  1.0
PortGroup                   archcheck 1.0
PortGroup                   compiler_blacklist_versions 1.0

# Please keep the wine, wine-devel and wine-crossover ports as similar as possible.

name                        wine-devel
conflicts                   wine wine-crossover
set my_name                 wine
version                     1.6-rc5

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_version      2.21
set wine_gecko_distfile     wine_gecko-${wine_gecko_version}-x86.msi
distfiles                   ${wine_distfile}:winesource ${wine_gecko_distfile}:winegecko
extract.only                ${wine_distfile}
build.target                depend all
use_parallel_build          yes

description                 Wine Is Not an Emulator

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

master_sites                http://www.ibiblio.org/pub/linux/system/emulators/wine/:winesource \
                            sourceforge:project/wine/Source:winesource \
                            sourceforge:project/wine/Wine%20Gecko/${wine_gecko_version}:winegecko

checksums                   ${wine_distfile} \
                            rmd160  160575878257f99adf84b3054f20fdf8a2afc511 \
                            sha256  b44f5ba6bb661e7e00e422ee7234b59e51208469d8989ce6fcdc128a0572ec77 \
                            ${wine_gecko_distfile} \
                            rmd160  e5aded4dfcde2462d9802478efe5aae1552e842d \
                            sha256  f01fafa6d7aab995c38add77315c4cbc2f32f52d5d6a9350056f42b62d631fd8

# Note: Most of the X11 libs are dlopen()'d
depends_lib                 port:expat \
                            port:fontconfig \
                            port:freetype \
                            port:gstreamer010 \
                            port:gstreamer010-gst-plugins-base \
                            port:jpeg \
                            port:lcms \
                            port:libiconv \
                            port:libpng \
                            port:libxml2 \
                            port:libxslt \
                            port:ncurses \
                            port:gnutls \
                            port:tiff \
                            port:zlib \
                            port:xorg-libsm \
                            port:xorg-libXcomposite \
                            port:xorg-libXcursor \
                            port:xorg-libXi \
                            port:xorg-libXinerama \
                            port:xorg-libXrandr \
                            port:xorg-libXxf86vm \
                            port:xrender \
                            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/libtiff.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/libXrender.dylib \
                            lib/libGL.dylib

depends_build               port:bison \
                            port:flex \
                            port:pkgconfig

patchfiles                  BOOL.patch \
                            mach_machine.patch \
                            tiger-shell.patch

configure.ldflags-append    -framework CoreServices \
                            -lz

configure.args              --without-alsa \
                            --without-capi \
                            --with-cms \
                            --with-coreaudio \
                            --with-cups \
                            --with-curses \
                            --with-fontconfig \
                            --with-freetype \
                            --without-gphoto \
                            --with-glu \
                            --with-gnutls \
                            --without-gsm \
                            --without-hal \
                            --with-jpeg \
                            --without-ldap \
                            --without-mpg123 \
                            --without-openal \
                            --with-opengl \
                            --without-oss \
                            --with-png \
                            --with-pthread \
                            --without-sane \
                            --with-tiff \
                            --without-v4l \
                            --with-xcomposite \
                            --with-xcursor \
                            --with-xinerama \
                            --with-xinput \
                            --with-xml \
                            --with-xrandr \
                            --with-xrender \
                            --with-xshape \
                            --with-xslt \
                            --with-xxf86vm \
                            --with-x \
                            --x-include=${prefix}/include \
                            --x-lib=${prefix}/lib

# This is not 64-bit friendly yet
supported_archs             i386

# llvm-gcc-4.2 doesn't respect force_align_arg_pointer; wine builds but fails to run
# http://bugs.winehq.org/show_bug.cgi?id=28030
compiler.blacklist-append   llvm-gcc-4.2 macports-llvm-gcc-4.2

# clang < 3.1 fails to build wine with "error: invalid operand for instruction lretw"
# http://bugs.winehq.org/show_bug.cgi?id=32872
compiler.blacklist-append   {clang < 425} macports-clang-2.9 macports-clang-3.0

# TODO: This should be done by base
if {${configure.compiler} eq "apple-gcc-4.2"} {
    depends_build-append port:apple-gcc42
    depends_skip_archcheck-append apple-gcc42
}

platform darwin {
    if {${os.major} <= 9} {
        # Fix "Xcode 3.x cannot build 16-bit code correctly. Use --disable-win16 if you don't need 16-bit support."
        # Only affects Xcode 3.0.x and 3.1.x, not 3.2.x.
        # See http://bugs.winehq.org/show_bug.cgi?id=14920
        configure.args-append --disable-win16
    }

    if {${os.major} >= 11} {
        # Needed or wine will SIGBUS
        configure.ldflags-append -Wl,-no_pie
    }
}

pre-fetch {
    if {${os.endian} eq "big"} {
        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 {${os.platform} eq "darwin" && ${os.major} < 9} {
        ui_error "${name} ${version} requires OS X 10.5 or greater."
        return -code error "incompatible OS X version"
    }
}

post-destroot {
    xinstall -d ${destroot}${prefix}/libexec/wine
    file rename ${destroot}${prefix}/bin/wine ${destroot}${prefix}/libexec/wine/wine
    system "install_name_tool -change @executable_path/../lib/libwine.1.dylib @executable_path/../../lib/libwine.1.dylib ${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]*([13579]|[02468]-rc\d+)(\.[0-9]+)*)"}
