#!/bin/bash
# To pass parameters to the cryptopp makefile, use `CRYPTOPP_FLAGS=... ./get-cryptopp`
set -e

DEPSRC=./depsrc
DEPINST=./depinst
DUMMIES="cryptopp-dummy.exe"

set -x

mkdir -p $DEPINST
DEPINST=`pwd -P`/$DEPINST  # remember absolute path

mkdir -p $DEPSRC
cd $DEPSRC

mkdir -p cryptopp562 && cd cryptopp562
if [ ! -f hmac.cpp ]; then
    wget http://www.cryptopp.com/cryptopp562.zip
    echo "5cbfd2fcb4a6b3aab35902e2e0f3b59d9171fee12b3fc2b363e1801dfec53574  cryptopp562.zip" | sha256sum -c
    unzip cryptopp562.zip
fi

make static dynamic CXXFLAGS='-DNDEBUG -g -O2 -fPIC' $CRYPTOPP_FLAGS
touch $DUMMIES # kludge: cryptopp's "make install" breaks if there are no such files to install
make install PREFIX=$DEPINST/ $CRYPTOPP_FLAGS
rm -f $DUMMIES
