1. Read `packages/$PKG/build.sh` to obtain package metadata (e.g. version, description, dependencies), URLs for source code and steps to build package.
4. Set up a standalone Android NDK toolchain and patch NDK sysroot from patches located in [ndk-patches](../ndk-patches) directory. This step performed only one time per each architecture.
6. Build the package under directory `$HOME/.termux-build/$PKG/build`. If `TERMUX_PKG_BUILD_IN_SRC` is set, then build will be done in directory `$HOME/.termux-build/$PKG/src`.
- Most programs expect that target is [FHS](https://uk.wikipedia.org/wiki/Filesystem_Hierarchy_Standard) compliant. They have hardcoded paths like `/etc`, `/bin`, `/usr/share`, `/tmp` which are not available in Termux at standard locations but only in `$TERMUX_PREFIX`.
- The Android bionic libc does not have iconv and gettext/libintl functionality built in. A `libandroid-support` package contains these and may be used by all packages.
- "error: z: no archive symbol table (run ranlib)" usually means that the build machine's libz is used instead of the one for cross-compilation due to the builder library -L path being setup incorrectly.
- rindex(3) does not exist, but strrchr(3) is preferred anyway.
-<sys/termios.h> does not exist, but <termios.h> is the standard location.
-<sys/fcntl.h> does not exist, but <fcntl.h> is the standard location.
-<sys/timeb.h> does not exist (removed in POSIX 2008), but ftime(3) can be replaced with gettimeofday(2).
-<glob.h> does not exist, but is available through the `libandroid-glob` package.
- SYSV shared memory is not supported by the kernel. A `libandroid-shmem` package, which emulates SYSV shared memory on top of the [ashmem](http://elinux.org/Android_Kernel_Features#ashmem) shared memory system, is available. Use it with `LDFLAGS+=" -landroid-shmem`.
- SYSV semaphores is not supported by the kernel. Use unnamed POSIX semaphores instead (named semaphores are unimplemented).
- Starting from Android 8, a [Seccomp](https://android-developers.googleblog.com/2017/07/seccomp-filter-in-android-o.html) was enabled for applications. Seccomp forbids usage of some system calls which results in crash with `Bad system call` errors.
- Starting from Android 8, programs cannot use `tcsetattr()` with `TCSAFLUSH` parameter due to SELinux. Use `TCSANOW` instead.
- Starting from Android 9, [Seccomp](https://android-developers.googleblog.com/2017/07/seccomp-filter-in-android-o.html) began to block `setuid()`-related system calls. Since Termux is primarily for single-user non-root usage, setuid/setgid functionality is discouraged anyway.
1. They differ in value from glibc ones, so cannot be hardcoded in files (DLFCN.py in python does this)
2. They are missing some values (`RTLD_BINDING_MASK`, ...)
### Android Dynamic Linker
The Android dynamic linker is located at `/system/bin/linker` (32-bit) or `/system/bin/linker64` (64-bit). Here are source links to different versions of the linker:
- The linker warns about unused [dynamic section entries](https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-42444.html) with a `WARNING: linker: $BINARY: unused DT entry: type ${VALUE_OF_d_tag}` message.
- The Termux build system uses [termux-elf-cleaner](https://github.com/termux/termux-elf-cleaner) to strip away unused ELF entries causing the above mentioned linker warnings.
- Symbol versioning is supported only as of Android 6.0, so is stripped away.
-`DT_RUNPATH`, the same as above but looked at after `LD_LIBRARY_PATH`, is supported only from Android 7.0, so is stripped away.
- Symbol visibility when opening shared libraries using `dlopen()` works differently. On a normal linker, when an executable linking against a shared library libA dlopen():s another shared library libB, the symbols of libA are exposed to libB without libB needing to link against libA explicitly. This does not work with the Android linker, which can break plug-in systems where the main executable dlopen():s a plug-in which doesn't explicitly link against some shared libraries already linked to by the executable. See [the relevant NDK issue](https://github.com/android-ndk/ndk/issues/201) for more information.