# makefile for PGP (unix)
#
# CFLAGS options:
#
# -DHIGHFIRST if building PGP on a big-endian system
# -DDEBUG     to include debugging information
# -DNOTERMIO  if your system has no termios
# -DSVR2      for System V release 2
# -DDYN_ALLOC if your compiler does not support large static arrays
# -DSMALL_MEM if your machine has a small memory (required for MSDOS)
# -DIDEA32    if your int's are 32 bits this is probably faster
#
# -DPORTABLE  and
# -DMPORTABLE to build the portable version of the RSA primitives
#             (ie if no optimized asm versions are available)
#
# Define one of:
# -DMERRITT    Merritt's modmult (fast on risc machines)
# -DPEASANT    Russian peasant modulo multiply algorithm
# -DUPTON      use Upton's modmult algorithm
# -DSMITH      use Smith's modmult
# See also the file platform.h for system defaults
#
# If you don't have a working FIONREAD ioctl you must use one of these:
# -DUSE_SELECT to use select() system call
# -DUSE_NBIO   to use non-blocking read()

# To define the OS we are compiling under, define one of:
# -DMSDOS, -DUNIX, -DVMS, -DATARI, -DAMIGA

CFLAGS= -O -DUNIX -DPORTABLE $(BYTEORDER)

# must set byte order for targets "sysv" and "bsd"
# BYTEORDER= -DHIGHFIRST

CC      = cc
LD      = cc		# Link command
LDFLAGS	=  			# Flags for linker
CPP     = $(CC) -E

ASM	= $(CC)			# Assembler command
ASMFLAGS = -c		# Flags for assembler

OBJS_EXT=			# ASM obj. files
LIBS_EXT=			# Libararies

PROJ	=pgp$E

default:
	@echo "type:"
	@echo "        make <system>"
	@echo ""
	@echo "where <system> can be:"
	@echo "        sun4gcc, sun4cc(*), sun3gcc, sun3asm, sun3cc(*), sun386i, sunspc,"
	@echo "        sysv_386, sco-2.0, x286(*), hpux, linux, mips-ultrix, vax-ultrix,"
	@echo "        os2, mach_386, 386bsd, isc, isc_asm, 3b1, 3b1_asm, rs6000,"
	@echo "        bsd, vax_bsd43, rt_aos4, osf, sgigcc_asm, sgigcc, irix"
	@echo ""
	@echo "for targets marked with (*) you must first get unproto, see"
	@echo "setup.doc for further details"


all: $(PROJ)

80386.o:	80386.S
	$(CPP) 80386.S > _80386.s
	$(ASM) $(ASMFLAGS) _80386.s -o $@
	rm -f _80386.s

8086.o: 8086.asm
	cp 8086.asm 8086.s
	$(ASM) $(ASMFLAGS) 8086.s
	rm -f 8086.s

zmatch.o:	zmatch.S
	$(CPP) zmatch.S > _zmatch.s
	$(ASM) $(ASMFLAGS) _zmatch.s -o $@
	rm -f _zmatch.s

ZIPOBJS= zbits.o zdeflate.o zfile_io.o zglobals.o \
	zinflate.o zip.o zipup.o ztrees.o zunzip.o 

OBJ1 =	pgp.o crypto.o keymgmt.o fileio.o \
	mdfile.o more.o armor.o mpilib.o mpiio.o \
	genprime.o rsagen.o random.o idea.o passwd.o \
	md5.o system.o language.o getopt.o keyadd.o \
	config.o keymaint.o charset.o

OBJS =	$(OBJ1) $(ZIPOBJS) $(OBJS_EXT)

$(PROJ):	$(OBJS)
		$(LD) $(OBJS) -o $(PROJ) $(LDFLAGS) $(LIBS_EXT)


linux:
	$(MAKE) all CC=gcc LD=gcc OBJS_EXT="80386.o zmatch.o" \
	CFLAGS="-O -DUNIX -DIDEA32 -DASM"

386bsd:
	$(MAKE) all CC=gcc LD=gcc OBJS_EXT="80386.o zmatch.o" \
	CFLAGS="-O -DUNIX -DIDEA32 -DASM -DMAX_NAMELEN=255"

