# SliTaz package receipt.

PACKAGE="xorg-server"
VERSION="1.20.14"
CATEGORY="x-window"
SHORT_DESC="Xorg core server."
MAINTAINER="devel@slitaz.org"
SUGGESTED="xorg-xf86-input-evdev xorg-xf86-video-vesa"
TARBALL="$PACKAGE-$VERSION.tar.xz"
WEB_SITE="http://www.x.org/"
WGET_URL="http://xorg.freedesktop.org/releases/individual/xserver/$TARBALL"

# Mesa build dep make also Xorg depends on libdrm.
DEPENDS="pixman eudev xorg-libxshmfence libdrm xorg-libX11 xorg-libXdmcp \
xorg-libXfont xorg-xkeyboard-config xorg-libpciaccess xorg-libXau xorg-libXaw \
xorg-libICE xorg-libSM xorg-libXext xorg-libXfixes xorg-libXi xorg-libXmu \
xorg-libXrender xorg-libXt xorg-libdmx libxcb freetype harfbuzz libpng bzip2 \
libcrypto xorg-libfontenc zlib xorg-xkbcomp"
BUILD_DEPENDS="patch xorg-util-macros pixman-dev eudev-dev dbus-dev \
xorg-libxshmfence-dev libdrm-dev xorg-libX11-dev mesa-dev xorg-libXdmcp-dev \
xorg-xproto xorg-libxkbfile-dev xorg-libXfont-dev xorg-libpciaccess-dev \
xorg-libXxf86dga-dev xorg-libdmx-dev xorg-libXaw-dev xorg-libXpm-dev \
xorg-libXtst-dev xorg-libXres-dev xorg-libXmu-dev xorg-libXext-dev \
xorg-libXrender-dev xorg-libXfixes-dev xorg-libXi-dev xorg-libXau-dev \
xcb-util-renderutil-dev xcb-util-dev xcb-util-image-dev xcb-util-wm-dev \
xcb-util-keysyms-dev expat-dev xorg-xtrans xorg-xkbcomp-dev openssl-dev \
harfbuzz-dev pcre-dev libgio-dev libepoxy-dev xorg-libXxf86misc-dev" 

# Rules to configure and make the package.
compile_rules()
{
    cd $src
    # Drop redundant screenInfo declaration
    # commit 794fd7e563ca9430a4a29a8e9f1923c07c23a480
    patch -p1 < $stuff/xorg-1.20-drop-redundant-screenInfo-declaration.patch
    export CFLAGS="$CFLAGS -Wno-array-bounds"

    # Xephyr make possible to use Xorg in a chroot: --enable-xephyr
    ./configure \
        --prefix=/usr \
        --sysconfdir=/etc \
        --mandir=/usr/share/man \
        --localstatedir=/var \
        --with-module-dir=/usr/lib/X11/modules \
        --with-xkb-output=/var/lib/xkb \
        --with-serverconfig-path=/etc/X11 \
        --enable-install-setuid \
        --enable-suid-wrapper \
        --disable-systemd-logind \
        --enable-dmx \
        --enable-xorg \
        --enable-config-udev \
        --disable-docs \
        --disable-devel-docs \
        --with-fontrootdir=/usr/share/fonts/X11 \
        --with-os-name="SliTaz GNU/Linux" \
        --with-vendor-web="https://www.slitaz.org/" \
        --with-builder-addr=$MAINTAINER \
        $CONFIGURE_ARGS &&
    make && make DESTDIR=$DESTDIR install || return 1
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
    mkdir -p $fs/usr/lib $fs/var $fs/etc/X11/xorg.conf.d
    cp -a $_pkg/usr/lib/X11 $fs/usr/lib
    cp -a $_pkg/usr/libexec $fs/usr/
    cp -a $_pkg/usr/bin $fs/usr
    cp -a $_pkg/var/lib $fs/var
    cp -a $_pkg/etc $fs
    # Remove static libs and split Xnest
    rm $fs/usr/lib/X11/*/*.*a
    rm $fs/usr/lib/X11/*/*/*.*a
    rm $fs/usr/bin/Xnest
    rm $fs/usr/bin/Xvfb
}

# We need /var/tmp rw to let xkbcomp builr XKB definition.
post_install()
{
    install -dm1777 -oroot -groot "$1/tmp/.ICE-unix" "$1/tmp/.X11-unix"
    chmod 1777 $1/var/tmp
}