Christophe Bernard avatar Christophe Bernard committed b935727

updated android action to build separate folder for each configuration

Comments (0)

Files changed (2)

src/actions/android/_android.lua

 		--end,
 		
 
-		onproject = function(prj)
-			premake.make_mkdirrule("jni")
-			premake.make_mkdirrule( "res" )
+		onproject = function( prj )
+        
+            premake.make_mkdirrule( "res" )
 			premake.make_mkdirrule( "libs" )
 			premake.make_mkdirrule( "src" )
 			premake.make_mkdirrule( "src/com" )
-			
-			premake.generate( prj, "jni/Android.mk", premake.android.project )
-			premake.generate( prj, "jni/Application.mk", premake.android.application )
-			premake.generate( prj, "build.xml", premake.android.buildxml )
+            
+            premake.generate( prj, "build.xml", premake.android.buildxml )
 			premake.generate( prj, "ant.properties", premake.android.antprop )
             premake.generate( prj, "project.properties", premake.android.projprop )
-			--premake.generate( prj, "AndroidManifest.xml", premake.android.manifest )
+			--premake.generate( prj, "AndroidManifest.xml", premake.android.manifest )
+			
+            premake.generate( prj, "dummy", premake.android.project )
 		end,
 
 		-- These functions are called for each solution, project, and target as part

src/actions/android/android.lua

 
 		return drive
 	end
+    
+    function get_config_suffix( config_name )
+    
+        -- debug config will be default jni folder to make sure ndk-build will not fail to locate the files
+        if string.find( string.lower( config_name ), "debug" ) then
+            return ""
+        end
+        
+        return string.gsub( config_name, "%s+", "" )
+    end
 
 	-- Android.mk file helper functions
 
 		end
 
 		-- preprocessor
+        
+        if premake.config.isdebugbuild( cfg ) then
+            _p( 1, '-D_DEBUG \\' )
+        end
+        
 		for i, define in ipairs( cfg.defines ) do
 			_p( 1, '-D%s \\', define )
 		end
 	--	_p( '</manifest>' )
 	--end
 
-	function premake.android.application( prj )
+	function premake.android.applicationmk( prj, cfg, jni_folder )
         local it_has_rtti = true
         local it_has_exceptions = true
         local cpp_features = ""
+            
+        local local_c_flags = premake.gcc.getcxxflags( cfg )
 
-        for cfg in premake.eachconfig(prj) do
-            local local_c_flags = premake.gcc.getcxxflags( cfg )
-
-		    for i, flag in ipairs( local_c_flags ) do
-			    if ( flag == "-fno-rtti" ) then
-                    it_has_rtti = false
-                end
-
-                if flag == "-fno-exceptions" then
-                    it_has_exceptions = false
-                end
-		    end
-
-            if ( it_has_rtti ) then
-                cpp_features = cpp_features .. "rtti "
+        for i, flag in ipairs( local_c_flags ) do
+            if ( flag == "-fno-rtti" ) then
+                it_has_rtti = false
             end
 
-            if ( it_has_exceptions ) then
-                cpp_features = cpp_features .. " exceptions"
+            if flag == "-fno-exceptions" then
+                it_has_exceptions = false
             end
-
-            break
         end
 
-		_p( 'APP_OPTIM 						:= debug' )
+        if ( it_has_rtti ) then
+            cpp_features = cpp_features .. "rtti "
+        end
+
+        if ( it_has_exceptions ) then
+            cpp_features = cpp_features .. " exceptions"
+        end
+
+        if premake.config.isdebugbuild( cfg ) then
+            _p( 'APP_OPTIM 						:= debug' )
+        end
+        
 		_p( 'APP_MODULES      				:= %s', prj.name )
         
         if #prj.androidappabi > 0 then
-            _p( 'APP_ABI 						:= %s', table.concat(prj.androidappabi, " ") )
+            -- TODO : check if the setup sdk is valid on this file system
+            _p( 'APP_ABI     					:= %s', table.concat(prj.androidappabi, " ") )
         else
             error( "must define at least one androidappabi (%s) ", table.concat( prj.androidappabi.allowed ) )
         end
 		_p( 'APP_PLATFORM 					:= %s', prj.androidsdk )
 		_p( 'APP_STL 						:= gnustl_shared' )
 		_p( 'APP_GNUSTL_FORCE_CPP_FEATURES 	:= %s', cpp_features )
