
PACKAGE = sequoyah
VERSION = 1.0

DESTDIR =
PREFIX = $(DESTDIR)/usr/local
PACKAGE_DIR = $(PREFIX)/share/$(PACKAGE)

DIST_FILES = AUTHORS COPYING ChangeLog Doxyfile Makefile NEWS README.md \
	     config.h doxy sequoyah-map.txt sequoyah.1 sequoyah.c \
	     sequoyah.dat sequoyah.html sequoyah.l

CFLAGS = -O2 -Wall -pedantic

all: sequoyah

sequoyah.c: sequoyah.l config.h

sequoyah.o: sequoyah.c

sequoyah: sequoyah.o
	$(CC) $(CFLAGS) sequoyah.o -o sequoyah

check: sequoyah sequoyah-map.txt
	@ echo "Checking for Cherokee --> ASCII --> Cherokee round-trip converson..."
	./sequoyah -i sequoyah-map.txt   -o sequoyah2ascii.txt
	./sequoyah -i sequoyah2ascii.txt -o round-trip.txt
	@ - cmp sequoyah-map.txt round-trip.txt && \
	   echo "*** Round-trip conversion test [32mPASSED[0m" || \
	   echo "*** Round-trip conversion test [31mFAILED[0m"

doxy/html/index.html: README.md sequoyah.l config.h Makefile
	doxygen

sequoyah.html: doxy/html/index.html
	rm -f sequoyah.html
	ln -s doxy/html/index.html sequoyah.html

doxy: doxy/html/index.html sequoyah.html

install: sequoyah
	install -d -m 0755 $(PREFIX)/bin
	install    -m 0755 sequoyah $(PREFIX)/bin
	install -d -m 0755 $(PREFIX)/share/man/man1
	install    -m 0644 sequoyah.1 $(PREFIX)/share/man/man1
	install -d -m 0755 $(PACKAGE_DIR)
	tar cf - doxy sequoyah-map.txt sequoyah.dat sequoyah.html | \
	   (cd $(PACKAGE_DIR) ; tar xpf -)

uninstall:
	rm -f $(PREFIX)/bin/sequoyah
	rm -f $(PREFIX)/share/man/man1/sequoyah.1
	rm -rf $(PACKAGE_DIR)

clean:
	rm -f sequoyah.o
	rm -f sequoyah2ascii.txt round-trip.txt

distclean: clean
	rm -f sequoyah

dist:
	cd .. && \
	rm -f $(PACKAGE)-$(VERSION).tar && \
	touch $(PACKAGE)-$(VERSION).tar && \
	for i in $(DIST_FILES) ; do \
	   tar rf $(PACKAGE)-$(VERSION).tar $(PACKAGE)-$(VERSION)/$$i ; \
	done && \
	rm -f $(PACKAGE)-$(VERSION).tar.gz && \
	gzip -9 $(PACKAGE)-$(VERSION).tar

.PHONY: all check clean distclean doxy install uninstall
