--- /dev/null
+diff -u -r ../apt-1.6~alpha3/CMakeLists.txt ./CMakeLists.txt
+--- ../apt-1.6~alpha3/CMakeLists.txt 2017-10-28 17:57:05.000000000 +0200
++++ ./CMakeLists.txt 2017-11-02 17:42:28.162838378 +0100
+@@ -33,7 +33,6 @@
+ include(GNUInstallDirs)
+ include(TestBigEndian)
+ find_package(Threads REQUIRED)
+-find_package(LFS REQUIRED)
+ find_package(Iconv REQUIRED)
+
+ find_package(Perl REQUIRED)
+@@ -44,11 +43,6 @@
+ include_directories(${Intl_INCLUDE_DIRS})
+ endif()
+
+-# Add large file support
+-add_compile_options(${LFS_COMPILE_OPTIONS})
+-add_definitions(${LFS_DEFINITIONS})
+-link_libraries(${LFS_LIBRARIES})
+-
+ # Set compiler flags
+ set(CMAKE_CXX_STANDARD 11)
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
+@@ -69,12 +63,6 @@
+ add_optional_compile_options(Wsign-promo)
+ add_optional_compile_options(Wundef)
+
+-# apt-ftparchive dependencies
+-find_package(BerkeleyDB REQUIRED)
+-if (BERKELEY_DB_FOUND)
+- set(HAVE_BDB 1)
+-endif()
+-
+ find_package(GnuTLS REQUIRED)
+ if (GNUTLS_FOUND)
+ set(HAVE_GNUTLS 1)
+@@ -87,22 +75,12 @@
+ endif()
+
+
+-find_package(BZip2 REQUIRED)
+-if (BZIP2_FOUND)
+- set(HAVE_BZ2 1)
+-endif()
+-
+ find_package(LZMA REQUIRED)
+ if (LZMA_FOUND)
+ set(HAVE_LZMA 1)
+ endif()
+
+
+-find_package(LZ4 REQUIRED)
+-if (LZ4_FOUND)
+- set(HAVE_LZ4 1)
+-endif()
+-
+ find_package(Udev)
+ if (UDEV_FOUND)
+ set(HAVE_UDEV 1)
+@@ -184,10 +162,10 @@
+ message(STATUS "Found dpkg data dir: ${DPKG_DATADIR_CMD}")
+ set(DPKG_DATADIR "${DPKG_DATADIR_CMD}" CACHE PATH "dpkg data directory")
+ endif()
+-if (NOT DEFINED COMMON_ARCH)
+- execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
+- OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
+-endif()
++# if (NOT DEFINED COMMON_ARCH)
++# execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
++ #OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
++# endif()
+ if (NOT DEFINED ROOT_GROUP)
+ execute_process(COMMAND id -gn root
+ OUTPUT_VARIABLE ROOT_GROUP OUTPUT_STRIP_TRAILING_WHITESPACE)
+@@ -215,11 +193,8 @@
+ add_subdirectory(apt-inst)
+ add_subdirectory(cmdline)
+ add_subdirectory(completions)
+-add_subdirectory(doc)
+ add_subdirectory(dselect)
+-add_subdirectory(ftparchive)
+ add_subdirectory(methods)
+-add_subdirectory(test)
+
+ if (USE_NLS)
+ add_subdirectory(po)
--- /dev/null
+diff -u -r ../apt-1.6~alpha3/apt-pkg/contrib/fileutl.cc ./apt-pkg/contrib/fileutl.cc
+--- ../apt-1.6~alpha3/apt-pkg/contrib/fileutl.cc 2017-10-28 17:57:05.000000000 +0200
++++ ./apt-pkg/contrib/fileutl.cc 2017-11-02 17:38:43.633482989 +0100
+@@ -37,7 +37,9 @@
+ #include <dirent.h>
+ #include <errno.h>
+ #include <fcntl.h>
++#ifndef __ANDROID__
+ #include <glob.h>
++#endif
+ #include <grp.h>
+ #include <pwd.h>
+ #include <signal.h>
+@@ -2790,6 +2792,7 @@
+ }
+ /*}}}*/
+
++#ifndef __ANDROID__
+ // Glob - wrapper around "glob()" /*{{{*/
+ std::vector<std::string> Glob(std::string const &pattern, int flags)
+ {
+@@ -2815,6 +2818,7 @@
+ globfree(&globbuf);
+ return result;
+ }
++#endif
+ /*}}}*/
+ static std::string APT_NONNULL(1) GetTempDirEnv(char const * const env) /*{{{*/
+ {
+diff -u -r ../apt-1.6~alpha3/apt-pkg/contrib/fileutl.h ./apt-pkg/contrib/fileutl.h
+--- ../apt-1.6~alpha3/apt-pkg/contrib/fileutl.h 2017-10-28 17:57:05.000000000 +0200
++++ ./apt-pkg/contrib/fileutl.h 2017-11-02 17:37:38.518249720 +0100
+@@ -262,7 +262,9 @@
+ APT_HIDDEN std::string flNormalize(std::string file);
+
+ // simple c++ glob
++#ifndef __ANDROID__
+ std::vector<std::string> Glob(std::string const &pattern, int flags=0);
++#endif
+
+ /** \brief Popen() implementation that execv() instead of using a shell
+ *
--- /dev/null
+diff -u -r ../apt-1.1.3/apt-pkg/contrib/srvrec.cc ./apt-pkg/contrib/srvrec.cc
+--- ../apt-1.1.3/apt-pkg/contrib/srvrec.cc 2015-11-30 03:08:24.000000000 -0500
++++ ./apt-pkg/contrib/srvrec.cc 2015-12-03 16:21:54.397715576 -0500
+@@ -40,14 +40,24 @@
+ struct servent *s_ent = nullptr;
+ std::vector<char> buf(1024);
+
++#ifdef __ANDROID__
++ s_ent = getservbyport(htons(port), "tcp");
++ if (s_ent == nullptr) return false;
++#else
+ res = getservbyport_r(htons(port), "tcp", &s_ent_buf, buf.data(), buf.size(), &s_ent);
+ if (res != 0 || s_ent == nullptr)
+ return false;
++#endif
+
+ strprintf(target, "_%s._tcp.%s", s_ent->s_name, host.c_str());
+ return GetSrvRecords(target, Result);
+ }
+
++#ifdef __ANDROID__
++extern "C" int __dn_skipname(const unsigned char* comp_dn, const unsigned char* eom);
++static inline int dn_skipname(const unsigned char* a, const unsigned char* b) { return __dn_skipname(a,b); }
++#endif
++
+ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result)
+ {
+ unsigned char answer[PACKETSZ];
--- /dev/null
+diff -u -r ../apt-1.4.7/apt-pkg/contrib/strutl.cc ./apt-pkg/contrib/strutl.cc
+--- ../apt-1.4.7/apt-pkg/contrib/strutl.cc 2017-07-13 23:45:39.000000000 +0200
++++ ./apt-pkg/contrib/strutl.cc 2017-07-23 22:58:23.103247428 +0200
+@@ -100,6 +100,7 @@
+ }
+ }
+ /*}}}*/
++#ifndef __ANDROID__
+ // UTF8ToCodeset - Convert some UTF-8 string for some codeset /*{{{*/
+ // ---------------------------------------------------------------------
+ /* This is handy to use before display some information for enduser */
+@@ -169,6 +170,7 @@
+
+ return true;
+ }
++#endif
+ /*}}}*/
+ // strstrip - Remove white space from the front and back of a string /*{{{*/
+ // ---------------------------------------------------------------------
--- /dev/null
+diff -u -r ../apt-1.6~alpha3/apt-pkg/deb/debrecords.cc ./apt-pkg/deb/debrecords.cc
+--- ../apt-1.6~alpha3/apt-pkg/deb/debrecords.cc 2017-10-28 17:57:05.000000000 +0200
++++ ./apt-pkg/deb/debrecords.cc 2017-11-02 17:40:35.816161798 +0100
+@@ -23,7 +23,9 @@
+ #include <sstream>
+ #include <string>
+ #include <vector>
++#ifndef __ANDROID__
+ #include <langinfo.h>
++#endif
+ #include <string.h>
+
+ #include <apti18n.h>
+@@ -151,12 +153,14 @@
+ orig = Section.FindS("Description");
+ }
+
++#ifndef __ANDROID__
+ char const * const codeset = nl_langinfo(CODESET);
+ if (strcmp(codeset,"UTF-8") != 0) {
+ string dest;
+ UTF8ToCodeset(codeset, orig, &dest);
+ return dest;
+ }
++#endif
+
+ return orig;
+ }
--- /dev/null
+--- ../cache/apt-1.4.7/apt-pkg/init.cc 2017-07-14 07:45:39.000000000 +1000
++++ ./apt-pkg/init.cc 2017-07-19 17:03:07.949752843 +1000
+@@ -51,7 +51,7 @@
+ return vec;
+ }
+
+-
++#ifndef __ANDROID__
+ // pkgInitArchTupleMap - Initialize the architecture tuple map /*{{{*/
+ // ---------------------------------------------------------------------
+ /* This initializes */
+@@ -116,7 +116,7 @@
+
+ return true;
+ }
+- /*}}}*/
++#endif /*}}}*/
+
+
+ // pkgInitConfig - Initialize the configuration class /*{{{*/
+@@ -133,6 +133,7 @@
+ Cnf.CndSet("APT::Install-Recommends", true);
+ Cnf.CndSet("APT::Install-Suggests", false);
+ Cnf.CndSet("Dir","/");
++ Cnf.CndSet("Acquire::Languages", "none");
+
+ // State
+ Cnf.CndSet("Dir::State", STATE_DIR + 1);
+@@ -158,9 +159,9 @@
+ Cnf.CndSet("Dir::Etc::trusted", "trusted.gpg");
+ Cnf.CndSet("Dir::Etc::trustedparts","trusted.gpg.d");
+ Cnf.CndSet("Dir::Bin::methods", LIBEXEC_DIR "/methods");
+- Cnf.CndSet("Dir::Bin::solvers::",LIBEXEC_DIR "/solvers");
+- Cnf.CndSet("Dir::Bin::planners::",LIBEXEC_DIR "/planners");
+- Cnf.CndSet("Dir::Media::MountPath","/media/apt");
++ Cnf.CndSet("Dir::Bin::solvers::",LIBEXEC_DIR "/solvers");
++ Cnf.CndSet("Dir::Bin::planners::", LIBEXEC_DIR "/planners");
++ Cnf.CndSet("Dir::Media::MountPath","media/apt");
+
+ // State
+ Cnf.CndSet("Dir::Log", LOG_DIR + 1);
+@@ -283,8 +284,6 @@
+ return _error->Error(_("Unable to determine a suitable packaging system type"));
+ }
+
+- if (pkgInitArchTupleMap() == false)
+- return false;
+
+ return Sys->Initialize(Cnf);
+ }
--- /dev/null
+diff -u -r ../apt-1.2.12/apt-private/private-download.cc ./apt-private/private-download.cc
+--- ../apt-1.2.12/apt-private/private-download.cc 2016-05-11 10:57:51.000000000 +0200
++++ ./apt-private/private-download.cc 2017-07-01 00:31:32.131776100 +0200
+@@ -121,7 +121,6 @@
+ /*}}}*/
+ bool CheckFreeSpaceBeforeDownload(std::string const &Dir, unsigned long long FetchBytes)/*{{{*/
+ {
+- uint32_t const RAMFS_MAGIC = 0x858458f6;
+ /* Check for enough free space, but only if we are actually going to
+ download */
+ if (_config->FindB("APT::Get::Print-URIs", false) == true ||
--- /dev/null
+TERMUX_PKG_HOMEPAGE=https://packages.debian.org/apt
+TERMUX_PKG_DESCRIPTION="Front-end for the dpkg package manager"
+TERMUX_PKG_DEPENDS="libutil, libcurl, liblzma, dpkg, gpgv, libc++"
+TERMUX_PKG_VERSION=1.6~alpha3
+TERMUX_PKG_SHA256=2acd561ff04fc3efa4c590139ca60cfdbc93787ea80334f7448ecf466faab119
+TERMUX_PKG_SRCURL=http://ftp.debian.org/debian/pool/main/a/apt/apt_${TERMUX_PKG_VERSION}.tar.xz
+TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
+-DPERL_EXECUTABLE=`which perl`
+-DCMAKE_INSTALL_FULL_LOCALSTATEDIR=$TERMUX_PREFIX
+-DCOMMON_ARCH=$TERMUX_ARCH
+-DDPKG_DATADIR=$TERMUX_PREFIX/share/dpkg
+-DUSE_NLS=OFF
+-DWITH_DOC=OFF
+"
+TERMUX_PKG_ESSENTIAL=yes
+TERMUX_PKG_CONFFILES="etc/apt/sources.list"
+TERMUX_PKG_CONFLICTS=apt-transport-https
+TERMUX_PKG_REPLACES=apt-transport-https
+TERMUX_PKG_RM_AFTER_INSTALL="
+bin/apt-cdrom
+bin/apt-extracttemplates
+bin/apt-mark
+bin/apt-sortpkgs
+etc/apt/apt.conf.d
+lib/apt/apt-helper
+lib/apt/methods/bzip2
+lib/apt/methods/cdrom
+lib/apt/methods/mirror
+lib/apt/methods/rred
+lib/apt/planners/
+lib/apt/solvers/
+lib/dpkg/
+lib/libapt-inst.so
+"
+
+termux_step_post_make_install() {
+ printf "# The main termux repository:\ndeb [arch=all,${TERMUX_ARCH}] https://termux.net stable main\n" > $TERMUX_PREFIX/etc/apt/sources.list
+ cp $TERMUX_PKG_BUILDER_DIR/trusted.gpg $TERMUX_PREFIX/etc/apt/
+ rm /data/data/com.termux/files/usr/include/apt-pkg -r
+}
--- /dev/null
+diff -u -r ../apt-1.4.7/cmdline/apt-key.in ./cmdline/apt-key.in
+--- ../apt-1.4.7/cmdline/apt-key.in 2017-07-13 23:45:39.000000000 +0200
++++ ./cmdline/apt-key.in 2017-07-26 12:18:17.424086422 +0200
+@@ -16,10 +16,7 @@
+ aptkey_echo() { echo "$@"; }
+
+ requires_root() {
+- if [ "$(id -u)" -ne 0 ]; then
+- apt_error "This command can only be used by root."
+- exit 1
+- fi
++continue
+ }
+
+ command_available() {
+@@ -260,7 +257,7 @@
+ if accessible_file_exists "$TRUSTEDFILE"; then
+ $ACTION "$TRUSTEDFILE" "$@"
+ fi
+- local TRUSTEDPARTS="/etc/apt/trusted.gpg.d"
++ local TRUSTEDPARTS="@TERMUX_PREFIX@/etc/apt/trusted.gpg.d"
+ eval "$(apt-config shell TRUSTEDPARTS Dir::Etc::TrustedParts/d)"
+ if [ -d "$TRUSTEDPARTS" ]; then
+ TRUSTEDPARTS="$(readlink -f "$TRUSTEDPARTS")"
+@@ -542,7 +539,7 @@
+ done
+
+ if [ -z "$TRUSTEDFILE" ]; then
+- TRUSTEDFILE="/etc/apt/trusted.gpg"
++ TRUSTEDFILE="@TERMUX_PREFIX@/etc/apt/trusted.gpg"
+ eval $(apt-config shell TRUSTEDFILE Apt::GPGV::TrustedKeyring)
+ eval $(apt-config shell TRUSTEDFILE Dir::Etc::Trusted/f)
+ fi
+@@ -612,7 +609,8 @@
+ unset TMPDIR
+ fi
+ fi
+- GPGHOMEDIR="$(mktemp --directory --tmpdir 'apt-key-gpghome.XXXXXXXXXX')"
++ # Use short options as busybox mktemp does not support long ones:
++ GPGHOMEDIR="$(mktemp -d -t 'apt-key-gpghome.XXXXXXXXXX')"
+ CURRENTTRAP="${CURRENTTRAP} cleanup_gpg_home;"
+ trap "${CURRENTTRAP}" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
+ if [ -z "$GPGHOMEDIR" ]; then
--- /dev/null
+diff -u -r ../apt-0.9.16.1/apt-pkg/contrib/cmndline.cc ./apt-pkg/contrib/cmndline.cc
+--- ../apt-0.9.16.1/apt-pkg/contrib/cmndline.cc 2014-03-15 17:23:45.000000000 +0100
++++ ./apt-pkg/contrib/cmndline.cc 2014-03-25 01:10:30.764711007 +0100
+@@ -27,6 +27,14 @@
+ /*}}}*/
+ using namespace std;
+
++#if defined(__ANDROID__)
++static char* strchrnul(char const* s, int c)
++{
++ char const* result = strchr(s, c);
++ return const_cast<char*>((result == NULL) ? (s + strlen(s)) : result);
++}
++#endif
++
+ // CommandLine::CommandLine - Constructor /*{{{*/
+ // ---------------------------------------------------------------------
+ /* */
--- /dev/null
+diff -u -r ../apt-0.9.16.1/apt-pkg/deb/debsrcrecords.cc ./apt-pkg/deb/debsrcrecords.cc
+--- ../apt-0.9.16.1/apt-pkg/deb/debsrcrecords.cc 2014-03-15 17:23:45.000000000 +0100
++++ ./apt-pkg/deb/debsrcrecords.cc 2014-03-25 01:23:30.652689687 +0100
+@@ -26,6 +26,14 @@
+ #include <string>
+ #include <vector>
+ /*}}}*/
++#if defined(__ANDROID__)
++static char* strchrnul(char const* s, int c)
++{
++ char const* result = strchr(s, c);
++ return const_cast<char*>((result == NULL) ? (s + strlen(s)) : result);
++}
++#endif
++
+
+ using std::max;
+ using std::string;
--- /dev/null
+diff -u -r ../apt-1.6~alpha3/methods/CMakeLists.txt ./methods/CMakeLists.txt
+--- ../apt-1.6~alpha3/methods/CMakeLists.txt 2017-10-28 17:57:05.000000000 +0200
++++ ./methods/CMakeLists.txt 2017-11-02 17:45:55.436395981 +0100
+@@ -9,11 +9,8 @@
+ add_executable(copy copy.cc)
+ add_executable(store store.cc)
+ add_executable(gpgv gpgv.cc)
+-add_executable(cdrom cdrom.cc)
+ add_executable(http http_main.cc $<TARGET_OBJECTS:httplib> $<TARGET_OBJECTS:connectlib>)
+ add_executable(mirror mirror.cc $<TARGET_OBJECTS:httplib> $<TARGET_OBJECTS:connectlib>)
+-add_executable(ftp ftp.cc $<TARGET_OBJECTS:connectlib>)
+-add_executable(rred rred.cc)
+ add_executable(rsh rsh.cc)
+
+ target_compile_definitions(connectlib PRIVATE ${GNUTLS_DEFINITIONS})
+@@ -22,10 +19,9 @@
+ # Additional libraries to link against for networked stuff
+ target_link_libraries(http ${GNUTLS_LIBRARIES})
+ target_link_libraries(mirror ${RESOLV_LIBRARIES} ${GNUTLS_LIBRARIES})
+-target_link_libraries(ftp ${GNUTLS_LIBRARIES})
+
+ # Install the library
+-install(TARGETS file copy store gpgv cdrom http ftp rred rsh mirror
++install(TARGETS file copy store gpgv http rsh mirror
+ RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/apt/methods)
+
+ add_slaves(${CMAKE_INSTALL_LIBEXECDIR}/apt/methods store)
--- /dev/null
+diff -u -r ../apt-1.6~alpha3/methods/connect.cc ./methods/connect.cc
+--- ../apt-1.6~alpha3/methods/connect.cc 2017-10-28 17:57:05.000000000 +0200
++++ ./methods/connect.cc 2017-11-02 17:47:18.803413361 +0100
+@@ -164,7 +164,7 @@
+
+ // Check the socket for an error condition
+ unsigned int Err;
+- unsigned int Len = sizeof(Err);
++ socklen_t Len = sizeof(Err);
+ if (getsockopt(Fd->Fd(), SOL_SOCKET, SO_ERROR, &Err, &Len) != 0)
+ return _error->Errno("getsockopt",_("Failed"));
+
+@@ -335,7 +335,10 @@
+ if(LastHost != Host || LastPort != Port)
+ {
+ SrvRecords.clear();
+- if (_config->FindB("Acquire::EnableSrvRecords", true) == true)
++ /* Disable by default in Termux due to it breaking on (some) HTC
++ devices (https://github.com/termux/termux-packages/issues/99). */
++
++ if (_config->FindB("Acquire::EnableSrvRecords", false) == true)
+ {
+ GetSrvRecords(Host, DefPort, SrvRecords);
+ // RFC2782 defines that a lonely '.' target is an abort reason
--- /dev/null
+diff -u -r ../upstream.git/apt-private/private-output.cc ./apt-private/private-output.cc
+--- ../upstream.git/apt-private/private-output.cc 2014-06-10 15:24:50.000000000 +0200
++++ ./apt-private/private-output.cc 2014-06-15 02:40:10.539223656 +0200
+@@ -20,7 +20,11 @@
+ #include <string.h>
+ #include <iomanip>
+ #include <iostream>
+-#include <langinfo.h>
++#ifdef __ANDROID__
++# include <termios.h>
++# else
++# include <langinfo.h>
++#endif
+ #include <unistd.h>
+ #include <signal.h>
+ #include <sys/ioctl.h>
+@@ -764,7 +768,7 @@
+ regex_t Pattern;
+ int Res;
+
+- Res = regcomp(&Pattern, nl_langinfo(YESEXPR),
++ Res = regcomp(&Pattern, "^[yY]",
+ REG_EXTENDED|REG_ICASE|REG_NOSUB);
+
+ if (Res != 0) {
--- /dev/null
+diff -u -r ../upstream.git/vendor/ubuntu/apt-vendor.ent ./vendor/ubuntu/apt-vendor.ent
+--- ../upstream.git/vendor/ubuntu/apt-vendor.ent 2014-04-25 13:39:00.000000000 +0200
++++ ./vendor/ubuntu/apt-vendor.ent 2014-06-03 11:53:11.535752314 +0200
+@@ -1,7 +1,7 @@
+ <!-- details about the keys used by the distribution -->
+-<!ENTITY keyring-distro "Ubuntu">
+-<!ENTITY keyring-package "<package>ubuntu-keyring</package>">
+-<!ENTITY keyring-filename "<filename>/usr/share/keyrings/ubuntu-archive-keyring.gpg</filename>">
+-<!ENTITY keyring-removed-filename "<filename>/usr/share/keyrings/ubuntu-archive-removed-keys.gpg</filename>">
+-<!ENTITY keyring-master-filename "/usr/share/keyrings/ubuntu-master-keyring.gpg">
++<!ENTITY keyring-distro "Termux">
++<!ENTITY keyring-package "<package>termux-keyring</package>">
++<!ENTITY keyring-filename "<filename>@TERMUX_PREFIX@/share/keyrings/termux-archive-keyring.gpg</filename>">
++<!ENTITY keyring-removed-filename "<filename>@TERMUX_PREFIX@/share/keyrings/termux-archive-removed-keys.gpg</filename>">
++<!ENTITY keyring-master-filename "@TERMUX_PREFIX@/share/keyrings/termux-master-keyring.gpg">
+ <!ENTITY keyring-uri "http://archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg">