Search code examples
androidandroid-ndkandroid-source

AOSP Build: How to skip local header from include


I have made a modification to bluedroid code.

My code needs to use the usual semaphore.h which is located at: <aosp_root>/prebuilts/ndk/current/platforms/<platform>/<arch>/usr/include/semaphore.h

Now, in AOSP 6.0+, bluedroid resides in <aosp_root>/system/bt/

In there, there is a header at: <aosp_root>system/bt/osi/include/semaphore.h

In usual AOSP build, if I leave a simple #include <semaphore.h> in my code, the osi header gets included, which is incompatible. Is there a way to modify the build system so that ndk's header gets used for my code?

I'd happily include from this relative path in my code, but <arch> (and probably <platform> ) is/are compile time variables, and should not be hardcoded. workarround for this is also welcomed as alternate answer.

Link to osi's header
Link to bluedroid main make file


Solution

  • I found that either I need to give fixed paths to correct header in my code, or -

    Since I was modifying bluedroid code anyway, I went ahead and modified bluedroid's semaphore.h too. This line in rouge semaphore.h helps:

    #include_next "semaphore.h"

    gcc extensions FTW. This should continue working till android ndk keeps using gcc..

    I know about the general warning that goes with it. Short of writing my own separate semaphore wrapper library based on correct semaphores, this was the only way I could find.

    Another alternate I considered was to rename bluedroid's semaphore.h but that will become a maintenance nightmare.