AUR

Since the addition of the pacman package manager, termux has been able to use the AUR.
=== What is AUR? ===
AUR (Arch User Repository) is a repository mainly for compiling package(s) on the device using makepkg for the pacman package manager (more details here).
Thanks to the AUR it is possible to compile packages that are not in the termux hosting or packages that are configured to run on termux (e.g. python packages).
=== What you need to know ===
Most of the AURs from aur.archlinux.org are not configured to compile in termux, this is due to the fact that termux differs from the usual linux (more details), so you need to configure them before compiling.
For makepkg in termux, there is a unique value for easy configuration or creating an AUR, these are:
* $terdir - it is a $pkgdir with an incomplete termux prefix, usually $pkgdir/data/data/com.termux/files.
* $prefix and $home - these are the familiar termux system values ​​$HOME and $PREFIX, but they do not depend on them. This is necessary for compiling on computers with different system values.
For normal operation and compilation of the AUR, it is recommended to use pacman as the main package manager on your device (the default is apt). That is, switch from apt to pacman. How to do this is written here. But you can continue to use apt, but be prepared for AUR dependency issues that can't be fixed.
=== Installing the required packages ===
To work with the AUR, you need to install the base-devel package group, this group contains compilers and other dependencies for makepkg and the stages of the AUR compilation itself.
 pacman -S base-devel
=== An example of creating an AUR for termux ===
As an example, let's create a hello-world package (it's best to do this in a separate directory). The directory should contain a main.c file with the following content.
 #include <stdio.h>
 
 int main() {
 printf("Hello, World!\n");
 return 0;
 }
After that, we can create a PKGBUILD file, this file contains all the information of the future package and compilation steps.
 pkgname="hello-world"
 pkgver=1
 pkgrel=0
 pkgdesc="Simple program for example AUR packages"
 arch=('aarch64' 'arm' 'x86_64' 'i686')
 url="anything"
 license=('MIT')
 source=('main.c')
 sha256sums=('1321ad6ef0689bf355fa4d028405acea89c6a3ff433b41ed45654a5c701c95ed')
 
 build() {
 gcc -o "${pkgname}" main.c
 }
 
 package() {
 install -Dm755 "${pkgname}" "${terdir}/usr/bin/${pkgname}" 
 }
Explanation of meaning and function:
* pkgname - package name.
* pkgver and pkgrel - package version.
* pkgdesc - package description.
* arch - processor architectures that the package supports. 
* url - home link of the package (project).
* license - package (project) license.
* source - path to the source code of the package. Usually, source contains a link to the source code archive, but in our case, we simply specify an already existing file in the directory.
* sha256sums - value to check the file.
* build() - this function should contain compilation of the package code in $srcdir.
* package() - this function should say how to place the package (commands) in $pkgdir.
All the meanings and their detailed explanation are here.
After that, we can start the compilation, for this we simply enter the makepkg command. 
=== Setting the AUR for termux ===
The main problem with the AUR from aur.archlinux.org is file locations, but other problems can also arise: dependency, architecture, and code compilation itself.
==== Fix file location ====
This problem is related to the location of the directory and files in the package. It occurs at compile time and before the package compression step, which are usually set above the /usr directory coordinate, but termux needs a different one. To fix this problem, you need to change the directory coordinates in those places where compilation is configured and where the file is being installed at a certain coordinate. 
An example change with configure and with make:
Before
 build() {
 ./configure --prefix=/usr
 make
 }
 
 package() {
 make DESTDIR="$pkgdir/" install
 }
After
 build() {
 ./configure --prefix=$prefix
 make
 }
 
 package() {
 make DESTDIR="$pkgdir/" install
 }
Note: in make's package(), we do not change the DESTDIR value to $terdir, since configure's build() already specifies the location of the file for termux and the compiler will create the necessary directories when located. But if configure is not run in build(), then such a change is definitely needed.
Example:
 build() {
 make
 }
 
 package() {
 make DESTDIR="$terdir/" install
 }
You also need to understand that the AUR uses different compilation methods and the way to change each one is different. For the example of compiling via python, the coordinates do not need to be changed, because everything is already set up in python.
==== Fixing dependencies ====
This problem occurs because pacman does not find the dependencies for the package in the dependency values ​​(see for details). Usually, to avoid this error, you need to run makepkg with the -s flag to install dependencies, but most of this is due to a wrong package name or a non-existent package specified in the host that needs to be installed not via pacman (for example, python packages that can only be installed via pip). To solve this problem, you need to rename the package or remove it in the dependency values, but before you take action, you need to understand if the package is in the hosting. To check if there is a package in the hosting, you can use pacman -Ss {namepackage}, this is a search for packages by name and description of what is in the database (I recommend changing the package name, removing numbers and parts of the word like lib or dev). If a package is found as a result of the search, then rename it. If not, then uninstall and try installing it through another package manager (google help).
==== Architecture fix ====
This issue is related to the wrong arch value in PKGBUILD. To fix it, you just need to change this value.
 arch=('aarch64' 'arm' 'x86_64' 'i686')
There can only be 4 architectures in the value (these are aarch64, arm, x86_64 and i686), because termux only supports them. It is also possible to remove a certain architecture from package dependencies.
==== Fix compiling code ====
This problem is related to the fact that the code does not compile or does not compile correctly. To solve this problem, patch files are used in the prepare() function. 
Creating a patch file and using
First, let's create a copy of the file (I recommend next to the original) that will contain the desired changes.
 cp src/path/to/file src/path/to/file.patch
 nano src/patch/file.patch
Then you can create a patch file. Note: all changes must occur through src, so specify files through src. If this is not done, then when trying to change, we will get an error.
 diff -uNr src/path/to/file src/path/to/file.patch > file.patch
After that, you can add a code change step to the PKGBUILD.
 source=(...
 file.patch) # here we specify the file
 
 ...
 
 sha256sums=(...
 {VALLUE}) # https://wiki.archlinux.org/title/PKGBUILD#Integrity
 
 ...
 
 prepare() { # here is the step of changing the code
 patch -Np1 -i "${srcdir}"/file.patch
 }