cp $RECIPE_DIR/makefile.inc .
cp $RECIPE_DIR/setup.py .

make tests/test_blas -j $(nproc)
echo "HERE"
make -j $(nproc)
echo "HERE2"
make py
echo "HERE3"

rm -f python/_swigfaiss_gpu.so

sed -i "s/from swigfaiss/from .swigfaiss/g" faiss.py

echo "HERE4"

find $SP_DIR/torch -name "*.so*" -maxdepth 1 -type f | while read sofile; do
    echo "Setting rpath of $sofile to " '$ORIGIN:$ORIGIN/../../..'
    patchelf --set-rpath '$ORIGIN:$ORIGIN/../../..' $sofile
    patchelf --print-rpath $sofile
done

echo "HERE5"
python setup.py install
