#
#
#                         DES SOFTWARE PACKAGE
#                             Version 2.2
#
#                                        _
# Copyright (c) 1990,1991,1992,1993 Stig Ostholm.
# All Rights Reserved
#
#
# The author takes no responsibility of actions caused by the use of this
# software package and does not guarantee the correctness of the functions.
#
# This software package may be freely distributed for non-commercial purpose
# as long as the copyright notice is kept. Any changes made should be
# accompanied by a comment indicating who made the change, when it was made
# and what was changed.
#
# This software package, or any parts of it, may not be used or in any way
# re-distributed for commercial purpose without the authors permission.
# The author keeps the right to decide between of what is commercial and
# what is non-commercial purpose.
#
# Restrictions due to national laws governing the use, import or export of
# cryptographic software is the responsibility of the software user/importer/
# exporter to follow.
#
#
#                                              _
#                                         Stig Ostholm
#                                         Chalmers University of Technology
#                                         Department of Computer Engineering
#                                         S-412 96 Gothenburg
#                                         Sweden
#                                         ----------------------------------
#                                         Email: ostholm@ce.chalmers.se
#                                         Phone: +46 31 772 1703
#                                         Fax:   +46 31 772 3663
#

#
# All make programs dont have the .h suffix defined
#
.SUFFIXES: .h .x .sh

         TOPDIR = ../..

#             CC = gcc
        DEFINES =
       INCLUDES = -I. -I.. -I${TOPDIR}/include -I${TOPDIR}/fips -I${TOPDIR}/config/include
          CCOPT = -O
#          CCOPT = -g
         CFLAGS = ${CCOPT} ${DEFINES} ${INCLUDES}

         RANLIB = ranlib

             RM = rm -f
             MV = mv
           MAKE = make
           ECHO = echo

      MAKE_ARGS = 'TOPDIR=${TOPDIR}' 'MAKE=${MAKE}' 'ECHO=${ECHO}' 'RM=${RM}' \
		  'CC=${CC}' 'CCOPT=${CCOPT}' 'BINDIR=${BINDIR}' \
		  'LIBDIR=${LIBDIR}' 'INCDIR=${INCDIR}' 'MANDIR=${MANDIR}'

   GEN_DEA_SRCS = gen_IP.c gen_IPinv.c gen_S_P.c gen_E.c
 GEN_SCHED_SRCS = gen_LS.c gen_PC1.c gen_PC2.c
       GEN_SRCS = ${GEN_DEA_SRCS} ${GEN_SCHED_SRCS}

   TAB_DEA_SRCS = tab_IP.c tab_IPinv.c tab_S_P.c tab_E.c
 TAB_SCHED_SRCS = tab_LS.c tab_PC1.c tab_PC2.c
     TAB_SRCS = ${TAB_DEA_SRCS} ${TAB_SCHED_SRCS}

   TAB_DEA_HDRS = tab_IP.h tab_IPinv.h tab_S_P.h tab_E.h
 TAB_SCHED_HDRS = tab_LS.h tab_PC1.h tab_PC2.h
       TAB_HDRS = ${TAB_DEA_HDRS} ${TAB_SCHED_HDRS}

   TAB_DEA_OBJS = tab_IP.o tab_IPinv.o tab_S_P.o tab_E.o
 TAB_SCHED_OBJS = tab_LS.o tab_PC1.o tab_PC2.o
       TAB_OBJS = ${TAB_DEA_OBJS} ${TAB_SCHED_OBJS}

  TAB_DEA_PROGS = tab_IP.x tab_IPinv.x tab_S_P.x tab_E.x
