{"id":330,"date":"2011-10-02T16:05:28","date_gmt":"2011-10-02T15:05:28","guid":{"rendered":"http:\/\/www.floyd.ch\/?p=330"},"modified":"2017-11-28T14:46:59","modified_gmt":"2017-11-28T13:46:59","slug":"cross-compiling-bash-for-android-arm","status":"publish","type":"post","link":"https:\/\/www.floyd.ch\/?p=330","title":{"rendered":"Cross-compiling bash for Android ARM"},"content":{"rendered":"<p>Most Android mobiles are running on the ARM architecture. Therefore you have to use a special compiler for such binaries. The Android SDK built in adb shell has no auto completion, which is really a nightmare in my opinion. Therefore I was looking for a way to compile bash for Android. Altough a lot of tutorials tell you to download the CodeSourcery cross-compiling toolchain, they are not really necessary (at least if you do a static compile like I do here).<\/p>\n<p>I wrote a script that compiles bash-4.0. Should work out-of-the-box in Ubuntu 11.04. Edit: By now I&#8217;ve also put it on github: <a href=\"https:\/\/github.com\/floyd-fuh\/ARM-cross-compile\" target=\"_blank\">https:\/\/github.com\/floyd-fuh\/ARM-cross-compile<\/a><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n#BASH source code from http:\/\/ftp.gnu.org\/gnu\/bash\/ \r\n#Example for compiling bash on Ubuntu 11.04\r\n#Warnings during the compilation process seem to be alright, errors would be bad\r\nBASH_VERSION=&quot;bash-4.1&quot;\r\n\r\necho &quot;&#x5B;INFO] Checking if packages installed&quot;\r\ndpkg --status autoconf | grep -q not-installed\r\nif &#x5B; $? -eq 0 ]; then\r\n    echo &quot;&#x5B;INFO] Apt-get installing autoconf, please provide sudo password&quot;\r\n    sudo apt-get install autoconf\r\nelse\r\n    echo &quot;&#x5B;INFO] autoconf already installed, good&quot;\r\nfi\r\ndpkg --status gcc-arm-linux-gnueabi | grep -q not-installed\r\nif &#x5B; $? -eq 0 ]; then\r\n    echo &quot;&#x5B;INFO] Apt-get installing gcc-arm-linux-gnueabi, please provide sudo password&quot;\r\n    sudo apt-get install gcc-arm-linux-gnueabi\r\nelse\r\n    echo &quot;&#x5B;INFO] gcc-arm-linux-gnueabi already installed, good&quot;\r\nfi\r\necho &quot;&#x5B;INFO] Starting bash source code download&quot;\r\nwget http:\/\/ftp.gnu.org\/gnu\/bash\/$BASH_VERSION.tar.gz\r\ntar xvfz $BASH_VERSION.tar.gz\r\ncd $BASH_VERSION\r\nCC=`which arm-linux-gnueabi-gcc`\r\n.\/configure --host=arm-linux-gnueabi --enable-static-link --without-bash-malloc\r\nmake clean\r\nmake\r\nfile bash | grep -q ARM\r\nif &#x5B; ! $? -eq 0 ]; then\r\n    echo &quot;&#x5B;ERROR] Looks like bash was incorrectly compiled with another compler than arm-linux-gnueabi-gcc&quot;\r\n    echo &quot;&#x5B;ERROR] The resulting bash binary will not run on ARM, therefore aborting!&quot;\r\n    exit\r\nfi\r\narm-linux-gnueabi-strip -o bash-stripped -s bash\r\ncp .\/bash-stripped ..\/bash\r\ncd ..\r\nfile bash\r\necho &quot;&#x5B;INFO] Your bash binary is finished (file 'bash' in current directory), happy autocompleting on ARM!&quot;\r\n<\/pre>\n<p>By changing the variable BASH_VERSION to bash-4.1 you should be able to compile an even newer version. Bash-4.2 did not work for me.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most Android mobiles are running on the ARM architecture. Therefore you have to use a special compiler for such binaries. The Android SDK built in adb shell has no auto completion, which is really a nightmare in my opinion. Therefore &hellip; <a href=\"https:\/\/www.floyd.ch\/?p=330\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,10],"tags":[158,30,31,32],"class_list":["post-330","post","type-post","status-publish","format-standard","hentry","category-android","category-mobile-security","tag-android","tag-arm","tag-cross-compiling","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=330"}],"version-history":[{"count":6,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/330\/revisions"}],"predecessor-version":[{"id":1047,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/330\/revisions\/1047"}],"wp:attachment":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}