Question

Trying to port a Delphi library to Android. Free Pascal has Android/ARM support - a prebuilt compiler for Windows is available. However, Android NDK now supports MIPS and x86 as well. What's the status of support for those in FPC? For now, my project is more or less CPU agnostic - the native bits are built for all four supported architectures. Don't want to let go of that.

I'm not after the full cycle of Android development in Pascal - just an algorithm library that does no I/O. I tried translating it into C with p2c, but the translator chokes on the sources.

Should I just try and build cross-compiler for the relevant CPU with Linux, and then link against the NDK libraries?

EDIT: I've built the cross-compiler for Intel/Linux from the sources of the Android branch. It works, except you have to invoke ppcross386 to compile, not fpc. The latter, it seems, ignores the -Tlinux option and invokes the Intel/Win32 compiler.

EDIT2: with a small change to the makefile and sources, the MIPS cross-compiler builds. However, as building moves on to the cross-CPU RTL, it errors out almost right away.

Was it helpful?

Solution

EDIT, finally: support for Android/MIPSEL compilation target is available in the FPC trunk. Export the latest, build the crosscompiler, code away.


While support for MIPS ISA can be found here and there in the FP sources, it's not officially done yet. Waiting for the 2.7 release.

In the meantime, there's support for compiling to Java bytecode in the trunk, it's documented in the FP wiki. Maybe I can leverage that as a stopgap...

EDIT: Free Pascal over JVM works in general on Android, but its rules are somewhat different from regular Pascal. Otherwise correct Pascal conks out when compiled to JVM. So it's unfit for porting large bodies of legacy Pascal code that was not written with JVM in mind in the first place.

EDIT: I got my FPC project working on MIPS/Android, but my recipe is not fit for general consumption, because the scope of Pascal RTL usage in my project is very limited. It involves cross-compiling from Pascal to MIPS assembly (targeting MIPSEL/Linux, available in the FPC trunk), then feeding the generated assembly sources to the NDK build system, providing along a C/assembly reimplementation of a limited subset of Pascal RTL.

The whole body of Pascal RTL is big and scary. My solution, which involves reimplementing the Pascal RTL in C from scratch, is, well, the opposite of generally applicable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top