# $Id: Makefile 1.12 Tue, 14 Oct 2003 20:25:02 +0200 warwick $
#
# Simple makefile for chpwdfile project

CC	= gcc
#COPTS	= -Wall -fpedantic
COPTS	= -s -O2

BINDIR	= /usr/local/bin
MANDIR	= /usr/local/man/man1

chpwdfile: chpwdfile.c util.c chpwdfile.h util.h
	$(CC) $(COPTS) -lcrypt -o chpwdfile chpwdfile.c util.c

chpwdfile-cgi: chpwdfile.c util.c chpwdfile.h util.h
	$(CC) -DCGI $(COPTS) -lcrypt -o chpwdfile-cgi chpwdfile.c util.c -lcgi

all: chpwdfile chpwdfile-cgi

.PHONY: clean install dist

clean:
	-rm chpwdfile chpwdfile-cgi

install:
	if [ ! -d $(DESTDIR)$(BINDIR) ] ; then mkdir -p $(DESTDIR)$(BINDIR) ; fi
	cp chpwdfile $(DESTDIR)$(BINDIR)
	ln -sf chpwdfile $(DESTDIR)$(BINDIR)/pwadd
	ln -sf chpwdfile $(DESTDIR)$(BINDIR)/pwdel
	ln -sf chpwdfile $(DESTDIR)$(BINDIR)/pwmod
	if [ ! -d $(DESTDIR)$(MANDIR) ] ; then mkdir -p $(DESTDIR)$(MANDIR) ; fi
	cp chpwdfile.1 $(DESTDIR)$(MANDIR)
	echo '.so chpwdfile.1' > $(DESTDIR)$(MANDIR)/pwadd.1
	echo '.so chpwdfile.1' > $(DESTDIR)$(MANDIR)/pwdel.1
	echo '.so chpwdfile.1' > $(DESTDIR)$(MANDIR)/pwmod.1

# PRCS is a fine thing
# $Format: "DISTDIR = chpwdfile-$ProjectVersion$"$
DISTDIR = chpwdfile-0.24
DISTFILES = chpwdfile.c chpwdfile.h util.c util.h \
	Makefile README chpwdfile.1 chpwdfile.spec \
	examples LICENSE
dist:
	if [ -d $(DISTDIR) ] ; then rm -r $(DISTDIR) ; fi
	mkdir $(DISTDIR)
	cp -r $(DISTFILES) $(DISTDIR)
	tar zcf ../$(DISTDIR).tar.gz $(DISTDIR)
	rm -r $(DISTDIR)


%.o: %.c
	$(CC) $(COPTS) -c -o $@ $<