# Sun 3 with gcc
sun3gcc:
	$(MAKE) all CC=gcc LD=gcc \
	CFLAGS="-O -DUNIX -DHIGHFIRST -DIDEA32 -DPORTABLE -DMPORTABLE"

# mc68020.s can also be used without -DMPORTABLE, but this needs some
# changes in mpilib.c, see comments in mc68020.s
sun3asm:
	$(MAKE) all CC=gcc LD=gcc OBJS_EXT=mc68020.s \
	CFLAGS="-O -DUNIX -DHIGHFIRST -DIDEA32 -DUNIT32 -DMPORTABLE"

# Sun 3 with standard cc: compile with unproto
sun3cc: unproto/cpp
	$(MAKE) all CC=cc LD=cc \
	CFLAGS="-Qpath unproto -O -DUNIX -DHIGHFIRST -DIDEA32 -DPORTABLE -DMPORTABLE"

# Sun 4 SPARC with gcc (tested with gcc 1.39 and newer, sparc.s can not be used
# with older versions of gcc)
sun4gcc:
	$(MAKE) all CC=gcc LD=gcc OBJS_EXT=sparc.o \
	CFLAGS="-O -fpcc-struct-return -DUNIX -DHIGHFIRST -DIDEA32"

# Sun 4 SPARC with standard cc: compile with unproto
sun4cc: unproto/cpp
	$(MAKE) all CC=cc LD=cc OBJS_EXT=sparc.o \
	CFLAGS="-Qpath unproto -O -DUNIX -DHIGHFIRST -DIDEA32"

sun386i:
	$(MAKE) all CC=gcc LD=gcc OBJS_EXT=80386.o \
	CFLAGS="-O -DUNIX -DIDEA32"

sunspc:
	$(MAKE) all CC="ccspc -B/1.8.6/sun4 -ansi -w -I/usr/include" \
	CFLAGS="-O -DUNIX -DIDEA32 -DHIGHFIRST -DUNIT32 -DMERRITT" \
	OBJS_EXT=sparc.o

sysv:
	$(MAKE) all CPP=/lib/cpp \
	CFLAGS="-O -DUNIX -DPORTABLE -DMPORTABLE -DUSE_NBIO $(BYTEORDER)"

# optimized version with 80386.S
sysv_386:
	$(MAKE) all CPP=/lib/cpp OBJS_EXT="80386.o zmatch.o" \
	CFLAGS="-O -DUNIX -DIDEA32 -DUSE_NBIO -DASM" ASMFLAGS=-DSYSV

# Interactive Unix SVR3/386 version 3.2 with gcc
isc:
	$(MAKE) all CC=gcc LD=gcc LDFLAGS="-lcposix" \
	CFLAGS="-O -DUNIX -DIDEA32 -DUSE_NBIO -DPORTABLE -DMPORTABLE"

isc_asm:
	$(MAKE) all CC=gcc LD=gcc OBJS_EXT=80386.o \
	CFLAGS="-O -DUNIX -DIDEA32 -DUSE_NBIO" LDFLAGS="-lcposix"

mach_386:
	$(MAKE) all CC=gcc LD=gcc CPP=/lib/cpp OBJS_EXT=80386.o \
	CFLAGS="-O -I. -DMACH -DUNIX -DIDEA32 -DNOTERMIO"

sco-2.0:
	$(MAKE) all CC=gcc LD=gcc CPP=/usr/lib/xcpp OBJS_EXT=80386.o \
	CFLAGS="-Dsco -O -DUNIX -DIDEA32 -DUSE_NBIO"

# Xenix 286
x286:
	$(MAKE) all CC="sh ccc.x286 -M2l" LD="cc -M2l" ASM="cc -M2l" \
	OBJS_EXT=8086.o  LDFLAGS="-F 3000" \
	CFLAGS="-LARGE -Ot -DUNIX -DNOPROTO -DSMALL_MEM -DDYN_ALLOC \
	-DUSE_NBIO -DSVR2"

