post_install() {

set -e

PACMAN_INSTALLED="false"
test -e /data/data/com.termux/files/usr/bin/pacman-conf && PACMAN_INSTALLED="true"
if [ "$PACMAN_INSTALLED" = "true" ]; then
	TERMUX_ARCH="$(pacman-conf Architecture)"
else
	TERMUX_ARCH="$(dpkg --print-architecture)"
fi
TERMUX_PLATFORM="$TERMUX_ARCH-linux-android"
test $TERMUX_ARCH = "arm" && TERMUX_PLATFORM="${TERMUX_PLATFORM}eabi"

CLANG_INSTALLED="false"
test -e /data/data/com.termux/files/usr/bin/clang && CLANG_INSTALLED="true"

if [ "$CLANG_INSTALLED" = "true" ]; then
	for tool in cc c++ cpp gcc g++ $TERMUX_PLATFORM-gcc $TERMUX_PLATFORM-g++ $TERMUX_PLATFORM-cpp; do
		mv -fv /data/data/com.termux/files/usr/bin/$tool /data/data/com.termux/files/usr/share/gcc-default/$tool
	done
fi

ln -sfv gcc-15 /data/data/com.termux/files/usr/bin/cc
ln -sfv gcc-15 /data/data/com.termux/files/usr/bin/gcc
ln -sfv gcc-15 /data/data/com.termux/files/usr/bin/$TERMUX_PLATFORM-gcc
ln -sfv g++-15 /data/data/com.termux/files/usr/bin/c++
ln -sfv g++-15 /data/data/com.termux/files/usr/bin/g++
ln -sfv g++-15 /data/data/com.termux/files/usr/bin/$TERMUX_PLATFORM-g++
ln -sfv cpp-15 /data/data/com.termux/files/usr/bin/cpp
ln -sfv cpp-15 /data/data/com.termux/files/usr/bin/$TERMUX_PLATFORM-cpp
ln -sfv gfortran-15 /data/data/com.termux/files/usr/bin/$TERMUX_PLATFORM-gfortran
ln -sfv gfortran-15 /data/data/com.termux/files/usr/bin/f90
ln -sfv gfortran-15 /data/data/com.termux/files/usr/bin/f77
ln -sfv gfortran-15 /data/data/com.termux/files/usr/bin/gfortran
}
pre_remove() {

set -e

if [ "$(command -v pacman-conf || true)" = "" ]; then
	TERMUX_ARCH="$(dpkg --print-architecture)"
else
	TERMUX_ARCH="$(pacman-conf Architecture)"
fi
TERMUX_PLATFORM="$TERMUX_ARCH-linux-android"
test $TERMUX_ARCH = "arm" && TERMUX_PLATFORM="${TERMUX_PLATFORM}eabi"

CLANG_INSTALLED="false"
test -e /data/data/com.termux/files/usr/bin/clang && CLANG_INSTALLED="true"

rm -fv /data/data/com.termux/files/usr/bin/$TERMUX_PLATFORM-gfortran
rm -fv /data/data/com.termux/files/usr/bin/f90
rm -fv /data/data/com.termux/files/usr/bin/f77
rm -fv /data/data/com.termux/files/usr/bin/gfortran

if [ "$CLANG_INSTALLED" = "true" ]; then
	for tool in cc c++ cpp gcc g++ $TERMUX_PLATFORM-gcc $TERMUX_PLATFORM-g++ $TERMUX_PLATFORM-cpp; do
		mv -fv /data/data/com.termux/files/usr/share/gcc-default/$tool /data/data/com.termux/files/usr/bin/$tool
	done
else
	for tool in cc c++ cpp gcc g++ $TERMUX_PLATFORM-gcc $TERMUX_PLATFORM-g++ $TERMUX_PLATFORM-cpp; do
		rm -fv /data/data/com.termux/files/usr/bin/$tool /data/data/com.termux/files/usr/share/gcc-default/$tool
	done
fi
}
