# -*- 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 107838 2013-07-06 22:56:18Z devans@macports.org $

# TODO: figure out how to make PAM happy without blowing a large hole
#       in the security of the OS or touching PAM

PortSystem      1.0

name            gdm
version         2.32.1
license         GPL-2
set branch      [join [lrange [split ${version} .] 0 1] .]
description     The Gnome Display Manager is a re-implementation of the well known xdm program.
long_description \
                The Gnome Display Manager is a re-implementation of the well \
                known xdm program. It displays a X11-based graphical login screen.
maintainers     devans openmaintainer
categories      gnome
platforms       darwin
homepage        http://www.gnome.org/
master_sites    gnome:sources/${name}/${branch}/

use_bzip2       yes

checksums       rmd160  70526a3ddec3ff8a1313243641bf807a2218f3ae \
                sha256  7ba9cb2a8efb9856994467b14e4837a281fcf6d9dc9a267ea38a9aae1ec55abc

depends_build   port:pkgconfig \
                port:intltool \
                port:gnome-doc-utils

depends_lib     port:gconf \
                port:libcanberra \
                port:libxklavier \
                port:libpanel-applet2

depends_run     port:gnome-session \
                port:gnome-settings-daemon
                
patchfiles      patch-fink-gdm-modified.diff \
                patch-configure.diff \
                patch-daemon-gdm-display-access-file.c.diff \
                fgetpwent.diff

if {${os.major} <= 9 && ${os.platform} == "darwin"} {
    patchfiles-append pam_location.diff
}

post-patch {
        reinplace "s|@MP_PREFIX@|${prefix}|" ${worksrcpath}/configure
        file attributes ${worksrcpath}/install-sh -permissions +x
}

configure.args  --x-includes=${prefix}/include \
                --x-libraries=${prefix}/lib \
                --without-console-kit \
                --without-selinux \
                --disable-schemas-install \
                --disable-scrollkeeper

configure.ldflags-append "-lresolv"

startupitem.create  yes
startupitem.name    gdm
startupitem.init    XDG_DATA_DIRS=${prefix}/share
startupitem.start   ${prefix}/sbin/gdm
startupitem.stop    ${prefix}/sbin/gdm-stop
startupitem.restart ${prefix}/sbin/gdm-restart

post-destroot   {
    xinstall -m 644 ${filespath}/pam.sample ${destroot}${prefix}/etc/gdm
    xinstall ${filespath}/macports-gdm-util ${destroot}${prefix}/bin
}

pre-activate {
    addgroup gdm
    adduser gdm gid=[existsgroup gdm] realname=GNOME\ Display\ Manager
}

post-activate {
    system "scrollkeeper-update"
    system "${prefix}/bin/gtk-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
    system "export GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` && \
        gconftool-2 --makefile-install-rule ${prefix}/etc/gconf/schemas/*.schemas"
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
    file mkdir ${prefix}/var/gdm
    file attributes ${prefix}/var/gdm -owner gdm -group gdm
}

livecheck.type  gnome
