#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

CFLAGS = -Wall -g -fPIC
CXXFLAGS = -fPIC

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

configure-stamp:
	dh_testdir
	AUTOMAKE=true LIBTOOLIZE=true AUTOHEADER=true dh_autoreconf
	dh_autotools-dev_updateconfig
	CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) \
        --build=$(DEB_BUILD_GNU_TYPE) \
        --prefix=/usr \
        --exec-prefix=/usr \
        --mandir=\$${prefix}/share/man \
        --sysconfdir=/etc \
        --datadir=\$${prefix}/share/ocp \
        --libdir=\$${prefix}/lib \
        --bindir=\$${prefix}/bin \
        --infodir=\$${prefix}/share/info \
        --with-x11 --with-dir-suffix= \
        --with-freepats=\$${prefix}/share/midi/freepats
	touch configure-stamp

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp

build-stamp: configure-stamp
	dh_testdir
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	[ ! -f Makefile ] || $(MAKE) clean distclean
	rm -f config.log config.status
	dh_autoreconf_clean
	dh_autotools-dev_restoreconfig
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	$(MAKE) install DESTDIR=$(CURDIR)/debian/opencubicplayer
	-mv debian/opencubicplayer/usr/share/doc/ocp/html/* \
            debian/opencubicplayer-doc/usr/share/doc/opencubicplayer-doc/html/
	-rm -rf debian/opencubicplayer/usr/share/doc/ocp
	cp debian/opencubicplayer32.xpm debian/opencubicplayer/usr/share/pixmaps/opencubicplayer.xpm
#	cp goodies/pack/pack $(CURDIR)/debian/opencubicplayer/usr/bin/pak
	rm -f debian/opencubicplayer/usr/bin/ultrafix.sh
	rm -rf debian/opencubicplayer/usr/share/ocp/ocp/
	rm -rf $(CURDIR)/debian/opencubicplayer/usr/share/info/dir*

# 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_installchangelogs
	dh_installdocs
	dh_installmenu
	dh_installman
	dh_link -popencubicplayer usr/share/man/man1/ocp.1 usr/share/man/man1/xocp.1
	dh_link -popencubicplayer usr/share/man/man1/ocp.1 usr/share/man/man1/ocp-curses.1
	dh_link -popencubicplayer usr/share/man/man1/ocp.1 usr/share/man/man1/ocp-sdl.1
	dh_link -popencubicplayer usr/share/man/man1/ocp.1 usr/share/man/man1/ocp-vcsa.1
	dh_link -popencubicplayer usr/share/man/man1/ocp.1 usr/share/man/man1/ocp-x11.1
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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