#!/usr/bin/make -f

export REPACK_SH=$(CURDIR)/debian/repack.sh

%:
	dh $@ --parallel --with python2,autoreconf

override_dh_auto_configure:
	dh_auto_configure -- --disable-rpath --disable-static --libexecdir=/usr/bin --libdir=/usr/lib/idjc

override_dh_auto_build:
ifneq (,$(findstring doopt,$(DEB_BUILD_OPTIONS)))
# do optimization for the different architectures
ifneq (,$(findstring i386,$(DEB_BUILD_ARCH)))
	OPTI_FLAGS := -D_REENTRANT -O3 -fomit-frame-pointer -ffast-math -fstrength-reduce -funroll-loops -mmmx -msse -mfpmath=sse -march=pentium4
	CXXFLAGS += $(OPTI_FLAGS)
	CFLAGS += $(OPTI_FLAGS)
endif
endif
	dh_auto_build

override_dh_auto_clean:
	rm -f AUTHORS.gz  ChangeLog.gz  NEWS.gz  README.gz
	rm -f idjcctrl idjcskype idjc
	rm -f artwork/idjc.png
	rm -fr libshout
	dh_auto_clean
#	rm -fv idjcpython/idjc_config.py

override_dh_auto_install:
	dh_auto_install
	dh_installdirs -pidjc usr/share/doc/idjc/html
	cp -a doc/* debian/idjc/usr/share/doc/idjc/html/
	# Delete auto-installed docs in wrong dir (rather than patching Makefiles)
	rm -rf debian/idjc/usr/share/doc/idjc-*
	# Fix pyexecdir path
	sed -i -e 's/\(pyexecdir=\)\(.*\)/\1\/usr\/share\/pyshared/' \
		debian/idjc/usr/bin/idjc
	sed -i -e 's/\(pkgpyexecdir=\)\(.*\)/\1\/usr\/share\/pyshared\/idjc/' \
		debian/idjc/usr/bin/idjc
	# Fix permission problem
	-chmod u+x debian/idjc/usr/lib/python*/*-packages/idjc/IDJCmultitagger.py
	# remove pyc files
	find debian/idjc/ -name \*.pyc -exec rm -v {} +
	find debian/idjc -type d -empty -delete
	# remove la file
	rm -f debian/idjc/usr/lib/idjc/idjc.la

override_dh_makeshlibs:
	# don't generate ldconfig calls for private libraries
	dh_makeshlibs -Xusr/lib/idjc

get-orig-source:
	uscan --force-download
