Browse Source

Initial commit

master
mid-kid 2 years ago
commit
d5e9991a06
  1. 6
      .gitignore
  2. 9
      BUGS.txt
  3. 150
      build-termux.sh
  4. 66
      gentoo.diff
  5. 48
      patches/sys-apps/portage/portage-3.0.44-termux-disable-hardlinking.patch
  6. 1
      patches/sys-apps/portage/series
  7. 24
      patches/sys-libs/glibc/glibc-2.36-termux-stub-syscalls.patch
  8. 1
      patches/sys-libs/glibc/series
  9. 5
      portage/env/dev-lang/perl
  10. 5
      portage/package.use

6
.gitignore

@ -0,0 +1,6 @@
/binpkgs/
/gentoo/
/portlog/
/sysroot/
/sysroot.tar
/sysroot.tar.xz

9
BUGS.txt

@ -0,0 +1,9 @@
When cross-compiling:
- Various shebangs don't point to the proper EPREFIX
On termux itself:
- dev-libs/libxml2 cannot be built (hardlinks in source tarball)
- sys-devel/libtool cannot be built (no error given...?)
- portage errors spectaularly if sys-apps/portage is anywhere in the dependency tree
- bash keeps spamming error messages: "shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied"
- after merging dev-lang/perl, no executable permission on /usr/bin/perl

150
build-termux.sh

