#! /usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -Wall
include /usr/share/dpkg/buildflags.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_BUILD_PARALLEL=yes
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/autoreconf.mk
include /usr/share/dpkg/buildflags.mk
CXXFLAGS := $(subst -O3,-O2,$(CXXFLAGS))
 
INSTALLDIR := $(CURDIR)/debian/tmp
datadir=/usr/share/squid3

DEB_DH_INSTALL_SOURCEDIR := $(INSTALLDIR)
DEB_INSTALL_DOCS_squid3-common := CONTRIBUTORS CREDITS QUICKSTART RELEASENOTES.html \
						SPONSORS 

DEB_CONFIGURE_EXTRA_FLAGS := --datadir=/usr/share/squid3 \
		--sysconfdir=/etc/squid3 \
		--mandir=/usr/share/man \
		--enable-inline \
		--enable-async-io=8 \
		--enable-storeio="ufs,aufs,diskd,rock" \
		--enable-removal-policies="lru,heap" \
		--enable-delay-pools \
		--enable-cache-digests \
		--enable-underscores \
		--enable-icap-client \
		--enable-follow-x-forwarded-for \
		--enable-auth-basic="DB,fake,getpwnam,LDAP,MSNT,MSNT-multi-domain,NCSA,NIS,PAM,POP3,RADIUS,SASL,SMB" \
		--enable-auth-digest="file,LDAP" \
		--enable-auth-negotiate="kerberos,wrapper" \
		--enable-auth-ntlm="fake,smb_lm" \
		--enable-external-acl-helpers="file_userip,kerberos_ldap_group,LDAP_group,session,SQL_session,unix_group,wbinfo_group" \
		--enable-url-rewrite-helpers="fake" \
		--enable-eui \
		--enable-esi \
		--enable-icmp \
		--enable-zph-qos \
		--enable-ecap \
		--disable-translation \
		--with-swapdir=/var/spool/squid3 \
		--with-logdir=/var/log/squid3 \
		--with-pidfile=/var/run/squid3.pid \
		--with-filedescriptors=65536 \
		--with-large-files \
		--with-default-user=proxy

DEB_HOST_ARCH_OS := $(shell dpkg-architecture -qDEB_HOST_ARCH_OS 2>/dev/null)

ifeq ($(DEB_HOST_ARCH_OS), kfreebsd)
		DEB_CONFIGURE_EXTRA_FLAGS += --enable-kqueue
endif
ifeq ($(DEB_HOST_ARCH_OS), linux)
		DEB_CONFIGURE_EXTRA_FLAGS += --enable-linux-netfilter
endif

DEB_MAKE_CLEAN_TARGET = distclean

DEB_FIXPERMS_EXCLUDE = /usr/lib/squid3/pinger

install/squid3::
	install -m 755 -g root -d $(INSTALLDIR)/usr/lib/cgi-bin
	mv $(INSTALLDIR)/etc/squid3/squid.conf.documented $(INSTALLDIR)/etc/squid3/squid.conf
	mv $(INSTALLDIR)/usr/lib/squid3/cachemgr.cgi $(INSTALLDIR)/usr/lib/cgi-bin/cachemgr.cgi
	mv $(INSTALLDIR)/usr/sbin/squid $(INSTALLDIR)/usr/sbin/squid3
	mv $(INSTALLDIR)/usr/share/man/man8/squid.8 $(INSTALLDIR)/usr/share/man/man8/squid3.8
	install -m 755 -g root -d $(INSTALLDIR)/etc/init.d
	install -m 755 -g root -d $(INSTALLDIR)/etc/init
	install -m 755 -g root -d $(INSTALLDIR)/etc/logrotate.d
	install -m 755 -g root -d $(INSTALLDIR)/etc/resolvconf
	install -m 755 -g root -d $(INSTALLDIR)/etc/resolvconf/update-libc.d
	install -m 755 -g root -d $(INSTALLDIR)/etc/ufw/applications.d
	install -m 755 -g root debian/squid3.rc $(INSTALLDIR)/etc/init.d/squid3
	install -m 644 -g root debian/squid3.upstart $(INSTALLDIR)/etc/init/squid3.conf
	install -m 755 -g root debian/squid3.resolvconf $(INSTALLDIR)/etc/resolvconf/update-libc.d/squid3
	install -m 644 -g root debian/squid3.logrotate $(INSTALLDIR)/etc/logrotate.d/squid3
	install -m 644 -g root debian/squid3.ufw.profile $(INSTALLDIR)/etc/ufw/applications.d/squid3
	install -m 755 -g root -d debian/squid3/var/log
	install -m 755 -g root -d debian/squid3/var/spool
	install -m 755 -g root -d debian/squid3/var/run
	install -m 750 -o proxy -g proxy -d debian/squid3/var/log/squid3
	install -m 750 -o proxy -g proxy -d debian/squid3/var/spool/squid3
	install -m 755 -g root -d $(INSTALLDIR)/usr/share/man/man1
	mv $(INSTALLDIR)/usr/bin/purge $(INSTALLDIR)/usr/bin/squid-purge
	chmod 4755 $(INSTALLDIR)/usr/lib/squid3/pinger
	install -m 755 -g root -d $(INSTALLDIR)/etc/apparmor.d/force-complain
	install -m 755 -g root -d $(INSTALLDIR)/etc/apparmor.d/disable
	install -m 644 -g root debian/usr.sbin.squid3 $(INSTALLDIR)/etc/apparmor.d
	dh_apparmor --profile-name=usr.sbin.squid3 -psquid3

clean::
	# nothing to do
