Permalink
Browse files

Added initial NDK support to transcc.

  • Loading branch information...
blitz-research
blitz-research committed Jun 29, 2013
1 parent b80a871 commit 88c2e50d52a665a6b32ef10912a1788d2aa18a35
View
@@ -36,3 +36,12 @@ FLEX_PATH="${HOME}/flex_sdk_4.6"
'Android SDK
ANDROID_PATH="${HOME}/android-sdk-macosx"
'--------------------
'--------------------
'Android NDK
'
'Must be set to a valid dir for ANDROID NDK target support
'
ANDROID_NDK_PATH="${HOME}/android-ndk-r8e"
'--------------------
View
@@ -64,12 +64,20 @@ JDK_PATH="${PROGRAMFILES}\Java\jdk1.6.0_19"
'--------------------
'Android SDK and tool paths.
'
'Must be set to a valid for for ANDROID target support
'Must be set to a valid dir for ANDROID target support
'
ANDROID_PATH="${SYSTEMDRIVE}\monkey_sdks\android-sdk-windows"
ANDROID_PATH="${SYSTEMDRIVE}\android-sdk-windows"
'--------------------
'--------------------
'Android NDK
'
'Must be set to a valid dir for ANDROID NDK target support
'
ANDROID_NDK_PATH="${SYSTEMDRIVE}\android-ndk-r8e"
'--------------------
'--------------------
'Flex SDK and flash player path.
'
@@ -220,8 +220,8 @@ void gc_flush_free( int size ){
while( gc_free_bytes>t ){
gc_object *p=gc_free_list.succ;
if( !p || p==&gc_free_list ){
printf("ERROR:p=%p gc_free_bytes=%i\n",p,gc_free_bytes);
fflush(stdout);
// printf("ERROR:p=%p gc_free_bytes=%i\n",p,gc_free_bytes);
// fflush(stdout);
gc_free_bytes=0;
break;
}
@@ -1474,40 +1474,15 @@ int Print( String t ){
t.Save( buf );
buf.push_back( '\n' );
buf.push_back( 0 );
#if __cplusplus_winrt
#if CFG_WIN8_PRINT_ENABLED
OutputDebugStringA( (const char*)&buf[0] );
#endif
#elif CFG_ANDROID_PRINT_ENABLED
LOGI( (const char*)&buf[0] );
#else
fputs( (const char*)&buf[0],stdout );
fflush( stdout );
#endif
/*
static char *buf;
static int len;
int n=t.Length();
if( n+100>len ){
len=n+100;
free( buf );
buf=(char*)malloc( len );
}
for( int i=0;i<n;++i ) buf[i]=t[i];
buf[n++]=10;
buf[n]=0;
#if __cplusplus_winrt
#if CFG_WIN8_PRINT_ENABLED
OutputDebugStringA( buf );
#endif
#else
fputs( buf,stdout );
fflush( stdout );
#endif
*/
return 0;
}
@@ -1518,7 +1493,6 @@ int Error( String err ){
if( !err.Length() ){
#if __cplusplus_winrt
throw BBExitApp();
// System::Windows::Application::Current->Terminate();
#else
exit( 0 );
#endif
@@ -0,0 +1,101 @@
Import builder
Class AndroidNdkBuilder Extends Builder
Method New( tcc:TransCC )
Super.New( tcc )
End
Method Config:String()
Local config:=New StringStack
For Local kv:=Eachin _cfgVars
config.Push "#define CFG_"+kv.Key+" "+kv.Value
Next
Return config.Join( "~n" )
End
Method IsValid:Bool()
Return tcc.ANDROID_PATH<>"" And tcc.ANDROID_NDK_PATH<>""
End
Method Begin:Void()
ENV_LANG="cpp"
_trans=New CppTranslator
End
Method MakeTarget:Void()
SetCfgVar "ANDROID_MAINFEST_MAIN",GetCfgVar( "ANDROID_MANIFEST_MAIN" ).Replace( ";","~n" )+"~n"
SetCfgVar "ANDROID_MAINFEST_APPLICATION",GetCfgVar( "ANDROID_MANIFEST_APPLICATION" ).Replace( ";","~n" )+"~n"
'create data dir
CreateDataDir "assets/monkey"
Local app_label:=GetCfgVar( "ANDROID_APP_LABEL" )
Local app_package:=GetCfgVar( "ANDROID_APP_PACKAGE" )
SetCfgVar "ANDROID_SDK_DIR",tcc.ANDROID_PATH.Replace( "\","\\" )
'create package
Local jpath:="src"
DeleteDir jpath,True
CreateDir jpath
For Local t:=Eachin app_package.Split(".")
jpath+="/"+t
CreateDir jpath
Next
jpath+="/MonkeyGame.java"
'template files
For Local file:=Eachin LoadDir( "templates",True )
Select ExtractExt( file ).ToLower()
Case "xml","properties","java"
Local str:=LoadString( "templates/"+file )
str=ReplaceEnv( str )
SaveString str,file
Default
CopyFile "templates/"+file,file
End
Next
'create main source file
Local main:=LoadString( "jni/main.cpp" )
main=ReplaceBlock( main,"TRANSCODE",transCode )
main=ReplaceBlock( main,"CONFIG",Config() )
SaveString main,"jni/main.cpp"
'create 'libs' dir
For Local lib:=Eachin GetCfgVar( "LIBS" ).Split( ";" )
Select ExtractExt( lib )
Case "jar","so"
CopyFile lib,"libs/"+StripDir( lib )
End
Next
If tcc.opt_build
If Not Execute( tcc.ANDROID_NDK_PATH+"/ndk-build" )
Die "Failed to build native code"
Endif
Local r:=Execute( "ant clean",False ) And Execute( "ant debug install",False )
If Not r
Die "Android build failed."
Else If tcc.opt_run
Execute "adb logcat -c",False
' Execute "adb shell am start -n "+app_package+"/"+app_package+".MonkeyGame",False
Execute "adb shell am start -n "+app_package+"/android.app.NativeActivity",False
' Execute "adb logcat [Monkey]:I *:E",False '?!?!?
Execute "adb logcat",False
'
'NOTE: This leaves ADB server running which can LOCK the .build dir making it undeletable...
'
Endif
Endif
End
End
@@ -2,6 +2,7 @@
Import transcc
Import android
Import android_ndk
Import flash
Import glfw
Import html5
@@ -15,6 +16,7 @@ Function Builders:StringMap<Builder>( tcc:TransCC )
Local builders:=New StringMap<Builder>
builders.Set "android",New AndroidBuilder( tcc )
builders.Set "android_ndk",New AndroidNdkBuilder( tcc )
builders.Set "glfw",New GlfwBuilder( tcc )
builders.Set "html5",New Html5Builder( tcc )
builders.Set "ios",New IosBuilder( tcc )
@@ -144,6 +144,7 @@ Class TransCC
'config file
Field ANDROID_PATH:String
Field ANDROID_NDK_PATH:String
Field ANT_PATH:String
Field JDK_PATH:String
Field FLEX_PATH:String
@@ -327,6 +328,10 @@ Class TransCC
If Not ANDROID_PATH And FileType( path )=FILETYPE_DIR
ANDROID_PATH=path
Endif
Case "ANDROID_NDK_PATH"
If Not ANDROID_NDK_PATH And FileType( path )=FILETYPE_DIR
ANDROID_NDK_PATH=path
Endif
Case "JDK_PATH"
If Not JDK_PATH And FileType( path )=FILETYPE_DIR
JDK_PATH=path

0 comments on commit 88c2e50

Please sign in to comment.