#!/usr/bin/make -f

export PDP_EXTRA_CFLAGS = -fPIC -Wno-error $(CPPFLAGS) $(CFLAGS)

ifeq ($(DEB_BUILD_ARCH),i386)
DEB_CONFIGURE_EXTRA_FLAGS = --enable-mmx
endif

ifeq ($(DEB_BUILD_ARCH),amd64)
DEB_CONFIGURE_EXTRA_FLAGS = --enable-mmx
endif

%:
	dh $@ --with autoreconf

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS)

override_dh_auto_build:
	dh build --before dh_auto_build
	make pdp_all
#	make -C opengl \
#		LDFLAGS="$(LDFLAGS)" \
#		ADDITIONAL_CFLAGS="$(CFLAGS)" \
#		ADDITIONAL_CPPFLAGS="$(CPPFLAGS)"
	docbook-to-man debian/pdp-config.sgml > pdp-config.1
	dh build --after dh_auto_build

override_dh_auto_clean:
	dh clean --before dh_auto_clean
#	[ ! -f opengl/Makefile.config ] || make -C opengl clean
	[ ! -f Makefile.config ] || make clean
	-$(RM) -rf bin/pdp-config include/pdp_config.h
	-$(RM) -f Makefile.config config.log config.status
	-$(RM) -f pdp-config.1
	dh clean --after dh_auto_clean

override_dh_installchangelogs:
	dh_installchangelogs CHANGES.LOG

override_dh_shlibdeps:
	find debian/pd-pdp -name "*.pd_linux" -exec \
		dpkg-shlibdeps -Tdebian/pd-pdp.substvars {} +

override_dh_strip:
	dh_strip
	find debian -name "*.pd_linux" -exec \
		strip --remove-section=.comment --remove-section=.note --strip-unneeded {} +

override_dh_fixperms:
	dh_fixperms
	find debian -name '*.pd_linux' -exec \
		chmod 0644 {} +
