#!/usr/bin/make -f
# debian/rules file for jed-extra
# GNU copyright 2003 by Rafael Laboissiere <rafael@debian.org>

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

sl_files =                  \
    ispell/flyspell.sl      \
    ispell/ispell_common.sl \
    ispell/ispell.sl        \
    ispell/vispell.sl       \
    ispell/look.sl          \
    sl_utils/bufutils.sl    \
    sl_utils/csvutils.sl    \
    sl_utils/datutils.sl    \
    sl_utils/sl_utils.sl    \
    sl_utils/strutils.sl    \
    sl_utils/txtutils.sl

slc_files = $(sl_files:%.sl=%.slc)

jed_root = /usr/share/jed
debroot = $(shell pwd)/debian/jed-extra
site_lib_dir = $(jed_root)/site-lib
jed_init_dir = /etc/jed-init.d

untar:
	dh_testdir
	tar xfz ispell.tgz
	mkdir -p sl_utils
	( cd sl_utils ; tar xfz ../sl_utils.tar.gz )
	tar xfz home-lib.tgz

patch:
	dh_testdir
	@for i in `find patch -name \*.patch` ; do \
	    echo Applying patch $$i ; \
	    patch -p0 --no-backup-if-mismatch < $$i ; \
	done

byte-compile:
	echo $(sl_files) | eperl compile-files.sl.in -o compile-files.sl
	jed -batch -l ./compile-files.sl

build: build-stamp
build-stamp: untar patch byte-compile
	dh_testdir
	touch build-stamp

clean:
	dh_testdir
	dh_testroot

	rm -rf ispell sl_utils home-lib compile-files.sl build-stamp

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs $(site_lib_dir) $(jed_init_dir)

	install --mode=644 $(sl_files) $(slc_files) $(debroot)$(site_lib_dir)
	install --mode=644 home-lib/home-lib.sl \
	    $(debroot)$(jed_init_dir)/05home-lib.sl
	install --mode=644 ispell/ispell_init.sl \
	    $(debroot)$(jed_init_dir)/55ispell.sl


# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
#	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
#	dh_installman
#	dh_link
#	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	dh_installdeb
#	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch:
# We have nothing to do by default.

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install untar patch \
    byte-compile
