If you need to cross-compile for Android a program written in Fortran, you know already that the official Android NDK does not come with the gfortran compiler, and if like me you need to port to Android code that depends on Fortran (such as the lapack libraries), you are out of luck.
Fortunately I managed to compile the gcc Fortran cross-compiler with the help of Mike Long's blog. As an added bonus, I managed to build gfortran 4.8.0 not only for the ARM but also for the x86 toolchain, as well as update the script to the latest Android NDK (currently r8d).
What you need to do is the following:
Note that I've successfully tested the script only on Ubuntu 12.04.
Fortunately I managed to compile the gcc Fortran cross-compiler with the help of Mike Long's blog. As an added bonus, I managed to build gfortran 4.8.0 not only for the ARM but also for the x86 toolchain, as well as update the script to the latest Android NDK (currently r8d).
What you need to do is the following:
- download the fortran4android shell script.
- download the ndk-r8d fortran patch.
- run the script in your directory:
$ fortran4android - wait, wait, wait, ... and you will see in the android-ndk-r8d/toolchains directory two new toolchains called arm-linux-androideabi-4.8.0 and x86-4.8.0
- Enjoy your new gfortran compiler.
Note that I've successfully tested the script only on Ubuntu 12.04.
Addendum of August 30, 2013
I now have available a patch for the newer android-ndk-r9. To use this instead of the patch above:- download the ndk-r9-fortran-patch
- change the fortran4android script by replacing "r8d" with "r9" everywhere
- run the fortran4android script in your directory.