+		_p( 'APP_BUILD_SCRIPT 				:= %s/Android.mk', jni_folder )
+		
+		
 	end
 
-	function premake.android.project(prj)
+	function premake.android.androidmk( prj, cfg )
 		printf( "generating ANDROID project file" )
 		io.eol = '\r\n'
 
 		_p( 'LOCAL_PATH := $(call my-dir)' )
 		_p( '' )
 
-		-- List the build configurations, and the settings for each
-		for cfg in premake.eachconfig(prj) do
-			local included_shared_libs = android.output_shared_libs( cfg )
+        local included_shared_libs = android.output_shared_libs( cfg )
 
-		    _p( '' )
-		    _p( 'include $(CLEAR_VARS)' )
-		    _p( '' )
-		    _p( 'LOCAL_MODULE := %s', prj.name )
-		    _p( '' )
+        _p( '' )
+        _p( 'include $(CLEAR_VARS)' )
+        _p( '' )
+        _p( 'LOCAL_MODULE := %s', prj.name )
+        _p( '' )
 
-			_p( 0, 'LOCAL_LDFLAGS := -Wl,-Map,xxx.map' ) -- no custom ld flags for now
-			_p( '' )
+        _p( 0, 'LOCAL_LDFLAGS := -Wl,-Map,xxx.map' ) -- no custom ld flags for now
+        _p( '' )
 
-			_p( '' )
-			android.output_compiler_flags( cfg )
-			_p( '' )
-			android.output_src_files( prj )
+        _p( '' )
+        android.output_compiler_flags( cfg )
+        _p( '' )
+        android.output_src_files( prj )
 
-			android.output_ld_libs( cfg, included_shared_libs )
+        android.output_ld_libs( cfg, included_shared_libs )
 
-			android.ouput_included_shared_libs( included_shared_libs )
+        android.ouput_included_shared_libs( included_shared_libs )
 
-            -- for native apps
-            _p( '' )
-            _p( 'LOCAL_STATIC_LIBRARIES := \\' )
-            _p( 1, 'android_native_app_glue' )
+        -- for native apps
+        _p( '' )
+        _p( 'LOCAL_STATIC_LIBRARIES := \\' )
+        _p( 1, 'android_native_app_glue' )
 
-			--
-			_p( '' )
-			_p( 'include $(BUILD_SHARED_LIBRARY)' )
-			_p( '' )
-			_p( '' )
-			_p( '$(call import-module,android/native_app_glue)' )
+        --
+        _p( '' )
+        _p( 'include $(BUILD_SHARED_LIBRARY)' )
+        _p( '' )
+        _p( '' )
+        _p( '$(call import-module,android/native_app_glue)' )
+	end
+    
+    -- HACK : android will
+    function premake.android.project( prj )
+    
+        -- make_dirrule does print 
+        for cfg in premake.eachconfig( prj, "android" ) do
+            local makefiles_directory = "jni" .. get_config_suffix( cfg.name )
+            
+            premake.make_mkdirrule( makefiles_directory )
+        end
+                
+		-- List the build configurations, and the settings for each
+		
+        for cfg in premake.eachconfig( prj, "android" ) do
+            local makefiles_directory = "jni" .. get_config_suffix( cfg.name )
+            
+            -- generate android.mk for this config
+            filename = premake.project.getfilename( prj, makefiles_directory .. "/Android.mk")
 
-			break -- find a way to process other configurations if needed
-		end
-	end
+            local f, err = io.open( filename, "wb" )
+            if ( not f ) then
+                error( err, 0 )
+            end
+
+            io.output( f )
+                premake.android.androidmk( prj, cfg )
+            f:close()
+            
+            -- generate application.mk for this config
+            filename = premake.project.getfilename( prj, makefiles_directory .. "/Application.mk" )
+
+            local f, err = io.open( filename, "wb" )
+            if ( not f ) then
+                error( err, 0 )
+            end
+
+            io.output( f )
+                premake.android.applicationmk( prj, cfg, makefiles_directory )
+            f:close()
+        end
+    end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.