#!/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

%:
	dh $@

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)"
	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
