prefix = /usr/local
bindir = $(prefix)/bin
mandir = $(prefix)/share/man
datadir = $(prefix)/share
plugindir = $(datadir)/games/plugins

CC?=gcc
CFLAGS?= -O2 -s
NAME = kingslayer
VERSION?=`grep 'define VERSION' simple.c | sed -e 's/.*"\(.*\)".*/\1/'`

ALL= $(NAME) $(NAME).6.gz

all: ${ALL}

$(NAME): simple.c
	$(CC) $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) simple.c -o $(NAME)

install: ${ALL}
	install -d -m0755 $(DESTDIR)$(bindir)
	cp $(NAME) $(DESTDIR)$(bindir)
	install -d -m0755 $(DESTDIR)$(mandir)/man6
	cp $(NAME).6.gz $(DESTDIR)$(mandir)/man6
	install -d -m0755 $(DESTDIR)$(plugindir)/logos
	cp data/logo.png $(DESTDIR)$(plugindir)/logos/$(NAME).png
	install -d -m0755 $(DESTDIR)$(plugindir)/xboard
	cp data/*.eng $(DESTDIR)$(plugindir)/xboard

$(NAME).6.gz: $(NAME).pod
	pod2man -s 6 $(NAME).pod | gzip -9n > $(NAME).6.gz

clean:
	rm -f ${ALL}

dist-clean:
	rm -f ${ALL} *~ data/*~ *.man md5sums

dist: ${ALL}
	install -d -m0755 Simple
	install -d -m0755 Simple/data
	rm -f $(NAME).tar $(NAME).tar.gz
	cp simple.c $(NAME).pod Makefile README changelog copyright Simple
	cp data/* Simple/data
	(md5sum Simple/* Simple/data/* > Simple/md5sums) || true
	tar -cvvf $(NAME)-$(VERSION).tar Simple
	gzip $(NAME)-$(VERSION).tar
	rm $(NAME)
	rm Simple/data/*
	rmdir Simple/data
	rm Simple/*
	rmdir Simple

uninstall:
	rm -f $(DESTDIR)$(plugindir)/logos/$(NAME).png
	rm -f $(DESTDIR)$(plugindir)/xboard/$(NAME).eng
	rm -f $(DESTDIR)$(mandir)/man6/$(NAME).6.gz
	rm -f $(DESTDIR)$(bindir)/$(NAME)

