#!/usr/bin/make -f

export DH_VERBOSE=1

NJOBS := -j$(shell getconf _NPROCESSORS_ONLN)

%:
	dh $@ --with autoreconf

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_MULTIARCH  ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

override_dh_auto_configure:
	dh_testdir
	# Add here commands to configure the package.
	CC_FOR_BUILD=cc ./configure \
		--host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/opt/alt/pcre/usr --mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) \
		--enable-utf8 --enable-unicode-properties \
		--enable-jit

override_dh_auto_build:
	iconv -f latin1 -t utf8 ChangeLog >ChangeLog.utf8
	touch --reference ChangeLog ChangeLog.utf8
	mv ChangeLog.utf8 ChangeLog
	$(MAKE) $(NJOBS) check VERBOSE=1

override_dh_auto_install:
	make install DESTDIR=$(CURDIR)/debian/tmp
	ln -fs /opt/alt/pcre/usr/lib/$(DEB_HOST_MULTIARCH)/libpcre.so.1 debian/tmp/opt/alt/pcre/usr/lib/$(DEB_HOST_MULTIARCH)/libpcre.so
	rm -f $(CURDIR)/debian/tmp/opt/alt/pcre/usr/lib/$(DEB_HOST_MULTIARCH)/*.la
	rm -rf $(CURDIR)/debian/tmp/opt/alt/pcre/usr/share/doc/pcre

override_dh_auto_clean:
	dh_testdir
	dh_testroot
	[ ! -f Makefile ] || $(MAKE) distclean
