# Makefile for rot13: read *all* of INSTALL first!

prefix = /usr/local
mandir = $(prefix)/man/man1
bindir = $(prefix)/bin
srcdir = .
VPATH  = $(srcdir)
SHELL  = /bin/sh

RM = rm -f
CC = gcc
CFLAGS = -O2 -Wall
LDFLAGS = -N -s
INSTALL_DATA = install -m 644
INSTALL_PROG = install -m 755

.PHONY: all clean clobber distclean doc test install uninstall

all: rot13

rot13: rot13.c
	$(CC) $(CFLAGS) -o rot13 $(srcdir)/rot13.c $(LDFLAGS)

doc: rot13.doc

rot13.doc: rot13.1
	groff -man $(srcdir)/rot13.1 | sed 's/.//g' >rot13.doc

test: rot13 rot13.doc
	./rot13 rot13.doc | ./rot13 >rot13.test
	@echo "comparing rot13.doc with rot13.test"
	@if cmp rot13.doc rot13.test ; then echo "test passed" ;\
	else echo "test failed" ; exit 1 ; fi
		
install: test
	$(INSTALL_DATA) $(srcdir)/rot13.1 $(mandir)
	$(INSTALL_PROG) ./rot13 $(bindir)

uninstall:
	$(RM) $(mandir)/rot13.1
	$(RM) $(bindir)/rot13

clean:
	$(RM) rot13 core rot13.test

clobber: clean
	$(RM) rot13.doc

distclean: clean
	$(RM) rot13.doc

