[Android Software Development] DualJoe:
These are my recipes/notes for Cryptsetup. They are more of reminders than strict instructions. Its possible that some don't work work anymore or are buggy/invalid.

I compile into /tmp/myout first and copy files manually into $SYSROOT. Some files/programs need quirks/manual patches. I've added comments here and there. My cross-compile toolchain bootstrap scripts (gcc-musl_wrapper-*.sh) are attached here.

Hope this helps. Good luck!

# 32Bit: . ~/android/gcc-musl_wrapper-hf.sh
# 64Bit: . ~/android/gcc-musl_wrapper-aarch64.sh

# Cryptsetup v2.3.5
# 13.04.2021
# wget https://mirrors.edge.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.5.tar.xz
# 1xAlpine patch, 1xTermux patch
# deps: popt, libgcrypt (precompiled static Alpine available), lvm2, json-c, argon2-libs, openssl (faster than libressl), libuuid/util-linux
./configure --host=${CROSS_COMPILE} --prefix=${SYSROOT}/usr --libdir=${SYSROOT}/usr/lib --includedir=${SYSROOT}/usr/include --bindir=${SYSROOT}/usr/bin --sbindir=${SYSROOT}/usr/sbin --enable-cryptsetup-reencrypt --disable-selinux --disable-udev --enable-static-cryptsetup --enable-static --disable-shared --disable-nls --disable-rpath --with-libgcrypt-prefix=${SYSROOT}/usr --with-luks2-lock-path=/dev/cryptsetup --enable-libargon2 ac_cv_func_explicit_bzero=no
make -j4
make install DESTDIR=/tmp/myout DEST_HOME=/tmp/myout/usr DEST_MAN=/tmp/myout/usr/share/man

# argon2-libs (phc-winner-argon2-20190702)
# https://github.com/P-H-C/phc-winner-argon2/releases
- makefile -> CFLAGS += ... -fPIC
make -j4
- fix pkgconfig

# json-c v0.15 12.12.2020
# wget https://github.com/json-c/json-c/archive/json-c-0.15-20200726.tar.gz
rm -rf json-c-build && mkdir json-c-build && cd json-c-build
# 32Bit
cmake -DCMAKE_TOOLCHAIN_FILE=~/android/cmake-toolchain.cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX=/tmp/myout/usr -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_C_FLAGS="$CFLAGS" ../json-c-json-c-0.15-20200726
# 64Bit
cmake -DCMAKE_TOOLCHAIN_FILE=~/android/cmake-toolchain64.cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX=/tmp/myout/usr -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_C_FLAGS="$CFLAGS" ../json-c-json-c-0.15-20200726
make -j4
make install
- fix pkgconfig/json-c.pc

# popt 1.18
# https://github.com/rpm-software-management/popt/releases/tag/popt-1.18-release
cp /usr/share/automake-1.16/config.guess . && cp /usr/share/automake-1.16/config.sub .
#aclocal && autoconf && autoreconf -i
./configure --host=${CROSS_COMPILE} --prefix=${SYSROOT}/usr --without-libintl-prefix --disable-shared --disable-nls --disable-rpath
make -j4
make install DESTDIR=/tmp/myout DEST_HOME=/tmp/myout/usr DEST_MAN=/tmp/myout/usr/share/man

# lvm2
# 12.12.2020
# 2.03 has no Alpine patches
# https://sourceware.org/git/?p=lvm2.git
# ftp://sourceware.org/pub/lvm2/
# 4xAlpine patches
# deps: libaio
export CC="${CROSS_PATH}-gcc ${CFLAGS}"
./configure --host=${CROSS_COMPILE} --prefix=${SYSROOT}/usr --sysconfdir=${SYSROOT}/etc --includedir=${SYSROOT}/usr/include --disable-selinux --enable-static_link --disable-udev-systemd-background-jobs --disable-readline --enable-pkgconfig --disable-use-lvmpolld --disable-use-lvmlockd --disable-nls ac_cv_func_realloc_0_nonnull=yes ac_cv_func_malloc_0_nonnull=yes
make -j4 device-mapper
make install_device-mapper DESTDIR=/tmp/myout DEST_HOME=/tmp/myout/usr DEST_MAN=/tmp/myout/usr/share/man
- fix file permissions: chmod -R u+w /tmp/myout/*

# libaio 0.3.112
# 11.05.2020
# https://releases.pagure.org/libaio/libaio-0.3.112.tar.gz
# 3xAlpine patches
make prefix="/tmp/myout/usr" \
sysconfdir="/tmp/myout/etc" \
mandir="/tmp/myout/usr/share/man" \
infodir="/tmp/myout/usr/share/info" \
install

# Install kernel headers
kernel root folder:
32Bit: CC=false make V=1 ARCH=arm INSTALL_HDR_PATH=/tmp/myout headers_install
64Bit: CC=false make V=1 ARCH=arm64 INSTALL_HDR_PATH=/tmp/myout headers_install

# libuuid / util-linux 2.36
# 12.12.2020
# https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.36/util-linux-2.36.tar.gz
# cp "$srcdir"/ttydefaults.h include/ (???)

libtoolize --force && aclocal -I m4 && autoconf && automake --add-missing

./configure --host=${CROSS_COMPILE} --prefix=${SYSROOT}/usr --libdir=${SYSROOT}/usr/lib --includedir=${SYSROOT}/usr/include --bindir=${SYSROOT}/usr/bin --localstatedir=${SYSROOT}/run --enable-fs-paths-extra=${SYSROOT}/usr/bin --enable-static --disable-shared --disable-nls --without-python --disable-all-programs --enable-libuuid

make -j4
fakeroot make install DESTDIR=/tmp/myout DEST_HOME=/tmp/myout/usr DEST_MAN=/tmp/myout/usr/share/man

# libgcrypt 1.9.2
# 13.04.2021
# deps: libgpg-error
# https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.8.7.tar.gz

./configure --disable-padlock-support --host=${CROSS_COMPILE} --enable-static --disable-shared --prefix=${SYSROOT}/usr --libdir=${SYSROOT}/usr/lib --includedir=${SYSROOT}/usr/include --with-gpg-error-prefix=${SYSROOT}/usr gcry_cv_gcc_arm_platform_as_ok=no
make -j4
make install DESTDIR=/tmp/myout DEST_HOME=/tmp/myout/usr DEST_MAN=/tmp/myout/usr/share/man

# libgpg-error 1.39
# 12.12.2020
# https://gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.39.tar.gz
# link libgpg-error-1.37/src/syscfg/lock-obj-pub.arm-unknown-linux-gnueabi.h to lock-obj-pub.linux-musleabihf.h
32bit: ln -sf lock-obj-pub.arm-unknown-linux-gnueabi.h src/syscfg/lock-obj-pub.linux-musleabihf.h
64bit: ln -sf lock-obj-pub.aarch64-unknown-linux-gnu.h src/syscfg/lock-obj-pub.linux-musl.h
./configure --host=${CROSS_COMPILE} --prefix=${SYSROOT}/usr --exec-prefix=${SYSROOT}/usr --disable-nls --disable-tests --disable-doc --enable-static --disable-nls --disable-shared --libdir=${SYSROOT}/usr/lib --includedir=${SYSROOT}/usr/include

# src/Makefile: "Confirm gpg-error-config works" - comment out 'exit 1'.

make -j4 #CC_FOR_BUILD="/usr/bin/gcc -s -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -Wp,-I/usr/include -Wl,-L/usr/lib,-O1,--sort-common,--as-needed,-z,relro"
make install DESTDIR=/tmp/myout DEST_HOME=/tmp/myout/usr DEST_MAN=/tmp/myout/usr/share/man

# openssl v1.1.1k
# 13.04.2021
# https://www.openssl.org/source/openssl-1.1.1k.tar.gz
# 3x Termux patches (Configurations-15-android.conf.patch, apps-ocsp.c.patch, crypto-armcap.c.patch <- fails, do manual)
unset CROSS_COMPILE
./Configure --prefix=${SYSROOT}/usr linux-armv4 no-shared no-hw no-comp no-async no-tests ${CFLAGS} ${LDFLAGS}
./Configure --prefix=${SYSROOT}/usr linux-aarch64 no-shared no-hw no-comp no-async no-tests ${CFLAGS} ${LDFLAGS}
make -j4
make install DESTDIR=/tmp/myout DEST_HOME=/tmp/myout/usr DEST_MAN=/tmp/myout/usr/share/man