# Tanım: VirtualBox, güçlü bir 32 ve 64 bit sanallaştırma ürünüdür
# URL: http://virtualbox.org
# Paketçi: milisarge
# Gerekler: libidl acpica alsa-lib cdrkit xorg-glu openjdk libidl libvncserver libvpx xorg-libxcomposite xorg-libxcursor xorg-libxinerama libxml2 xorg-libxmu xorg-libxrandr libxslt xorg-libxtst xorg-mesa pulseaudio python qt5 sdl sdl-ttf xorg-proto xorg-server yasm virtualbox-modules
# Grup: sistem

isim=virtualbox
surum=5.2.14
devir=1
kaynak=(https://download.virtualbox.org/virtualbox/${surum}/VirtualBox-${surum}.tar.bz2
		60-vboxdrv.rules
		60-vboxguest.rules
		LocalConfig.kmk
		driver-path.patch
		include-path.patch)

derle() {
    cd $SRC/VirtualBox-${surum}
    patch -p1 -i ${SRC}/driver-path.patch
    #patch -p1 -i ${SRC}/include-path.patch
    #sed -i -e 's|/usr/X11R6/bin/xterm|/usr/X11R6/bin/xterm|' src/VBox/Runtime/VBox/RTAssertShouldPanic-vbox.cpp
    sed -i -e 's|X11R6/||' configure
    #sed -i -e 's|CXX_FLAGS=""|CXX_FLAGS="-std=c++11"|' configure
    sed -i -e 's|X11R6/||' Config.kmk
    sed -i -e 's|.*&& check_makeself||' configure
    sed -i -e 's|smc-napa|smcnapa|' src/VBox/Devices/PC/vbox.dsl
    sed -i -e 's|$(filter-out vboxvideo_drv_%,$(DLLS)) vboxvideo_drv_system|$(filter-out vboxvideo_drv_%,$(DLLS))|' src/VBox/Additions/x11/vboxvideo/Makefile.kmk
    cp ${SRC}/LocalConfig.kmk .
    sed -i 's/^check_gcc$/#check_gcc/' configure
    echo "VBOX_GCC_OPT=$CXXFLAGS -I/usr/include/glib-2.0 " >> LocalConfig.kmk
    
    cd $SRC/VirtualBox-${surum}
    
    ./configure \
        --disable-docs \
        --disable-kmods \
        --disable-vmmraw \
        --enable-pulse \
        --enable-vde \
		--enable-vnc \
		--nofatal \
        --enable-qt5 
    source ./env.sh
    kmk KBUILD_VERBOSE=2 all

    source $SRC/VirtualBox-${surum}/env.sh
    cd $SRC/VirtualBox-${surum}/out/linux.amd64/release/bin
    # ikililer
    install -dm755 ${PKG}/usr/bin
    install -m755 VBox.sh ${PKG}/usr/bin/VBox
    for i in VBoxHeadless VBoxManage VBoxSDL VirtualBox VBoxBalloonCtrl; do
        ln -sf VBox ${PKG}/usr/bin/$i
        ln -sf VBox ${PKG}/usr/bin/${i,,}
    done
    install -m755 VBoxTunctl ${PKG}/usr/bin
    # kütüphaneler
    install -dm755 ${PKG}/usr/lib/virtualbox
    install -m755 *.so ${PKG}/usr/lib/virtualbox
    install -m644 *.r0 VBoxEFI*.fd ${PKG}/usr/lib/virtualbox
    ## kök dizin izinleri
    install -m4755 VBoxSDL VirtualBox VBoxHeadless VBoxNetDHCP VBoxNetAdpCtl VBoxNetNAT -t ${PKG}/usr/lib/virtualbox
    ## diğer ikililer
    install -m755 VBoxManage VBoxSVC VBoxExtPackHelperApp VBoxXPCOMIPCD VBoxTestOGL VBoxBalloonCtrl -t ${PKG}/usr/lib/virtualbox
    # bileşenler
    install -dm755 ${PKG}/usr/lib/virtualbox/components
    install -m755 components/* -t ${PKG}/usr/lib/virtualbox/components
    # ek paketler pasif şuan
    #install -dm755 ${PKG}/usr/lib/virtualbox/ExtensionPacks
    #install -m755 ExtensionPacks/* -t ${PKG}/usr/lib/virtualbox/ExtensionPacks
    # dil desteği
    install -dm755 ${PKG}/usr/share/virtualbox/nls
    install -m755 nls/*.qm -t ${PKG}/usr/share/virtualbox/nls
    # betikler
    install -m755 VBoxCreateUSBNode.sh VBoxSysInfo.sh -t ${PKG}/usr/share/virtualbox
    # simge seti
    install -Dm644 VBox.png ${PKG}/usr/share/pixmaps/VBox.png
    pushd icons >/dev/null
    for i in *; do
        install -d ${PKG}/usr/share/icons/hicolor/$i/mimetypes
        cp $i/* ${PKG}/usr/share/icons/hicolor/$i/mimetypes
    done
    popd >/dev/null
    # masaüstü
    install -Dm644 virtualbox.desktop ${PKG}/usr/share/applications/virtualbox.desktop
    install -Dm644 virtualbox.xml ${PKG}/usr/share/mime/packages/virtualbox.xml
    # ayar dosyaları
    install -dm755 ${PKG}/etc/vbox
    echo 'INSTALL_DIR=/usr/lib/virtualbox' > ${PKG}/etc/vbox/vbox.cfg
    install -dm755 ${PKG}/etc/ld.so.conf.d
    echo '/usr/lib/virtualbox' > ${PKG}/etc/ld.so.conf.d/virtualbox.conf
    cd ${SRC}
    install -Dm644 VirtualBox-${surum}/COPYING ${PKG}/usr/share/licenses/$isim/LICENSE
    # udev kuralları
    install -Dm644 60-vboxdrv.rules ${PKG}/usr/lib/udev/rules.d/60-vboxdrv.rules
    # ekler
    pushd VirtualBox-${surum}/out/linux.amd64/release/bin/additions
    install -d ${PKG}/usr/bin
    install -m755 VBoxClient VBoxControl VBoxService mount.vboxsf ${PKG}/usr/bin
    install -m755 -D ${SRC}/VirtualBox-${surum}/src/VBox/Additions/x11/Installer/98vboxadd-xclient ${PKG}/usr/bin/VBoxClient-all
    install -m755 -D ${SRC}/VirtualBox-${surum}/src/VBox/Additions/x11/Installer/vboxclient.desktop ${PKG}/etc/xdg/autostart/vboxclient.desktop
    #install -D vboxvideo_drv_system.so ${PKG}/usr/lib/xorg/modules/drivers/vboxvideo.so
    install -d ${PKG}/usr/lib/xorg/modules/dri
    install -m755 VBoxOGL*.so ${PKG}/usr/lib
    ln -s /usr/lib/VBoxOGL.so ${PKG}/usr/lib/xorg/modules/dri/vboxvideo_dri.so
    install -m755 -D pam_vbox.so ${PKG}/usr/lib/security/pam_vbox.so
    popd
    install -Dm644 60-vboxguest.rules ${PKG}/usr/lib/udev/rules.d/60-vboxguest.rules
    # servis dosyası eklenebilir- serkur ile de kurulabilir.
}
