# Makefile for Qfax 1.0
# (c) 1994 Robert LeBlanc and Renaissoft

# The directory the executables go into (e.g. /usr/local/bin, /usr/bin)
# Note: if you change this value, be sure you tell your mailer where
#       Qfax is (see INSTALL, step 3). 
BINDIR=/usr/local/bin

# The directory the man pages go into (e.g. /usr/man/man1)
MANDIR=/usr/man/man1

# The directory the documentation goes into (e.g. /usr/info/qfax)
INFODIR=/usr/info/fax

# The owner of Efax and Qfax (note: this UID must exist!)
OWNER=fax

# The group Efax and Qfax belong to (e.g. uucp)
GROUP=uucp

# Your C compiler (e.g. cc, gcc)
CC=gcc

# Any compiler flags you'd like to add (e.g. -m486, -g, -O)
CFLAGS=-m486 -O -Wall

# Any extra flags you need for the linker
LDFLAGS=

# Just in case you've got header files in a strange place
INCLS=

# ...or need extra libraries compiled in for some strange reason
LIBS=

############## End of user-configurable options ###########################

PROGS=qfax qrun qsend qstat qdel efax
MANS=qfax.1 qrun.1 qsend.1 qstat.1 qdel.1 qfax.phonebook.1 efax.1 fax.1

all:	utils Makefile
	@set -x ;for i in $(PROGS) ; do \
	$(CC) $(CFLAGS) -o $$i $(LIBS) $$i.c qfaxlib.a ; done

utils:	qfax.h config.h Makefile
	$(CC) $(CFLAGS) $(INCLS) -c qfaxutil.c
	ar ruv qfaxlib.a qfaxutil.o
	ranlib qfaxlib.a

qfax:	utils Makefile
	$(CC) $(CFLAGS) -o qfax $(LIBS) qfax.c qfaxlib.a

qrun:	utils Makefile
	$(CC) $(CFLAGS) -o qrun $(LIBS) qrun.c qfaxlib.a

qsend:	utils Makefile
	$(CC) $(CFLAGS) -o qsend $(LIBS) qsend.c qfaxlib.a

qstat:	utils Makefile
	$(CC) $(CFLAGS) -o qstat $(LIBS) qstat.c qfaxlib.a

qdel:	utils Makefile
	$(CC) $(CFLAGS) -o qdel $(LIBS) qdel.c qfaxlib.a

efax:	config.h Makefile
	$(CC) $(CFLAGS) -o efax $(LIBS) efax.c

clean:	
	rm -f core *~ *.o *.a $(PROGS)

install:	all
		@echo Installing binaries...
		@set -x ;for i in $(PROGS) ; do \
		install -c -s \
                           -m 4755 \
                           -o $(OWNER) \
                           -g $(GROUP) \
                        $$i $(BINDIR) ; done
		@if [ -f fax ]; then \
			install -c \
				-m 755 \
				-o $(OWNER) \
				-g $(GROUP) \
				fax $(BINDIR);\
		fi 
		@echo Installing man pages...
		@set -x ;for i in $(MANS) ; do \
		install -c $$i $(MANDIR) ; done
		@echo Installing docs...
		install -c -d -m 777 $(INFODIR)
		cp doc/* README INSTALL TODO COPYING $(INFODIR)


# Apply various patches to clean efax06a sources.

patch-06b:	
		@echo Patching efax 06a to 06b...
		patch -s < patches/efax.06a-06b.patch

patch-buffer:	
		@echo Applying the buffer patch to efax...
		patch -s < patches/efax.buffer.patch

patch-errcap:	
		@echo Applying the error cap patch to efax...
		patch -s < patches/efax.errcap.patch

patch-fax:	
		@echo Applying the Qfax patch to fax...
		patch -s < patches/fax.qfax.patch

patch-efax:	
		@echo Applying the Qfax patch to efax...
		patch -s < patches/efax.qfax.patch


# Apply only those patches necessary to make efax run with Qfax

patch-qfax:	patch-efax patch-fax


# Prepare a qfax1.0.tar.gz distribution archive.

tgz:	
	tar -cvzf qfax1.0.tar.gz *.c *.h *.1 doc patches README INSTALL \
                                 COPYING TODO Makefile fax.rc fax.db \
			         cover-template.ps
