#!/usr/bin/make -f

SHELL = /bin/bash

package = fortunes-bg

source = bgauthors intauthors bgproverb intproverb history others
compiled = $(source:%=%.dat)
u8 = $(source:%=%.u8)

FORTUNEROOT=/usr/share/games/fortunes

build: $(compiled) $(u8)
	rm -r bg/
	mkdir bg
	cp -d $(source) $(compiled) $(u8) bg/

install: build
	cp -r bg/ $(FORTUNEROOT)/

%.dat: %
	strfile $<

%.u8: %
	ln -s $< $@

clean:
	$(checkdir)
	-rm -rf *~ tmp files* substvars
	-rm -f *.dat *.u8

binary-indep:	checkroot build
	$(checkdir)
	-rm -rf tmp
	install -d tmp/DEBIAN
	install -d tmp/usr/share/doc/$(package)
	cp copyright tmp/usr/share/doc/$(package)
	cp changelog tmp/usr/share/doc/$(package)/changelog
	gzip -9v tmp/usr/share/doc/$(package)/changelog
	install -d tmp/usr/share/games/fortunes/bg/
	cp -d $(source) $(compiled) $(u8) tmp/usr/share/games/fortunes/bg/
	dpkg-gencontrol -isp
	chown -R root.root tmp
	chmod -R go=rX,u=rwX tmp
	dpkg --build tmp ..

binary-arch:	checkroot build
	$(checkdir)

define checkdir
	test -f bgauthors -a -f debian/rules
endef

binary:		binary-indep binary-arch

checkroot:
	$(checkdir)
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot

