#!/usr/bin/make -f
# debian/rules file for smpeg

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

DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# Handle DEB_BUILD_OPTIONS
CFLAGS = -Wall -g

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

CXX = g++

config.status: configure
	dh_testdir
	
	# Work around aclocal.m4 getting patched before others
	# which matters on slow buildds
	touch aclocal.m4
	touch Makefile.in
	touch audio/Makefile.in
	touch video/Makefile.in
	touch config.h.in
	touch stamp-h.in
	touch configure
	
	CFLAGS="$(CFLAGS)" CXXFLAGS="$(CFLAGS)" CXX=$(CXX) ./configure \
	  --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
	  --prefix=/usr \
	  --enable-mmx=no \
	  --enable-opengl-player=no

build-indep:

build-arch: config.status
	dh_testdir
	
	$(MAKE)

build: build-arch build-indep

clean:
	dh_testdir
	dh_testroot
	
	[ ! -f Makefile ] ||$(MAKE) distclean
	
	dh_clean

install: DH_OPTIONS=-a
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	
	$(MAKE) install prefix=$(CURDIR)/debian/tmp/usr

	dh_movefiles

	# Make /usr/share/doc/libsmpeg-dev a symlink to libsmpeg0's docs
	ln -s libsmpeg0 debian/libsmpeg-dev/usr/share/doc/libsmpeg-dev

# Build architecture-independent files here.
binary-indep: build install
	# We have nothing to do here

# Build architecture-dependent files here.
binary-arch: DH_OPTIONS=-a
binary-arch: build install
	dh_testdir 
	dh_testroot 
	dh_installdocs README
	dh_installmenu
	dh_installman
	dh_installmime
	dh_installchangelogs -plibsmpeg0 -psmpeg-plaympeg -psmpeg-gtv CHANGES
	dh_strip 
	dh_compress 
	dh_fixperms
#	dh_makeshlibs -V
	dh_installdeb
	dh_shlibdeps -ldebian/libsmpeg0/usr/lib
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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