#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
#include /usr/share/cdbs/1/rules/autoreconf.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/patchsys-quilt.mk

DEB_DBG_PACKAGE_libnghttp2-5 = libnghttp2-5-dbg

DEB_CONFIGURE_EXTRA_FLAGS += --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) \
  --bindir=\$${prefix}/bin/$(DEB_HOST_MULTIARCH) \
  --disable-failmalloc \
  --with-libxml2=yes \
  --with-spdylay=no

ifeq (,$(filter hurd-%,$(DEB_BUILD_ARCH)))
  DEB_CONFIGURE_EXTRA_FLAGS += --with-jemalloc=yes
endif

LDFLAGS += -Wl,--default-symver

## Show what dh_autoreconf is deleting / moving / restoring
#DEB_DH_AUTORECONF_ARGS := --verbose

# Do not want README so set the default docs explicitly
DEB_INSTALL_DOCS_ALL = AUTHORS README.rst

# Install scripts for nghttpx init script installed in install/nghttp2 below
DEB_DH_INSTALLINIT_ARGS_nghttp2 := --onlyscripts --name=nghttpx

clean::
	rm -rf doc/manual/html doc/manual/doctrees doc/apiref.rst

# Need to install the contrib files, rename them and set the modes
install/nghttp2::
	install -d debian/nghttp2/etc/init.d
	sed -e 's,^DAEMON=.*/,DAEMON=/usr/sbin/,' contrib/nghttpx-init > debian/nghttp2/etc/init.d/nghttpx
	chmod 755 debian/nghttp2/etc/init.d/nghttpx
	install -d debian/nghttp2/etc/nghttpx
	install -m644 nghttpx.conf.sample debian/nghttp2/etc/nghttpx/nghttpx.conf
	install -d debian/nghttp2/etc/logrotate.d
	install -p -m644 contrib/nghttpx-logrotate debian/nghttp2/etc/logrotate.d/nghttpx

install/libnghttp2-dev::
	rm -f debian/tmp/usr/lib/*/libnghttp2.la

build/libnghttp2-doc::
	$(MAKE) html

install/libnghttp2-doc::
	d=$(CURDIR)/debian/libnghttp2-doc/usr/share/doc/libnghttp2-doc; \
	mkdir -p $$d; \
	cp -pr doc/manual/html/* $$d; \
	cd $$d; \
	rm -f objects.inv; \
	cd _static; \
	ln -sf /usr/share/javascript/jquery/jquery.js; \
	ln -sf /usr/share/javascript/underscore/underscore.js
