#!/usr/bin/make -f

DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

ifeq ($(DEB_BUILD_ARCH),i386)
additional_confflags := --disable-sse2
endif

%:
	dh $@ --parallel

override_dh_auto_configure:
	ln -sf /usr/share/misc/config.sub .
	ln -sf /usr/share/misc/config.guess .
	dh_auto_configure -- --disable-rpath --enable-chardet $(additional_confflags)

override_dh_auto_clean:
	dh_auto_clean
	rm -f man/*.1 config.status config.log config.h *.pc buildsys.mk
	rm -f src/audacious/dbus-client-bindings.h src/audacious/dbus-server-bindings.h
	find -name '.deps' -delete
	# Drop this png file cleanup after the next upstream release (probably 2.4)
	rm -f pixmaps/*.png src/audacious/images/audacious_player.xpm

override_dh_auto_build:
	# Change build id from UNSUPPORTED VERSION to <vendor> package
	echo "const char *build_stamp = \"$(shell dpkg-vendor --query vendor) package\";" > src/audacious/build_stamp.c;
	# Drop this png file creation after the next upstream release (probably 2.4)
	for size in 16 22 32 36; do \
		rsvg -h $${size} -w $${size} pixmaps/audacious.svg pixmaps/audacious-$${size}.png || exit 1; \
	done
	rsvg pixmaps/audacious.svg pixmaps/audacious.png
	convert -bordercolor Transparent -border 1x1 pixmaps/audacious-22.png pixmaps/audacious-24.png
	convert pixmaps/audacious.png src/audacious/images/audacious_player.xpm
	sed -i "s/audacious_player/audacious_player_xpm/" src/audacious/images/audacious_player.xpm
	dh_auto_build --parallel

override_dh_strip:
	dh_strip --dbg-package=audacious-dbg

override_dh_installdirs:
	dh_installdirs
	mkdir -p debian/tmp/usr/share/pixmaps
	convert pixmaps/audacious-16.png debian/tmp/usr/share/pixmaps/audacious-16.xpm
	convert pixmaps/audacious-32.png debian/tmp/usr/share/pixmaps/audacious-32.xpm

override_dh_install:
	dh_install
	dh_link usr/share/man/man1/audacious2.1 usr/share/man/man1/audacious.1
	dh_link usr/share/man/man1/audtool2.1 usr/share/man/man1/audtool.1