3b1:
	$(MAKE) all CC=gcc LD=gcc CPP=/usr/lib/cpp \
	CFLAGS="-O -I. -DUNIX -DSVR2 -DPORTABLE -DMPORTABLE -DUSE_NBIO -DHIGHFIRST"

3b1_asm:
	$(MAKE) all CC=gcc LD=gcc CPP=/usr/lib/cpp OBJS_EXT=3B1_68010.o \
	CFLAGS="-O -I. -DUNIX -DSVR2 -DUSE_NBIO -DHIGHFIRST"

# Silicon Graphics Iris IRIX
sgigcc:
	$(MAKE) all CC=gcc LD=gcc CPP=/usr/lib/cpp \
	CFLAGS="-O -DUNIX -DPORTABLE -DUSE_NBIO -DHIGHFIRST"

# SGI with assembler modules
sgigcc_asm:
	$(MAKE) all CC=gcc LD=gcc CPP=/usr/lib/cpp OBJS_EXT="r3000.o r3kd.o" \
	CFLAGS="-O -DUNIX -DUSE_NBIO -DHIGHFIRST"

irix:
	$(MAKE) all CC=cc LD=cc \
	CFLAGS="-O -DUNIX -DPORTABLE -DUSE_NBIO -DHIGHFIRST -acpp"

hpux:
	$(MAKE) all CPP=/usr/lib/cpp \
	CFLAGS="+DA1.0 -Aa +O3 Obb5000 -D_INCLUDE_POSIX_SOURCE \
	-D_INCLUDE_HPUX_SOURCE -D_INCLUDE_XOPEN_SOURCE -DHIGHFIRST -DUNIX \
	-DMPORTABLE -DPORTABLE -DUSE_NBIO -DIDEA32"

# VAX Ultrix 4.2 BSD rev. 96, system #3 with gcc
vax-ultrix:
	$(MAKE) all CC=gcc LD=gcc \
	CFLAGS="-O -DUNIX -DPORTABLE -DMPORTABLE -DUSE_SELECT \
	-DSIG_IGN=1 -DSIG_DFL=0"

# DEC Ultrix 4.2 BSD with gcc with MIPSco processors
#
# To use dec's cc on mips you should
# uncomment the next two lines because you can't compile r3000.c 
#r3000.o: r3000.s
#	$(AS) -o $@ r3000.s
#
mips-ultrix:
	$(MAKE) all CC=gcc LD=gcc OBJS_EXT="r3kd.o r3000.o"\
	CFLAGS="-O -DUNIX -DUSE_SELECT -DIDEA32"

# RS6000 running AIX
rs6000:
	$(MAKE) all CFLAGS="-O -DUNIX -DUSE_NBIO -DPORTABLE \
	-DHIGHFIRST -DIDEA32"

next:
	$(MAKE) all \
	CFLAGS="-O -DNEXT -DUNIX -DHIGHFIRST -DBSD -DPORTABLE -DMPORTABLE -DNOTERMIO"

bsd:
	$(MAKE) all "LD=cc -s" \
	CFLAGS="-O -I. -B/lib/ -DNOTERMIO -DBSD -DUNIX -DPORTABLE -DMPORTABLE -DUSE_NBIO $(BYTEORDER)"

sequent: unproto/cpp
	$(MAKE) all "LD=cc -s -j" CPP=/usr/lib/cpp \
	CFLAGS="-j -O -I. -Yp,unproto -DUNIX -DNOTERMIO -DPORTABLE -DMPORTABLE -DUSE_NBIO $(BYTEORDER)"

# RT running bsd with gcc
rt_aos4:
	$(MAKE) all CC=gcc LD=gcc \
	CFLAGS="-O -DUNIX -DBSD -DPORTABLE -DMPORTABLE -DHIGHFIRST -DNOTERMIO -I."

# Vax running bsd with gcc
vax_bsd43:
	$(MAKE) all CC=gcc LD=gcc \
	CFLAGS="-O -I. -DUNIX -DBSD -DNOTERMIO -DPORTABLE -DMPORTABLE"

