#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#DH_VERBOSE = 1

# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

REALVERSION = $(shell dpkg-parsechangelog | grep '^Version: ' | sed -n 's/^Version: \([.0-9]*\).*/\1/p')
UPVERSION = $(REALVERSION)
FFMPEGVERSION = 2.1.3
DATE = 2016-08-10 17:15:24 -0600
SRC_URI = https://github.com/stepmania/stepmania/archive/v$(UPVERSION).tar.gz


# main packaging script based on dh7 syntax
%:
	dh $@ --parallel

override_dh_auto_configure:
	tar jxf $(CURDIR)/debian/ffmpeg-$(FFMPEGVERSION).tar.bz2
	mv ffmpeg-$(FFMPEGVERSION) \
		$(CURDIR)/extern/ffmpeg-linux-$(FFMPEGVERSION)
	dh_auto_configure --buildsystem=cmake -- \
		-DWITH_MINIMAID=OFF \
		-DWITH_CRYSTALHD_DISABLED=ON

override_dh_auto_test:

override_dh_auto_install:

override_dh_auto_clean:
	dh_auto_clean --buildsystem=cmake --parallel
	rm -fr \
		src/generated \
		stepmania \
		GtkModule.so \
		ffmpeg-$(FFMPEGVERSION) \
		extern/ffmpeg-linux-$(FFMPEGVERSION)

get-orig-source:
	rm -fr \
		stepmania-$(UPVERSION) \
		stepmania_$(REALVERSION)+dfsg \
		v$(UPVERSION).tar.gz \
		stepmania_$(REALVERSION)+dfsg.orig.tar.xz
	wget $(SRC_URI)
	tar zxf v$(UPVERSION).tar.gz
	mv stepmania-$(UPVERSION) stepmania_$(REALVERSION)+dfsg
	rm -fr \
		stepmania_$(REALVERSION)+dfsg/Program/* \
		stepmania_$(REALVERSION)+dfsg/Xcode/* \
		stepmania_$(REALVERSION)+dfsg/Utils/* \
		stepmania_$(REALVERSION)+dfsg/extern/ffmpeg/* \
		stepmania_$(REALVERSION)+dfsg/extern/for_mingw/* \
		stepmania_$(REALVERSION)+dfsg/extern/glew*/* \
		stepmania_$(REALVERSION)+dfsg/extern/libjpeg/* \
		stepmania_$(REALVERSION)+dfsg/extern/libmmmagic/* \
		stepmania_$(REALVERSION)+dfsg/extern/libpng/* \
		stepmania_$(REALVERSION)+dfsg/extern/mad*/* \
		stepmania_$(REALVERSION)+dfsg/extern/newogg/* \
		stepmania_$(REALVERSION)+dfsg/extern/newvorbis/* \
		stepmania_$(REALVERSION)+dfsg/extern/pcre/* \
		stepmania_$(REALVERSION)+dfsg/extern/zlib/* \
		stepmania_$(REALVERSION)+dfsg/Docs/license-ext/vlgothic \
		stepmania_$(REALVERSION)+dfsg/Docs/Copying.MAD
	touch -d "$(DATE)" \
		stepmania_$(REALVERSION)+dfsg/Program \
		stepmania_$(REALVERSION)+dfsg/Xcode \
		stepmania_$(REALVERSION)+dfsg/Utils \
		stepmania_$(REALVERSION)+dfsg/extern/ffmpeg \
		stepmania_$(REALVERSION)+dfsg/extern/for_mingw \
		stepmania_$(REALVERSION)+dfsg/extern/glew* \
		stepmania_$(REALVERSION)+dfsg/extern/libjpeg \
		stepmania_$(REALVERSION)+dfsg/extern/libmmmagic \
		stepmania_$(REALVERSION)+dfsg/extern/libpng \
		stepmania_$(REALVERSION)+dfsg/extern/mad* \
		stepmania_$(REALVERSION)+dfsg/extern/newogg \
		stepmania_$(REALVERSION)+dfsg/extern/newvorbis \
		stepmania_$(REALVERSION)+dfsg/extern/pcre \
		stepmania_$(REALVERSION)+dfsg/extern/zlib \
		stepmania_$(REALVERSION)+dfsg/extern \
		stepmania_$(REALVERSION)+dfsg/Docs/license-ext \
		stepmania_$(REALVERSION)+dfsg/Docs \
		stepmania_$(REALVERSION)+dfsg
	find stepmania_$(REALVERSION)+dfsg -exec chmod g-w {} \;
	chmod -x stepmania_$(REALVERSION)+dfsg/Themes/_fallback/Graphics/CreditsLogo\ kyzentun.png
	tar cf - stepmania_$(REALVERSION)+dfsg | xz -9e > stepmania_$(REALVERSION)+dfsg.orig.tar.xz
	rm -fr \
		stepmania_$(REALVERSION)+dfsg \
		v$(UPVERSION).tar.gz

override_dh_strip:
	dh_strip --no-automatic-dbgsym
