--- /dev/null
+# Executing "npm install serve" and other npm commands
+# segfaults in v8::internal::DoubleToRadixCString() at ../deps/v8/src/conversions.cc:445
+TERMUX_PKG_HOMEPAGE=http://nodejs.org/
+TERMUX_PKG_DESCRIPTION="Platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications"
+TERMUX_PKG_VERSION=5.1.0
+TERMUX_PKG_SRCURL=https://nodejs.org/dist/v${TERMUX_PKG_VERSION}/node-v${TERMUX_PKG_VERSION}.tar.gz
+TERMUX_PKG_EXTRA_CONFIGURE_ARGS="--dest-os=android --shared-openssl --shared-zlib --shared-libuv"
+TERMUX_PKG_DEPENDS="openssl, libuv"
+TERMUX_PKG_RM_AFTER_INSTALL="lib/node_modules/npm/html lib/node_modules/npm/make.bat share/systemtap lib/dtrace"
+TERMUX_PKG_BUILD_IN_SRC=yes
+
+termux_step_configure () {
+ LDFLAGS+=" -lgnustl_shared" #
+
+ #FIXME: node.js build does not handle already installed headers
+ # https://github.com/nodejs/node/issues/2637
+ rm -Rf $TERMUX_PREFIX/{include/gtest/,/include/ares*}
+
+ if [ $TERMUX_ARCH = "arm" ]; then
+ TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" --dest-cpu=arm"
+ elif [ $TERMUX_ARCH = "i686" ]; then
+ TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" --dest-cpu=ia32"
+ elif [ $TERMUX_ARCH = "aarch64" ]; then
+ TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" --dest-cpu=arm64"
+ elif [ $TERMUX_ARCH = "x86_64" ]; then
+ TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" --dest-cpu=x64"
+ else
+ echo "Unsupported arch: $TERMUX_ARCH"
+ exit 1
+ fi
+
+ ./configure --prefix=$TERMUX_PREFIX ${TERMUX_PKG_EXTRA_CONFIGURE_ARGS}
+}
--- /dev/null
+diff -u -r ../node-v4.2.2/deps/cares/src/ares_init.c ./deps/cares/src/ares_init.c
+--- ../node-v4.2.2/deps/cares/src/ares_init.c 2015-11-03 15:00:03.000000000 -0500
++++ ./deps/cares/src/ares_init.c 2015-12-01 21:18:14.327288234 -0500
+@@ -43,7 +43,35 @@
+ #endif
+
+ #if defined(ANDROID) || defined(__ANDROID__)
++# ifdef __LP64__
++# include <dlfcn.h>
++// http://stackoverflow.com/questions/28413530/api-to-get-android-system-properties-is-removed-in-arm64-platforms
++// Android 'L' makes __system_property_get a non-global symbol.
++// Here we provide a stub which loads the symbol from libc via dlsym.
++#define PROP_NAME_MAX 31
++#define PROP_VALUE_MAX 91
++typedef int (*PFN_SYSTEM_PROP_GET)(const char *, char *);
++int __system_property_get(const char* name, char* value)
++{
++ static PFN_SYSTEM_PROP_GET __real_system_property_get = NULL;
++ if (!__real_system_property_get) {
++ // libc.so should already be open, get a handle to it.
++ void *handle = dlopen("libc.so", RTLD_NOLOAD);
++ if (!handle) {
++ printf("Cannot dlopen libc.so: %s.\n", dlerror());
++ } else {
++ __real_system_property_get = (PFN_SYSTEM_PROP_GET)dlsym(handle, "__system_property_get");
++ }
++ if (!__real_system_property_get) {
++ printf("Cannot resolve __system_property_get(): %s.\n", dlerror());
++ }
++ }
++ return (*__real_system_property_get)(name, value);
++}
++# else
+ #include <sys/system_properties.h>
++#endif
++
+ /* From the Bionic sources */
+ #define DNS_PROP_NAME_PREFIX "net.dns"
+ #define MAX_DNS_PROPERTIES 8
--- /dev/null
+diff -u -r ../node-v5.1.0/deps/npm/lib/build.js ./deps/npm/lib/build.js
+--- ../node-v5.1.0/deps/npm/lib/build.js 2015-11-17 15:55:27.000000000 -0500
++++ ./deps/npm/lib/build.js 2015-11-17 19:01:33.061204729 -0500
+@@ -223,6 +223,8 @@
+
+ function linkBin (from, to, gently, cb) {
+ if (process.platform !== 'win32') {
++ // Fix shebang paths in binary scripts:
++ require('child_process').spawn('termux-fix-shebang', [from])
+ return linkIfExists(from, to, gently, cb)
+ } else {
+ return cmdShimIfExists(from, to, cb)
--- /dev/null
+See https://github.com/nodejs/node-v0.x-archive/issues/8540
+
+diff -u -r ../node-v4.0.0/lib/net.js ./lib/net.js
+--- ../node-v4.0.0/lib/net.js 2015-09-08 11:30:45.000000000 -0400
++++ ./lib/net.js 2015-09-08 17:37:04.293684663 -0400
+@@ -951,7 +951,7 @@
+ // systems. See
+ // http://lists.freebsd.org/pipermail/freebsd-bugs/2008-February/028260.html
+ // for more information on the lack of support for FreeBSD.
+- if (process.platform !== 'freebsd')
++ if (process.platform !== 'freebsd' && process.platform !== 'android')
+ dnsopts.hints |= dns.V4MAPPED;
+ }
+
--- /dev/null
+diff -u -r ../node-v0.12.3/lib/os.js ./lib/os.js
+--- ../node-v0.12.3/lib/os.js 2015-05-13 20:30:45.000000000 -0400
++++ ./lib/os.js 2015-05-22 13:23:14.286889554 -0400
+@@ -51,7 +51,7 @@
+ return process.env.TMPDIR ||
+ process.env.TMP ||
+ process.env.TEMP ||
+- '/tmp';
++ '@TERMUX_PREFIX@/tmp';
+ }
+ };
+
--- /dev/null
+Termux is effectively a single-user system so chown:ing
+does not make much sense.
+
+Without this patch npm fails with EPERM on chown
+for cache.json when first building the local index.
+diff -u -r ../node-v0.12.7/deps/npm/lib/cache/update-index.js ./deps/npm/lib/cache/update-index.js
+--- ../node-v0.12.7/deps/npm/lib/cache/update-index.js 2015-07-09 18:41:19.000000000 -0400
++++ ./deps/npm/lib/cache/update-index.js 2015-07-24 20:45:21.078116384 -0400
+@@ -4,7 +4,7 @@
+ var assert = require('assert')
+ var path = require('path')
+ var mkdir = require('mkdirp')
+-var chownr = require('chownr')
++var chownr = function(path, uid, gid, cb) { cb(null); }
+ var npm = require('../npm.js')
+ var log = require('npmlog')
+ var cacheFile = require('npm-cache-filename')
--- /dev/null
+diff -u -r ../node-v0.12.7/deps/npm/node_modules/osenv/node_modules/os-tmpdir/index.js ./deps/npm/node_modules/osenv/node_modules/os-tmpdir/index.js
+--- ../node-v0.12.7/deps/npm/node_modules/osenv/node_modules/os-tmpdir/index.js 2015-07-09 18:41:19.000000000 -0400
++++ ./deps/npm/node_modules/osenv/node_modules/os-tmpdir/index.js 2015-07-24 20:56:42.278310940 -0400
+@@ -14,7 +14,7 @@
+ path = process.env.TMPDIR ||
+ process.env.TMP ||
+ process.env.TEMP ||
+- '/tmp';
++ '@TERMUX_PREFIX@/tmp';
+ }
+
+ if (trailingSlashRe.test(path)) {
--- /dev/null
+Without this patch functions such as process.getgroups
+are not built on Android, which breaks things such as
+npm/node_modules/which/which.js.
+
+diff -u -r ../node-v4.0.0/src/node.cc ./src/node.cc
+--- ../node-v4.0.0/src/node.cc 2015-09-08 11:30:45.000000000 -0400
++++ ./src/node.cc 2015-09-08 19:06:39.415724588 -0400
+@@ -69,7 +69,7 @@
+ #include <unistd.h> // setuid, getuid
+ #endif
+
+-#if defined(__POSIX__) && !defined(__ANDROID__)
++#if defined(__POSIX__)
+ #include <pwd.h> // getpwnam()
+ #include <grp.h> // getgrnam()
+ #endif
+@@ -1590,7 +1590,7 @@
+ }
+
+
+-#if defined(__POSIX__) && !defined(__ANDROID__)
++#if defined(__POSIX__)
+
+ static const uid_t uid_not_found = static_cast<uid_t>(-1);
+ static const gid_t gid_not_found = static_cast<gid_t>(-1);
+@@ -1910,7 +1910,7 @@
+ }
+ }
+
+-#endif // __POSIX__ && !defined(__ANDROID__)
++#endif // __POSIX__
+
+
+ void Exit(const FunctionCallbackInfo<Value>& args) {
+@@ -2866,7 +2866,7 @@
+
+ env->SetMethod(process, "umask", Umask);
+
+-#if defined(__POSIX__) && !defined(__ANDROID__)
++#if defined(__POSIX__)
+ env->SetMethod(process, "getuid", GetUid);
+ env->SetMethod(process, "geteuid", GetEUid);
+ env->SetMethod(process, "setuid", SetUid);
+@@ -2880,7 +2880,7 @@
+ env->SetMethod(process, "getgroups", GetGroups);
+ env->SetMethod(process, "setgroups", SetGroups);
+ env->SetMethod(process, "initgroups", InitGroups);
+-#endif // __POSIX__ && !defined(__ANDROID__)
++#endif // __POSIX__
+
+ env->SetMethod(process, "_kill", Kill);
+