CFLAGS = $(CCOPTS) $(DEFS)

##DOSBUILDTOP = ..\..\..
##DOSLIBNAME=..\crypto.lib
##DOS!include $(BUILDTOP)\config\windows.in

COMERRLIB=$(BUILDTOP)/util/et/libcom_err.$(LIBEXT)

KLIB = $(TOPLIBD)/libkrb5.$(LIBEXT) $(TOPLIBD)/libcrypto.$(LIBEXT) $(COMERRLIB)
DEPKLIB = $(TOPLIBD)/libkrb5.$(LIBEXT) $(TOPLIBD)/libcrypto.$(LIBEXT) $(COMERRLIB)

OTHERSRCS=$(srcdir)/f_cbc.c $(srcdir)/f_cksum.c \
	$(srcdir)/f_sched.c $(srcdir)/f_ecb.c $(srcdir)/f_parity.c \
	$(srcdir)/f_tables.c

OTHEROBJS=f_cbc.$(OBJEXT) f_cksum.$(OBJEXT) f_sched.$(OBJEXT) f_ecb.$(OBJEXT) f_parity.$(OBJEXT) f_tables.$(OBJEXT)

.c.o:
	$(CC) $(CFLAGS) -c $(srcdir)/$*.c
@SHARED_RULE@

OBJS=	cbc_cksum.$(OBJEXT)	\
	cs_entry.$(OBJEXT)	\
	finish_key.$(OBJEXT)	\
	fin_rndkey.$(OBJEXT)	\
	init_rkey.$(OBJEXT)	\
	process_ky.$(OBJEXT)	\
	random_key.$(OBJEXT)	\
	string2key.$(OBJEXT)	\
	new_rn_key.$(OBJEXT)	\
	key_sched.$(OBJEXT)	\
	weak_key.$(OBJEXT)	\
	$(OTHEROBJS)

SRCS=	$(srcdir)/cs_entry.c	\
	$(srcdir)/cbc_cksum.c	\
	$(srcdir)/finish_key.c	\
	$(srcdir)/fin_rndkey.c	\
	$(srcdir)/init_rkey.c	\
	$(srcdir)/process_ky.c	\
	$(srcdir)/random_key.c	\
	$(srcdir)/string2key.c	\
	$(srcdir)/new_rn_key.c	\
	$(srcdir)/key_sched.c	\
	$(srcdir)/weak_key.c	\
	$(OTHERSRCS)

all:: all-$(WHAT) $(OBJS)

all-unix:: shared
all-mac:: shared
all-windows::

shared:
	mkdir shared

includes:: depend

depend:: $(SRCS)

# FIXME, this is left from the previous DES implementation.
clean::
	$(RM) fp.c ip.c key_perm.h odd.h p.c p_table.h s_table.h

verify$(EXEEXT): verify.$(OBJEXT) $(DEPKLIB)
	$(CC) -o $@ verify.$(OBJEXT) $(KLIB) $(LIBS) $(CFLAGS) $(LDFLAGS) 

destest$(EXEEXT): destest.$(OBJEXT) $(DEPKLIB)
	$(CC) -o $@ destest.$(OBJEXT) $(KLIB) $(LIBS) $(CFLAGS) $(LDFLAGS) 

check:: check-$(WHAT)

check-mac: check-unix

check-unix:: destest verify
	./verify -z
	./verify -m
	./verify
	./destest < $(srcdir)/keytest.data

check-windows::

clean:: clean-$(WHAT)
	$(RM) destest$(EXEEXT) verify$(EXEEXT) destest.$(OBJEXT) verify.$(OBJEXT)

clean-unix::
	$(RM) shared/*
clean-mac::
	$(RM) shared/*
clean-windows::
