#!/bin/sh

mkdir -p deps
cd deps


echo "Downloading RDKit source"
rdkit_release="Release_2023_09_3"
curl -L https://github.com/rdkit/rdkit/archive/refs/tags/$rdkit_release.tar.gz -o "$rdkit_release.tar.gz"

echo "Unpacking RDKit source"
tar xf "$rdkit_release.tar.gz"
echo

echo "Downloading graphene source"
curl -L https://github.com/ebassi/graphene/archive/refs/tags/1.10.8.tar.gz -o graphene_1.10.8.tar.gz
echo

echo "Unpacking graphene source"
tar xf "graphene_1.10.8.tar.gz"
echo

echo "Downloading libsigc++ source"
curl -L https://github.com/libsigcplusplus/libsigcplusplus/archive/refs/tags/3.6.0.tar.gz -o libsigcplusplus_3.6.0.tar.gz
echo

echo "Unpacking libsigc++ source"
tar xf "libsigcplusplus_3.6.0.tar.gz"
echo

#Create an empty file silly.c and then compile it with USE_ZLIB and USE_LIBPNG to force emsdk to get zlib/png.
echo "Attempting to get emsdk zlib/png ports"
echo
echo "" > silly.c
emcc silly.c -s USE_ZLIB=1 -s USE_LIBPNG=1 -s USE_FREETYPE=1
rm -f silly.c
rm -f a.out.js
rm -f a.out.wasm

# #Get RDKit
# echo "Downloading RDKit_minimal js/wasm"
# echo
# curl -L https://unpkg.com/@rdkit/rdkit/Code/MinimalLib/dist/RDKit_minimal.wasm -o web_example/RDKit_minimal.wasm
# curl -L https://unpkg.com/@rdkit/rdkit/Code/MinimalLib/dist/RDKit_minimal.js -o web_example/RDKit_minimal.js

echo "Checking out boost"
curl -L https://boostorg.jfrog.io/artifactory/main/release/1.83.0/source/boost_1_83_0.tar.bz2 -o boost_1_83_0.tar.bz2
tar xf boost_1_83_0.tar.bz2

ln -s boost_1_83_0 boost
ln -s "rdkit-$rdkit_release" rdkit


patch -p0 < ../patches/boost-emscripten.patch
patch -p0 < ../patches/boost-cxx-17.patch

cd ..



