# $Id: Portfile 56468 2009-08-28 09:21:12Z ryandesign@macports.org $

PortSystem              1.0

name                    perforce
version                 2009.1
categories              devel
platforms               darwin
maintainers             nomaintainer

description             Fast source code management system

long_description        Perforce is a commercial revision control system \
                        that can be used gratis for developing free \
                        software. (see the WWW page for details).

homepage                http://www.perforce.com/
master_sites            http://www.perforce.com/downloads/perforce/r[string range ${version} 2 end]/bin.darwin80u/:prog \
                        http://www.perforce.com/perforce/doc.052/man/:man

dist_subdir             ${name}/${version}
worksrcdir              ${name}

distfiles               p4:prog p4.1:man p4d:prog p4d.1:man

checksums               p4      md5     e850f62223925c2a199ae402d9842417 \
                                sha1    13c601dcf7801a459cf4095f5d5afa95ac6c1e84 \
                                rmd160  133fb9ba0f7c9f297062e4e15e19a779d1b222be \
                        p4.1    md5     e5cada2f402e1e016be7999fdc49035d \
                                sha1    f0740627c5232e2eb72a278fd62d5764b7fcbdbb \
                                rmd160  c32ac846dfa8110fadba131ca4c7a3782cf1c180 \
                        p4d     md5     0bf148cc2e76f51fe6b4ddeb7645a4db \
                                sha1    9ce54008912e5955df679ee808b3beba31197ee2 \
                                rmd160  cf41efd49556c63bce116ec03365782c31da5e03 \
                        p4d.1   md5     1aa86f28ba0698266bf1dcaded3e4106 \
                                sha1    0383e5eb515ff1a4ecd6fb148aa544a49e68eb59 \
                                rmd160  913efbe9b299030a143e3c6a1fbf672ec526d7b7

extract {
    system "mkdir -p ${worksrcpath}"
    system "cp ${distpath}/* ${worksrcpath}/"
}

use_configure           no

build {}

destroot {
    xinstall -W ${worksrcpath} p4 ${destroot}${prefix}/bin
    xinstall -W ${worksrcpath} p4d ${destroot}${prefix}/sbin
    xinstall -W ${worksrcpath} -m 644 p4.1 ${destroot}${prefix}/share/man/man1
    xinstall -W ${worksrcpath} -m 644 p4d.1 ${destroot}${prefix}/share/man/man8
}

variant server {
    startupitem.create  yes
    startupitem.start   "su -c ${prefix}/sbin/p4d -d -r ${prefix}/share/perforce/depot -L ${prefix}/share/perforce/log"
    
    post-destroot {
        addgroup perforce
        set gid [existsgroup perforce]
        adduser perforce realname=Perforce\ Server gid=${gid} home=${prefix}/share/perforce shell=/bin/sh
        system "install -o perforce -m 755 -d ${destroot}${prefix}/share/perforce/depot"
        system "install -o perforce -m 644 -c /dev/null ${destroot}${prefix}/share/perforce/log"
    }
}

default_variants +universal
variant universal {}
pre-fetch {
    if {![variant_isset universal]} {
        return -code error "${name} is only available in a universal version"
    }
}
