# -*- 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

PortSystem              1.0

name                    qemu
version                 2.3.1
categories              emulators
license                 GPL-2+
maintainers             nomaintainer

description             Emulator for various architectures
long_description        QEMU is a generic and open source machine emulator. \
                        It can run OSes and programs made for one machine on \
                        a different machine. By using dynamic translation, it \
                        achieves very good performance.

homepage                http://qemu.org
master_sites            http://download.qemu.org
use_bzip2               yes
checksums               rmd160  c2596f7104e3a78302a43ffad67f6a721a658c20 \
                        sha256  661d029809421cae06b4b1bc74ac0e560cb4ed47c9523c676ff277fa26dca15f \
                        size    24692020

patchfiles              patch-configure.diff

# gcc exists...
patchfiles-append       patch-fix-gcc.diff

depends_build           port:bison \
                        port:libtool \
                        path:bin/pkg-config:pkgconfig \
                        port:texinfo

# python is only used for build scripts, no linking
set py_ver              2.7
set py_ver_nodot        [string map {. {}} ${py_ver}]
depends_build-append    \
                        port:python${py_ver_nodot}
license_noconflict      python${py_ver_nodot}

depends_lib             port:bzip2 \
                        port:curl \
                        path:lib/pkgconfig/glib-2.0.pc:glib2 \
                        path:lib/pkgconfig/pixman-1.pc:libpixman \
                        port:lzo2 \
                        port:zlib

# rcu.h:78: error: thread-local storage not supported for this target
compiler.thread_local_storage yes

# Select compiler
configure.args          --cpu=${configure.build_arch} \
                        --cc=${configure.cc} \
                        --objcc=${configure.objc} \
                        --host-cc=${configure.cc} \
                        --python=${prefix}/bin/python${py_ver} \

# Select features
configure.args-append   --disable-attr \
                        --disable-bluez \
                        --disable-brlapi \
                        --disable-cap-ng \
                        --disable-cocoa \
                        --disable-curses \
                        --disable-glusterfs \
                        --disable-gtk \
                        --disable-libiscsi \
                        --disable-libssh2 \
                        --disable-libusb \
                        --disable-rbd \
                        --disable-rdma \
                        --disable-sdl \
                        --disable-seccomp \
                        --disable-smartcard-nss \
                        --disable-spice \
                        --disable-usb-redir \
                        --disable-vde \
                        --disable-vnc \
                        --enable-curl \
                        --enable-uuid \
                        --enable-vhdx \
                        --with-system-pixman

# libtool: unknown option character `-' in: --mode=compile
configure.env-append   LIBTOOL=${prefix}/bin/glibtool

set target_list {}
pre-configure {
    configure.args-append --target-list=${target_list}
}

# disable silent rules
build.args-append       V=1

default_variants        +usb

foreach t {i386 x86_64 alpha {arm aarch64} cris lm32 m68k {microblaze microblazeel} {mips mipsel mips64 mips64el} \
           moxie or32 {ppc ppcemb ppc64} {sh4 sh4eb} {sparc sparc64} s390x {xtensa xtensaeb} unicore32} {
    variant target_[lindex $t 0] description "Add target support for [join $t {, }]" "append target_list \",[join $t -softmmu,]-softmmu\""
}
default_variants-append +target_i386 +target_x86_64 +target_ppc

if {![variant_isset curses]} {
    default_variants-append +cocoa
}

variant cocoa description {Use the native Mac OS X graphical user interface} conflicts curses sdl gtk2 gtk3 {
    configure.args-replace  --disable-cocoa --enable-cocoa
}

variant curses description {Use the curses text-only user interface} conflicts cocoa sdl gtk2 gtk3 {
    configure.args-replace --disable-curses --enable-curses
    depends_lib-append      port:ncurses
}

variant gtk3 description {Build GTK+ GUI for GTK+ 3 (experimental)} conflicts cocoa curses gtk2 sdl {
    configure.args-replace  --disable-gtk --enable-gtk
    configure.args-append   --with-gtkabi=3.0
    depends_lib-append      path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                            port:vte
}

variant gtk2 description {Use the GTK+ 2 graphical user interface} conflicts cocoa curses gtk3 sdl {
    configure.args-replace  --disable-gtk --enable-gtk
    configure.args-append   --with-gtkabi=2.0
    depends_lib-append      port:gtk2 \
                            port:vte
}

variant sdl description {Use the SDL graphical user interface} conflicts cocoa curses gtk2 gtk3 {
    configure.args-replace --disable-sdl --enable-sdl
    depends_lib-append      port:libsdl
}

#variant sdl2 description {Use the SDL 2 graphical user interface} conflicts cocoa curses gtk2 gtk3 sdl {
#    configure.args-replace  --disable-sdl --enable-sdl
#    configure.args-append   --with-sdlabi=2.0
#    depends_lib-append      port:libsdl2
#}

variant usb description {Support forwarding of USB devices to the guest} {
    configure.args-replace  --disable-libusb --enable-libusb
    depends_lib-append      path:lib/pkgconfig/libusb-1.0.pc:libusb
}

variant vnc description {Support VNC server} {
    configure.args-replace  --disable-vnc --enable-vnc
    configure.args-append   --enable-vnc-tls --enable-vnc-ws --enable-vnc-sasl --enable-vnc-jpeg --enable-vnc-png
    depends_lib-append      path:lib/pkgconfig/gnutls.pc:gnutls \
                            port:cyrus-sasl2 \
                            path:lib/libjpeg.dylib:jpeg \
                            port:libpng
}

variant vde description {Support VDE networking} {
    configure.args-replace  --disable-vde --enable-vde
    depends_lib-append      port:vde2
}

variant ssh description {Support remote block devices over SSH} {
    configure.args-replace  --disable-libssh2 --enable-libssh2
    depends_lib-append      port:libssh2
}

# Default universal variant does not work
universal_variant       no

platform darwin 8 {
    depends_build-append port:gmake
    build.cmd ${prefix}/bin/gmake
}

livecheck.type  regex
livecheck.url   [lindex ${master_sites} 0]
livecheck.regex ${name}-(\\d+(?:\\.\\d+)*)(?:-\\d+)*\\.tar
