#
#  Makefile for mp, the PostScript pretty printer.
#
#  @(#)Makefile 1.10 95/08/25
#
#  Copyright (c) Steve Holden and Rich Burridge.
#                All rights reserved.
#
#  Permission is given to distribute these sources, as long as the
#  copyright messages are not removed, and no monies are exchanged.
#
#  No responsibility is taken for any errors inherent either
#  to the comments or the code of this program, but if reported
#  to me then an attempt will be made to fix them.
#
#  NOTE: The following definitions are expected to be overridden by the
#        calling Makefile in the parent directory.
#
#=====================================================================
#  Mp will extract the user's gecos field, and try to make sense of what
#  it finds. It applies various rules to do this. If this field is too long,
#  then it needs to truncate sensibly. If it's extracted N "words" or has
#  found a comma, then it stops extracting. If an ampersand is found, this
#  is expanded to the users name in capitals.
#  This option allows you to change the number of "words" that mp extracts
#  from the gecos field. By default this is 3. If needed, then it should
#  be uncommented, and set accordingly.
#
#GECOSFIELDS     = -DGECOSFIELDS=3
#---------------------------------------------------------------------
#  Mp will extract upto a certain number of characters from the user's
#  passwd gecos field. By default, this is 40. This option allows you to
#  set this to something different. If needed, then it should be uncommented,
#  and set accordingly.
#
#GECOSLENGTH     = -DGECOSLENGTH=40
#---------------------------------------------------------------------
#  It is possible to change the location of the mp prologue file
#  with the -p command line option. It can also be defined at compile
#  time, by uncommenting the macro definition below and setting
#  appropriately. If it's not present, then a sensible default value
#  is used.
#
#PROLOGUE = -DPROLOGUE=\"$(MPLIBDIR)\"
#---------------------------------------------------------------------
#  Mp uses X11 to read/write it's resource files. You will need to set the
#  following two lines appropriately.
#
X11INCDIR       = -I$(OPENWINHOME)/include
X11LIBDIR       = -L$(OPENWINHOME)/lib
#---------------------------------------------------------------------
#  Alternate names for the mailp frontend
#
MAILPNAMES = mailp newsp digestp filep filofaxp filofaxpp franklinp \
	     proplanp timemanp timesysip timesyspp
#---------------------------------------------------------------------
#
#  Default locations where mp files will be installed.
#  You might wish to alter these values.
#
MPPATH     = /usr/local
MPBINDIR   = $(MPPATH)/bin
MPLIBDIR   = $(MPPATH)/lib/mp
MPMANDIR   = $(MPPATH)/man/man$(MPMANSECT)
MPMANSECT  = l
#---------------------------------------------------------------------
#  Compilation flags and standard macro definitions.
#
CDEFS	 = $(GECOSFIELDS) $(GECOSLENGTH) $(PROLOGUE) $(X11INCDIR) \
	   -I../common
CCOMP	 = -O
CC       = gcc
CCFLAGS  = $(CCOMP) $(CDEFS)
LDFLAGS  = $(X11LIBDIR)
LIBS     = -lX11

#=================================================================

.KEEP_STATE:

SRCS     = header.c input.c main.c ../common/option.c print.c
OBJS     = header.o input.o main.o option.o print.o
HDRS     = header.h input.h print.h
MPAGES   = mp.man mp.man.text

mp:	$(OBJS) mp.man
	$(CC) $(CFLAGS) -o mp $(OBJS) $(LDFLAGS) $(LIBS)
	-sed -e s,LIBDIR,$(MPLIBDIR),g \
	     -e s,BINDIR,$(MPBINDIR),g mp.man > mp.1

option.o: ../common/option.c ../common/option.h ../common/patchlevel.h
	$(CC) -c $(CFLAGS) ../common/option.c

SHELL = /bin/sh

install:
#                                                         mp
	   -if [ -f mp ]; then \
		cp mp $(MPBINDIR); \
		chmod 751 $(MPBINDIR)/mp; \
		strip $(MPBINDIR)/mp; \
	   fi
#                                                         mp.1
	   -if [ -f mp ]; then \
		cp mp.1 $(MPMANDIR)/mp.$(MPMANSECT); \
		chmod 644 $(MPMANDIR)/mp.$(MPMANSECT); \
	   fi
#
	   -if [ ! -d $(MPLIBDIR) ]; then \
		mkdir $(MPLIBDIR); \
	   fi
#                                                         mp.common.ps
	   -cp ../prologue/mp.common.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.common.ps
#                                                         mp.pro.ps
	   -cp ../prologue/mp.pro.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.ps
#                                                         mp.pro.l.ps
	   -cp ../prologue/mp.pro.l.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.l.ps
#                                                         mp.pro.alt.ps
	   -cp ../prologue/mp.pro.alt.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.alt.ps
#                                                         mp.pro.altl.ps
	   -cp ../prologue/mp.pro.altl.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.altl.ps
#                                                         mp.pro.ff.ps
	   -cp ../prologue/mp.pro.ff.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.ff.ps
#                                                         mp.pro.ffp.ps
	   -cp ../prologue/mp.pro.ffp.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.ffp.ps
#                                                         mp.pro.fp.ps
	   -cp ../prologue/mp.pro.fp.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.fp.ps
#                                                         mp.pro.pp.ps
	   -cp ../prologue/mp.pro.pp.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.pp.ps
#                                                         mp.pro.tm.ps
	   -cp ../prologue/mp.pro.tsi.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.tm.ps
#                                                         mp.pro.tsi.ps
	   -cp ../prologue/mp.pro.tsp.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.tsi.ps
#                                                         mp.pro.tsp.ps
	   -cp ../prologue/mp.pro.tsp.ps $(MPLIBDIR)
	   -chmod 644 $(MPLIBDIR)/mp.pro.tsp.ps
#
#  NOTE: If you don't want the mailp, newsp, filep ... symbolic links
#        installed, then you should comment out the following seven lines.
#
	   @echo Making mp links
	   -for name in $(MAILPNAMES); do \
		echo -n $$name " "; \
		rm -f $(MPBINDIR)/$$name; \
		ln -s $(MPBINDIR)/mp $(MPBINDIR)/$$name; \
	   done
	   @echo

clean:
	rm -rf *.Z *.uu mp.1 mp *.o core

create:    SCCS
	-sccs create $(SRCS) $(HDRS) $(MPAGES)

lint:
	lint $(CDEFS) $(SRCS)

saber:
	#load $(CDEFS) $(SRCS) $(LDFLAGS) $(LIBS)

SCCS:
	mkdir SCCS
	chmod 755 SCCS

header.o:	header.h input.h ../common/option.h print.h
input.o:	header.h input.h ../common/option.h print.h
main.o:		header.h input.h ../common/option.h print.h
print.o:	header.h input.h ../common/option.h print.h