@ -0,0 +1,150 @@
#!/bin/sh
set -e
# Main settings
PROFILE=default/linux/arm64/17.0/prefix/kernel-3.2+
ldso=/lib/ld-linux-aarch64.so.1
virtual_os_headers=sys-kernel/linux-headers
virtual_libc=sys-libs/glibc
# Output paths
export PORTDIR="$PWD/gentoo"
export ROOT="$PWD/sysroot"
export EPREFIX=/data/data/com.termux/files/gentoo
PKGDIR="$PWD/binpkgs"
PORTAGE_LOGDIR="$PWD/portlog"
# Cleanup (optional)
#rm -rf "$ROOT"
# Configure portage profile and gather variables
EROOT="$ROOT$EPREFIX"
export SYSROOT="$ROOT"
export PORTAGE_CONFIGROOT="$EROOT"
rm -rf "$PORTAGE_CONFIGROOT/etc/portage"
mkdir -p "$PORTAGE_CONFIGROOT/etc/portage"
ln -srfT "$PORTDIR/profiles/$PROFILE" "$PORTAGE_CONFIGROOT/etc/portage/make.profile"
BROOT="$(portageq envvar BROOT)"
CHOST="$(portageq envvar CHOST)"
ARCH="$(portageq envvar ARCH)"
LIBDIR="$(portageq envvar LIBDIR_$ARCH)"
# Portage settings
export EMERGE_LOG_DIR="${EMERGE_LOG_DIR:-$EROOT/var/log}"
export PORTAGE_LOGDIR="${PORTAGE_LOGDIR:-$EROOT/var/log/portage}"
export PORTAGE_TMPDIR="${PORTAGE_TMPDIR:-$EROOT/var/tmp}"
export PKGDIR="${PKGDIR:-$EROOT/var/cache/distfiles}"
export PORTAGE_REPO_DUPLICATE_WARN=0
cat > "$PORTAGE_CONFIGROOT/etc/portage/make.conf" << EOF
ACCEPT_KEYWORDS="\$ARCH -~\$ARCH"
EOF
# Install patches
cp -a "$PWD/patches" "$PORTAGE_CONFIGROOT/etc/portage/patches"
# Configure the toolchain
rm -rf "$ROOT/tmp-bin"
mkdir -p "$ROOT/tmp-bin"
cat > "$ROOT/tmp-bin/$CHOST-gcc" << EOF
#!/bin/sh
exec '$(command -v $CHOST-gcc)' --sysroot='$EROOT' -specs='$ROOT/tmp-bin/$CHOST.specs' "\$@"
EOF
cat > "$ROOT/tmp-bin/$CHOST-g++" << EOF
#!/bin/sh
exec '$(command -v $CHOST-g++)' --sysroot='$EROOT' -specs='$ROOT/tmp-bin/$CHOST.specs' "\$@"
EOF
cat > "$ROOT/tmp-bin/$CHOST.specs" << EOF
%rename link old_link
*link:
%(old_link) %{!static:%{!static-pie:%{!shared:--dynamic-linker=$EPREFIX$ldso}}}
EOF
chmod +x "$ROOT/tmp-bin/$CHOST-gcc" "$ROOT/tmp-bin/$CHOST-g++"
#export PREROOTPATH="$ROOT/tmp-bin" # doesn't work anymore
cat > "$BROOT/etc/env.d/000tmp" << EOF
PATH='$ROOT/tmp-bin'
EOF
( unset EPREFIX ROOT SYSROOT; env-update )
export PKG_CONFIG_PATH="$EROOT/usr/$LIBDIR/pkgconfig"
# Sanity check
gcc_host="$(portageq best_visible "$EROOT" sys-devel/gcc | cut -d/ -f2)"
gcc_build="$(unset EPREFIX ROOT SYSROOT; portageq best_version "$BROOT" "cross-$CHOST/gcc" | cut -d/ -f2)"
if [ "$gcc_host" != "$gcc_build" ]; then
echo "Host and build gcc mismatch!"
echo "Please update your build's gcc to match"
echo "host: sys-devel/$gcc_host"
echo "build: cross-$CHOST/$gcc_build"
exit 1
fi
# Autoconf defines...
export ac_cv_func_malloc_0_nonnull=yes # required by sys-process/procps (old autoconf)
export ac_cv_func_realloc_0_nonnull=yes # required by sys-process/procps (old autoconf)
export ac_cv_file__dev_ptmx=yes # required by dev-lang/python
export ac_cv_file__dev_ptc=no # required by dev-lang/python
export CHOST # required by cross-emerge
if [ -n "$*" ]; then
cross-emerge -vnbk -1 "$@"
else
cross-emerge -vnbk -O1 sys-apps/baselayout
cross-emerge -vnbk -o --onlydeps-with-rdeps=n $virtual_os_headers
cross-emerge -vnbk -O1 $virtual_os_headers virtual/os-headers
cross-emerge -vnbk -o --onlydeps-with-rdeps=n $virtual_libc
cross-emerge -vnbk -O1 $virtual_libc virtual/libc
cross-emerge -vnbk -DN @system
cross-emerge -c --with-bdeps=n
fi
# NOTE: Modified portage/package/ebuild/doebuild.py to hardcode eprefix and get
# ccache to work...
#unset CCACHE_DISABLE
#export CCACHE_DIR="$PWD/ccache"
#export FEATURES="ccache"
#cross-emerge -vnbk -O $virtual_os_headers
#FEATURES="ccache nostrip" CFLAGS="-O2 -ggdb" cross-emerge -v -O $virtual_libc
# Cleanup
rm -rf "$EROOT/var/log" "$EROOT/var/tmp" "$EROOT/var/cache"
rm -rf "$ROOT/tmp-bin"
rm -f "$BROOT/etc/env.d/000tmp"
( unset EPREFIX ROOT SYSROOT; env-update )
# Finalize the portage config
ln -sfT "../../var/db/repos/gentoo/profiles/$PROFILE" "$PORTAGE_CONFIGROOT/etc/portage/make.profile"
# Install additional files
mkdir -p "$EROOT/etc"
cat > "$EROOT/etc/resolv.conf" << EOF
# Termux defaults ¯\\_(ツ)_/¯
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
# Package up
rm -f sysroot.tar sysroot.tar sysroot.tar.xz
tar cf sysroot.tar -C "$ROOT" --hard-dereference .
xz -9v sysroot.tar
# Termux setup:
# - pkg up / termux-change-repo
# - pkg in openssh
# - passwd
# - sshd
# - ifconfig
# Copying the files:
# - scp -P 8022 sysroot.tar.xz <ip>:~
# - ssh -p 8022 <ip>
# - cd /; tar xf ~/sysroot.tar.xz
# Running the environment:
# - LD_PRELOAD= /data/data/com.termux/files/gentoo/bin/bash -l
# First-time initialization:
# - /data/data/com.termux/files/gentoo/sbin/ldconfig
# - /data/data/com.termux/files/gentoo/usr/sbin/env-update
# - echo "termux:x:$(id -u):$(id -g):termux:/data/data/com.termux/files/home:/data/data/com.termux/gentoo/bin/bash" >> /data/data/com.termux/files/gentoo/etc/passwd
# - echo "termux::$(id -g):" >> /data/data/com.termux/files/gentoo/etc/group
# - exec /data/data/com.termux/files/gentoo/bin/bash -l
# - emerge-webrsync

