#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

IMGPV="1.4.14.2616"

build:

clean:
	dh_testdir
	dh_testroot
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	# attempt to create proper library softlinks
	install -d debian/tmp/usr/lib/gfx_rel_es2.x
	install -d debian/tmp/usr/lib/gfx_rel_es3.x
	install -d debian/tmp/usr/lib/gfx_rel_es5.x
	for lib in gfx_rel_es2.x/*.so gfx_rel_es3.x/*.so gfx_rel_es5.x/*.so; do \
		cp $$lib debian/tmp/usr/lib/$$lib.$(IMGPV) ; \
		ln -s /usr/lib/$$lib.$(IMGPV) \
			debian/tmp/usr/lib/$$lib ; \
		ln -s /usr/lib/$$lib.$(IMGPV) \
			debian/tmp/usr/lib/$$lib$$(echo $(IMGPV) | awk -F. '{print "." $$1}') ; \
	done
	# to be compatible with libgles2-mesa
	for dir in gfx_rel_es2.x gfx_rel_es3.x gfx_rel_es5.x; do \
		ln -s /usr/lib/$$dir/libGLESv2.so.$(IMGPV) debian/tmp/usr/lib/$$dir/libGLESv2.so.2 ; \
	done
	# to be compatible with the newer library name (that doesn't include the EGL entry points)
	for dir in gfx_rel_es2.x gfx_rel_es3.x gfx_rel_es5.x; do \
		ln -s /usr/lib/$$dir/libGLES_CM.so.$(IMGPV) debian/tmp/usr/lib/$$dir/libGLESv1_CM.so ; \
		ln -s /usr/lib/$$dir/libGLES_CM.so.$(IMGPV) debian/tmp/usr/lib/$$dir/libGLESv1_CM.so.1 ; \
	done
	# bins
	install -d debian/tmp/usr/bin
	for dir in gfx_rel_es2.x gfx_rel_es3.x gfx_rel_es5.x; do \
		cp $$dir/pvrsrvinit debian/tmp/usr/bin/pvrsrvinit$$(echo $$dir | sed -e 's/^[a-z_]*//g') ; \
		cp $$dir/pvr2d_test debian/tmp/usr/bin/pvr2d_test$$(echo $$dir | sed -e 's/^[a-z_]*//g') ; \
	done
	dh_install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs -s
	dh_installudev -s --priority=50
	dh_installchangelogs -s
	dh_installinit -s --error-handler=true
	dh_lintian
	dh_strip -plibegl1-sgx-omap3 --dbg-package=libegl1-sgx-omap3-dbg
	dh_strip -plibgles1-sgx-omap3 --dbg-package=libgles1-sgx-omap3-dbg
	dh_strip -plibgles2-sgx-omap3 --dbg-package=libgles2-sgx-omap3-dbg
	dh_strip -plibopenvg1-sgx-omap3 --dbg-package=libopenvg1-sgx-omap3-dbg
	dh_strip -popengles-sgx-omap3 --dbg-package=opengles-sgx-omap3-dbg
	dh_link -s
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_shlibdeps
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep:

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