#!/usr/bin/env bash

TARGET="$1"
shift
PARAMS=""
if [ $# -gt 1 ]; then
  PARAMS="$@"
fi
# Optimized (slow to build)
if [[ ! "$TARGET" -eq 2 ]]; then 
  mex CXXOPTIMFLAGS='-O0 -w -s -ffast-math -fopenmp -msse2 -fPIC' CXXFLAGS="$PARAMS -DUNIX_MODE -DMEXMODE -fPIC -g -ftls-model=global-dynamic" CXXLIBS='${CXXLIBS} -Wl,--export-dynamic -Wl,-e,mexFunction -shared' -I./include/ -I/usr/include/ src/nnfMex.cpp -output nnmex -output nnmex
fi
if [[ ! "$TARGET" -eq 1 ]]; then
  mex CXXOPTIMFLAGS='-O0 -w -s -ffast-math -fopenmp -msse2 -fPIC' CXXFLAGS="$PARAMS -DUNIX_MODE -DMEXMODE -g" CXXLIBS='${CXXLIBS} -Wl,--export-dynamic -Wl,-e,mexFunction -shared' -I./include/ -I/usr/include/ src/voteMex.cpp -output votemex -output votemex
fi
# mex CXXOPTIMFLAGS='-O6 -w -s -ffast-math -fomit-frame-pointer -fstrength-reduce -fopenmp -msse2 -funroll-loops -fPIC' CXXFLAGS='-DNDEBUG -DUNIX_MODE -DMEXMODE -fopenmp' CXXLIBS='${CXXLIBS} -Wl,--export-dynamic -Wl,-e,mexFunction -shared -lgomp' -inline knn.cpp mexutil.cpp nn.cpp votemex.cpp patch.cpp vecnn.cpp simnn.cpp allegro_emu.cpp -output nnmex -output votemex
# mex CXXOPTIMFLAGS='-O6 -w -s -ffast-math -fomit-frame-pointer -fstrength-reduce -fopenmp -msse2 -funroll-loops -fPIC' CXXFLAGS='-DNDEBUG -DUNIX_MODE -DMEXMODE -fopenmp' CXXLIBS='${CXXLIBS} -Wl,--export-dynamic -Wl,-e,mexFunction -shared -lgomp' -L/usr/include/opencv -lopencv_core -lopencv_highgui -lopencv_imgproc -I./include/ -I/usr/include/ -I/usr/include/opencv/ src/mex/mxarray.cpp src/nnfMex.cpp -output nnmex -output nnmex

# Unoptimized (fast to build)
#mex CXXOPTIMFLAGS='-w -fPIC' CXXFLAGS='-DNDEBUG -DUNIX_MODE -DMEXMODE -fopenmp' CXXLIBS='${CXXLIBS} -Wl,--export-dynamic -Wl,-e,mexFunction -shared -lgomp' -inline knn.cpp mexutil.cpp nn.cpp nnmex.cpp patch.cpp vecnn.cpp simnn.cpp allegro_emu.cpp -output nnmex -output nnmex
#mex CXXOPTIMFLAGS='-w -fPIC' CXXFLAGS='-DNDEBUG -DUNIX_MODE -DMEXMODE -fopenmp' CXXLIBS='${CXXLIBS} -Wl,--export-dynamic -Wl,-e,mexFunction -shared -lgomp' -inline knn.cpp mexutil.cpp nn.cpp votemex.cpp patch.cpp vecnn.cpp simnn.cpp allegro_emu.cpp -output nnmex -output votemex

