#!/usr/bin/make -f

#export DH_VERBOSE=1

COMMON_OPTIONS = --srcdir=.. --program-transform-name='s/\.pl//'
COMMON_OPTIONS_normal = --with-mesa --without-opengl
COMMON_OPTIONS_opengl = --without-mesa

LDFLAGS ?=
LDFLAGS += -Wl,-z,defs -Wl,--as-needed

%:
	dh $@ --parallel

override_dh_auto_configure: normal/config.status opengl/config.status

%/config.status: configure
	dh_testdir
	mkdir $(@D)
	dh_auto_configure --builddirectory=$(@D) -- $(COMMON_OPTIONS) \
	    $(if $(findstring $(@D),opengl),$(COMMON_OPTIONS_opengl),$(COMMON_OPTIONS_normal)) \
	    LDFLAGS="$(LDFLAGS)"

override_dh_auto_build:
	dh_auto_build --builddirectory=normal
	dh_auto_build --builddirectory=opengl

override_dh_auto_install:
	dh_auto_install --builddirectory=normal -- DESTDIR=$(CURDIR)/debian/xmakemol
	dh_auto_install --builddirectory=opengl -- DESTDIR=$(CURDIR)/debian/xmakemol-gl
	# When upstream adds the xmake_anim.pl.1 manpage to the man_MANS variable
	# we can remove the following steps - the --program-transform-name
	# configure option will do everything for us.
	install xmake_anim.pl.1 $(CURDIR)/debian/xmakemol/usr/share/man/man1/xmake_anim.1
	install xmake_anim.pl.1 $(CURDIR)/debian/xmakemol-gl/usr/share/man/man1/xmake_anim.1

override_dh_auto_clean:
	dh_auto_clean
	$(RM) -r normal/ opengl/

override_dh_clean:
	dh_clean config.h

override_dh_installchangelogs:
	dh_installchangelogs -A NEWS

override_dh_installdocs:
	dh_installdocs -A PROBLEMS README xmakemol.html xmakemol.txt

override_dh_install:
	dh_install -A debian/xmakemol.desktop usr/share/applications/

override_dh_installexamples:
	dh_installexamples -A examples/*
