#
# mpage:	A program to reduce pages of print so that several pages
# 	  	of output appear on one sheet of paper.
#
# Copyright (c) 1994-2004 Marcel J.E. Mol, The Netherlands
# Copyright (c) 1988 Mark P. Hahn, Herndon, Virginia
#     
#     Permission is granted to anyone to make or distribute verbatim
#     copies of this document as received, in any medium, provided
#     that this copyright notice is preserved, and that the
#     distributor grants the recipient permission for further
#     redistribution as permitted by this notice.
#
#     Marcel Mol                     MESA Consulting
#                                    P.o. box 112
#                                    2630 AC Nootdorp
#                                    The Netherlands
#                                    phone: +31-6-54724868
#     marcel@mesa.nl                 info@mesa.nl
#                                    http://www.mesa.nl/pub/mpage
#                                    ftp://ftp.mesa.nl/pub/mpage
#  

# Set this to an ANSI compatible C compiler (preferably gcc)
# See also system specific settings below
#CC=cc
CC=gcc

############################################################################
#
#  MPAGE Configuration
#
############################################################################

#
# Define your favorite page size:
#          Letter for US letter
#          Legal for legal
#          A4 for European A4
#  See glob.c for all possibilities
#
# PAGESIZE=Letter
PAGESIZE=A4

#
# Define your spooler type
#          ATT_SPOOLER for 'lp ...' type printing
#          BSD_SPOOLER for 'lpr ..' tpye printing
#
SPOOL_TYPE=BSD_SPOOLER

# PREFIX=e:/usr		# OS/2 type
PREFIX=/usr/local
#PREFIX=/usr
BINDIR=$(PREFIX)/bin
LIBDIR=$(PREFIX)/share
MANDIR=$(PREFIX)/man/man1

#
# A default encoding is given in encoding.h. Setting ENCODING=1 will
# activate this encoding by default. 0 switches default off.
# The -C option (without subargument) can be used to switch.
#
ENCODING=1

#
# Set the default sheet margin in 1/72 inches. 
#
SHEETMARGIN=18 

#
# Set intial duplex mode
#
DEFAULT_DUPLEX=0

DEFS = -DPAGE_DEF=\"${PAGESIZE}\" -DLIBDIR=\"${LIBDIR}/mpage\" -DDEFAULT_ENCODING=${ENCODING} -DDEFAULT_DUPLEX=${DEFAULT_DUPLEX} -DDEFAULTSMARGIN=${SHEETMARGIN} -DSPOOLER=${SPOOL_TYPE} # -DKANJI


############################################################################
#
#  OPERATING SYSTEM SETUP
#
############################################################################

# Unix extensions
E = 
O = .o

# OS/2:
# CFLAGS = -O2 $(DEFS) -Wall
# LIBS   = -Zcrtdll -s
# DEF_FILE = mpage.defM
# E = .exe
# O = .o

# MSDOS extensions
# E = .exe
# O = .obj

############################################################################
#
#  UNIXEN SPECIFICS
#
############################################################################

# Choose one of the following CFLAGS/CC definitions:
# If you are using gcc, you probably don't need to change anything here.

# Linux:
CFLAGS = -O2 -s $(DEFS) -Wall

# AIX (xlC on aix 4):
#CFLAGS = -O2 -s $(DEFS)

# SunOS 4.1.3_U1 1 sun4m (gcc 2.7.2)
#CFLAGS = -O2 -s $(DEFS) -D__USE_FIXED_PROTOTYPES__ -Wall

# SunOS 4.1.3_U1 1 sun4m (standard C-compiler (NOTE: sample.c will not
#     compile, since the standard cc is not ANSI-standard)
#CFLAGS = -O2 -s $(DEFS)

# HP-UX A.09.01 A 9000/735 (standard cc)
#CFLAGS = -Aa +O3 -s $(DEFS) -D_INCLUDE_POSIX_SOURCE -Wall

# BeOS
#CFLAGS= -O2 $(DEFS)

# OS X (10.2.2):
#CFLAGS = -O2  $(DEFS) -Wall


############################################################################
#
# END OF CONFIGURATION OPTIONS
#

# pattern rules. Should we define these?
%$(O): %.c
	$(CC) $(CFLAGS) -c -o $@ $<


HEAD =  mpage.h
DENC =  encoding.h
SRCS =  mpage.c glob.c text.c post.c file.c page.c args.c util.c
MOBJ =  mpage$(O) glob$(O) text$(O) post$(O) file$(O) page$(O) args$(O) util$(O)
SMPL =  sample.c page.c glob.c args.c
SOBJ =  sample$(O) page$(O) glob$(O) args$(O)

default:	mpage$(E) msample$(E) mpage.1
	@echo Done!

mpage$(E):	$(MOBJ)
	$(CC) $(CFLAGS) -o mpage$(E) $(MOBJ) $(LIBS)

msample$(E):	$(SOBJ)
	$(CC) $(CFLAGS) -o msample$(E) $(SOBJ) $(LIBS)

mpage.1: mpage.1.in
	sed 's:PREFIX:${PREFIX}:' < mpage.1.in > mpage.1
clean:
	rm -rf $(MOBJ) mpage$(E) mpage.ps $(SOBJ) msample$(E) mpage.1 make.log core

mpage$(O):	$(HEAD) $(DENC) mpage.c
glob$(O):	$(HEAD) glob.c
text$(O):	$(HEAD) text.c
post$(O):	$(HEAD) post.c
file$(O):	$(HEAD) file.c
page$(O):	$(HEAD) page.c
args$(O):	$(HEAD) args.c
util$(O):	$(HEAD) util.c
sample$(O):	$(HEAD) sample.c

mpage.ps:	mpage.1
	psroff -t -man mpage.1 > mpage.ps


#
# add your proper install stuff
#
install:
	if [ ! -d $(LIBDIR)/mpage ] ; then mkdir -p $(LIBDIR)/mpage ; fi
	if [ ! -d $(BINDIR) ] ; then mkdir -p $(BINDIR) ; fi
	if [ ! -d $(MANDIR) ] ; then mkdir -p $(MANDIR) ; fi
	cp mpage$(E) $(BINDIR)
	cp mpage.1 $(MANDIR)
	-cp Encodings/* $(LIBDIR)/mpage
	-chmod 644 $(LIBDIR)/mpage/*
