#!/usr/bin/make -f

export DH_ALWAYS_EXCLUDE=.svn

LDFLAGS=-Wl,-z,defs -Wl,--as-needed -Wl,--no-undefined
CFLAGS=-std=gnu89

config: config-stamp
config-stamp: 
	dh_testdir
	[ ! -d debian/patches ] || $(MAKE) -f /usr/share/quilt/quilt.make patch
	touch $@

build: build-stamp
build-stamp: config
	dh_testdir
	cd camera/ && \
		gcc $(CFLAGS) -fPIC -c *.c
	cd camera/ && \
		gcc $(LDFLAGS) -shared *.o -lv4l2 -ldl -o so.CameraPlugin
	cd scratch/ && \
		gcc $(CFLAGS) -fPIC -c *.c
	cd scratch/ && \
		gcc $(LDFLAGS) -shared *.o -lm -o so.ScratchPlugin
	cd unicode/ && \
		gcc $(CFLAGS) -fPIC -c `pkg-config --cflags pangocairo` *.c
	cd unicode/ && \
		gcc $(LDFLAGS) -shared *.o `pkg-config --libs pangocairo` -lc -o so.UnicodePlugin
	cd wedo/ && \
		gcc $(CFLAGS) -fPIC -c *.c
	cd wedo/ && \
		gcc $(LDFLAGS) -shared *.o -o so.WeDoPlugin
	touch $@

clean: 
	dh_testdir
	dh_testroot
	rm -fv build-stamp config-stamp
	rm -fv camera/*.o camera/so.CameraPlugin
	rm -fv scratch/*.o scratch/so.ScratchPlugin
	rm -fv unicode/*.o unicode/so.UnicodePlugin
	rm -fv wedo/*.o wedo/so.WeDoPlugin
	rm -fv App/* Plugins/*
	[ ! -d debian/patches ] || $(MAKE) -f /usr/share/quilt/quilt.make unpatch
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

binary-indep:

binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs -a
	dh_installdocs -a
	dh_installexamples -a
	dh_install -a
	dh_installman -a
	dh_link -a
	dh_strip -a --dbg-package=squeak-plugins-scratch-dbg
	dh_compress -a
	dh_fixperms -a
#	dh_makeshlibs -a
	[ ! -e /usr/bin/dh_buildinfo ] || dh_buildinfo -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean
