2019-02-27 18:58:17 +00:00
|
|
|
termux_step_massage() {
|
2019-08-14 17:29:58 +00:00
|
|
|
[ "$TERMUX_PKG_METAPACKAGE" = "true" ] && return
|
|
|
|
|
2023-08-30 20:40:08 +00:00
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX_CLASSICAL"
|
|
|
|
|
|
|
|
local ADDING_PREFIX=""
|
|
|
|
if [ "$TERMUX_PACKAGE_LIBRARY" = "glibc" ]; then
|
|
|
|
ADDING_PREFIX="glibc/"
|
|
|
|
fi
|
2019-02-27 18:58:17 +00:00
|
|
|
|
|
|
|
# Remove lib/charset.alias which is installed by gettext-using packages:
|
|
|
|
rm -f lib/charset.alias
|
|
|
|
|
2023-04-30 13:59:31 +00:00
|
|
|
# Remove cache file created by update-desktop-database:
|
|
|
|
rm -f share/applications/mimeinfo.cache
|
|
|
|
|
|
|
|
# Remove cache file created by glib-compile-schemas:
|
|
|
|
rm -f share/glib-2.0/schemas/gschemas.compiled
|
|
|
|
|
2023-10-17 07:35:31 +00:00
|
|
|
# Removing the pacman log that is often included in the package:
|
|
|
|
rm -f var/log/pacman.log
|
|
|
|
|
2023-04-30 13:59:31 +00:00
|
|
|
# Remove cache file created by gtk-update-icon-cache:
|
|
|
|
rm -f share/icons/hicolor/icon-theme.cache
|
|
|
|
|
2019-02-27 18:58:17 +00:00
|
|
|
# Remove locale files we're not interested in::
|
|
|
|
rm -Rf share/locale
|
|
|
|
|
2023-04-30 15:46:43 +00:00
|
|
|
# `update-mime-database` updates NOT ONLY "$PREFIX/share/mime/mime.cache".
|
|
|
|
# Simply removing this specific file does not solve the issue.
|
|
|
|
if [ -e "share/mime/mime.cache" ]; then
|
|
|
|
termux_error_exit "MIME cache found in package. Please disable \`update-mime-database\`."
|
|
|
|
fi
|
|
|
|
|
2019-02-27 18:58:17 +00:00
|
|
|
# Remove old kept libraries (readline):
|
2019-08-06 12:39:42 +00:00
|
|
|
find . -name '*.old' -print0 | xargs -0 -r rm -f
|
2019-02-27 18:58:17 +00:00
|
|
|
|
|
|
|
# Move over sbin to bin:
|
|
|
|
for file in sbin/*; do if test -f "$file"; then mv "$file" bin/; fi; done
|
2023-08-30 20:40:08 +00:00
|
|
|
if [ "$TERMUX_PACKAGE_LIBRARY" = "glibc" ]; then
|
|
|
|
for file in glibc/sbin/*; do if test -f "$file"; then mv "$file" glibc/bin/; fi; done
|
|
|
|
fi
|
2019-02-27 18:58:17 +00:00
|
|
|
|
2019-08-06 12:39:42 +00:00
|
|
|
# Remove world permissions and make sure that user still have read-write permissions.
|
|
|
|
chmod -Rf u+rw,g-rwx,o-rwx . || true
|
2019-02-27 18:58:17 +00:00
|
|
|
|
2023-08-30 20:40:08 +00:00
|
|
|
if [ "$TERMUX_PACKAGE_LIBRARY" = "bionic" ]; then
|
|
|
|
if [ "$TERMUX_PKG_NO_STRIP" != "true" ] && [ "$TERMUX_DEBUG_BUILD" = "false" ]; then
|
|
|
|
# Strip binaries. file(1) may fail for certain unusual files, so disable pipefail.
|
|
|
|
set +e +o pipefail
|
|
|
|
find . \( -path "./bin/*" -o -path "./lib/*" -o -path "./libexec/*" \) -type f |
|
|
|
|
xargs -r file | grep -E "ELF .+ (executable|shared object)" | cut -f 1 -d : |
|
|
|
|
xargs -r "$STRIP" --strip-unneeded --preserve-dates
|
|
|
|
set -e -o pipefail
|
|
|
|
fi
|
2019-08-06 12:39:42 +00:00
|
|
|
|
2023-08-30 20:40:08 +00:00
|
|
|
if [ "$TERMUX_PKG_NO_ELF_CLEANER" != "true" ]; then
|
|
|
|
# Remove entries unsupported by Android's linker:
|
|
|
|
find . \( -path "./bin/*" -o -path "./lib/*" -o -path "./libexec/*" -o -path "./opt/*" \) -type f -print0 | xargs -r -0 \
|
|
|
|
"$TERMUX_ELF_CLEANER" --api-level $TERMUX_PKG_API_LEVEL
|
|
|
|
fi
|
2020-10-01 16:33:58 +00:00
|
|
|
fi
|
2019-02-27 18:58:17 +00:00
|
|
|
|
2021-10-25 09:47:13 +00:00
|
|
|
if [ "$TERMUX_PKG_NO_SHEBANG_FIX" != "true" ]; then
|
|
|
|
# Fix shebang paths:
|
|
|
|
while IFS= read -r -d '' file; do
|
2023-09-10 11:02:41 +00:00
|
|
|
if head -c 100 "$file" | head -n 1 | grep -E "^#!.*/bin/.*" | grep -q -E -v -e "^#! ?/system" -e "^#! ?$TERMUX_PREFIX_CLASSICAL"; then
|
|
|
|
sed --follow-symlinks -i -E "1 s@^#\!(.*)/bin/(.*)@#\!$TERMUX_PREFIX/bin/\2@" "$file"
|
2023-01-18 20:30:19 +00:00
|
|
|
fi
|
2021-10-25 09:47:13 +00:00
|
|
|
done < <(find -L . -type f -print0)
|
|
|
|
fi
|
2019-02-27 18:58:17 +00:00
|
|
|
|
2020-07-07 16:22:00 +00:00
|
|
|
# Delete the info directory file.
|
2023-08-30 20:40:08 +00:00
|
|
|
rm -rf ./${ADDING_PREFIX}share/info/dir
|
2020-07-07 16:22:00 +00:00
|
|
|
|
2021-03-01 22:17:36 +00:00
|
|
|
# Mostly specific to X11-related packages.
|
2023-08-30 20:40:08 +00:00
|
|
|
rm -f ./${ADDING_PREFIX}share/icons/hicolor/icon-theme.cache
|
2021-03-01 22:17:36 +00:00
|
|
|
|
2019-02-27 18:58:17 +00:00
|
|
|
test ! -z "$TERMUX_PKG_RM_AFTER_INSTALL" && rm -Rf $TERMUX_PKG_RM_AFTER_INSTALL
|
|
|
|
|
|
|
|
find . -type d -empty -delete # Remove empty directories
|
|
|
|
|
2023-08-30 20:40:08 +00:00
|
|
|
if [ -d ./${ADDING_PREFIX}share/man ]; then
|
2019-08-06 12:39:42 +00:00
|
|
|
# Remove non-english man pages:
|
2023-08-30 20:40:08 +00:00
|
|
|
find ./${ADDING_PREFIX}share/man -mindepth 1 -maxdepth 1 -type d ! -name man\* | xargs -r rm -rf
|
2019-08-06 12:39:42 +00:00
|
|
|
|
2019-02-27 18:58:17 +00:00
|
|
|
# Compress man pages with gzip:
|
2023-08-30 20:40:08 +00:00
|
|
|
find ./${ADDING_PREFIX}share/man -type f ! -iname \*.gz -print0 | xargs -r -0 gzip
|
2019-04-09 14:45:43 +00:00
|
|
|
|
2019-02-27 18:58:17 +00:00
|
|
|
# Update man page symlinks, e.g. unzstd.1 -> zstd.1:
|
2022-03-22 20:07:57 +00:00
|
|
|
while IFS= read -r -d '' file; do
|
2019-02-27 18:58:17 +00:00
|
|
|
local _link_value
|
|
|
|
_link_value=$(readlink $file)
|
|
|
|
rm $file
|
|
|
|
ln -s $_link_value.gz $file.gz
|
2023-08-30 20:40:08 +00:00
|
|
|
done < <(find ./${ADDING_PREFIX}share/man -type l ! -iname \*.gz -print0)
|
2019-02-27 18:58:17 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-16 16:55:31 +00:00
|
|
|
# Check so files were actually installed. Exclude
|
|
|
|
# share/doc/$TERMUX_PKG_NAME/ as a license file is always
|
|
|
|
# installed there.
|
2023-08-30 20:40:08 +00:00
|
|
|
if [ "$(find . -path "./${ADDING_PREFIX}share/doc/$TERMUX_PKG_NAME" -prune -o -type f -print | head -n1)" = "" ]; then
|
2022-07-26 08:59:37 +00:00
|
|
|
if [ -f "$TERMUX_PKG_SRCDIR"/configure.ac -o -f "$TERMUX_PKG_SRCDIR"/configure.in ]; then
|
|
|
|
termux_error_exit "No files in package. Maybe you need to run autoreconf -fi before configuring."
|
|
|
|
else
|
|
|
|
termux_error_exit "No files in package."
|
|
|
|
fi
|
2021-05-16 16:55:31 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
local HARDLINKS
|
|
|
|
HARDLINKS="$(find . -type f -links +1)"
|
|
|
|
if [ -n "$HARDLINKS" ]; then
|
2023-08-30 20:40:08 +00:00
|
|
|
if [ "$TERMUX_PACKAGE_LIBRARY" = "bionic" ]; then
|
|
|
|
termux_error_exit "Package contains hard links: $HARDLINKS"
|
|
|
|
elif [ "$TERMUX_PACKAGE_LIBRARY" = "glibc" ]; then
|
|
|
|
local declare hard_list
|
|
|
|
for i in $HARDLINKS; do
|
|
|
|
hard_list[$(ls -i "$i" | awk '{printf $1}')]+="$i "
|
|
|
|
done
|
|
|
|
local root_file
|
|
|
|
for i in ${!hard_list[@]}; do
|
|
|
|
root_file=""
|
|
|
|
for j in ${hard_list[$i]}; do
|
|
|
|
if [ -z "$root_file" ]; then
|
|
|
|
root_file="$j"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
ln -sf "${TERMUX_PREFIX_CLASSICAL}/${root_file:2}" "${j}"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
fi
|
2021-05-16 16:55:31 +00:00
|
|
|
fi
|
|
|
|
|
2023-01-10 01:05:05 +00:00
|
|
|
# Check for directory "$PREFIX/man" which indicates packaging error.
|
2023-08-30 20:40:08 +00:00
|
|
|
if [ -d "./${ADDING_PREFIX}man" ]; then
|
2023-01-10 01:05:05 +00:00
|
|
|
termux_error_exit "Package contains directory \"\$PREFIX/man\" ($TERMUX_PREFIX/man). Use \"\$PREFIX/share/man\" ($TERMUX_PREFIX/share/man) instead."
|
|
|
|
fi
|
|
|
|
|
2023-01-06 21:44:41 +00:00
|
|
|
# Check for directory "$PREFIX/$PREFIX" which almost always indicates
|
|
|
|
# packaging error.
|
|
|
|
if [ -d "./${TERMUX_PREFIX#/}" ]; then
|
|
|
|
termux_error_exit "Package contains directory \"\$PREFIX/\$PREFIX\" ($TERMUX_PREFIX/${TERMUX_PREFIX#/})"
|
|
|
|
fi
|
|
|
|
|
2023-01-08 07:46:29 +00:00
|
|
|
# Check for Debianish Python directory which indicates packaging error.
|
2023-08-30 20:40:08 +00:00
|
|
|
local _python_deb_install_layout_dir="${ADDING_PREFIX}lib/python3/dist-packages"
|
2023-01-08 07:46:29 +00:00
|
|
|
if [ -d "./${_python_deb_install_layout_dir}" ]; then
|
|
|
|
termux_error_exit "Package contains directory \"\$PREFIX/${_python_deb_install_layout_dir}\" ($TERMUX_PREFIX/${_python_deb_install_layout_dir})"
|
|
|
|
fi
|
|
|
|
|
2022-07-17 21:18:00 +00:00
|
|
|
# Check so that package is not affected by
|
|
|
|
# https://github.com/android/ndk/issues/1614, or
|
|
|
|
# https://github.com/termux/termux-packages/issues/9944
|
2023-08-30 20:40:08 +00:00
|
|
|
if [ "$TERMUX_PACKAGE_LIBRARY" = "bionic" ] && [ -d "lib" ]; then
|
2022-08-01 13:21:24 +00:00
|
|
|
SYMBOLS="$($READELF -s $($TERMUX_HOST_PLATFORM-clang -print-libgcc-file-name) | grep "FUNC GLOBAL HIDDEN" | awk '{print $8}')"
|
2022-07-17 21:18:00 +00:00
|
|
|
SYMBOLS+=" $(echo libandroid_{sem_{open,close,unlink},shm{ctl,get,at,dt}})"
|
2023-01-03 21:46:27 +00:00
|
|
|
SYMBOLS+=" $(echo backtrace{,_symbols{,_fd}})"
|
2023-01-18 04:12:50 +00:00
|
|
|
SYMBOLS+=" posix_spawn posix_spawnp"
|
2022-07-17 21:18:00 +00:00
|
|
|
grep_pattern="$(create_grep_pattern $SYMBOLS)"
|
2023-01-14 07:58:19 +00:00
|
|
|
for lib in $(find lib -name "*.so"); do
|
2022-08-01 13:21:24 +00:00
|
|
|
if ! $READELF -h "$lib" &> /dev/null; then
|
2022-08-01 08:50:51 +00:00
|
|
|
continue
|
2022-04-02 08:26:26 +00:00
|
|
|
fi
|
2022-08-01 13:21:24 +00:00
|
|
|
if $READELF -s "$lib" | egrep "${grep_pattern}" &> /dev/null; then
|
|
|
|
termux_error_exit "$lib contains undefined symbols:\n$($READELF -s "$lib" | egrep "${grep_pattern}")"
|
2022-04-02 08:26:26 +00:00
|
|
|
fi
|
|
|
|
done
|
2022-07-17 21:18:00 +00:00
|
|
|
fi
|
2022-04-02 08:26:26 +00:00
|
|
|
|
2021-09-10 16:10:02 +00:00
|
|
|
if [ "$TERMUX_PACKAGE_FORMAT" = "debian" ]; then
|
|
|
|
termux_create_debian_subpackages
|
|
|
|
elif [ "$TERMUX_PACKAGE_FORMAT" = "pacman" ]; then
|
|
|
|
termux_create_pacman_subpackages
|
|
|
|
fi
|
2019-02-27 18:58:17 +00:00
|
|
|
|
2023-01-03 18:51:43 +00:00
|
|
|
# Remove unnecessary files in haskell packages:
|
2023-01-23 16:57:05 +00:00
|
|
|
if ! [[ $TERMUX_PKG_NAME =~ ghc|ghc-libs ]]; then
|
2023-08-30 20:40:08 +00:00
|
|
|
test -f ./${ADDING_PREFIX}lib/ghc-*/settings && rm -rf ./${ADDING_PREFIX}lib/ghc-*/settings
|
2022-03-22 20:07:57 +00:00
|
|
|
fi
|
2022-03-09 18:56:10 +00:00
|
|
|
|
2019-02-27 18:58:17 +00:00
|
|
|
# .. remove empty directories (NOTE: keep this last):
|
|
|
|
find . -type d -empty -delete
|
|
|
|
}
|
2022-07-17 21:18:00 +00:00
|
|
|
|
|
|
|
# Local function called by termux_step_massage
|
|
|
|
create_grep_pattern() {
|
|
|
|
symbol_type='NOTYPE[[:space:]]+GLOBAL[[:space:]]+DEFAULT[[:space:]]+UND[[:space:]]+'
|
|
|
|
echo -n "$symbol_type$1"'$'
|
|
|
|
shift 1
|
|
|
|
for arg in "$@"; do
|
2022-08-14 07:12:40 +00:00
|
|
|
echo -n "|$symbol_type$arg"'$'
|
2022-07-17 21:18:00 +00:00
|
|
|
done
|
|
|
|
}
|