#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

CONFFLAGS := -DENABLE_RTMP=TRUE -DAUDIO_BACKEND="pulse sdl"

ifeq ($(DEB_HOST_ARCH),powerpcspe)
	CONFFLAGS += -DDISABLE_ALTIVEC=TRUE
endif

UVER := $(shell dpkg-parsechangelog|sed -n '/^Version/{s/Version: \(.*\)/\1/p}'|cut -f1 -d-)

ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
	ALTLINK=/usr/lib/mozilla/plugins/flashplugin-alternative.so
	ALTNAME=mozilla-flashplugin
else
	ALTLINK=/usr/lib/mozilla/plugins/flash-mozilla.so
	ALTNAME=flash-mozilla.so
endif
INFILES := $(wildcard debian/*.in)
GENERATED := $(INFILES:.in=)

$(GENERATED):
	sed -e "s#@ALTLINK@#$(ALTLINK)#" -e "s#@ALTNAME@#$(ALTNAME)#" $@.in > $@

%:
	dh $@ --parallel

override_dh_auto_configure:
	dh_auto_configure -- $(CONFFLAGS)

override_dh_strip:
	dh_strip --dbg-package=lightspark-dbg

override_dh_install: $(GENERATED)
	dh_install --list-missing

override_dh_shlibdeps:
	export LD_LIBRARY_PATH="$(CURDIR)/debian/lightspark-common/usr/lib/lightspark:$$LD_LIBRARY_PATH" ; \
	    dh_shlibdeps -Llightspark-common \
	    -pbrowser-plugin-lightspark -plightspark \
	    -- -Ldebian/common.shlibs
	
	dh_shlibdeps --remaining-packages

override_dh_makeshlibs:
	dh_makeshlibs -X/usr/lib/lightspark

override_dh_clean:
	dh_clean
	rm -f $(GENERATED)

VER = $(UVER)+git$(shell date -u '+%Y%m%d')
TMPDIR = lightspark-$(VER)
get-orig-source:
	@echo Git cloning lightspark $(VER)...
	git clone --depth 1 https://github.com/lightspark/lightspark.git $(TMPDIR)
	@echo Generating tarball...
	cd $(TMPDIR) && tar --exclude .git -Jcf ../../lightspark_$(VER).orig.tar.xz .
	rm -rf $(TMPDIR) && dch -v $(VER)-1 "New upstream snapshot."
