#! /usr/bin/make -f

# Debian package information
package		= gtoaster
docdir		= /usr/share/doc/$(package)
tmpdir		= $(shell pwd)/debian/tmp

# C compiler information
CC		= gcc
CFLAGS		= -g -O2
LDFLAGS		= -s
build: configure
	./configure --prefix=/usr/share --exec-prefix=/usr --with-gnome
	make
	touch build

configure: configure.in
	aclocal
	autoheader
	automake --gnu Makefile
	autoconf

.PHONY: clean
clean:
	rm -f build
	-make distclean
	-rm -rf debian/tmp debian/{files,substvars}

.PHONY: binary
binary: binary-indep binary-arch

.PHONY: binary-indep
binary-indep:
	@echo Close, but no sigar.


.PHONY: binary-arch
binary-arch: build
	-rm -rf debian/tmp debian/{files,substvars}

	install -d -m 755 -o root -g root debian/tmp/var/cdfs
# Install gtoaster
	install -d -m 755 -o root -g root debian/tmp/usr/bin
	install -s -m 755 -o root -g root gtoaster debian/tmp/usr/bin/
# Install the documentation
	install -d -m 755 -o root -g root debian/tmp$(docdir)/html
	install -p -m 644 -o root -g root Documentation/*html \
			debian/tmp$(docdir)/html/
	install -p -m 644 -o root -g root Documentation/*txt debian/tmp$(docdir)
	install -p -m 644 -o root -g root Documentation/*sgml debian/tmp$(docdir)
	install -p -m 644 -o root -g root README TODO debian/tmp$(docdir)

	install -d -m 755 -o root -g root debian/tmp/usr/share/man/man1
	ln -s ../man7/undocumented.7.gz debian/tmp/usr/share/man/man1/gtoaster.1.gz

# Generate the changelog with the current builddate
	sed -e "s/@VERSION@/0.`date +%Y%m%d`/g" -e "s/@DATE@/`date -R`/" \
		debian/changelog.in > debian/changelog

# Install Debian-specific stuff
	install -d -m 755 -o root -g root debian/tmp/usr/share/doc-base
	install -p -m 644 -o root -g root debian/doc-base \
			debian/tmp/usr/share/doc-base/$(package)

	install -p -m 644 -o root -g root debian/changelog \
			debian/tmp$(docdir)/changelog.Debian
	# We expect an error here for the html-subdirectory
	-gzip -9 debian/tmp$(docdir)/*
	install -p -m 644 -o root -g root debian/copyright debian/tmp$(docdir)

	install -d -o root -g root -m 755 $(tmpdir)/DEBIAN
	install -p -o root -g root -m 755 debian/postinst $(tmpdir)/DEBIAN
	install -p -o root -g root -m 755 debian/prerm $(tmpdir)/DEBIAN

# Build the package
	dpkg-shlibdeps gtoaster
	dpkg-gencontrol -isp
	dpkg --build debian/tmp ..

