Simple Android ndk support

Hello.

I'm implementing ndk-build files generation for Android projects and now I have couple of questions to You.
I want to write it with compatibility with all premake standards and conventions because maybe someday my implementation will be merged to official premake sources.

First: I need to add support for choosing correct android platform version. The simplest method that's coming to my mind is to make new variable like:

elseif(os.get() == 'android') then
androidplatform = 9
end

But as I understand I cannot do that because its not compatible with reference from: http://industriousone.com/scripting-reference am I thinking right? So how to make it other way?

Second: how can I define different definers/buildoptions for CFLAGS and CXXFLAGS?
For example:

LOCAL_CFLAGS += -D_CRT_SECURE_NO_WARNINGS -DLAB_OS_ANDROID -D_UNICODE -D_7ZIP_ST -DLAB_SCRIPT_V8 -DSTATICLIB -DGLEW_STATIC -DGWEN_COMPILE_STATIC -DPH_USE_GLFW -D_DEBUG -DLAB_IS_DEBUG -ULAB_USE_GWEN
LOCAL_CFLAGS += -fstrict-aliasing -fprefetch-loop-arrays -w -g -O0

LOCAL_CPPFLAGS += -fexceptions
LOCAL_CPPFLAGS += -frtti

I cannot have -fexceptions and -frtti for CFLAGS so I need to split them. Easier option is to add new variables
there like:

elseif(os.get() == 'android') then
additionalcflags = "-fstrict-aliasing -fprefetch-loop-arrays -w -g -O0"
additionalcxxflags = "-fexceptions -frtti"
end

But thats not standard-like aproach, right?

And last question for this post (but not neccessary my last question on this forum :P)

I need to give programmer possibility to use android local static libraries like android_native_app_glue or gnustl_static. The best option there is to use http://industriousone.com/flags , right? So for example he will make "flags" parameter like:

elseif(os.get() == 'android') then
flags { "UseNativeActivity" }
end

Then premake will add:

LOCAL_STATIC_LIBRARIES := android_native_app_glue
$(call import-module,android/native_app_glue)

To my build scripts for Android but is that correct and standard-like? Maybe I should implement it differently? Can I add new flag option from my action?

Thats all (for now)
Hope anyone could answer me :)

The simplest method that's coming to my mind is to make new variable like...
I think this approach is valid, however, you'd better keep your variables inside table ("namespace"):

-- In "core" Android support code
android = {}
-- In project file
android.platformversion = 9

os.get() == 'android'
Do it declaratively:

configuration "android"
    -- Android-specific options

Of course you'll need to patch Premake to know "android" as first-class OS (if you haven't do it yet)

About RTTI and exceptions: probably it's better to add flags "RTTI" and "Exceptions" (similar to existing "No" counterparts). BTW: are you sure you can use this features safely - AFAIK Bionic C library is not interoperable with them (I haven't really coded anything for Android though)

About "UseNativeActivity" flag: as far as I can see, developers are trying to keep flags platform independent, but this one does not make sense anywhere but Android. I have a patch which adds custom footer into Makefile, and I'm using it for implementing Qt support now.

$(call import-module,android/native_app_glue)
That's something coming from Android-provided Makefiles, right?


$(call import-module,android/native_app_glue)
That's something coming from Android-provided Makefiles, right?

Yes. That's module importing function from Android makefiles, required only if we're using nativeactivity - Android build-in static library.


About RTTI and exceptions: probably it's better to add flags "RTTI" and "Exceptions" (similar to existing "No" counterparts). BTW: are you sure you can use this features safely - AFAIK Bionic C library is not interoperable with them (I haven't really coded anything for Android though)

We can use them since android-ndk-r6 version :)


About "UseNativeActivity" flag: as far as I can see, developers are trying to keep flags platform independent, but this one does not make sense anywhere but Android. I have a patch which adds custom footer into Makefile, and I'm using it for implementing Qt support now.

Okay, I will look at it then and try to implement it for ndk makefile generator, thanks :)

Take a look at how I handle the the different platforms in tools/gcc.lua. That should give you some ideas. And keep us posted on your progress; this would be a great addition to Premake!

kkszysiu: Any news regarding this?

Could you share your current code?