#!/usr/bin/make -f

# This script uses debhelper by Joey Hess
#export DH_VERBOSE=1
DEB=$(CURDIR)/debian/tmp
DEV=debian/libsocksd0-dev

# Aim for the top, adapt if anything should break on the buildds.
DEB_BUILD_MAINT_OPTIONS=	hardening=+all
export DEB_BUILD_MAINT_OPTIONS

override_dh_auto_configure:
	dh_auto_configure -- \
	  --with-socks-conf=/etc/dante.conf \
	  --with-sockd-conf=/etc/danted.conf \
	  --with-pidfile=/var/run/danted.pid \
	  --without-gssapi
	cp lib/config_parse.c lib/config_scan.c dlib/
	cp lib/config_parse.c lib/config_scan.c sockd/

override_dh_auto_clean:
	dh_auto_clean
	for d in sockd dlib; do \
	  cd $$d; \
	  for i in *; do \
	    if [ -L "$$i" ]; then rm $$i; cp -a ../lib/$$i . ; fi \
	  done; \
	  cd ..; \
	done
	rm -rf example/renamed

override_dh_install:
	cp $(DEB)/usr/share/man/man5/socks.conf.5  $(DEB)/usr/share/man/man5/dante.conf.5
	cp $(DEB)/usr/share/man/man5/sockd.conf.5  $(DEB)/usr/share/man/man5/danted.conf.5
	cp $(DEB)/usr/share/man/man8/sockd.8 $(DEB)/usr/share/man/man8/danted.8
	cp $(DEB)/usr/sbin/sockd $(DEB)/usr/sbin/danted
	mkdir -p example/renamed
	for i in example/sockd*.conf; do \
		sed -e 's/sample sockd.conf/sample danted.conf/' < "$$i" > example/renamed/"`basename $$i | sed -e s/sockd/danted/`"; \
	done
	for i in example/socks*.conf; do \
		sed -e 's/sample socks.conf/sample dante.conf/' < "$$i" > example/renamed/"`basename $$i | sed -e s/socks/dante/`"; \
	done
	dh_install

override_dh_installdocs:
	dh_installdocs -A README doc/README.usage doc/README.survey BUGS CREDITS SUPPORT
	dh_installdocs -pdante-client doc/README.socksify
	dh_installdocs -pdante-client -pdante-server
	dh_installdocs -pdante-server doc/SOCKS4.protocol

override_dh_installchangelogs:
	dh_installchangelogs NEWS

override_dh_installinit:
	dh_installinit -pdante-server --init-script=danted --error-handler=dante_service_error

%:
	dh '$@' --without systemd
