# $Id: Portfile 108355 2013-07-20 19:22:16Z jeremyhu@macports.org $

PortSystem                  1.0

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

name                        wine-crossover
conflicts                   wine wine-devel
version                     12.2.1
license                     LGPL-2.1+
categories                  x11
maintainers                 jeremyhu openmaintainer
homepage                    http://www.codeweavers.com/
platforms                   darwin
distname                    crossover-sources-${version}
dist_subdir                 wine
set wine_distfile           ${distname}${extract.suffix}
set wine_gecko_version      1.8
set wine_gecko_distfile     wine_gecko-${wine_gecko_version}-x86.msi
distfiles                   ${wine_distfile}:winesource ${wine_gecko_distfile}:winegecko
extract.only                ${wine_distfile}
worksrcdir                  sources/wine
build.target                depend all
use_parallel_build          yes

description                 Wine Is Not an Emulator (1.5.15 with CodeWeavers modifications for CrossOver)

long_description            Wine is an implementation of the Windows APIs on top of X11. \
                            This version contains the Codeweavers patches for CrossOver

master_sites                http://ftp.codeweavers.com/pub/crossover/source/:winesource \
                            http://ftp.codeweavers.com/pub/crossover/source/archive/${version}/:winesource \
                            sourceforge:project/wine/Wine%20Gecko/${wine_gecko_version}:winegecko

checksums                   crossover-sources-12.2.1.tar.gz \
                            rmd160  b03ccb6124d46299dd4c0ddb5fcf1dd0c42d2ff2 \
                            sha256  c7c25b03b8a9aba60682d442422bbb29e67a1f79a75878618afb30445c91e2cb \
                            wine_gecko-1.8-x86.msi \
                            rmd160  f7b86d2e5ff82bf345b2420c9a8e9cfbc3c9989c \
                            sha256  28f3b7e497e1f884a64b2d982b61dda3167efac4c843de198654a1c9144ff9dc

# 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:openssl \
                            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

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

# Extract only the wine directory. We don't need the others, and their presence
# interferes with the wine build (which uses parts of them if present).
extract.post_args-append    ${worksrcdir}

patchfiles                  BOOL.patch \
                            mach_machine.patch \
                            winedbg.patch

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

configure.args              --without-alsa \
                            --without-capi \
                            --with-cms \
                            --with-coreaudio \
                            --with-cups \
                            --with-curses \
                            --with-fontconfig \
                            --with-freetype \
                            --without-gphoto \
                            --with-glu \
                            --without-gnutls \
                            --without-gsm \
                            --without-hal \
                            --with-jpeg \
                            --without-ldap \
                            --without-mpg123 \
                            --without-openal \
                            --with-opengl \
                            --with-openssl \
                            --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

# BUILD FIX TODO: llvm-gcc-4.2, clang
# llvm-gcc does not respect force_align_arg_pointer
# clang fails due to CFI-foo (winebuild uses /usr/bin/as to assemble clang-generated assembly)
compiler.whitelist gcc-4.2 apple-gcc-4.2

# 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/wineloader ${destroot}${prefix}/libexec/wine/wine
    system "install_name_tool -change @executable_path/../lib/libwine.1.dylib ${prefix}/lib/libwine.1.dylib ${destroot}${prefix}/libexec/wine/wine"

    foreach dll [glob ${destroot}${prefix}/lib/wine/*.so] {
        system "install_name_tool -change @executable_path/../lib/libwine.1.dylib ${prefix}/lib/libwine.1.dylib ${dll}"
    }

    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.url               http://ftp.codeweavers.com/pub/crossover/source/
livecheck.regex             crossover-sources-(\[0-9.\]+)\\.tar
