description="The ISC DHCP package contains both the client and server programs for DHCP."
url="ftp://ftp.isc.org/isc/dhcp"

contributors="Berlius,Greg,Tnut"
packager="spiky <spiky@nutyx.org>"

name=dhcp
version=4.4.3

makedepends=(perl)

runyx_version=20201011

source=(http://downloads.tuxfamily.org/nutyx/files/runyx-${runyx_version}.tar.xz
	ftp://ftp.isc.org/isc/dhcp/$version/dhcp-$version.tar.gz
	dhclient.conf dhcpd.conf )

build() {

	unset MAKEFLAGS
	cd $name-$version
	sed -i '/o.*dhcp_type/d' server/mdb.c
	sed -r '/u.*(local|remote)_port/d'    \
	    -i client/dhclient.c              \
	    relay/dhcrelay.c
	CFLAGS="-D_PATH_DHCLIENT_SCRIPT='\"/sbin/dhclient-script\"' \
	-D_PATH_DHCPD_CONF='\"/etc/dhcp/dhcpd.conf\"' \
	-D_PATH_DHCLIENT_CONF='\"/etc/dhcp/dhclient.conf\"'" \
	
	./configure --prefix=/usr                                           \
	            --sysconfdir=/etc/dhcp                                  \
	            --localstatedir=/var                                    \
	            --with-srv-lease-file=/var/lib/dhcpd/dhcpd.leases       \
	            --with-srv6-lease-file=/var/lib/dhcpd/dhcpd6.leases     \
	            --with-cli-lease-file=/var/lib/dhclient/dhclient.leases \
	            --with-cli6-lease-file=/var/lib/dhclient/dhclient6.leases 
	make -j1

	make DESTDIR=$PKG install

	install -v -dm 755 $PKG/sbin

	mv -v $PKG/usr/sbin/dhclient $PKG/sbin
	install -v -m755 client/scripts/linux $PKG/sbin/dhclient-script

	cp -v $SRC/dhclient.conf $PKG/etc/dhcp/dhclient.conf

	install -v -dm 755 $PKG/var/lib/dhclient
	install -v -dm 755 $PKG/etc/sysconfig

	# Service
	cd $SRC/runyx-${runyx_version}
	make DESTDIR=$PKG -C services/sysv install-service-dhclient
        make DESTDIR=$PKG -C services/runyx install-service-dhclient
	make DESTDIR=$PKG install-sysd-dhclient


	install -v -dm 755 $PKG/var/lib/dhcpd

	cp -v $SRC/dhcpd.conf $PKG/etc/dhcp/dhcpd.conf
	make DESTDIR=$PKG install-sysv-dhcpd
	make DESTDIR=$PKG install-sysd-dhcpd
	make DESTDIR=$PKG install-runyx-dhcpd
}