66
gentoo.diff

@ -0,0 +1,66 @@
diff --git a/app-admin/eselect/eselect-1.4.20.ebuild b/app-admin/eselect/eselect-1.4.20.ebuild
index 338c3aba0..63490c9b4 100644
--- a/app-admin/eselect/eselect-1.4.20.ebuild
+++ b/app-admin/eselect/eselect-1.4.20.ebuild
@@ -26,6 +26,13 @@ BDEPEND="doc? ( dev-python/docutils )"
PDEPEND="emacs? ( app-emacs/eselect-mode )
vim-syntax? ( app-vim/eselect-syntax )"
+# https://bugs.gentoo.org/905934
+src_configure() {
+ econf \
+ ac_cv_path_BASH="${EPREFIX}/bin/bash" \
+ ac_cv_path_ENV_UPDATE="${EPREFIX}/usr/sbin/env-update"
+}
+
src_compile() {
emake
use doc && emake html
diff --git a/dev-libs/gmp/gmp-6.2.1-r5.ebuild b/dev-libs/gmp/gmp-6.2.1-r5.ebuild
index 585425499..a32e1c107 100644
--- a/dev-libs/gmp/gmp-6.2.1-r5.ebuild
+++ b/dev-libs/gmp/gmp-6.2.1-r5.ebuild
@@ -35,7 +35,10 @@ RESTRICT="!cpudetection? ( bindist )"
BDEPEND="
app-arch/xz-utils
sys-devel/m4
+ sys-devel/flex
+ sys-devel/bison
"
+# https://bugs.gentoo.org/905905
DOCS=( AUTHORS ChangeLog NEWS README doc/configuration doc/isa_abi_headache )
HTML_DOCS=( doc )
diff --git a/sys-apps/portage/portage-3.0.44-r1.ebuild b/sys-apps/portage/portage-3.0.44-r1.ebuild
index f6c5de541..e2df2848c 100644
--- a/sys-apps/portage/portage-3.0.44-r1.ebuild
+++ b/sys-apps/portage/portage-3.0.44-r1.ebuild
@@ -177,6 +177,11 @@ python_prepare_all() {
fi
}
+python_compile() {
+ distutils-r1_python_compile \
+ --executable="${EPREFIX}/usr/bin/${EPYTHON}"
+}
+
python_compile_all() {
local targets=()
use doc && targets+=( docbook )
@@ -195,6 +200,7 @@ python_install() {
# Install sbin scripts to bindir for python-exec linking
# they will be relocated in pkg_preinst()
distutils-r1_python_install \
+ --prefix="${EPREFIX}/usr" \
--system-prefix="${EPREFIX}/usr" \
--bindir="$(python_get_scriptdir)" \
--docdir="${EPREFIX}/usr/share/doc/${PF}" \
@@ -237,7 +243,7 @@ python_install_all() {
}
pkg_preinst() {
- if ! use build; then
+ if [[ -z ${ROOT} ]] && ! use build; then
python_setup
local sitedir=$(python_get_sitedir)
[[ -d ${D}${sitedir} ]] || die "${D}${sitedir}: No such directory"

48
patches/sys-apps/portage/portage-3.0.44-termux-disable-hardlinking.patch

@ -0,0 +1,48 @@
Termux: Don't create hardlinks
The termux environment doesn't support hardlinking (permission denied), so we
need to replace/stub out anything that relies on them, to at least get most of
the functionality of the package manager to work.
--- portage-3.0.44.orig/bin/estrip
+++ portage-3.0.44/bin/estrip
@@ -281,7 +281,7 @@
dst=${dst_dirname}/${dst_basename}
if [[ ! -e ${dst} ]]; then
debug-print "creating hard link: target: '${inode_debug}' name: '${dst}'"
- ln -L "${inode_debug}" "${dst}" || die "failed to create hard link '${dst}'"
+ cp -aLT "${inode_debug}" "${dst}" || die "failed to create hard link '${dst}'"
fi
else
dst_basename=${src_basename}.debug
@@ -340,7 +340,7 @@
# So, use a lockfile to prevent interference (easily observed with
# dev-vcs/git which creates ~111 hardlinks to one file in
# /usr/libexec/git-core).
- while ! ln "${inode_link}" "${lockfile}" 2>/dev/null; do
+ while ! ln -s "${inode_link}" "${lockfile}" 2>/dev/null; do
(( --locktries > 0 )) || die "failed to acquire lock '${lockfile}'"
sleep 1
done
@@ -374,9 +374,9 @@
if ${already_stripped} ; then
rm -f "${x}" || die "rm failed unexpectedly"
- ln "${inode_link}_stripped" "${x}" || die "ln failed unexpectedly"
+ cp -aT "${inode_link}_stripped" "${x}" || die "ln failed unexpectedly"
else
- ln "${x}" "${inode_link}_stripped" || die "ln failed unexpectedly"
+ cp -aT "${x}" "${inode_link}_stripped" || die "ln failed unexpectedly"
if [[ ${xt_data} ]] ; then
restore_xattrs <<< "${xt_data}"
fi
--- portage-3.0.44.orig/lib/portage/locks.py
+++ portage-3.0.44/lib/portage/locks.py
@@ -423,6 +423,7 @@
if e.errno not in (errno.ENOENT, errno.ESTALE):
_raise_exc(e)
return (True, None)
+ return (False, fstat_st)
# Since stat is not reliable for removed files on NFS with the default
# file attribute cache behavior ('ac' mount option), create a temporary

1
patches/sys-apps/portage/series

@ -0,0 +1 @@
portage-3.0.44-termux-disable-hardlinking.patch

24
patches/sys-libs/glibc/glibc-2.36-termux-stub-syscalls.patch

@ -0,0 +1,24 @@
Termux: Stub out some syscalls
These syscalls are either blacklisted in Android's seccomp policy, or simply
not implemented by the running kernel (android kernels lag behind quite a bit!).
Whichever of the two it is, calling any of these results in the process being
killed with SIGSYS, usually killing the entire process. To prevent this, we
stub them with an ENOSYS result, pretending they aren't implemented.
--- glibc-2.36.orig/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ glibc-2.36/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -167,7 +167,11 @@
# undef INTERNAL_SYSCALL_RAW
# define INTERNAL_SYSCALL_RAW(name, nr, args...) \
({ long _sys_result; \
- { \
+ switch (name) { \
+ case SYS_ify(set_robust_list): \
+ case SYS_ify(rseq): \
+ case SYS_ify(faccessat2): \
+ _sys_result = -ENOSYS; break; default: \
LOAD_ARGS_##nr (args) \
register long _x8 asm ("x8") = (name); \
asm volatile ("svc 0 // syscall " # name \

1
patches/sys-libs/glibc/series

@ -0,0 +1 @@
glibc-2.36-termux-stub-syscalls.patch

5
portage/env/dev-lang/perl

@ -0,0 +1,5 @@
# The ebuild uses the perl-cross build system when it detects a cross build
# The regular perl build system sucks in general but breaks spectacularly in a
# setup like this, so it's best to avoid
tc-is-cross-compiler() { true; }

5
portage/package.use

@ -0,0 +1,5 @@
dev-vcs/git -curl -gpg -perl -webdav -nls
app-editors/vim -crypt -nls
app-portage/portage-utils -qmanifest
sys-devel/m4 -nls
sys-apps/help2man -nls
Loading…
Cancel
Save