diff --git a/build-package.sh b/build-package.sh index a8deddc656..98fea42fa0 100755 --- a/build-package.sh +++ b/build-package.sh @@ -437,6 +437,36 @@ termux_check_package_in_building_packages_list() { return $? } +# Configure variables (TERMUX_ARCH, TERMUX__PREFIX__INCLUDE_DIR, TERMUX__PREFIX__LIB_DIR) for multilib-compilation +termux_conf_multilib_vars() { + # Change the 64-bit architecture type to its 32-bit counterpart in the `TERMUX_ARCH` variable + case $TERMUX_ARCH in + "aarch64") TERMUX_ARCH="arm";; + "x86_64") TERMUX_ARCH="i686";; + *) termux_error_exit "It is impossible to set multilib arch for ${TERMUX_ARCH} arch." + esac + TERMUX__PREFIX__INCLUDE_DIR="$TERMUX__PREFIX__MULTI_INCLUDE_DIR" + TERMUX__PREFIX__LIB_DIR="$TERMUX__PREFIX__MULTI_LIB_DIR" +} + +# Run functions for normal compilation and multilib-compilation +termux_run_base_and_multilib_build_step() { + case "${1}" in + termux_step_configure|termux_step_make|termux_step_make_install) local func="${1}";; + *) termux_error_exit "Unsupported function '${1}'." + esac + cd "$TERMUX_PKG_BUILDDIR" + if [ "$TERMUX_PKG_BUILD_ONLY_MULTILIB" = "false" ]; then + "${func}" + fi + if [ "$TERMUX_PKG_BUILD_MULTILIB" = "true" ]; then + ( + termux_step_setup_multilib_environment + "${func}_multilib" + ) + fi +} + # Special hook to prevent use of "sudo" inside package build scripts. # build-package.sh shouldn't perform any privileged operations. sudo() { @@ -700,17 +730,14 @@ for ((i=0; i<${#PACKAGE_LIST[@]}; i++)); do # Even on continued build we might need to setup paths # to tools so need to run part of configure step - cd "$TERMUX_PKG_BUILDDIR" - termux_step_configure + termux_run_base_and_multilib_build_step termux_step_configure if [ "$TERMUX_CONTINUE_BUILD" == "false" ]; then cd "$TERMUX_PKG_BUILDDIR" termux_step_post_configure fi - cd "$TERMUX_PKG_BUILDDIR" - termux_step_make - cd "$TERMUX_PKG_BUILDDIR" - termux_step_make_install + termux_run_base_and_multilib_build_step termux_step_make + termux_run_base_and_multilib_build_step termux_step_make_install cd "$TERMUX_PKG_BUILDDIR" termux_step_post_make_install termux_step_install_pacman_hooks diff --git a/disabled-packages/attr32/build.sh b/disabled-packages/attr32/build.sh new file mode 100644 index 0000000000..7373a95f87 --- /dev/null +++ b/disabled-packages/attr32/build.sh @@ -0,0 +1,12 @@ +TERMUX_PKG_HOMEPAGE=http://savannah.nongnu.org/projects/attr/ +TERMUX_PKG_DESCRIPTION="Utilities for manipulating filesystem extended attributes (for testing multilib-compilation on bionic)" +TERMUX_PKG_LICENSE="GPL-2.0" +TERMUX_PKG_MAINTAINER="@termux" +TERMUX_PKG_VERSION="2.5.2" +TERMUX_PKG_SRCURL=http://download.savannah.gnu.org/releases/attr/attr-${TERMUX_PKG_VERSION}.tar.gz +TERMUX_PKG_SHA256=39bf67452fa41d0948c2197601053f48b3d78a029389734332a6309a680c6c87 +TERMUX_PKG_EXTRA_CONFIGURE_ARGS="--enable-gettext=no" +TERMUX_PKG_RM_AFTER_INSTALL="share/man/man5/attr.5" +TERMUX_PKG_BUILD_IN_SRC=true +TERMUX_PKG_EXCLUDED_ARCHES="arm, i686" +TERMUX_PKG_BUILD_MULTILIB=true diff --git a/disabled-packages/attr32/tools-attr.c.patch b/disabled-packages/attr32/tools-attr.c.patch new file mode 120000 index 0000000000..4095878c01 --- /dev/null +++ b/disabled-packages/attr32/tools-attr.c.patch @@ -0,0 +1 @@ +../../packages/attr/tools-attr.c.patch \ No newline at end of file diff --git a/disabled-packages/attr32/walk_tree.c.patch b/disabled-packages/attr32/walk_tree.c.patch new file mode 120000 index 0000000000..887fda2ca7 --- /dev/null +++ b/disabled-packages/attr32/walk_tree.c.patch @@ -0,0 +1 @@ +../../packages/attr/walk_tree.c.patch \ No newline at end of file diff --git a/scripts/build/configure/termux_step_configure.sh b/scripts/build/configure/termux_step_configure.sh index df27c8c476..72729ea7ee 100644 --- a/scripts/build/configure/termux_step_configure.sh +++ b/scripts/build/configure/termux_step_configure.sh @@ -32,3 +32,7 @@ termux_step_configure() { termux_step_configure_meson fi } + +termux_step_configure_multilib() { + termux_step_configure +} diff --git a/scripts/build/configure/termux_step_configure_autotools.sh b/scripts/build/configure/termux_step_configure_autotools.sh index 06d9e7ab64..aaa75c3622 100644 --- a/scripts/build/configure/termux_step_configure_autotools.sh +++ b/scripts/build/configure/termux_step_configure_autotools.sh @@ -32,7 +32,7 @@ termux_step_configure_autotools() { QUIET_BUILD="--enable-silent-rules --silent --quiet" fi - if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then + if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && [ ! -d "$TERMUX_PKG_TMPDIR/config-scripts" ]; then # Some packages provides a $PKG-config script which some configure scripts pickup instead of pkg-config: mkdir "$TERMUX_PKG_TMPDIR/config-scripts" for f in $TERMUX_PREFIX/bin/*config; do @@ -103,9 +103,10 @@ termux_step_configure_autotools() { # shellcheck disable=SC2086 env $AVOID_GNULIB "$TERMUX_PKG_SRCDIR/configure" \ --disable-dependency-tracking \ - --prefix=$TERMUX_PREFIX \ - --libdir=$TERMUX_PREFIX/lib \ - --sbindir=$TERMUX_PREFIX/bin \ + --prefix="$TERMUX_PREFIX" \ + --libdir="$TERMUX__PREFIX__LIB_DIR" \ + --includedir="$TERMUX__PREFIX__INCLUDE_DIR" \ + --sbindir="$TERMUX_PREFIX/bin" \ --disable-rpath --disable-rpath-hack \ $HOST_FLAG \ $TERMUX_PKG_EXTRA_CONFIGURE_ARGS \ diff --git a/scripts/build/configure/termux_step_configure_cmake.sh b/scripts/build/configure/termux_step_configure_cmake.sh index e1af9afb20..10fdbbbde8 100644 --- a/scripts/build/configure/termux_step_configure_cmake.sh +++ b/scripts/build/configure/termux_step_configure_cmake.sh @@ -45,8 +45,9 @@ termux_step_configure_cmake() { -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \ -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ - -DCMAKE_INSTALL_PREFIX=$TERMUX_PREFIX \ - -DCMAKE_INSTALL_LIBDIR=$TERMUX_PREFIX/lib \ + -DCMAKE_INSTALL_PREFIX="$TERMUX_PREFIX" \ + -DCMAKE_INSTALL_LIBDIR="$TERMUX__PREFIX__LIB_DIR" \ + -DCMAKE_INSTALL_INCLUDEDIR="$TERMUX__PREFIX__INCLUDE_DIR" \ -DCMAKE_MAKE_PROGRAM=$MAKE_PROGRAM_PATH \ -DCMAKE_SKIP_INSTALL_RPATH=ON \ -DCMAKE_USE_SYSTEM_LIBRARIES=True \ diff --git a/scripts/build/configure/termux_step_configure_meson.sh b/scripts/build/configure/termux_step_configure_meson.sh index c845d76640..838db32992 100644 --- a/scripts/build/configure/termux_step_configure_meson.sh +++ b/scripts/build/configure/termux_step_configure_meson.sh @@ -14,7 +14,8 @@ termux_step_configure_meson() { $TERMUX_PKG_BUILDDIR \ --$(test "${TERMUX_PKG_MESON_NATIVE}" = "true" && echo "native-file" || echo "cross-file") $TERMUX_MESON_CROSSFILE \ --prefix $TERMUX_PREFIX \ - --libdir lib \ + --libdir $(test "${TERMUX_ARCH}" = "${TERMUX_REAL_ARCH}" && echo "lib" || echo "lib32") \ + --includedir $(test "${TERMUX_ARCH}" = "${TERMUX_REAL_ARCH}" && echo "include" || echo "include32") \ --buildtype ${_meson_buildtype} \ ${_meson_stripflag} \ $TERMUX_PKG_EXTRA_CONFIGURE_ARGS \ diff --git a/scripts/build/setup/termux_setup_golang.sh b/scripts/build/setup/termux_setup_golang.sh index 5e7c106934..518ced87c9 100644 --- a/scripts/build/setup/termux_setup_golang.sh +++ b/scripts/build/setup/termux_setup_golang.sh @@ -54,6 +54,6 @@ termux_setup_golang() { exit 1 fi - export GOROOT="$TERMUX_PREFIX/lib/go" + export GOROOT="$TERMUX__PREFIX__LIB_DIR/go" fi } diff --git a/scripts/build/termux_create_debian_subpackages.sh b/scripts/build/termux_create_debian_subpackages.sh index 2627b08b1b..689e885b58 100644 --- a/scripts/build/termux_create_debian_subpackages.sh +++ b/scripts/build/termux_create_debian_subpackages.sh @@ -4,10 +4,10 @@ termux_create_debian_subpackages() { if [[ "$TERMUX_PACKAGE_LIBRARY" == 'glibc' ]]; then _ADD_PREFIX="glibc/" fi - if [[ "$TERMUX_PKG_NO_STATICSPLIT" == 'false' && -n "$(shopt -s globstar; shopt -s nullglob; echo ${_ADD_PREFIX}lib/**/*.a)" ]]; then + if [[ "$TERMUX_PKG_NO_STATICSPLIT" == 'false' && -n "$(shopt -s globstar; shopt -s nullglob; echo ${_ADD_PREFIX}lib{,32}/**/*.a)" ]]; then # Add virtual -static sub package if there are include files: local _STATIC_SUBPACKAGE_FILE=$TERMUX_PKG_TMPDIR/${TERMUX_PKG_NAME}-static.subpackage.sh - echo TERMUX_SUBPKG_INCLUDE=\"$(find ${_ADD_PREFIX}lib -name '*.a' -o -name '*.la') $TERMUX_PKG_STATICSPLIT_EXTRA_PATTERNS\" > "$_STATIC_SUBPACKAGE_FILE" + echo TERMUX_SUBPKG_INCLUDE=\"$(find ${_ADD_PREFIX}lib{,32} -name '*.a' -o -name '*.la' 2> /dev/null) $TERMUX_PKG_STATICSPLIT_EXTRA_PATTERNS\" > "$_STATIC_SUBPACKAGE_FILE" echo "TERMUX_SUBPKG_DESCRIPTION=\"Static libraries for ${TERMUX_PKG_NAME}\"" >> "$_STATIC_SUBPACKAGE_FILE" fi diff --git a/scripts/build/termux_create_pacman_subpackages.sh b/scripts/build/termux_create_pacman_subpackages.sh index 868af223a1..6ef21b7cfd 100644 --- a/scripts/build/termux_create_pacman_subpackages.sh +++ b/scripts/build/termux_create_pacman_subpackages.sh @@ -4,10 +4,10 @@ termux_create_pacman_subpackages() { if [[ "$TERMUX_PACKAGE_LIBRARY" == 'glibc' ]]; then _ADD_PREFIX="glibc/" fi - if [[ "$TERMUX_PKG_NO_STATICSPLIT" == 'false' && -n "$(shopt -s globstar; shopt -s nullglob; echo ${_ADD_PREFIX}lib/**/*.a)" ]]; then + if [[ "$TERMUX_PKG_NO_STATICSPLIT" == 'false' && -n "$(shopt -s globstar; shopt -s nullglob; echo ${_ADD_PREFIX}lib{,32}/**/*.a)" ]]; then # Add virtual -static sub package if there are include files: local _STATIC_SUBPACKAGE_FILE=$TERMUX_PKG_TMPDIR/${TERMUX_PKG_NAME}-static.subpackage.sh - echo TERMUX_SUBPKG_INCLUDE=\"$(find ${_ADD_PREFIX}lib -name '*.a' -o -name '*.la') $TERMUX_PKG_STATICSPLIT_EXTRA_PATTERNS\" > "$_STATIC_SUBPACKAGE_FILE" + echo TERMUX_SUBPKG_INCLUDE=\"$(find ${_ADD_PREFIX}lib{,32} -name '*.a' -o -name '*.la' 2> /dev/null) $TERMUX_PKG_STATICSPLIT_EXTRA_PATTERNS\" > "$_STATIC_SUBPACKAGE_FILE" echo "TERMUX_SUBPKG_DESCRIPTION=\"Static libraries for ${TERMUX_PKG_NAME}\"" >> "$_STATIC_SUBPACKAGE_FILE" fi diff --git a/scripts/build/termux_step_elf_cleaner.sh b/scripts/build/termux_step_elf_cleaner.sh index e775f5ac2a..ede67bd0fe 100644 --- a/scripts/build/termux_step_elf_cleaner.sh +++ b/scripts/build/termux_step_elf_cleaner.sh @@ -1,5 +1,5 @@ termux_step_elf_cleaner() { - termux_step_elf_cleaner__from_paths . \( -path "./bin/*" -o -path "./lib/*" -o -path "./libexec/*" -o -path "./opt/*" \) + termux_step_elf_cleaner__from_paths . \( -path "./bin/*" -o -path "./lib/*" -o -path "./lib32/*" -o -path "./libexec/*" -o -path "./opt/*" \) } termux_step_elf_cleaner__from_paths() { diff --git a/scripts/build/termux_step_make.sh b/scripts/build/termux_step_make.sh index ff86047002..a2ccf3cf37 100644 --- a/scripts/build/termux_step_make.sh +++ b/scripts/build/termux_step_make.sh @@ -25,3 +25,7 @@ termux_step_make() { ${TERMUX_PKG_EXTRA_CONFIGURE_ARGS:+ $TERMUX_PKG_EXTRA_CONFIGURE_ARGS} fi } + +termux_step_make_multilib() { + termux_step_make +} diff --git a/scripts/build/termux_step_make_install.sh b/scripts/build/termux_step_make_install.sh index 4d78826564..e410f6e1c4 100644 --- a/scripts/build/termux_step_make_install.sh +++ b/scripts/build/termux_step_make_install.sh @@ -34,3 +34,7 @@ termux_step_make_install() { $TERMUX_PKG_EXTRA_CONFIGURE_ARGS fi } + +termux_step_make_install_multilib() { + termux_step_make_install +} diff --git a/scripts/build/termux_step_massage.sh b/scripts/build/termux_step_massage.sh index c6ead1be72..f5db28b449 100644 --- a/scripts/build/termux_step_massage.sh +++ b/scripts/build/termux_step_massage.sh @@ -182,6 +182,37 @@ termux_step_massage() { fi fi + # Remove duplicate headers from `include32/` directory + if [[ -d ./${ADDING_PREFIX}/include32 && -d ${TERMUX__PREFIX__BASE_INCLUDE_DIR} ]]; then + local hpath + for hpath in $(find ./${ADDING_PREFIX}/include32 -type f); do + local h=$(sed "s|./${ADDING_PREFIX}/include32/||g" <<< "$hpath") + if [[ -f "${TERMUX__PREFIX__BASE_INCLUDE_DIR}/${h}" && \ + "$(md5sum < "${hpath}")" = "$(md5sum < "${TERMUX__PREFIX__BASE_INCLUDE_DIR}/${h}")" ]]; then + rm "${hpath}" + fi + done + fi + + # Configure pkgconfig files for proper multilib-compilation + if [[ -d ./${ADDING_PREFIX}/lib32/pkgconfig ]]; then + local pc + for pc in $(grep -s -r -l "^includedir=.*/include32" ./${ADDING_PREFIX}/lib32/pkgconfig); do + local pc_cflags="$(grep '^Cflags:' "${pc}" | awk -F ':' '{printf $2 "\n"}')" + if ! grep -q ' -I' <<< "${pc_cflags}"; then + continue + fi + local pc_multilib_path="$(grep '^includedir=' "${pc}" | sed "s|${TERMUX_PREFIX}|\${prefix}|g" | awk -F '{prefix}/include' '{printf $2}')" + local pc_edit_cflags="$(sed "s|\${includedir}|\${includedir}${pc_multilib_path}|g" <<< "${pc_cflags}")" + local pc_new_cflags="$(tr ' ' '\n' <<< "${pc_edit_cflags}" | sed 's|\({includedir}\)32|\1|gp; s|\(/include\)32|\1|gp; d' | tr '\n' ' ')" + sed -i -e "s|\(^includedir=.*/\)include32\(.*\)|\1include|g" \ + -e "s|^Cflags:${pc_cflags}$|Cflags:${pc_edit_cflags} ${pc_new_cflags::-1}|g" \ + "${pc}" + # Apply the modified pkgconfig to the system for proper multilib-compilation work + cp -r "${pc}" "${TERMUX__PREFIX__MULTI_LIB_DIR}/pkgconfig" + done + fi + # Check for directory "$PREFIX/man" which indicates packaging error. if [ -d "./${ADDING_PREFIX}man" ]; then termux_error_exit "Package contains directory \"\$PREFIX/man\" ($TERMUX_PREFIX/man). Use \"\$PREFIX/share/man\" ($TERMUX_PREFIX/share/man) instead." diff --git a/scripts/build/termux_step_setup_build_folders.sh b/scripts/build/termux_step_setup_build_folders.sh index f9aceb66c1..32fd42ba6e 100644 --- a/scripts/build/termux_step_setup_build_folders.sh +++ b/scripts/build/termux_step_setup_build_folders.sh @@ -3,6 +3,7 @@ termux_step_setup_build_folders() { # permissions which makes them undeletable. We need to fix # that. [ -d "$TERMUX_PKG_BUILDDIR" ] && chmod +w -R "$TERMUX_PKG_BUILDDIR" || true + [ -d "$TERMUX_PKG_MULTILIB_BUILDDIR" ] && chmod +w -R "$TERMUX_PKG_MULTILIB_BUILDDIR" || true [ -d "$TERMUX_PKG_SRCDIR" ] && chmod +w -R "$TERMUX_PKG_SRCDIR" || true if [ "$TERMUX_SKIP_DEPCHECK" = false ] && \ [ "$TERMUX_INSTALL_DEPS" = true ] && \ @@ -17,6 +18,7 @@ termux_step_setup_build_folders() { # Cleanup old build state: rm -Rf "$TERMUX_PKG_BUILDDIR" \ + "$TERMUX_PKG_MULTILIB_BUILDDIR" \ "$TERMUX_PKG_SRCDIR" # Cleanup old packaging state: @@ -48,6 +50,9 @@ termux_step_setup_build_folders() { "$TERMUX_PKG_TMPDIR" \ "$TERMUX_PKG_CACHEDIR" \ "$TERMUX_PKG_MASSAGEDIR" + if [ "$TERMUX_PKG_BUILD_MULTILIB" = "true" ] && [ "$TERMUX_PKG_BUILD_ONLY_MULTILIB" = "false" ]; then + mkdir -p "$TERMUX_PKG_MULTILIB_BUILDDIR" + fi if [ "$TERMUX_PACKAGE_LIBRARY" = "bionic" ]; then mkdir -p $TERMUX_PREFIX/{bin,etc,lib,libexec,share,share/LICENSES,tmp,include} elif [ "$TERMUX_PACKAGE_LIBRARY" = "glibc" ]; then diff --git a/scripts/build/termux_step_setup_cgct_environment.sh b/scripts/build/termux_step_setup_cgct_environment.sh index 97db97932c..4b3f9e9e9a 100644 --- a/scripts/build/termux_step_setup_cgct_environment.sh +++ b/scripts/build/termux_step_setup_cgct_environment.sh @@ -1,70 +1,110 @@ -# Installing packages if necessary for the full operation of CGCT (main use: not in Termux devices) +# Installing packages if necessary for the full operation of CGCT (main use: not in Termux devices). termux_step_setup_cgct_environment() { [ "$TERMUX_ON_DEVICE_BUILD" = "true" ] && return - if [ "$TERMUX_REPO_APP__PACKAGE_NAME" != "$TERMUX_APP_PACKAGE" ]; then - echo "WARNING: It is not possible to install glibc core packages from the repo for operation of CGCT, you must install glibc packages for your application with the prefix '$TERMUX_PREFIX' yourself (core packages: glibc and linux-api-headers-glibc)." - return + termux_install_temporary_glibc + termux_set_links_to_libgcc_of_cgct + + if [ "$TERMUX_PKG_BUILD_MULTILIB" = "true" ]; then + ( + termux_conf_multilib_vars + termux_install_temporary_glibc + termux_set_links_to_libgcc_of_cgct + ) + fi +} + +# The temporary glibc is a glibc used only during compilation of simple packages +# or a full glibc that will be customized for the system and replace the temporary glibc. +termux_install_temporary_glibc() { + local PKG="glibc" + local multilib_glibc=false + if [ "$TERMUX_ARCH" != "$TERMUX_REAL_ARCH" ]; then + multilib_glibc=true + PKG+="32" fi - for PKG in gcc-libs-glibc glibc linux-api-headers-glibc; do - local PKG_DIR=$(ls ${TERMUX_SCRIPTDIR}/*/${PKG}/build.sh 2> /dev/null || \ - ls ${TERMUX_SCRIPTDIR}/*/${PKG/-glibc/}/build.sh 2> /dev/null) - if [ -z "$PKG_DIR" ]; then - termux_error_exit "Could not find build.sh file for package '${PKG}'" + # Checking if temporary glibc needs to be installed. + if [ -f "$TERMUX_BUILT_PACKAGES_DIRECTORY/$PKG-temporary-for-cgct" ]; then + return + fi + local PKG_DIR=$(ls ${TERMUX_SCRIPTDIR}/*/${PKG}/build.sh 2> /dev/null || \ + ls ${TERMUX_SCRIPTDIR}/*/${PKG}/build.sh 2> /dev/null) + if [ -n "$PKG_DIR" ]; then + read -r DEP_ARCH DEP_VERSION DEP_VERSION_PAC _ < <(termux_extract_dep_info $PKG "${PKG_DIR/'/build.sh'/}") + if termux_package__is_package_version_built "$PKG" "$DEP_VERSION"; then + return fi - local PKG_DIR_SPLIT=(${PKG_DIR//// }) + fi - local REPO_NAME="" - local LIST_PACKAGES_DIRECTORIES=(${TERMUX_PACKAGES_DIRECTORIES}) - for idx in ${!LIST_PACKAGES_DIRECTORIES[@]}; do - if [ "${LIST_PACKAGES_DIRECTORIES[$idx]}" = "${PKG_DIR_SPLIT[-3]}" ]; then - REPO_NAME=$(echo "${TERMUX_REPO_URL[$idx]}" | sed -e 's%https://%%g' -e 's%http://%%g' -e 's%/%-%g') - if [ "$TERMUX_REPO_PKG_FORMAT" = "debian" ]; then - REPO_NAME+="-${TERMUX_REPO_DISTRIBUTION[$idx]}-Release" - elif [ "$TERMUX_REPO_PKG_FORMAT" = "pacman" ]; then - REPO_NAME+="-json" - fi - break + [ ! "$TERMUX_QUIET_BUILD" = "true" ] && echo "Installing temporary '${PKG}' for the CGCT tool environment." + + local PREFIX_TMP_GLIBC="data/data/com.termux/files/usr/glibc" + local PATH_TMP_GLIBC="$TERMUX_COMMON_CACHEDIR/temporary_glibc_for_cgct" + mkdir -p "$PATH_TMP_GLIBC" + + local GPKG_LINK="https://service.termux-pacman.dev/gpkg/$TERMUX_ARCH" + local GPKG_JSON="$PATH_TMP_GLIBC/gpkg-$TERMUX_ARCH.json" + termux_download "$GPKG_LINK/gpkg.json" \ + "$GPKG_JSON" \ + SKIP_CHECKSUM + + # Installing temporary glibc. + local GLIBC_PKG=$(jq -r '."glibc"."FILENAME"' "$GPKG_JSON") + if [ ! -f "$PATH_TMP_GLIBC/$GLIBC_PKG" ]; then + termux_download "$GPKG_LINK/$GLIBC_PKG" \ + "$PATH_TMP_GLIBC/$GLIBC_PKG" \ + $(jq -r '."glibc"."SHA256SUM"' "$GPKG_JSON") + fi + + [ ! "$TERMUX_QUIET_BUILD" = true ] && echo "extracting temporary $PKG..." + + # Unpacking temporary glibc. + tar -xJf "$PATH_TMP_GLIBC/$GLIBC_PKG" -C "$PATH_TMP_GLIBC" data + if [ "$multilib_glibc" = "true" ]; then + # Installing `lib32`. + mkdir -p "$TERMUX__PREFIX__LIB_DIR" + cp -r "$PATH_TMP_GLIBC/$PREFIX_TMP_GLIBC/lib/"* "$TERMUX__PREFIX__LIB_DIR" + # Installing `include32`. + mkdir -p "$TERMUX__PREFIX__INCLUDE_DIR" + local hpath + for hpath in $(find "$PATH_TMP_GLIBC/$PREFIX_TMP_GLIBC/include" -type f); do + local h=$(sed "s|$PATH_TMP_GLIBC/$PREFIX_TMP_GLIBC/include/||g" <<< "$hpath") + if [ -f "$TERMUX__PREFIX__BASE_INCLUDE_DIR/$h" ] && \ + [ $(md5sum "$hpath" | awk '{printf $1}') = $(md5sum "$TERMUX__PREFIX__BASE_INCLUDE_DIR/$h" | awk '{printf $1}') ]; then + rm "$hpath" fi done - if [ -z "$REPO_NAME" ]; then - termux_error_exit "Could not find '${PKG_DIR_SPLIT[-3]}' repo" - fi + find "$PATH_TMP_GLIBC/$PREFIX_TMP_GLIBC/include" -type d -empty -delete + cp -r "$PATH_TMP_GLIBC/$PREFIX_TMP_GLIBC/include/"* "$TERMUX__PREFIX__INCLUDE_DIR" + # Installing dynamic linker in lib. + mkdir -p "$TERMUX__PREFIX__BASE_LIB_DIR" + local ld_path=$(ls "$TERMUX__PREFIX__LIB_DIR"/ld-*) + ln -sr "${ld_path}" "$TERMUX__PREFIX__BASE_LIB_DIR/$(basename ${ld_path})" + else + # Complete installation of glibc components. + cp -r "$PATH_TMP_GLIBC/$PREFIX_TMP_GLIBC/"* "$TERMUX_PREFIX" + fi + # It is necessary to reconfigure the paths in libs for correct + # work of multilib-compilation and compilation in forked projects. + grep -I -s -r -l "/$PREFIX_TMP_GLIBC/lib/" "$TERMUX__PREFIX__LIB_DIR" | xargs sed -i "s|/$PREFIX_TMP_GLIBC/lib/|$TERMUX__PREFIX__LIB_DIR/|g" - read -r DEP_ARCH DEP_VERSION DEP_VERSION_PAC _ < <(termux_extract_dep_info $PKG "${PKG_DIR/'/build.sh'/}") + # Marking the installation of temporary glibc. + rm -fr "$PATH_TMP_GLIBC/data" + mkdir -p "$TERMUX_BUILT_PACKAGES_DIRECTORY" + touch "$TERMUX_BUILT_PACKAGES_DIRECTORY/$PKG-temporary-for-cgct" +} - if ! termux_package__is_package_version_built "$PKG" "$DEP_VERSION" && [ ! -f "$TERMUX_BUILT_PACKAGES_DIRECTORY/$PKG-for-cgct" ]; then - [ ! "$TERMUX_QUIET_BUILD" = "true" ] && echo "Installing '${PKG}' for the CGCT tool environment." - - if [ ! -f "${TERMUX_COMMON_CACHEDIR}-${DEP_ARCH}/${REPO_NAME}" ]; then - TERMUX_INSTALL_DEPS=true termux_get_repo_files - fi - - if ! TERMUX_WITHOUT_DEPVERSION_BINDING=true termux_download_deb_pac $PKG $DEP_ARCH $DEP_VERSION $DEP_VERSION_PAC; then - termux_error_exit "Failed to download package '${PKG}'" - fi - - [ ! "$TERMUX_QUIET_BUILD" = true ] && echo "extracting $PKG to $TERMUX_COMMON_CACHEDIR-$DEP_ARCH..." - ( - cd $TERMUX_COMMON_CACHEDIR-$DEP_ARCH - if [ "$TERMUX_REPO_PKG_FORMAT" = "debian" ]; then - ar x ${PKG}_${DEP_VERSION}_${DEP_ARCH}.deb data.tar.xz - if tar -tf data.tar.xz|grep "^./$">/dev/null; then - tar -xf data.tar.xz --strip-components=1 \ - --no-overwrite-dir -C / - else - tar -xf data.tar.xz --no-overwrite-dir -C / - fi - elif [ "$TERMUX_REPO_PKG_FORMAT" = "pacman" ]; then - tar -xJf "${PKG}-${DEP_VERSION_PAC}-${DEP_ARCH}.pkg.tar.xz" \ - --anchored --exclude=.{BUILDINFO,PKGINFO,MTREE,INSTALL} \ - --force-local --no-overwrite-dir -C / - fi - ) - mkdir -p $TERMUX_BUILT_PACKAGES_DIRECTORY - echo "" > "$TERMUX_BUILT_PACKAGES_DIRECTORY/$PKG-for-cgct" +# Sets up symbolic links to libgcc* libraries (from cgct) in the application environment +# to allow cgct to work properly, if necessary. +termux_set_links_to_libgcc_of_cgct() { + local libgcc_cgct + mkdir -p "$TERMUX__PREFIX__LIB_DIR" + for libgcc_cgct in $(find "$CGCT_DIR/$TERMUX_ARCH/lib" -maxdepth 1 -type f -name 'libgcc*'); do + if [ ! -e "$TERMUX__PREFIX__LIB_DIR/$(basename $libgcc_cgct)" ]; then + cp -r "$libgcc_cgct" "$TERMUX__PREFIX__LIB_DIR" fi done } + diff --git a/scripts/build/termux_step_setup_toolchain.sh b/scripts/build/termux_step_setup_toolchain.sh index 5a636750e0..9705f9e734 100644 --- a/scripts/build/termux_step_setup_toolchain.sh +++ b/scripts/build/termux_step_setup_toolchain.sh @@ -24,3 +24,14 @@ termux_step_setup_toolchain() { termux_setup_toolchain_gnu fi } + +termux_step_setup_multilib_environment() { + termux_conf_multilib_vars + if [ "$TERMUX_PKG_BUILD_ONLY_MULTILIB" = "false" ]; then + TERMUX_PKG_BUILDDIR="$TERMUX_PKG_MULTILIB_BUILDDIR" + fi + termux_step_setup_arch_variables + termux_step_setup_pkg_config_libdir + termux_step_setup_toolchain + cd $TERMUX_PKG_BUILDDIR +} diff --git a/scripts/build/termux_step_setup_variables.sh b/scripts/build/termux_step_setup_variables.sh index 8a2b7aafdd..0ac9dbffa6 100644 --- a/scripts/build/termux_step_setup_variables.sh +++ b/scripts/build/termux_step_setup_variables.sh @@ -37,7 +37,7 @@ termux_step_setup_variables() { fi if [ "$TERMUX_PACKAGE_LIBRARY" = "glibc" ]; then - export TERMUX_PREFIX="$TERMUX_PREFIX/glibc" + termux_build_props__set_termux_prefix_dir_and_sub_variables "$TERMUX__PREFIX_GLIBC" if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && [ "$TERMUX_PREFIX" != "$CGCT_DEFAULT_PREFIX" ]; then export CGCT_APP_PREFIX="$TERMUX_PREFIX" fi @@ -54,7 +54,7 @@ termux_step_setup_variables() { if [ "$TERMUX_PACKAGE_LIBRARY" = "bionic" ]; then # On-device builds without termux-exec are unsupported. - if [[ ":${LD_PRELOAD:-}:" != ":${TERMUX_PREFIX}/lib/libtermux-exec"*".so:" ]]; then + if [[ ":${LD_PRELOAD:-}:" != ":${TERMUX__PREFIX__LIB_DIR}/libtermux-exec"*".so:" ]]; then termux_error_exit "On-device builds without termux-exec are not supported." fi fi @@ -65,23 +65,9 @@ termux_step_setup_variables() { # TERMUX_PKG_MAINTAINER should be explicitly set in build.sh of the package. : "${TERMUX_PKG_MAINTAINER:="default"}" - if [ "x86_64" = "$TERMUX_ARCH" ] || [ "aarch64" = "$TERMUX_ARCH" ]; then - TERMUX_ARCH_BITS=64 - else - TERMUX_ARCH_BITS=32 - fi - - if [ "$TERMUX_PACKAGE_LIBRARY" = "bionic" ]; then - TERMUX_HOST_PLATFORM="${TERMUX_ARCH}-linux-android" - else - TERMUX_HOST_PLATFORM="${TERMUX_ARCH}-linux-gnu" - fi - if [ "$TERMUX_ARCH" = "arm" ]; then - TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}eabi" - if [ "$TERMUX_PACKAGE_LIBRARY" = "glibc" ]; then - TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}hf" - fi - fi + termux_step_setup_arch_variables + TERMUX_REAL_ARCH="$TERMUX_ARCH" + TERMUX_REAL_HOST_PLATFORM="$TERMUX_HOST_PLATFORM" if [ "$TERMUX_PACKAGE_LIBRARY" = "bionic" ]; then if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && [ ! -d "$NDK" ]; then @@ -136,6 +122,9 @@ termux_step_setup_variables() { TERMUX_PKG_BUILDDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/build TERMUX_PKG_BUILD_DEPENDS="" TERMUX_PKG_BUILD_IN_SRC=false + TERMUX_PKG_BUILD_MULTILIB=false # multilib-compilation (compilation of 32-bit packages for 64-bit devices) + TERMUX_PKG_BUILD_ONLY_MULTILIB=false # Specifies that the package is compiled only via multilib-compilation. Enabled automatically if multilib-compilation is enabled and the `TERMUX_PKG_EXCLUDED_ARCHES` variable contains `arm` and `i686` values. + TERMUX_PKG_MULTILIB_BUILDDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/multilib-build # path to the assembled components of the 32-bit package if multilib-compilation is enabled TERMUX_PKG_CONFFILES="" TERMUX_PKG_CONFLICTS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts TERMUX_PKG_DEPENDS="" @@ -186,7 +175,7 @@ termux_step_setup_variables() { TERMUX_PKG_PYTHON_BUILD_DEPS="" # python modules to be installed via build-pip TERMUX_PKG_PYTHON_COMMON_DEPS="" # python modules to be installed via pip3 or build-pip TERMUX_PYTHON_CROSSENV_PREFIX="$TERMUX_TOPDIR/python${TERMUX_PYTHON_VERSION}-crossenv-prefix-$TERMUX_PACKAGE_LIBRARY-$TERMUX_ARCH" # python modules dependency location (only used in non-devices) - TERMUX_PYTHON_HOME=$TERMUX_PREFIX/lib/python${TERMUX_PYTHON_VERSION} # location of python libraries + TERMUX_PYTHON_HOME=$TERMUX__PREFIX__LIB_DIR/python${TERMUX_PYTHON_VERSION} # location of python libraries TERMUX_PKG_MESON_NATIVE=false TERMUX_PKG_CMAKE_CROSSCOMPILING=true TERMUX_PROOT_EXTRA_ENV_VARS="" # Extra environvent variables for proot command in termux_setup_proot @@ -194,3 +183,24 @@ termux_step_setup_variables() { unset CFLAGS CPPFLAGS LDFLAGS CXXFLAGS unset TERMUX_MESON_ENABLE_SOVERSION # setenv to enable SOVERSION suffix for shared libs built with Meson } + +# Setting architectural informations according to the `TERMUX_ARCH` variable +termux_step_setup_arch_variables() { + if [ "x86_64" = "$TERMUX_ARCH" ] || [ "aarch64" = "$TERMUX_ARCH" ]; then + TERMUX_ARCH_BITS=64 + else + TERMUX_ARCH_BITS=32 + fi + + if [ "$TERMUX_PACKAGE_LIBRARY" = "bionic" ]; then + TERMUX_HOST_PLATFORM="${TERMUX_ARCH}-linux-android" + else + TERMUX_HOST_PLATFORM="${TERMUX_ARCH}-linux-gnu" + fi + if [ "$TERMUX_ARCH" = "arm" ]; then + TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}eabi" + if [ "$TERMUX_PACKAGE_LIBRARY" = "glibc" ]; then + TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}hf" + fi + fi +} diff --git a/scripts/build/termux_step_start_build.sh b/scripts/build/termux_step_start_build.sh index 8a428e0039..15b56c8215 100644 --- a/scripts/build/termux_step_start_build.sh +++ b/scripts/build/termux_step_start_build.sh @@ -62,16 +62,26 @@ termux_step_start_build() { fi fi + if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ] || [ "$TERMUX_ARCH_BITS" = "32" ]; then + TERMUX_PKG_BUILD_MULTILIB=false + fi + if [ "$TERMUX_PKG_BUILD_MULTILIB" = "true" ] && [ $(tr ' ' '\n' <<< "${TERMUX_PKG_EXCLUDED_ARCHES//,/}" | grep -c -e '^arm$' -e '^i686$') = "2" ]; then + TERMUX_PKG_BUILD_ONLY_MULTILIB=true + fi + echo "termux - building $TERMUX_PKG_NAME for arch $TERMUX_ARCH..." test -t 1 && printf "\033]0;%s...\007" "$TERMUX_PKG_NAME" # Avoid exporting PKG_CONFIG_LIBDIR until after termux_step_host_build. - export TERMUX_PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig:$TERMUX_PREFIX/share/pkgconfig + termux_step_setup_pkg_config_libdir local TERMUX_PKG_BUILDDIR_ORIG="$TERMUX_PKG_BUILDDIR" if [ "$TERMUX_PKG_BUILD_IN_SRC" = "true" ]; then TERMUX_PKG_BUILDDIR=$TERMUX_PKG_SRCDIR fi + if [ "$TERMUX_PKG_BUILD_MULTILIB" = "true" ] && [ "$TERMUX_PKG_BUILD_ONLY_MULTILIB" = "false" ] && ([ "$TERMUX_PKG_BUILD_IN_SRC" = "true" ] || [ "$TERMUX_PKG_MULTILIB_BUILDDIR" = "$TERMUX_PKG_BUILDDIR" ]); then + termux_error_exit "It is not possible to build 32-bit and 64-bit versions of a package in one place, the build location must be separate." + fi if [ "$TERMUX_CONTINUE_BUILD" == "true" ]; then # If the package has a hostbuild step, verify that it has been built @@ -128,3 +138,7 @@ termux_step_start_build() { done fi } + +termux_step_setup_pkg_config_libdir() { + export TERMUX_PKG_CONFIG_LIBDIR=$TERMUX__PREFIX__LIB_DIR/pkgconfig:$TERMUX_PREFIX/share/pkgconfig +} diff --git a/scripts/build/termux_step_strip_elf_symbols.sh b/scripts/build/termux_step_strip_elf_symbols.sh index 2ffe7e0f71..7bb462de7e 100644 --- a/scripts/build/termux_step_strip_elf_symbols.sh +++ b/scripts/build/termux_step_strip_elf_symbols.sh @@ -1,5 +1,5 @@ termux_step_strip_elf_symbols() { - termux_step_strip_elf_symbols__from_paths . \( -path "./bin/*" -o -path "./lib/*" -o -path "./libexec/*" \) + termux_step_strip_elf_symbols__from_paths . \( -path "./bin/*" -o -path "./lib/*" -o -path "./lib32/*" -o -path "./libexec/*" \) } termux_step_strip_elf_symbols__from_paths() { diff --git a/scripts/build/toolchain/termux_setup_toolchain_23c.sh b/scripts/build/toolchain/termux_setup_toolchain_23c.sh index 41f6a18a18..8c24921820 100644 --- a/scripts/build/toolchain/termux_setup_toolchain_23c.sh +++ b/scripts/build/toolchain/termux_setup_toolchain_23c.sh @@ -1,7 +1,7 @@ termux_setup_toolchain_23c() { export CFLAGS="" export CPPFLAGS="" - export LDFLAGS="-L${TERMUX_PREFIX}/lib" + export LDFLAGS="-L${TERMUX__PREFIX__LIB_DIR}" export AS=$TERMUX_HOST_PLATFORM-clang export CC=$TERMUX_HOST_PLATFORM-clang @@ -31,7 +31,7 @@ termux_setup_toolchain_23c() { if [ $TERMUX_ARCH = arm ]; then CCTERMUX_HOST_PLATFORM=armv7a-linux-androideabi$TERMUX_PKG_API_LEVEL fi - LDFLAGS+=" -Wl,-rpath=$TERMUX_PREFIX/lib" + LDFLAGS+=" -Wl,-rpath=$TERMUX__PREFIX__LIB_DIR" else export CC_FOR_BUILD=$CC # Some build scripts use environment variable 'PKG_CONFIG', so @@ -83,8 +83,11 @@ termux_setup_toolchain_23c() { export CXXFLAGS="$CFLAGS" # set the proper header include order - first package includes, then prefix includes - # -isystem${TERMUX_PREFIX}/include/c++/v1 is needed here for on-device building to work correctly - export CPPFLAGS+=" -isystem${TERMUX_PREFIX}/include/c++/v1 -isystem${TERMUX_PREFIX}/include" + # -isystem${TERMUX__PREFIX__BASE_INCLUDE_DIR}/c++/v1 is needed here for on-device building to work correctly + export CPPFLAGS+=" -isystem${TERMUX__PREFIX__BASE_INCLUDE_DIR}/c++/v1 -isystem${TERMUX__PREFIX__INCLUDE_DIR}" + if [ "$TERMUX_ARCH" != "$TERMUX_REAL_ARCH" ]; then + export CPPFLAGS+=" -isystem${TERMUX__PREFIX__BASE_INCLUDE_DIR}" + fi # If libandroid-support is declared as a dependency, link to it explicitly: if [ "$TERMUX_PKG_DEPENDS" != "${TERMUX_PKG_DEPENDS/libandroid-support/}" ]; then @@ -94,7 +97,10 @@ termux_setup_toolchain_23c() { export GOOS=android export CGO_ENABLED=1 export GO_LDFLAGS="-extldflags=-pie" - export CGO_CFLAGS="-isystem$TERMUX_PREFIX/include" + export CGO_CFLAGS="-isystem${TERMUX__PREFIX__INCLUDE_DIR}" + if [ "$TERMUX_ARCH" != "$TERMUX_REAL_ARCH" ]; then + export CGO_CFLAGS+=" -isystem${TERMUX__PREFIX__BASE_INCLUDE_DIR}" + fi export CARGO_TARGET_NAME="${TERMUX_ARCH}-linux-android" if [[ "${TERMUX_ARCH}" == "arm" ]]; then @@ -102,7 +108,7 @@ termux_setup_toolchain_23c() { fi local env_host="${CARGO_TARGET_NAME//-/_}" export CARGO_TARGET_${env_host@U}_LINKER="${CC}" - export CARGO_TARGET_${env_host@U}_RUSTFLAGS="-L${TERMUX_PREFIX}/lib -C link-arg=-Wl,-rpath=${TERMUX_PREFIX}/lib -C link-arg=-Wl,--enable-new-dtags" + export CARGO_TARGET_${env_host@U}_RUSTFLAGS="-L${TERMUX__PREFIX__LIB_DIR} -C link-arg=-Wl,-rpath=${TERMUX__PREFIX__LIB_DIR} -C link-arg=-Wl,--enable-new-dtags" export CFLAGS_${env_host}="${CPPFLAGS} ${CFLAGS}" export CC_x86_64_unknown_linux_gnu="gcc" export CFLAGS_x86_64_unknown_linux_gnu="-O2" diff --git a/scripts/build/toolchain/termux_setup_toolchain_27c.sh b/scripts/build/toolchain/termux_setup_toolchain_27c.sh index efb7fd0ef3..2a704c3148 100644 --- a/scripts/build/toolchain/termux_setup_toolchain_27c.sh +++ b/scripts/build/toolchain/termux_setup_toolchain_27c.sh @@ -1,7 +1,7 @@ termux_setup_toolchain_27c() { export CFLAGS="" export CPPFLAGS="" - export LDFLAGS="-L${TERMUX_PREFIX}/lib" + export LDFLAGS="-L${TERMUX__PREFIX__LIB_DIR}" export AS=$TERMUX_HOST_PLATFORM-clang export CC=$TERMUX_HOST_PLATFORM-clang @@ -31,7 +31,7 @@ termux_setup_toolchain_27c() { if [ $TERMUX_ARCH = arm ]; then CCTERMUX_HOST_PLATFORM=armv7a-linux-androideabi$TERMUX_PKG_API_LEVEL fi - LDFLAGS+=" -Wl,-rpath=$TERMUX_PREFIX/lib" + LDFLAGS+=" -Wl,-rpath=$TERMUX__PREFIX__LIB_DIR" else export CC_FOR_BUILD=$CC # Some build scripts use environment variable 'PKG_CONFIG', so @@ -83,8 +83,11 @@ termux_setup_toolchain_27c() { export CXXFLAGS="$CFLAGS" # set the proper header include order - first package includes, then prefix includes - # -isystem${TERMUX_PREFIX}/include/c++/v1 is needed here for on-device building to work correctly - export CPPFLAGS+=" -isystem${TERMUX_PREFIX}/include/c++/v1 -isystem${TERMUX_PREFIX}/include" + # -isystem${TERMUX__PREFIX__BASE_INCLUDE_DIR}/c++/v1 is needed here for on-device building to work correctly + export CPPFLAGS+=" -isystem${TERMUX__PREFIX__BASE_INCLUDE_DIR}/c++/v1 -isystem${TERMUX__PREFIX__INCLUDE_DIR}" + if [ "$TERMUX_ARCH" != "$TERMUX_REAL_ARCH" ]; then + export CPPFLAGS+=" -isystem${TERMUX__PREFIX__BASE_INCLUDE_DIR}" + fi # If libandroid-support is declared as a dependency, link to it explicitly: if [ "$TERMUX_PKG_DEPENDS" != "${TERMUX_PKG_DEPENDS/libandroid-support/}" ]; then @@ -95,7 +98,10 @@ termux_setup_toolchain_27c() { export CGO_ENABLED=1 export GO_LDFLAGS="-extldflags=-pie" export CGO_LDFLAGS="${LDFLAGS/ -Wl,-z,relro,-z,now/}" - export CGO_CFLAGS="-isystem$TERMUX_PREFIX/include" + export CGO_CFLAGS="-isystem${TERMUX__PREFIX__INCLUDE_DIR}" + if [ "$TERMUX_ARCH" != "$TERMUX_REAL_ARCH" ]; then + export CGO_CFLAGS+=" -isystem${TERMUX__PREFIX__BASE_INCLUDE_DIR}" + fi export CARGO_TARGET_NAME="${TERMUX_ARCH}-linux-android" if [[ "${TERMUX_ARCH}" == "arm" ]]; then @@ -103,7 +109,7 @@ termux_setup_toolchain_27c() { fi local env_host="${CARGO_TARGET_NAME//-/_}" export CARGO_TARGET_${env_host@U}_LINKER="${CC}" - export CARGO_TARGET_${env_host@U}_RUSTFLAGS="-L${TERMUX_PREFIX}/lib -C link-arg=-Wl,-rpath=${TERMUX_PREFIX}/lib -C link-arg=-Wl,--enable-new-dtags" + export CARGO_TARGET_${env_host@U}_RUSTFLAGS="-L${TERMUX__PREFIX__LIB_DIR} -C link-arg=-Wl,-rpath=${TERMUX__PREFIX__LIB_DIR} -C link-arg=-Wl,--enable-new-dtags" export CFLAGS_${env_host}="${CPPFLAGS} ${CFLAGS}" export CC_x86_64_unknown_linux_gnu="gcc" export CFLAGS_x86_64_unknown_linux_gnu="-O2" diff --git a/scripts/build/toolchain/termux_setup_toolchain_gnu.sh b/scripts/build/toolchain/termux_setup_toolchain_gnu.sh index 27c832d98a..7288e37f53 100644 --- a/scripts/build/toolchain/termux_setup_toolchain_gnu.sh +++ b/scripts/build/toolchain/termux_setup_toolchain_gnu.sh @@ -20,11 +20,17 @@ termux_setup_toolchain_gnu() { export CXXFILT=$TERMUX_HOST_PLATFORM-c++filt fi - if [ ! -d "$TERMUX_PREFIX/lib/" ]; then - termux_error_exit "glibc library directory was not found ('$TERMUX_PREFIX/lib/')" + if [ ! -d "$TERMUX__PREFIX__LIB_DIR/" ]; then + termux_error_exit "glibc library directory was not found ('$TERMUX__PREFIX__LIB_DIR/')" fi - if [ ! -d "$TERMUX_PREFIX/include/" ]; then - termux_error_exit "glibc header directory was not found ('$TERMUX_PREFIX/include/')" + if [ ! -f "$TERMUX__PREFIX__LIB_DIR/libgcc_s.so" ] && [ ! -f "$TERMUX__PREFIX__LIB_DIR/libgcc_s.so.1" ]; then + termux_error_exit "libgcc not found, there is a risk of incorrect compiler operation" + fi + if [ ! -d "$TERMUX__PREFIX__BASE_INCLUDE_DIR/" ]; then + termux_error_exit "glibc base header directory was not found ('$TERMUX__PREFIX__BASE_INCLUDE_DIR/')" + fi + if [ "$TERMUX_ARCH" != "$TERMUX_REAL_ARCH" ] && [ ! -d "$TERMUX__PREFIX__MULTI_INCLUDE_DIR/" ]; then + termux_error_exit "glibc multi header directory was not found ('$TERMUX__PREFIX__MULTI_INCLUDE_DIR/')" fi if [ "$TERMUX_ARCH" = "aarch64" ]; then @@ -40,7 +46,7 @@ termux_setup_toolchain_gnu() { CFLAGS+=" -march=i686" export DYNAMIC_LINKER="ld-linux.so.2" fi - export PATH_DYNAMIC_LINKER="$TERMUX_PREFIX/lib/$DYNAMIC_LINKER" + export PATH_DYNAMIC_LINKER="$TERMUX__PREFIX__BASE_LIB_DIR/$DYNAMIC_LINKER" if [ ! -f "$PATH_DYNAMIC_LINKER" ]; then termux_error_exit "glibc dynamic linker was not found ('$PATH_DYNAMIC_LINKER')" @@ -51,6 +57,12 @@ termux_setup_toolchain_gnu() { "x86_64"|"i686") CFLAGS+=" -mtune=generic -fcf-protection";; esac + case "$TERMUX_ARCH" in + "aarch64") export LINUX_ARCH="arm64";; + "arm") export LINUX_ARCH="arm";; + "x86_64"|"i686") export LINUX_ARCH="x86";; + esac + export CCTERMUX_HOST_PLATFORM=$TERMUX_HOST_PLATFORM export PKG_CONFIG=pkg-config diff --git a/scripts/buildorder.py b/scripts/buildorder.py index cf6226584a..b69f4c32d1 100755 --- a/scripts/buildorder.py +++ b/scripts/buildorder.py @@ -93,7 +93,11 @@ def parse_build_file_variable_bool(path, var): return value == 'true' def add_prefix_glibc_to_pkgname(name): - return name.replace("-static", "-glibc-static") if "static" == name.split("-")[-1] else name+"-glibc" + return name.replace("-static", "-glibc-static") if "static" == name.split("-")[-1] else name+"-glibc" + +def has_prefix_glibc(pkgname): + pkgname = pkgname.split("-") + return "glibc" in pkgname or "glibc32" in pkgname class TermuxPackage(object): "A main package definition represented by a directory with a build.sh file." @@ -102,7 +106,7 @@ class TermuxPackage(object): self.fast_build_mode = fast_build_mode self.name = os.path.basename(self.dir) self.pkgs_cache = [] - if "gpkg" in self.dir.split("/")[-2].split("-") and "glibc" not in self.name.split("-"): + if "gpkg" in self.dir.split("/")[-2].split("-") and not has_prefix_glibc(self.name): self.name = add_prefix_glibc_to_pkgname(self.name) # search package build.sh @@ -159,7 +163,7 @@ class TermuxPackage(object): if not self.fast_build_mode or self.dir == dir_root: self.deps.difference_update([subpkg.name for subpkg in self.subpkgs]) for dependency_name in sorted(self.deps): - if termux_global_library == "true" and termux_pkg_library == "glibc" and "glibc" not in dependency_name.split("-"): + if termux_global_library == "true" and termux_pkg_library == "glibc" and not has_prefix_glibc(dependency_name): mod_dependency_name = add_prefix_glibc_to_pkgname(dependency_name) dependency_name = mod_dependency_name if mod_dependency_name in pkgs_map else dependency_name if dependency_name not in self.pkgs_cache: @@ -179,7 +183,7 @@ class TermuxSubPackage: raise Exception("SubPackages should have a parent") self.name = os.path.basename(subpackage_file_path).split('.subpackage.sh')[0] - if "gpkg" in subpackage_file_path.split("/")[-3].split("-") and "glibc" not in self.name.split("-"): + if "gpkg" in subpackage_file_path.split("/")[-3].split("-") and not has_prefix_glibc(self.name): self.name = add_prefix_glibc_to_pkgname(self.name) self.parent = parent self.deps = set([parent.name]) @@ -339,7 +343,7 @@ def generate_target_buildorder(target_path, pkgs_map, fast_build_mode): target_path = target_path[:-1] package_name = os.path.basename(target_path) - if "gpkg" in target_path.split("/")[-2].split("-") and "glibc" not in package_name.split("-"): + if "gpkg" in target_path.split("/")[-2].split("-") and not has_prefix_glibc(package_name): package_name += "-glibc" package = pkgs_map[package_name] # Do not depend on any sub package @@ -392,8 +396,8 @@ def main(): for pkg in build_order: pkg_name = pkg.name - if termux_global_library == "true" and termux_pkg_library == "glibc" and "glibc" not in pkg_name.split("-"): - pkg_name = add_prefix_glibc_to_pkgname(pkgname) + if termux_global_library == "true" and termux_pkg_library == "glibc" and not has_prefix_glibc(pkg_name): + pkg_name = add_prefix_glibc_to_pkgname(pkg_name) print("%-30s %s" % (pkg_name, pkg.dir)) if __name__ == '__main__': diff --git a/scripts/properties.sh b/scripts/properties.sh index 03902e5ad4..da0859acbe 100644 --- a/scripts/properties.sh +++ b/scripts/properties.sh @@ -930,6 +930,15 @@ __termux_build_props__add_variables_validator_actions "TERMUX__PREFIX_SUBDIR" "a # on-device, so make sure a safe path is set if running `clean.sh` in # Termux docker or host OS build environment. # +# At runtime, `TERMUX__PREFIX` may be overridden and set to +# `TERMUX__PREFIX_GLIBC` when compiling `glibc` packages by calling +# `termux_build_props__set_termux_prefix_dir_and_sub_variables` in +# `termux_step_setup_variables` if `TERMUX_PACKAGE_LIBRARY` equals `glibc`. +# However, `TERMUX__PREFIX_CLASSICAL` retains the original value +# set below for `TERMUX__PREFIX`. +# - https://github.com/termux/termux-packages/pull/16901 +# - https://github.com/termux/termux-packages/pull/20864 +# # Default value: `/data/data/com.termux/files/usr` ## [[ "$TERMUX__ROOTFS" != "/" ]] && TERMUX__PREFIX="$TERMUX__ROOTFS${TERMUX__PREFIX_SUBDIR:+"/$TERMUX__PREFIX_SUBDIR"}" || \ @@ -942,14 +951,44 @@ else __termux_build_props__add_variables_validator_actions "TERMUX__PREFIX" " path_under_termux_rootfs" fi -TERMUX__PREFIX_CLASSICAL="$TERMUX__PREFIX" - -# The `glibc` modifies `TERMUX_PREFIX` during compilation to append -# `/glibc` in `termux_step_setup_variables()`. -# - https://github.com/termux/termux-packages/pull/16901 TERMUX_PREFIX="$TERMUX__PREFIX" # Deprecated alternative variable for `TERMUX__PREFIX` + + + +## +# The original value for `TERMUX__PREFIX` set above, as `TERMUX__PREFIX` +# can be overridden at runtime, like when compiling `glibc` packages. +# Checks variable docs of `TERMUX__PREFIX` for more info. +# +# Default value: `/data/data/com.termux/files/usr` +## +TERMUX__PREFIX_CLASSICAL="$TERMUX__PREFIX" TERMUX_PREFIX_CLASSICAL="$TERMUX__PREFIX" # Deprecated alternative variable for `TERMUX__PREFIX_CLASSICAL` + + +## +# Termux subdirectory path for `TERMUX__PREFIX_GLIBC`. +# +# Default value: `glibc` +## +TERMUX__PREFIX_GLIBC_SUBDIR="glibc" + +## +# Termux `glibc` prefix directory path under `TERMUX__PREFIX` +# where all Termux `glibc` packages data is installed. +# +# **See Also:** +# - https://github.com/termux-pacman/glibc-packages +# - https://github.com/termux/glibc-packages (mirror) +# +# Default value: `/data/data/com.termux/files/usr/glibc` +## +TERMUX__PREFIX_GLIBC="$TERMUX__PREFIX/$TERMUX__PREFIX_GLIBC_SUBDIR" +__termux_build_props__add_variables_validator_actions "TERMUX__PREFIX_GLIBC" "safe_absolute_path invalid_termux_prefix_paths path_under_termux_rootfs" + + + ## # The max length for the `TERMUX__PREFIX` including the null '\0' # terminator. @@ -962,24 +1001,6 @@ TERMUX_PREFIX_CLASSICAL="$TERMUX__PREFIX" # Deprecated alternative variable for TERMUX__PREFIX_DIR___MAX_LEN="$((TERMUX__ROOTFS_DIR___MAX_LEN + 1 + 3))" # "/usr" (90) - -## -# Termux subdirectory path for `TERMUX__PREFIX__BIN_DIR`. -# -# Constant value: `bin` -## -TERMUX__PREFIX__BIN_SUBDIR="bin" - -## -# Termux bin directory path under `TERMUX__PREFIX`. -# -# - https://github.com/termux/termux-packages/wiki/Termux-file-system-layout#termux-bin-directory -# -# Default value: `/data/data/com.termux/files/usr/bin` -## -TERMUX__PREFIX__BIN_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__BIN_SUBDIR" - - ## # The max length for the `TERMUX__BIN_DIR` including the null '\0' terminator. # @@ -1019,6 +1040,59 @@ TERMUX__FILE_HEADER__BUFFER_SIZE="340" + +## +# `termux_build_props__set_termux_prefix_dir_and_sub_variables` `` [``] +## +termux_build_props__set_termux_prefix_dir_and_sub_variables() { + +local termux__prefix="${1:-}" +local skip_validation="${2:-}" + +if [[ "$skip_validation" != "true" ]]; then + if [[ ! "$termux__prefix" =~ ${TERMUX_REGEX__SAFE_ABSOLUTE_PATH:?} ]] || \ + [[ "$termux__prefix" =~ ${TERMUX_REGEX__SINGLE_OR_DOUBLE_DOT_CONTAINING_PATH:?} ]]; then + echo "The termux__prefix '$termux__prefix' passed to 'termux_build_props__set_termux_prefix_dir_and_sub_variables' with length ${#termux__prefix} is invalid." 1>&2 + echo "The termux__prefix must match a safe absolute path that starts with a \`/\` with at least one \ +characters under rootfs \`/\`. Duplicate or trailing path separators \`/\` are not allowed. \ +The path component characters must be in the range \`[a-zA-Z0-9+,.=_-]\`. The path must not contain single \`/./\` or \ +double \`/../\` dot components." 1>&2 + return 1 + fi + + if [[ "$termux__prefix" =~ ${TERMUX_REGEX__INVALID_TERMUX_PREFIX_PATHS:?} ]]; then + echo "The termux__prefix '$termux__prefix' passed to 'termux_build_props__set_termux_prefix_dir_and_sub_variables' with length ${#termux__prefix} is invalid." 1>&2 + echo "The termux__prefix must not match one of the invalid paths \ +in TERMUX_REGEX__INVALID_TERMUX_PREFIX_PATHS \`$TERMUX_REGEX__INVALID_TERMUX_PREFIX_PATHS\`." 1>&2 + return 1 + fi +fi + + +# Override `TERMUX__PREFIX`, but keep original value in `TERMUX__PREFIX_CLASSICAL`. +TERMUX__PREFIX="$termux__prefix" +TERMUX_PREFIX="$termux__prefix" + + + +## +# Termux subdirectory path for `TERMUX__PREFIX__BIN_DIR`. +# +# Constant value: `bin` +## +TERMUX__PREFIX__BIN_SUBDIR="bin" + +## +# Termux bin directory path under `TERMUX__PREFIX`. +# +# - https://github.com/termux/termux-packages/wiki/Termux-file-system-layout#termux-bin-directory +# +# Default value: `/data/data/com.termux/files/usr/bin` +## +TERMUX__PREFIX__BIN_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__BIN_SUBDIR" + + + ## # Termux subdirectory path for `TERMUX__PREFIX__ETC_DIR`. # @@ -1034,36 +1108,85 @@ TERMUX__PREFIX__ETC_SUBDIR="etc" TERMUX__PREFIX__ETC_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__ETC_SUBDIR" + ## -# Termux subdirectory path for `TERMUX__PREFIX__INCLUDE_DIR`. +# Termux subdirectory path for `TERMUX__PREFIX__BASE_INCLUDE_DIR`. # # Constant value: `include` ## -TERMUX__PREFIX__INCLUDE_SUBDIR="include" +TERMUX__PREFIX__BASE_INCLUDE_SUBDIR="include" + +## +# Termux base include directory path under `TERMUX__PREFIX`. +# +# Default value: `/data/data/com.termux/files/usr/include` +## +TERMUX__PREFIX__BASE_INCLUDE_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__BASE_INCLUDE_SUBDIR" + + +## +# Termux subdirectory path for `TERMUX__PREFIX__MULTI_INCLUDE_DIR`. +# +# Constant value: `include32` +## +TERMUX__PREFIX__MULTI_INCLUDE_SUBDIR="include32" + +## +# Termux multi include directory path under `TERMUX__PREFIX`. +# +# Default value: `/data/data/com.termux/files/usr/include32` +## +TERMUX__PREFIX__MULTI_INCLUDE_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__MULTI_INCLUDE_SUBDIR" + ## # Termux include directory path under `TERMUX__PREFIX`. # -# Default value: `/data/data/com.termux/files/usr/include` +# Default value: `/data/data/com.termux/files/usr/include` (`$TERMUX__PREFIX__BASE_INCLUDE_DIR`) ## -TERMUX__PREFIX__INCLUDE_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__INCLUDE_SUBDIR" +TERMUX__PREFIX__INCLUDE_DIR="$TERMUX__PREFIX__BASE_INCLUDE_DIR" + ## -# Termux subdirectory path for `TERMUX__PREFIX__LIB_DIR`. +# Termux subdirectory path for `TERMUX__PREFIX__BASE_LIB_DIR`. # # Constant value: `lib` ## -TERMUX__PREFIX__LIB_SUBDIR="lib" +TERMUX__PREFIX__BASE_LIB_SUBDIR="lib" + +## +# Termux base lib directory path under `TERMUX__PREFIX`. +# +# Default value: `/data/data/com.termux/files/usr/lib` +## +TERMUX__PREFIX__BASE_LIB_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__BASE_LIB_SUBDIR" + + +## +# Termux subdirectory path for `TERMUX__PREFIX__MULTI_LIB_DIR`. +# +# Constant value: `lib32` +## +TERMUX__PREFIX__MULTI_LIB_SUBDIR="lib32" + +## +# Termux multi lib directory path under `TERMUX__PREFIX`. +# +# Default value: `/data/data/com.termux/files/usr/lib32` +## +TERMUX__PREFIX__MULTI_LIB_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__MULTI_LIB_SUBDIR" + ## # Termux lib directory path under `TERMUX__PREFIX`. # # - https://github.com/termux/termux-packages/wiki/Termux-file-system-layout#termux-lib-directory # -# Default value: `/data/data/com.termux/files/usr/lib` +# Default value: `/data/data/com.termux/files/usr/lib` (`$TERMUX__PREFIX__BASE_LIB_DIR`) ## -TERMUX__PREFIX__LIB_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__LIB_SUBDIR" +TERMUX__PREFIX__LIB_DIR="$TERMUX__PREFIX__BASE_LIB_DIR" + ## @@ -1081,6 +1204,7 @@ TERMUX__PREFIX__LIBEXEC_SUBDIR="libexec" TERMUX__PREFIX__LIBEXEC_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__LIBEXEC_SUBDIR" + ## # Termux subdirectory path for `TERMUX__PREFIX__OPT_DIR`. # @@ -1096,6 +1220,7 @@ TERMUX__PREFIX__OPT_SUBDIR="opt" TERMUX__PREFIX__OPT_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__OPT_SUBDIR" + ## # Termux subdirectory path for `TERMUX__PREFIX__SHARE_DIR`. # @@ -1111,6 +1236,36 @@ TERMUX__PREFIX__SHARE_SUBDIR="share" TERMUX__PREFIX__SHARE_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__SHARE_SUBDIR" + +## +# Termux subdirectory path for `TERMUX__PREFIX__VAR_DIR`. +# +# Constant value: `var` +## +TERMUX__PREFIX__VAR_SUBDIR="var" + +## +# Termux var directory path under `TERMUX__PREFIX`. +# +# Default value: `/data/data/com.termux/files/usr/var` +## +TERMUX__PREFIX__VAR_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__VAR_SUBDIR" + +} + +# Set Termux prefix sub variables to be under the original value of +# `TERMUX__PREFIX` set in `TERMUX__PREFIX_CLASSICAL` by default, +# which is set earlier in this file. +# Skip validation as it will be done below by `__termux_build_props__validate_variables`. +termux_build_props__set_termux_prefix_dir_and_sub_variables "$TERMUX__PREFIX" "true" || exit $? + + + + + +# The following variables must always be under the original value of +# `TERMUX__PREFIX` set in `TERMUX__PREFIX_CLASSICAL` by default. + ## # Termux subdirectory path for `TERMUX__PREFIX__TMP_DIR`. # @@ -1137,21 +1292,6 @@ TERMUX__PREFIX__TMP_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__TMP_SUBDIR" TERMUX__PREFIX__TMP_DIR___MAX_LEN=94 -## -# Termux subdirectory path for `TERMUX__PREFIX__VAR_DIR`. -# -# Constant value: `var` -## -TERMUX__PREFIX__VAR_SUBDIR="var" - -## -# Termux var directory path under `TERMUX__PREFIX`. -# -# Default value: `/data/data/com.termux/files/usr/var` -## -TERMUX__PREFIX__VAR_DIR="$TERMUX__PREFIX/$TERMUX__PREFIX__VAR_SUBDIR" - - ## # Termux `profile.d` directory path under `TERMUX__PREFIX__ETC_DIR`. @@ -2379,6 +2519,24 @@ including the null \`\0\` terminator." 1>&2 return 1 fi + if [[ "$TERMUX__PREFIX" == "$TERMUX__PREFIX_GLIBC" ]]; then + echo "The TERMUX__PREFIX '$TERMUX__PREFIX' or TERMUX__PREFIX_GLIBC '$TERMUX__PREFIX_GLIBC' is invalid." 1>&2 + echo "The TERMUX__PREFIX must not be equal to TERMUX__PREFIX_GLIBC." 1>&2 + return 1 + fi + + if [[ "$TERMUX__PREFIX__BASE_LIB_DIR" == "$TERMUX__PREFIX__MULTI_LIB_DIR" ]]; then + echo "The TERMUX__PREFIX__BASE_LIB_DIR '$TERMUX__PREFIX__BASE_LIB_DIR' or TERMUX__PREFIX__MULTI_LIB_DIR '$TERMUX__PREFIX__MULTI_LIB_DIR' is invalid." 1>&2 + echo "The TERMUX__PREFIX__BASE_LIB_DIR must not be equal to TERMUX__PREFIX__MULTI_LIB_DIR." 1>&2 + return 1 + fi + + if [[ "$TERMUX__PREFIX__BASE_INCLUDE_DIR" == "$TERMUX__PREFIX__MULTI_INCLUDE_DIR" ]]; then + echo "The TERMUX__PREFIX__BASE_INCLUDE_DIR '$TERMUX__PREFIX__BASE_INCLUDE_DIR' or TERMUX__PREFIX__MULTI_INCLUDE_DIR '$TERMUX__PREFIX__MULTI_INCLUDE_DIR' is invalid." 1>&2 + echo "The TERMUX__PREFIX__BASE_INCLUDE_DIR must not be equal to TERMUX__PREFIX__MULTI_INCLUDE_DIR." 1>&2 + return 1 + fi + } __termux_build_props__validate_variables || exit $? diff --git a/scripts/utils/termux/package/termux_package.sh b/scripts/utils/termux/package/termux_package.sh index c2ba79a8d5..31f249c8bc 100644 --- a/scripts/utils/termux/package/termux_package.sh +++ b/scripts/utils/termux/package/termux_package.sh @@ -56,7 +56,7 @@ termux_package__is_package_version_built() { ## -# Check if the package name has a prefix called `glibc`. +# Check if the package name has a prefix called `glibc` or `glibc32`. # . # . # **Parameters:** @@ -71,7 +71,7 @@ termux_package__is_package_version_built() { termux_package__is_package_name_have_glibc_prefix() { for __pkgname_part in ${1//-/ }; do - if [ "$__pkgname_part" = "glibc" ]; then + if [ "$__pkgname_part" = "glibc" ] || [ "$__pkgname_part" = "glibc32" ]; then return 0 fi done