# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: 

inherit eutils

DESCRIPTION="SOCKS5 Implementation"
SLOT="0"
LICENSE="GPL-2"
KEYWORDS="amd64 x86"
RDEPEND="sys-libs/ncurses"

S=${WORKDIR}/socks5-v1.0r11

src_unpack() {
    tar xjf ${FILESDIR}/socks5-v1.0r11.tar.bz2
    EPATCH_OPTS="-p0 -d socks5-v1.0r11" epatch ${FILESDIR}/socks5-v1.0r11.patch1.txt.bz2
    EPATCH_OPTS="-p1 -d socks5-v1.0r11" epatch ${FILESDIR}/socks5-vararg.patch.bz2
    EPATCH_OPTS="-p1 -d socks5-v1.0r11" epatch ${FILESDIR}/socks5-v1.0r11-ifaaddr.patch.bz2
}

src_compile() {
    econf	--with-srvpidfile=/var/run/socks5.pid \
		--with-libconffile=/etc/libsocks5.conf \
		--with-srvconffile=/etc/socks5.conf \
		--with-syslog-facility \
		--with-threads || die
    emake || die
}

src_install() {
    into /usr

    echo "-----------------"
    echo ${D}
    cd ${P}-r11/work/socks5-v1.0r11
    make install prefix=${D}/usr || die
    cd ${D}/usr/bin/
    mv rarchie s5archie
    mv rfinger s5finger
    mv rftp s5ftp
    mv rping s5ping
    mv rtelnet s5telnet
    mv rtraceroute s5traceroute
    mv rwhois s5whois
    
    chmod 511 s5*
    strip s5*
    
    mkdir ../sbin
    strip socks5
    mv socks5 stopsocks ../sbin
    
    mkdir -p ${D}/etc/init.d/
    install -m 755 ${FILESDIR}/socks5.init ${D}/etc/init.d/socks5
    install -m 755 ${FILESDIR}/unsocks ${D}/usr/bin
    echo "socks5 - - - - -" > ${D}/etc/libsocks5.conf
}