TAB_SCHED_PROGS = tab_LS.x tab_PC1.x tab_PC2.x
      TAB_PROGS = ${TAB_DEA_PROGS} ${TAB_SCHED_PROGS}

        SRCS = des_dea.c des_dea3.c des_dea3b.c des_sched.c ${GEN_SRCS}

        OBJS = des_dea.o des_dea3.o des_dea3b.o des_sched.o ${TAB_OBJS}


         LIB = libdea.a


  BENCH_PROG = ${TOPDIR}/util/bench.sh

 BENCH_LOOPS = 100000

  BENCH_ARGS = ${MFLAGS} ${MAKE_ARGS} 'MFLAGS=${MFLAGS}' \
	       'INCLUDES=${INCLUDES}' 'BENCH_LOOPS=${BENCH_LOOPS}'

  BENCH_OBJS =


     REMOVES = ${LIB} ${TAB_SRCS} ${TAB_HDRS} ${TAB_PROGS} \
	       bench *.bench dea_conf.h dea3_conf.h sch_conf.h


# This rule should be defined in all make programs.
#
#.c.o:
#	${CC} ${CFLAGS} -c $* $<

.x.c:
	${RM} tmp.c
	./$*.x -c $* > tmp.c
	${MV} tmp.c $@

.x.h:
	${RM} tmp.h
	./$*.x -h $* > tmp.h
	${MV} tmp.h $@


all	: ${LIB}

${LIB}	: ${OBJS}
	ar r $@ $?
	${RANLIB} $@

install	: ${LIB}
	@ case '${MFLAGS}' in -*s*) :;; *) ${ECHO} 'Nothing to install';; esac

clean	:
	${RM} ${REMOVES} *.o core a.out tmp.c tmp.h *.NEW *.BAK

depend  : ${THDRS}
	${TOPDIR}/util/mkdepend.sh ${MFLAGS} 'CC=${CC}' 'CFLAGS=${CFLAGS}' 'RM=${RM}' -f Makefile ${SRCS}


tab_IP.x	: gen_IP.c ${TOPDIR}/fips/fips_IP.h
	${CC} ${CFLAGS} -o $@ gen_IP.c ${LDFLAGS}
tab_IPinv.x	: gen_IPinv.c ${TOPDIR}/fips/fips_IPinv.h
	${CC} ${CFLAGS} -o $@ gen_IPinv.c ${LDFLAGS}
tab_S_P.x	: gen_S_P.c ${TOPDIR}/fips/fips_S.h ${TOPDIR}/fips/fips_P.h
	${CC} ${CFLAGS} -o $@ gen_S_P.c ${LDFLAGS}
tab_S.x		: gen_S.c ${TOPDIR}/fips/fips_S.h
	${CC} ${CFLAGS} -o $@ gen_S.c ${LDFLAGS}
tab_P.x		: gen_P.c ${TOPDIR}/fips/fips_P.h
	${CC} ${CFLAGS} -o $@ gen_P.c ${LDFLAGS}
tab_E.x		: gen_E.c ${TOPDIR}/fips/fips_E.h
	${CC} ${CFLAGS} -o $@ gen_E.c ${LDFLAGS}

tab_LS.x	: gen_LS.c ${TOPDIR}/fips/fips_LS.h
	${CC} ${CFLAGS} -o $@ gen_LS.c ${LDFLAGS}
tab_PC1.x	: gen_PC1.c ${TOPDIR}/fips/fips_PC1.h
	${CC} ${CFLAGS} -o $@ gen_PC1.c ${LDFLAGS}
tab_PC2.x	: gen_PC2.c ${TOPDIR}/fips/fips_PC2.h
	${CC} ${CFLAGS} -o $@ gen_PC2.c ${LDFLAGS}

tab_IP.h	: tab_IP.x
tab_IPinv.h	: tab_IPinv.x
tab_S_P.h	: tab_S_P.x
tab_S.h		: tab_S.x
tab_P.h		: tab_P.x
tab_E.h		: tab_E.x

tab_LS.h	: tab_LS.x
tab_PC1.h	: tab_PC1.x
tab_PC2.h	: tab_PC2.x

tab_IP.c	: tab_IP.x tab_IP.h
tab_IPinv.c	: tab_IPinv.x tab_IPinv.h
tab_S_P.c	: tab_S_P.x tab_S_P.h
tab_S.c		: tab_S.x tab_S.h
tab_P.c		: tab_P.x tab_P.h
tab_E.c		: tab_E.x tab_E.h

tab_LS.c	: tab_LS.x tab_LS.h
tab_PC1.c	: tab_PC1.x tab_PC1.h
tab_PC2.c	: tab_PC2.x tab_PC2.h


bench.o	: ${TOPDIR}/verify/bench.c
	${CC} ${CFLAGS} -c ${TOPDIR}/verify/bench.c

bench	: bench.o ${BENCH_OBJS}
	${CC} ${CCOPT} -o $@ bench.o ${BENCH_OBJS}


dea_conf.h	: ${BENCH_PROG} dea_conf.cr des_dea.c ${GEN_DEA_SRCS}
	${RM} tmp.h
	${BENCH_PROG} ${BENCH_ARGS} 'DEFINES=-DDEA_TEST ${DEFINES}' \
		'BENCH_REMOVES=bench dea_bench.o ${TAB_DEA_PROGS}' \
		'BENCH_OBJS=dea_bench.o ${TAB_DEA_OBJS}' \
		-d dea.bench -f dea_conf.cr -o tmp.h bench
	${MV} tmp.h $@

dea_bench.o	: des_dea.c ${TAB_DEA_HDRS}
	${RM} des_dea.o
	${CC} ${CFLAGS} -c des_dea.c
	${MV} des_dea.o $@


dea3_conf.h	: ${BENCH_PROG} dea3_conf.cr des_dea3.c des_dea.o ${TAB_DEA_OBJS}
	${RM} tmp.h
	${BENCH_PROG} ${BENCH_ARGS} 'DEFINES=-DDEA3_TEST ${DEFINES}' \
		'BENCH_REMOVES=bench dea3_bench.o' \
		'BENCH_OBJS=dea3_bench.o des_dea.o ${TAB_DEA_OBJS}' \
		-d dea3.bench -f dea3_conf.cr -o tmp.h bench
	${MV} tmp.h $@

dea3_bench.o	: des_dea3.c ${TAB_DEA_HDRS}
	${RM} des_dea3.o
	${CC} ${CFLAGS} -c des_dea3.c
	${MV} des_dea3.o $@


sch_conf.h	: ${BENCH_PROG} sch_conf.cr des_sched.c ${GEN_SCHED_SRCS}
	${RM} tmp.h
	${BENCH_PROG} ${BENCH_ARGS} 'DEFINES=-DSCH_TEST ${DEFINES}' \
		'BENCH_REMOVES=bench sch_bench.o ${TAB_SCHED_PROGS}' \
		'BENCH_OBJS=sch_bench.o ${TAB_SCHED_OBJS}' \
		-d sch.bench -f sch_conf.cr -o tmp.h bench
	${MV} tmp.h $@

sch_bench.o	: des_sched.c ${TAB_SCHED_HDRS}
	${RM} des_sched.o
	${CC} ${CFLAGS} -c des_sched.c
	${MV} des_sched.o $@


# To keep old make programs happy.
des_dea.o	: des_dea.c dea.h dea_conf.h ${TAB_DEA_HDRS}
des_dea3.o	: des_dea3.c dea.h dea_conf.h dea3_conf.h ${TAB_DEA_HDRS}
des_dea3b.o	: des_dea3b.c dea.h dea_conf.h dea3_conf.h ${TAB_DEA_HDRS}
des_sched.o	: des_sched.c sch_conf.h ${TAB_SCHED_HDRS}

tab_IP.o	: tab_IP.c
tab_IPinv.o	: tab_IPinv.c
tab_S_P.o	: tab_S_P.c
tab_S.o		: tab_S.c
tab_P.o		: tab_P.c
tab_E.o		: tab_E.c

tab_LS.o	: tab_LS.c
tab_PC1.o	: tab_PC1.c
tab_PC2.o	: tab_PC2.c

# DEPEND
#
# Don not change the lines below, run make depend
#
