#!/usr/bin/make -f

-include /usr/share/dpkg/buildtools.mk
STRIP ?= strip

tmp=$(shell pwd)/debian/leave

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  stripflag=-s --strip-program=$(STRIP)
endif

leave: leave.c
	$(CC) $(shell dpkg-buildflags --get CFLAGS) -D__COPYRIGHT\(x\)= -D__RCSID\(x\)= leave.c -o leave
# used to have 'pmake CFLAGS="..." leave' here, but why?

build: leave
build-arch: build
build-indep: build

clean:
	rm -f build-stamp leave leave.o leave.cat1 debian/files debian/substvars
	rm -rf $(tmp)

binary-arch binary: build
	rm -rf $(tmp)
	install -d -m 755 $(tmp)/usr/bin $(tmp)/usr/share/man/man1 \
		$(tmp)/DEBIAN $(tmp)/usr/share/doc/leave
	install $(stripflag) -m 755 leave $(tmp)/usr/bin
	gzip -c9n leave.1 > $(tmp)/usr/share/man/man1/leave.1.gz
	gzip -c9n debian/changelog > $(tmp)/usr/share/doc/leave/changelog.Debian.gz
	install -m 644 debian/copyright $(tmp)/usr/share/doc/leave
	dpkg-shlibdeps $(tmp)/usr/bin/leave
	dpkg-gencontrol -isp -P$(tmp)
	chmod -R g-ws $(tmp)
	dpkg-deb --root-owner-group --build $(tmp) ..

binary-indep:
# do nothing, successfully!
