#
# Makefile
#

TOPLEVEL=../../..
CRYPTOTOP=..
OBJDIRNAME = obj

include $(CRYPTOTOP)/common.mk

# Input and output files for this subdirectory
APPS= $(BINDIR)/rsa_test $(BINDIR)/rsa_compat_test $(BINDIR)/aes_wraptest   \
      $(BINDIR)/aes_ecbtest $(BINDIR)/aes_ctstest $(BINDIR)/aes_cbctest     \
      $(BINDIR)/prng
APPS.exe = $(patsubst %, %.exe, $(APPS))
LIBS= $(LIBDIR)/libcrypto.a

#
# Where to put the output binaries from this build
#
OUTPUTDIR = $(BINDIR)

# Search paths (none for this project)
VPATH =

.PHONY: dobuild all clean cleanobjs

all: dobuild $(APPS)

SOURCE_FILES = $(RSASRC)

DEPENDS = $(patsubst %.c, $(OBJDIR)/%.d, $(SOURCE_FILES))

COBJS = $(patsubst %.c, $(OBJDIR)/%.o, $(SOURCE_FILES))

OBJS = $(COBJS)

# Include the various dependancy files.
ifneq ($(MAKECMDGOALS), clean)
 ifneq ($(MAKECMDGOALS), cleanobjs)
  -include $(DEPENDS)
 endif # cleanobjs
endif # clean

$(BINDIR)/rsa_test: rsa_test.c $(LIBS)
	$(CC) $(CFLAGS) -o $(BINDIR)/rsa_test $^ -L$(LIBDIR) -lcrypto

$(BINDIR)/rsa_compat_test: rsa_compat_test.c $(LIBS)
	$(CC) $(CFLAGS) -o $@ $^ -L$(LIBDIR) -lcrypto

$(BINDIR)/aes_wraptest: aes_wraptest.c $(LIBS)
	$(CC) $(CFLAGS) -o $(BINDIR)/aes_wraptest $^ -L$(LIBDIR) -lcrypto

$(BINDIR)/aes_ctstest: aes_ctstest.c $(LIBS)
	$(CC) $(CFLAGS) -o $(BINDIR)/aes_ctstest $^ -L$(LIBDIR) -lcrypto

$(BINDIR)/aes_cbctest: aes_cbctest.c $(LIBS)
	$(CC) $(CFLAGS) -o $(BINDIR)/aes_cbctest $^ -L$(LIBDIR) -lcrypto

$(BINDIR)/aes_ecbtest: aes_ecbtest.c $(LIBS)
	$(CC) $(CFLAGS) -o $(BINDIR)/aes_ecbtest $^ -L$(LIBDIR) -lcrypto

ifeq ($(TEST),yes)
$(BINDIR)/prng: prng_test.c $(LIBS)
	$(CC) $(CFLAGS) -o $(BINDIR)/prng_test $^ -L$(LIBDIR) -lcrypto
else
$(BINDIR)/prng: prng_test.c $(LIBS)
	$(CC) $(CFLAGS) -o $(BINDIR)/prng_release $^ -L$(LIBDIR) -lcrypto
endif

clean:
	rm -fr $(APPS) $(APPS.exe)

cleanobjs:
