#
# Makefile for configuration files
# things to make:
#	lib		the DESZIP library, with the given settings
#	desnnn.o	the des library file (see below for what nnn is)
#	cdesnnn.o	the des library file (see below for what nnn is)
#	sdesnnn.o	the des library file (see below for what nnn is)
#	genbox		the DESZIP box generation program
#	Makefile	the Makefile
#	clean		to delete intermediate files
#	clobber		to delete all files except the original sources
#			and the Makefile
#	clobberall	to delete all files except the original sources
#
#################################################################
# Copyright notice.						#
# This software is copyrighted (c) 1991 by Matt Bishop and the	#
# Trustees of Dartmouth College.  All rights reserved.		#
# 								#
# Author:	Matt Bishop					#
# Address:	Department of Mathematics and Computer Science	#
#	 	Dartmouth College				#
# 		Hanover, NH  03755-1831				#
# 		USA						#
# telephone:	+1 603 646 3267					#
# fax:		+1 603 646 1312					#
# internet:	Matt.Bishop@dartmouth.edu			#
# usenet:	...!decvax!dartvax!Matt.Bishop			#
#################################################################
#
VERSION="Version GAMMA 6/31/91 Matt.Bishop@dartmouth.edu"	# version

# the M4 configuration file
include(../../config/config.m4)
#
# these parameters are the DEFAULT settings for:
# PATH		number of bits per chunk given to the SPE table
#		legal values are 06 and 12 (the "0" in 06 IS NEEDED)
# KEY		number of permutations to generate the key schedule
#		legal values are 1 and 3
# COMPSALT	whether the salt should be precomputed into the SPE table
#		legal values are ONFLY (no) or PRECOMPUTE (yes)
# PACKBITS	how the bits should be accessed
#		legal values are BYTES (pack 6 bits/byte), SHIFTANDMASK
#		(pack them as 24 bits/word and use shifting and masking to
#		access them), or BITFIELDS (pack them as 24 bits/word and
#		declare the word as 4 6-bit fields)
# ADDRMODE	how to access a series of arrays
#		legal values are IMMED (immediate mode style, which just
#		puts the addresses into the I space) and AUTOINC (auto-
#		increment mode, which loads the addresses into an array and
#		indexes indirectly using a pointer that can be auto-incre-
#		mented and walked through the array)
# ARRINDEX	how to handle array addresses
#		legal values are TYPEPUN (type punning, which converts
#		a[i] into *(type *)((unsigned char *)a) + i); this produces
#		faster code on some systems) and USUAL (don't convert a[i],
#		but let the compiler do it)
# Note there is one setting for the DES and one for the crypt(3)
DESKEY		= 3
DESPATH		= 06
DESSALT		= PRECOMPUTE
DESBITS		= SHIFTANDMASK
CDESKEY		= 3
CDESPATH	= 06
CDESSALT	= $(DESSALT)
CDESBITS	= $(DESBITS)
ADDRMODE	= IMMED
ARRINDEX	= TYPEPUN
# flags and files
# CFLAGS	options to compile anything
# CDESFLAGS	cpp flags to compile the DES and UNIX-DES
# CCDESFLAGS	cpp flags to compile the crypt with the UNIX interface
# CSDESFLAGS	cpp flags to compile the crypt with the DESZIP interface
DES_DEFINES	= -DDES -DWHICH=des -DKEY=$(DESKEY) -DPATH=$(DESPATH) \
			-DCOMPSALT=$(DESSALT) -DPACKBITS=$(DESBITS)   \
			-DADDRMODE=$(ADDRMODE) -DARRINDEX=$(ARRINDEX)
CDES_DEFINES	= -DCDES -DWHICH=cdes -DKEY=$(CDESKEY) -DPATH=$(CDESPATH) \
			-DCOMPSALT=$(CDESSALT) -DPACKBITS=$(CDESBITS)     \
			-DADDRMODE=$(ADDRMODE) -DARRINDEX=$(ARRINDEX)
SDES_DEFINES	= -DSDES -DWHICH=sdes -DKEY=$(CDESKEY) -DPATH=$(CDESPATH) \
			-DCOMPSALT=$(CDESSALT) -DPACKBITS=$(CDESBITS)     \
			-DADDRMODE=$(ADDRMODE) -DARRINDEX=$(ARRINDEX)
CPPDESFLAGS	= $(CPP_OPTS) -I$(LIBINC) -I../../include $(DES_DEFINES)
CPPCDESFLAGS	= $(CPP_OPTS) -I$(LIBINC) -I../../include $(CDES_DEFINES)
CPPSDESFLAGS	= $(CPP_OPTS) -I$(LIBINC) -I../../include $(SDES_DEFINES)
CFLAGS		= $(C_OPTS) -I$(LIBINC) -I../../include
CDESFLAGS	= $(CFLAGS) $(DES_DEFINES)
CCDESFLAGS	= $(CFLAGS) $(CDES_DEFINES)
CSDESFLAGS	= $(CFLAGS) $(SDES_DEFINES)
# header, source, and object files
# BOXES		labels to generate boxes for the desired configuration
# HDRBOX	sources for the lookup tables
# MAPS		objects for the maps for the desired configuration
# OBJBOX	objects for the lookup tables
# OBJECT	object files for the UNIX wrapping programs
# OBJMAP	object files for the encryption programs
# SRCBOX	sources for the lookup tables
HDRBOX	= b_key.h b_pc1.h b_lsh.h b_pc2.h b_ipe.h b_spe6.h b_spe12.h b_eipinv.h
OBJBOX	= b_key.o b_pc1.o b_lsh.o b_pc2.o b_ipe.o b_spe6.o b_spe12.o b_eipinv.o
SRCBOX	= b_key.c b_pc1.c b_lsh.c b_pc2.c b_ipe.c b_spe6.c b_spe12.c b_eipinv.c
SRCMAP	= des061.c cdes061.c sdes061.c des063.c cdes063.c sdes063.c \
		des121.c cdes121.c sdes121.c des123.c cdes123.c sdes123.c
