#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

PYVERS=$(shell pyversions -r debian/control)

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

configure: configure-stamp
configure-stamp:
	dh_testdir
	for python in $(PYVERS); \
		do CFLAGS="$(CFLAGS)" $$python config.py; \
	done
	touch $@

build: build-stamp
build-stamp:
	dh_testdir
	for python in $(PYVERS); \
		do $$python setup.py build; \
	done
	touch $@

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

	# We ignore errors, as if the build is already clean
	# (Setup has been removed) this command doesn't run
	-for python in $(PYVERS); \
		do $$python setup.py clean; \
	done
	# Other files that setup.py clean doesn't remove.
	rm -f *.pyc
	rm -fr build
	rm -f Setup

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	for python in $(PYVERS); \
		do $$python setup.py install \
			--root=$(CURDIR)/debian/python-pygame --prefix=/usr; \
	done

# We include all the documentation except:
# util (which is for building the docs from the source)
# fullinstall.txt (which is installation instructions)
# LGPL (which is in /usr/share/common-licenses/LGPL under Debian)
doclist = $(filter-out docs/util docs/fullinstall.txt docs/LGPL,$(wildcard docs/*))

binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_installdocs -a $(doclist)
	dh_installchangelogs -a WHATSNEW
	dh_bugfiles -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_pycentral -a
	#fix permission, replace freesansbold.ttf
	cd $(CURDIR)/debian/python-pygame/usr/share/pyshared/pygame/ && chmod a-x pygame_icon* pygame.ico && rm freesansbold.ttf && ln -s  /usr/share/fonts/truetype/freefont/FreeSansBold.ttf freesansbold.ttf
	# fix above link as well
	dh_link -a

	dh_installdeb -a
	dh_shlibdeps -a 
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary-indep:

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