Compdigitec Labs

« | Home | »

Compiling GNU Nano for Android

By admin | July 13, 2012

If you just want a pre-built, ready to use version of Nano for Android, you can get the pre-built version.

The results of these steps include:

GNU Nano running on Android

# Export toolchain for build
export ANDROID_NDK=/opt/android-ndk-r8
export CC="$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot=/opt/android-ndk-r8/platforms/android-5/arch-arm"
export CXX="ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ --sysroot=/opt/android-ndk-r8/platforms/android-5/arch-arm"

# Build ncurses static lib
wget ftp://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz -O- | tar zxvf -
cd ncurses-5.9/

# ../form/fty_num.c:226: error: 'struct lconv' has no member named 'decimal_point'
# fty_num.c:(.text+0x280): undefined reference to `localeconv'
patch -p0 << NcursesPatch
--- form/fty_num.c	2012-07-13 23:04:53.914039027 -0400
+++ form/fty_num.c	2012-07-13 23:05:38.057484067 -0400
@@ -36,6 +36,12 @@

 MODULE_ID("$Id: fty_num.c,v 1.28 2010/01/23 21:14:36 tom Exp $")

+/* "MISSING FROM BIONIC - DEFINED TO MAKE libstdc++-v3 happy" */
+#ifdef HAVE_LOCALE_H
+#   undef HAVE_LOCALE_H
+#   define HAVE_LOCALE_H 0
+#endif
+
 #if HAVE_LOCALE_H
 #include <locale.h>
 #endif

NcursesPatch

./configure --with-normal --without-shared --without-cxx-binding --enable-root-environ --disable-widec --without-tests --host=arm-linux
make -j3

# Nano 2.2.6 build
cd ..
wget http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz -O- | tar zxvf -
cd nano-2.2.6/

# Patch to get around bionic deficiencies
patch -p0 << NanoAndroid
--- src/chars.c	2012-07-13 22:02:21.741210225 -0400
+++ src/chars.c	2012-07-13 22:04:02.887938640 -0400
@@ -79,6 +79,7 @@
     return ((unsigned int)c == (unsigned char)c);
 }

+/*
 static void mbtowc_reset(void)
 {
     IGNORE_CALL_RESULT(mbtowc(NULL, NULL, 0));
@@ -88,6 +89,7 @@
 {
     IGNORE_CALL_RESULT(wctomb(NULL, 0));
 }
+*/

 /* This function is equivalent to isalnum() for multibyte characters. */
 bool is_alnum_mbchar(const char *c)
--- src/files.c	2012-07-13 22:13:35.516739719 -0400
+++ src/files.c	2012-07-13 22:13:38.796698486 -0400
@@ -2237,13 +2237,16 @@
 	    tilde_dir = mallocstrncpy(NULL, buf, i + 1);
 	    tilde_dir[i] = '\0';

+	    /*
 	    do {
 		userdata = getpwent();
 	    } while (userdata != NULL && strcmp(userdata->pw_name,
 		tilde_dir + 1) != 0);
 	    endpwent();
-	    if (userdata != NULL)
-		tilde_dir = mallocstrcpy(tilde_dir, userdata->pw_dir);
+	    */
+	    char* home = getenv("HOME");
+	    if (home != NULL)
+		tilde_dir = mallocstrcpy(tilde_dir, home);
 	}

 	retval = charalloc(strlen(tilde_dir) + strlen(buf + i) + 1);
@@ -2340,7 +2343,7 @@
     assert(buf != NULL && num_matches != NULL && buf_len > 0);

     *num_matches = 0;
-
+#if 0
     while ((userdata = getpwent()) != NULL) {
 	if (strncmp(userdata->pw_name, buf + 1, buf_len - 1) == 0) {
 	    /* Cool, found a match.  Add it to the list.  This makes a
@@ -2362,7 +2365,7 @@
 	}
     }
     endpwent();
-
+#endif
     return matches;
 }

--- src/nano.c	2012-07-13 22:49:46.001453034 -0400
+++ src/nano.c	2012-07-13 22:51:23.860222781 -0400
@@ -1534,6 +1534,12 @@
     }
 #endif

+    /* Workaround for enter key */
+    /* https://github.com/Evervolv/android_external_nano/commit/7b568f0b417c1fe3fe8597c600bdbcda4837013f */
+    if (input == 10) {
+        input = NANO_CONTROL_M;
+    }
+
     /* Check for a shortcut in the main list. */
     s = get_shortcut(MMAIN, &input, meta_key, func_key);

--- src/prompt.c.old	2012-07-13 22:51:47.839921315 -0400
+++ src/prompt.c	2012-07-13 22:51:49.615898989 -0400
@@ -87,6 +87,10 @@
     }
 #endif

+    if (input == 10) {
+        input = NANO_CONTROL_M;
+    }
+
     /* Check for a shortcut in the current list. */
     s = get_shortcut(currmenu, &input, meta_key, func_key);

NanoAndroid

./configure --disable-rpath --disable-nls --host=arm-linux --disable-color --disable-utf8 --disable-browser CFLAGS="-I$PWD/../ncurses-5.9/include" LIBS="$PWD/../ncurses-5.9/lib/libncurses.a" LDFLAGS="-L$PWD/../ncurses-5.9/lib"
make -j3

# Create a terminfo package (skip if you already have one)
tar cvf terminfo.tar -C /lib terminfo/
adb push terminfo.tar /data/local/tmp

# deploy to phone
adb push ./src/nano /data/local/tmp
adb shell
# On Android phone now:
cd /data/local/tmp
tar xf terminfo.tar # skip if you did not do "create a terminfo package" above
export TERMINFO=./terminfo # or wherever your terminfo is
# Run nano on Android phone
./nano
# If you get an error like Error opening terminal: vt100.
# It means that you did not do the TERMINFO thing properly.

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: Mobile | 3 Comments »

3 Responses to “Compiling GNU Nano for Android”

  1. john bessa Says:
    July 20th, 2012 at 11:37 am

    any chance you will be able to type in “gcc” in the foreseeable future?

  2. Futurian Says:
    July 31st, 2012 at 8:37 am

    In order to use Nano via SSHDroid it was important to extract the contents of “terminfo.tar” and place into “/etc/terminfo” ;-)

  3. nano 2.5.3をAndroid Terminal Emulatorで日本語が使えるようにビルドした。 | 谺の隠れ家 Says:
    May 7th, 2016 at 6:11 am

    […] まずはncursesが必要なので、ncursesをビルドすることにする。 ビルドするにあたっては下記サイトを参考にした。 Compiling GNU Nano for Android at Compdigitec Labs […]

Comments