Search code examples
craspberry-piarmc-preprocessor

Predefined macro to determine if running on a Raspberry?


I'm maintaining an application that runs on GNU/Linux (x86, x86_64), Windows (x86, x86_64), Bionic/Android (armeabi-v7a, arm64-v8a, x86, x86_64) and also on Raspberry Pi (armhf). Since Raspberry OS is actually a modified version of GNU/Linux Debian, i can determine if i'm running linux (__linux__) on ARM (__arm__), but i can't discern if it's hard-float or not. (Yes, this may be an XY Problem.)

I need a way to pinpoint raspberry as some parts of the code are not to be implemented on Android. Yes, i could use -DRASPBERRY at compile time but was wondering if the compiler already does that for me. Preferably a standard macro instead of a compiler-specific one, but i'm cross-compiling on linux with gcc.

I'm considering __ARM_FP, but not sure.

This software runs on models 2 and up, any tips are appreciated.

Edit 1

To determine this, i've been using the output of the native gcc on linux x86_64, the 4 NDK variants and a mingw crross-compiler for x86. These caught my attention:

__ARM_ARCH is on all
__ARM_32BIT_STATE and __ARM_64BIT_STATE may be useful
__ARM_EABI__ and __ARMEL__ seem to only appear in Android's armeabi-v7a and the gcc in Raspbian, so may be good candidates
__ARM_FP has a different value on all of them, which may also be useful once i figure out what it means


Solution

  • Well, according to Arm C Language Extensions

    5.5.1 Hardware floating point
    __ARM_FP is set if hardware floating-point is available.

    ...and proceeds to enumerate the possible valid values as 0x04, 0x6, 0xC and 0xE.

    The NDK sets 0xC for armeabi-v7a and 0xE for arm64-v8a and i got a bit confused because the gcc compiler in Raspberry OS sets it to 12... which is 0x0C.