#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/gnome.mk

# In order to regenerate 'debian/control' :
#   DEB_AUTO_UPDATE_DEBIAN_CONTROL=yes fakeroot debian/rules clean
# Then check manually if everything's ok


# note: explicit linking with libdl is missing (see #554692)
DEB_CONFIGURE_SCRIPT_ENV += LDFLAGS=" -Wl,-z,defs -Wl,-O1 -Wl,--as-needed -ldl"
export MOD_LDFLAGS=-Wl,-O1 -Wl,--as-needed
DEB_AC_AUX_DIR := $(DEB_SRCDIR)/config
DEB_MAKE_INSTALL_TARGET := install prefix=$(CURDIR)/debian/gnusound/usr
DEB_MAKE_CLEAN_TARGET := distclean


build/gnusound:: doc-gen-stamp
doc-gen-stamp:
	# generate documentation
	$(MAKE) -C $(DEB_BUILDDIR)/doc/ dist
	touch doc-gen-stamp

install/gnusound::
	# move .desktop file to right directory
	# (must be done early to be caught by dh_desktop)
	mkdir debian/gnusound/usr/share/applications/
	mv debian/gnusound/usr/share/gnome/apps/Multimedia/gnusound.desktop debian/gnusound/usr/share/applications/
	rm -rf debian/gnusound/usr/share/gnome/apps

binary-install/gnusound::
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	# Better stripping for modules
	find debian/gnusound/usr/lib/gnusound/modules/ -name "*.so" -type f -exec strip --remove-section=.comment --remove-section=.note --strip-unneeded {} \;
endif
	# Wrapper to set LADSPA_PATH
	mv debian/gnusound/usr/bin/gnusound debian/gnusound/usr/bin/gnusound.real
	cp debian/maintfiles/gnusound debian/gnusound/usr/bin/gnusound
	chmod a+x debian/gnusound/usr/bin/gnusound
	dh_link usr/share/man/man1/gnusound.1 usr/share/man/man1/gnusound.real.1

# _must_ be called in a rule, and not in debian/clean, because
# dh_clean is called before the makefile clean rule and would
# prevent make clean/distclean to work
clean::
	rm -f Makefile