OBJMAP	= des061.o cdes061.o sdes061.o des063.o cdes063.o sdes063.o \
		des121.o cdes121.o sdes121.o des123.o cdes123.o sdes123.o
OBJECTS	= encrypt.o crypt.o shortcrypt.o
OBJMAPS	= des$(DESPATH)$(DESKEY).o cdes$(CDESPATH)$(CDESKEY).o \
			 sdes$(CDESPATH)$(CDESKEY).o

# install the cookies
install:	lib
	$(MV) libdes.a $(DESTLIB)/libdes.a
	-$(RANLIB) $(DESTLIB)/libdes.a
	$(CP) des.h $(LIBINC)/mach.h $(DESTINC)
	
# bake the cookies
lib:	$(OBJECTS) $(OBJMAPS)
	$(RM) -f libdes.a
	$(AR_MAKE) libdes.a `$(LORDER) $(OBJMAPS) $(OBJECTS) b_*.o | $(TSORT)`
	-$(RANLIB) libdes.a

# make the mappings with the desired configurations
des$(DESPATH)$(DESKEY).o:
	$(CPP) -P $(CPPDESFLAGS) < hdr.m4 | \
		$(M4) - csdes.m4 > des$(DESPATH)$(DESKEY).c
	$(CC) $(CDESFLAGS) -c des$(DESPATH)$(DESKEY).c

cdes$(CDESPATH)$(CDESKEY).o:
	$(CPP) -P $(CPPCDESFLAGS) < hdr.m4 | \
		 $(M4) - csdes.m4 > cdes$(CDESPATH)$(CDESKEY).c
	$(CC) $(CCDESFLAGS) -c cdes$(CDESPATH)$(CDESKEY).c

sdes$(CDESPATH)$(CDESKEY).o:
	$(CPP) -P $(CPPSDESFLAGS) < hdr.m4 | \
		 $(M4) - csdes.m4 > sdes$(CDESPATH)$(CDESKEY).c
	$(CC) $(CSDESFLAGS) -c sdes$(CDESPATH)$(CDESKEY).c

# make the program to make the tables
genbox:
	(cd genbox32; make $(MFLAGS) genbox); $(MV) genbox32/genbox genbox

# make the tables

$(HDRBOX):	genbox
	./genbox -b $(DESBITS),$(DESPATH),$(ARRINDEX) -h $@

$(SRCBOX):	genbox
	./genbox -b $(DESBITS),$(DESPATH),$(ARRINDEX) -c $@

# generate the Makefile
Makefile:
	$(M4) Makefile.m4 > Makefile

# clean up -- delete anything user specifies
clean:
	$(RM) $(RM_FORCE) $(OBJBOX) $(OBJMAP) $(OBJECTS)
	(cd genbox32; make clean)

# clobber everything being cleaned, plus whatever else the user wants
clobber:
	$(RM) $(RM_FORCE) $(SRCBOX) $(HDRBOX) $(SRCMAP) \
		$(OBJBOX) $(OBJMAP) $(OBJECTS) genbox *.a a.out core
	(cd genbox32; make clobber)

# here come the dependencies
des061.o cdes061.o sdes061.o:	b_ipe.o b_spe6.o  b_eipinv.o b_key.o \
				des.h ../include/mach.h \
				b_ipe.h b_eipinv.h b_spe6.h b_key.h \
				hdr.m4 csdes.m4
des063.o cdes063.o sdes063.o:	b_ipe.o b_spe6.o b_eipinv.o \
				b_pc1.o b_lsh.o b_pc2.o \
				des.h ../include/mach.h \
				b_ipe.h b_eipinv.h b_spe6.h \
				b_pc1.h b_lsh.h b_pc2.h \
				hdr.m4 csdes.m4
des121.o cdes121.o sdes121.o:	b_ipe.o b_spe12.o b_eipinv.o b_key.o \
				des.h ../include/mach.h \
				b_ipe.h b_eipinv.h b_spe12.h b_key.h \
				hdr.m4 csdes.m4
des123.o cdes123.o sdes123.o:	b_ipe.o b_spe12.o b_eipinv.o \
				b_pc1.o b_lsh.o b_pc2.o \
				des.h ../include/mach.h \
				b_ipe.h b_eipinv.h b_spe12.h \
				b_pc1.h b_lsh.h b_pc2.h \
				hdr.m4 csdes.m4
$(OBJBOX):			genbox des.h ../include/mach.h

