#!/usr/bin/make -f

export DH_VERBOSE=1

DEB_CFLAGS_MAINT_APPEND := -Wall -fno-strict-aliasing

%:
	dh $@ --parallel --with autoreconf --with autotools_dev

override_dh_auto_build:
	# Get rid of rpath
	set -e; \
	 tmpfile=`mktemp`; \
	 sed "s/^REP_LIBS=\(.*\)-Wl,--rpath -Wl,[^ ]* \(.*\)$$/REP_LIBS=\1 \2/" Makedefs >$$tmpfile ;\
	 mv $$tmpfile Makedefs
	dh_auto_build -O--parallel

override_dh_auto_install:
	dh_auto_install -O--parallel
	# Fixup libdir in .la files
	find debian/tmp -name \*.la | while read file; do \
	  libdir=`echo $$file | sed -e 's@debian/tmp\(.*\)/[^/]*la$$@\1@' `; \
	  tmpfile=`mktemp`; \
	  sed "s@^libdir=.*@libdir='$$libdir'@" $$file >$$tmpfile; \
	  mv $$tmpfile $$file; \
	done

	# Remove info files installed by Makefile. dh_installinfo will do it again without creating info.dir
	find debian -type d -name info | xargs rm -rf
	#empty dependency_libs file in la files
	find debian/tmp/usr/lib -name *.la | xargs \
		sed -i "/dependency_libs/ s/'.*'/''/"


override_dh_install:
	[ ! -f debian/sawfish-lisp-source.install ] || rm debian/sawfish-lisp-source.install
	find debian/tmp/usr/share/sawfish/lisp -name \*.jl | \
	 cut -d/ -f3- | grep -v 'autoload\|custom-defaults' > debian/sawfish-lisp-source.install

	cp debian/sawfish-data.install.in debian/sawfish-data.install
	find debian/tmp/usr/share/sawfish/lisp -name \*.jlc | \
	 cut -d/ -f3- | grep -v 'main' >> debian/sawfish-data.install

	#dh_install --fail-missing
	dh_install --list-missing
