#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. 
# GNU copyright 1997 by Joey Hess.
#
# This version is for a hypothetical package that builds an
# architecture-dependant package, as well as an architecture-independent
# package.

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

# This is the debhelper compatability version to use.
export DH_COMPAT=3

# This has to be exported to make some magic below work.
export DH_OPTIONS

FRIBIDI_UDEB=lib-renpy-fribidi0-udeb
DEBVERSION=$(shell dpkg-parsechangelog | grep '^Version: ' | sed -e 's/^Version: //')
UDEBNAME=$(FRIBIDI_UDEB)_$(DEBVERSION)_$(shell dpkg --print-architecture).udeb

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
OBJS += xmalloc.o
STRIP= /bin/true
else
STRIPTOOL=strip
STRIP= $(STRIPTOOL) --remove-section=.note --remove-section=.comment
endif

build: build-stamp
build-stamp:
	dh_testdir

	$(MAKE)
	$(MAKE) build

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	-$(MAKE) clean

	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) install

# Build architecture-independent files here.
# Pass -i to all debhelper commands in this target to reduce clutter.
binary-indep: 

# Build architecture-dependent files here.
# Pass -a to all debhelper commands in this target to reduce clutter.
binary-arch: DH_OPTIONS=-a
binary-arch: build install
	# Need this version of debhelper for DH_OPTIONS to work.
	dh_testdir
	dh_testroot

	dh_movefiles

	dh_installdocs -a -N$(FRIBIDI_UDEB)
	dh_installman -a -N$(FRIBIDI_UDEB)
	dh_installchangelogs fribidi-0.19.2/ChangeLog -a -N$(FRIBIDI_UDEB)
	mkdir -p debian/$(FRIBIDI_UDEB)/lib
	cp -a debian/lib-renpy-fribidi0/usr/lib/*.so.0.* debian/$(FRIBIDI_UDEB)/lib
	$(STRIP) debian/$(FRIBIDI_UDEB)/lib/libfribidi.so.0.3.1
	dh_strip
	dh_link
	dh_compress
	dh_fixperms
	dh_makeshlibs -N$(FRIBIDI_UDEB)
	dh_shlibdeps -Xusr/bin/fribidi -N$(FRIBIDI_UDEB)
	dh_installdeb -N$(FRIBIDI_UDEB)
	dh_gencontrol -a -N$(FRIBIDI_UDEB)
	dh_md5sums -a -N$(FRIBIDI_UDEB)
	dh_builddeb -a -N$(FRIBIDI_UDEB)
	dh_gencontrol -p$(FRIBIDI_UDEB) -- -fdebian/files~
	dpkg-distaddfile $(UDEBNAME) debian-installer extra
	dh_builddeb $(FRIBIDI_UDEB) --filename=$(UDEBNAME)

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