# The Open Software Foundation's OSF/1
osf:
	$(MAKE) all \
	CFLAGS="-O -I. -D_BSD -DUNIX -DNOTERMIO -DPORTABLE -DMPORTABLE $(BYTEORDER)"

# optimized version with 80386.S for emx 0.8e, OS/2 2.0 or DOS
os2:
	$(MAKE) all E=.exe OBJS_EXT="80386.o zmatch.o" \
	CC="gcc" CFLAGS="-O -DOS2 -DASM -DIDEA32" \
	ASM="gcc" ASMFLAGS="-c -x assembler" \
	LD="gcc" LDFLAGS="pgp.def"

#
# unproto for K&R compilers
#
# unproto was posted on comp.sources.misc: v23i012 v23i013
#
# unpack the unproto package in subdirectory unproto
#

# unproto: needs preprocessed input
unproto/unproto::
	cd unproto && $(MAKE) PROG=unproto PIPE=

# cpp: pipes through /lib/cpp
unproto/cpp::
	cd unproto && $(MAKE)

clean:
	-rm -f *.o $(PROJ) core a.out tags

tags:
	ctags *.c *.h


## Dependencies ##
armor.o : armor.c mpilib.h usuals.h platform.h fileio.h mpiio.h language.h \
  pgp.h 
charset.o : charset.c usuals.h language.h fileio.h 
config.o : config.c usuals.h fileio.h pgp.h 
crypto.o : crypto.c mpilib.h usuals.h platform.h mpiio.h random.h idea.h \
  crypto.h keymgmt.h mdfile.h md5.h fileio.h language.h pgp.h 
fileio.o : fileio.c random.h usuals.h mpilib.h platform.h mpiio.h fileio.h \
  language.h pgp.h 
genprime.o : genprime.c mpilib.h usuals.h platform.h genprime.h random.h 
getopt.o : getopt.c 
idea.o : idea.c idea.h usuals.h 
keyadd.o : keyadd.c mpilib.h usuals.h platform.h idea.h random.h crypto.h \
  fileio.h keymgmt.h genprime.h rsagen.h mpiio.h language.h pgp.h 
keymaint.o : keymaint.c mpilib.h usuals.h platform.h random.h crypto.h \
  fileio.h keymgmt.h mpiio.h language.h pgp.h 
keymgmt.o : keymgmt.c mpilib.h usuals.h platform.h idea.h random.h crypto.h \
  fileio.h keymgmt.h genprime.h rsagen.h mpiio.h language.h pgp.h md5.h 
language.o : language.c usuals.h fileio.h language.h pgp.h 
md5.o : md5.c md5.h 
mdfile.o : mdfile.c mpilib.h usuals.h platform.h mdfile.h md5.h fileio.h \
  language.h pgp.h 
more.o : more.c mpilib.h usuals.h platform.h language.h fileio.h pgp.h 
mpiio.o : mpiio.c mpilib.h usuals.h platform.h mpiio.h pgp.h 
mpilib.o : mpilib.c mpilib.h usuals.h platform.h 
passwd.o : passwd.c random.h usuals.h md5.h language.h pgp.h 
pgp.o : pgp.c mpilib.h usuals.h platform.h random.h crypto.h fileio.h \
  keymgmt.h language.h pgp.h 
random.o : random.c random.h usuals.h language.h 
rsagen.o : rsagen.c mpilib.h usuals.h platform.h genprime.h rsagen.h \
  random.h 
system.o : system.c 
zbits.o : zbits.c zip.h ztailor.h ziperr.h 
zdeflate.o : zdeflate.c zip.h ztailor.h ziperr.h 
zfile_io.o : zfile_io.c zunzip.h 
zglobals.o : zglobals.c zip.h ztailor.h ziperr.h 
zinflate.o : zinflate.c zunzip.h 
zip.o : zip.c usuals.h fileio.h language.h pgp.h 
zipup.o : zipup.c zip.h ztailor.h ziperr.h zrevisio.h 
ztrees.o : ztrees.c zip.h ztailor.h ziperr.h 
zunzip.o : zunzip.c zunzip.h 
