#! /usr/bin/make -f

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

# C compiler information
CC=gcc
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif

INSTALL_PROGRAM=install
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
INSTALL_PROGRAM += -s
endif


all build:
	${MAKE} CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"
	touch stamp-build

clean:
	${MAKE} distclean
	rm -f stamp-build debian/files debian/substvars
	rm -rf debian/tmp

binary: binary-indep binary-arch

binary-indep:

binary-arch: checkroot
	-rm -rf debian/tmp debian/{files,substvars}
	test -f stamp-build || ${MAKE} -f debian/rules build

# Install executable
	install -d -o root -g root -m 755 $(tmpdir)/bin
	${INSTALL_PROGRAM} -p -o root -g root -m 755 fdflush $(tmpdir)/bin/

# Install manpages
	install -d -o root -g root -m 755 $(tmpdir)/usr/share/man/man8
	install -p -o root -g root -m 644 fdflush.8 $(tmpdir)/usr/share/man/man8/
	gzip -9 $(tmpdir)/usr/share/man/man8/*

# Install other documentation
	install -d -o root -g root -m 755 $(tmpdir)$(docdir)
	install -p -o root -g root -m 644 debian/changelog $(tmpdir)$(docdir)/changelog.Debian
	gzip -9 $(tmpdir)$(docdir)/*
	install -p -o root -g root -m 644 debian/copyright $(tmpdir)$(docdir)

# Build the package
	mkdir -p debian/tmp/DEBIAN
	dpkg-shlibdeps debian/tmp/bin/fdflush
	dpkg-gencontrol -isp
	dpkg --build debian/tmp ..

checkroot:
    test root = "`whoami`"

