{"id":302,"date":"2012-07-13T22:39:21","date_gmt":"2012-07-14T03:39:21","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=302"},"modified":"2012-07-13T22:50:22","modified_gmt":"2012-07-14T03:50:22","slug":"compiling-gnu-nano-for-android","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2012\/07\/13\/compiling-gnu-nano-for-android\/","title":{"rendered":"Compiling GNU Nano for Android"},"content":{"rendered":"<p>If you just want a pre-built, ready to use version of <strong>Nano for Android<\/strong>, you can get the <a href=\"http:\/\/www.compdigitec.com\/labs\/files\/nano-android.7z\">pre-built version<\/a>.<\/p>\n<p>The results of these steps include:<\/p>\n<ul>\n<li>GNU Nano 2.2.6 with statically-linked libncurses<\/li>\n<li>Compatibility with \u2265 Android 2.1<\/li>\n<li>A working enter key, in adb shell and Term.apk<\/li>\n<li>A terminfo package<\/li>\n<\/ul>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.compdigitec.com\/labs\/wp-content\/uploads\/2012\/07\/nano-android.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-303 aligncenter\" title=\"GNU Nano running on Android\" src=\"http:\/\/www.compdigitec.com\/labs\/wp-content\/uploads\/2012\/07\/nano-android.png\" alt=\"GNU Nano running on Android\" width=\"450\" height=\"500\" \/><\/a><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# Export toolchain for build\r\nexport ANDROID_NDK=\/opt\/android-ndk-r8\r\nexport CC=&quot;$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&quot;\r\nexport CXX=&quot;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&quot;\r\n\r\n# Build ncurses static lib\r\nwget ftp:\/\/ftp.gnu.org\/pub\/gnu\/ncurses\/ncurses-5.9.tar.gz -O- | tar zxvf -\r\ncd ncurses-5.9\/\r\n\r\n# ..\/form\/fty_num.c:226: error: 'struct lconv' has no member named 'decimal_point'\r\n# fty_num.c:(.text+0x280): undefined reference to `localeconv'\r\npatch -p0 &lt;&lt; NcursesPatch\r\n--- form\/fty_num.c\t2012-07-13 23:04:53.914039027 -0400\r\n+++ form\/fty_num.c\t2012-07-13 23:05:38.057484067 -0400\r\n@@ -36,6 +36,12 @@\r\n\r\n MODULE_ID(&quot;$Id: fty_num.c,v 1.28 2010\/01\/23 21:14:36 tom Exp $&quot;)\r\n\r\n+\/* &quot;MISSING FROM BIONIC - DEFINED TO MAKE libstdc++-v3 happy&quot; *\/\r\n+#ifdef HAVE_LOCALE_H\r\n+#   undef HAVE_LOCALE_H\r\n+#   define HAVE_LOCALE_H 0\r\n+#endif\r\n+\r\n #if HAVE_LOCALE_H\r\n #include &lt;locale.h&gt;\r\n #endif\r\n\r\nNcursesPatch\r\n\r\n.\/configure --with-normal --without-shared --without-cxx-binding --enable-root-environ --disable-widec --without-tests --host=arm-linux\r\nmake -j3\r\n\r\n# Nano 2.2.6 build\r\ncd ..\r\nwget http:\/\/www.nano-editor.org\/dist\/v2.2\/nano-2.2.6.tar.gz -O- | tar zxvf -\r\ncd nano-2.2.6\/\r\n\r\n# Patch to get around bionic deficiencies\r\npatch -p0 &lt;&lt; NanoAndroid\r\n--- src\/chars.c\t2012-07-13 22:02:21.741210225 -0400\r\n+++ src\/chars.c\t2012-07-13 22:04:02.887938640 -0400\r\n@@ -79,6 +79,7 @@\r\n     return ((unsigned int)c == (unsigned char)c);\r\n }\r\n\r\n+\/*\r\n static void mbtowc_reset(void)\r\n {\r\n     IGNORE_CALL_RESULT(mbtowc(NULL, NULL, 0));\r\n@@ -88,6 +89,7 @@\r\n {\r\n     IGNORE_CALL_RESULT(wctomb(NULL, 0));\r\n }\r\n+*\/\r\n\r\n \/* This function is equivalent to isalnum() for multibyte characters. *\/\r\n bool is_alnum_mbchar(const char *c)\r\n--- src\/files.c\t2012-07-13 22:13:35.516739719 -0400\r\n+++ src\/files.c\t2012-07-13 22:13:38.796698486 -0400\r\n@@ -2237,13 +2237,16 @@\r\n \t    tilde_dir = mallocstrncpy(NULL, buf, i + 1);\r\n \t    tilde_dir[i] = '&#92;&#48;';\r\n\r\n+\t    \/*\r\n \t    do {\r\n \t\tuserdata = getpwent();\r\n \t    } while (userdata != NULL &amp;&amp; strcmp(userdata-&gt;pw_name,\r\n \t\ttilde_dir + 1) != 0);\r\n \t    endpwent();\r\n-\t    if (userdata != NULL)\r\n-\t\ttilde_dir = mallocstrcpy(tilde_dir, userdata-&gt;pw_dir);\r\n+\t    *\/\r\n+\t    char* home = getenv(&quot;HOME&quot;);\r\n+\t    if (home != NULL)\r\n+\t\ttilde_dir = mallocstrcpy(tilde_dir, home);\r\n \t}\r\n\r\n \tretval = charalloc(strlen(tilde_dir) + strlen(buf + i) + 1);\r\n@@ -2340,7 +2343,7 @@\r\n     assert(buf != NULL &amp;&amp; num_matches != NULL &amp;&amp; buf_len &gt; 0);\r\n\r\n     *num_matches = 0;\r\n-\r\n+#if 0\r\n     while ((userdata = getpwent()) != NULL) {\r\n \tif (strncmp(userdata-&gt;pw_name, buf + 1, buf_len - 1) == 0) {\r\n \t    \/* Cool, found a match.  Add it to the list.  This makes a\r\n@@ -2362,7 +2365,7 @@\r\n \t}\r\n     }\r\n     endpwent();\r\n-\r\n+#endif\r\n     return matches;\r\n }\r\n\r\n--- src\/nano.c\t2012-07-13 22:49:46.001453034 -0400\r\n+++ src\/nano.c\t2012-07-13 22:51:23.860222781 -0400\r\n@@ -1534,6 +1534,12 @@\r\n     }\r\n #endif\r\n\r\n+    \/* Workaround for enter key *\/\r\n+    \/* https:\/\/github.com\/Evervolv\/android_external_nano\/commit\/7b568f0b417c1fe3fe8597c600bdbcda4837013f *\/\r\n+    if (input == 10) {\r\n+        input = NANO_CONTROL_M;\r\n+    }\r\n+\r\n     \/* Check for a shortcut in the main list. *\/\r\n     s = get_shortcut(MMAIN, &amp;input, meta_key, func_key);\r\n\r\n--- src\/prompt.c.old\t2012-07-13 22:51:47.839921315 -0400\r\n+++ src\/prompt.c\t2012-07-13 22:51:49.615898989 -0400\r\n@@ -87,6 +87,10 @@\r\n     }\r\n #endif\r\n\r\n+    if (input == 10) {\r\n+        input = NANO_CONTROL_M;\r\n+    }\r\n+\r\n     \/* Check for a shortcut in the current list. *\/\r\n     s = get_shortcut(currmenu, &amp;input, meta_key, func_key);\r\n\r\nNanoAndroid\r\n\r\n.\/configure --disable-rpath --disable-nls --host=arm-linux --disable-color --disable-utf8 --disable-browser CFLAGS=&quot;-I$PWD\/..\/ncurses-5.9\/include&quot; LIBS=&quot;$PWD\/..\/ncurses-5.9\/lib\/libncurses.a&quot; LDFLAGS=&quot;-L$PWD\/..\/ncurses-5.9\/lib&quot;\r\nmake -j3\r\n\r\n# Create a terminfo package (skip if you already have one)\r\ntar cvf terminfo.tar -C \/lib terminfo\/\r\nadb push terminfo.tar \/data\/local\/tmp\r\n\r\n# deploy to phone\r\nadb push .\/src\/nano \/data\/local\/tmp\r\nadb shell\r\n# On Android phone now:\r\ncd \/data\/local\/tmp\r\ntar xf terminfo.tar # skip if you did not do &quot;create a terminfo package&quot; above\r\nexport TERMINFO=.\/terminfo # or wherever your terminfo is\r\n# Run nano on Android phone\r\n.\/nano\r\n# If you get an error like Error opening terminal: vt100.\r\n# It means that you did not do the TERMINFO thing properly.\r\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>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 2.2.6 with statically-linked libncurses Compatibility with \u2265 Android 2.1 A working enter key, in adb shell and Term.apk A terminfo package<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[759],"tags":[760,13,809,810,761],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/302"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=302"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/302\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=302"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}