#!/usr/bin/make -f
NJOBS := $(shell echo ${DEB_BUILD_OPTIONS} | sed -rn 's/.*parallel=([0-9]*).*/\1/p')
FMEDIAINFO := $(shell dpkg -l | grep mediainfo >/dev/null && echo "-i" || echo " ")
DPKGXZ := $(shell cat /etc/issue | grep "Ubuntu 21.10\|Kinetic Kudu\|Ubuntu 22\|Jammy Jellyfish\|Impish Indri" >/dev/null && echo "-- -Zxz" || echo "")


build: build-stamp
build-stamp:
	dh_testdir
	./depot_tools/ninja -j $(NJOBS) -C out pdfium
	touch build-stamp
	#clean all unrequired stuff
	#rm -rf `ls | grep -v "out\|public"`

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

install: build
	dh_install out/obj/libpdfium.a /usr/lib/
	for i in `find public -type f`; do a=`echo $$i | awk -F "/" 'BEGIN{OFS="/"}{NF--;print $$0}' | sed "s#public##g"`; dh_install $$i /usr/include/$$a; done

# Build architecture-independent files here.
binary-indep: build install
	# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
	dh_installcron
	dh_installman
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs
	dh_link
#	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb $(DPKGXZ)

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

