#!/bin/sh

# convert ssleay libs to use rsaref.
# ssleay should be build with ./Configure -DRSAref system-type
# and -I../../rsaref should be added to CFLAGS in the top Makefile.
# do a 'make', and run this script after it barfs out on the SSL
# apps (linking ssleay). then run 'make' again to finish off.
#
# dugsong@monkey.org

TMPDIR=/tmp/ssleay-rsaref$$
CWD=`pwd`

trap 'rm -rf $TMPDIR ; exit 0' 0 1 2 3 13 15

if [ ! -f librsaref.a ]; then
  echo "where is librsaref? put it in $CWD"
  exit 1
fi

mkdir $TMPDIR
cp *.a $TMPDIR
cd $TMPDIR

echo "unpacking rsaref libs"
ar xv libRSAglue.a
ar xv librsaref.a

echo "adding rsaref objs to libcrypto"
ar -r -a rsa_enc.o libcrypto.a \
`(ar t libRSAglue.a ; ar t librsaref.a) | egrep '\.o'`

# can't do this cos we need to map RSA_PKCS1_SSLeay -> RSA_PKCS1_RSAref
# could modify src, but it's a pain to maintain.
#echo "getting rid of rsa_enc.o"
#ar dv libcrypto.a rsa_enc.o

echo "generating new symbol table"
ranlib libcrypto.a

echo "backing up original libcrypto and libRSAglue"
cd $CWD
mv libcrypto.a libcrypto.a.orig
mv libRSAglue.a libRSAglue.a.orig
cp $TMPDIR/libcrypto.a .

echo "done."

exit 0
