#!/bin/bash
if test $# -ge 1; then
export HTTPS_PROXY=$1
fi
if test -z $HTTPS_PROXY; then
yum install -y epel-release
yum-config-manager --add-repo=https://download.opensuse.org/repositories/science:/dlr/CentOS_7/
yum install -y --nogpgcheck ccache libxerces-c-devel proj-devel fox16-devel bzip2-devel gl2ps-devel swig3 eigen3-devel
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y geos311-devel
yum install -y https://packages.apache.org/artifactory/arrow/centos/$(cut -d: -f5 /etc/system-release-cpe | cut -d. -f1)/apache-arrow-release-latest.rpm
yum install -y arrow-devel parquet-devel
pipx install -f patchelf==0.16.1.0
fi
if test $# -ge 2; then
pushd ..
git clone https://github.com/PedestrianDynamics/jupedsim -b $2 --depth 1
mkdir jupedsim-build jupedsim-install
cd jupedsim-build
cmake -DCMAKE_INSTALL_PREFIX=$PWD/../jupedsim-install ../jupedsim
cmake --build . -j$(nproc)
cmake --install .
popd
fi
mkdir -p $HOME/.ccache
echo "hash_dir = false" >> $HOME/.ccache/ccache.conf
echo "base_dir = $PWD/_skbuild/linux-x86_64-3.8" >> $HOME/.ccache/ccache.conf
cp build_config/pyproject.toml .
py=/opt/python/cp312-cp312
$py/bin/python tools/build_config/version.py tools/build_config/setup-sumo.py ./setup.py
$py/bin/python -m build --wheel
mv dist/eclipse_sumo-* `echo dist/eclipse_sumo-* | sed 's/cp312-cp312/py2.py3-none/'`
auditwheel repair dist/eclipse_sumo*.whl
cp -a data tools/libsumo
for py in /opt/python/cp3[1789]*; do
rm dist/*.whl
pminor=`echo $py | sed 's,/opt/python/cp3,,;s/-.*//'`
echo "base_dir = $PWD/_skbuild/linux-x86_64-3.${pminor}" >> $HOME/.ccache/ccache.conf
$py/bin/python tools/build_config/version.py tools/build_config/setup-sumo.py ./setup.py
$py/bin/python -m build --wheel
$py/bin/python tools/build_config/version.py tools/build_config/setup-libsumo.py tools/setup.py
$py/bin/python -m build --wheel tools -o dist
auditwheel repair dist/libsumo*.whl
done
rm -rf tools/*.egg-info tools/build_config/*.egg-info tools/build tools/libsumo/data pyproject.toml setup.py tools/setup.py data/locale
find tools -name __pycache__ | xargs rm -rf
chmod -R a+w _skbuild dist wheelhouse