Browse Source

Added universal ios builds (x86+x64, armv7+arm64).

woollybah 10 years ago
parent
commit
2238dbd755
6 changed files with 225 additions and 26 deletions
  1. 17 1
      bmk.bmx
  2. 3 3
      bmk_config.bmx
  3. 107 16
      bmk_make.bmx
  4. 37 0
      bmk_modutil.bmx
  5. 19 5
      bmk_ng.bmx
  6. 42 1
      bmk_util.bmx

+ 17 - 1
bmk.bmx

@@ -1,5 +1,6 @@
 '
 ' Change History :
+' 3.06 31/08/2015 - Added universal ios builds (x86+x64, armv7+arm64).
 ' 3.05 04/08/2015 - Added support for ios target.
 ' 3.04 03/07/2015 - Added -quick app build option - skips building/checking required module if .a and .i present.
 ' 3.03 20/06/2015 - Legacy bcc installations can now use local MinGW32 dir.
@@ -357,7 +358,7 @@ Function MakeApplication( args$[],makelib )
 		EndIf
 	EndIf
 
-	If processor.Platform() = "macos" Then
+	If processor.Platform() = "macos" Or processor.Platform() = "osx" Then
 		If opt_apptype="gui"
 	
 			'Local appId$=StripDir( opt_outfile )
@@ -442,6 +443,21 @@ Function MakeApplication( args$[],makelib )
 	buildManager.MakeApp(Main, makelib)
 	buildManager.DoBuild(True)
 
+	If opt_universal And processor.Platform() = "ios" Then
+
+		processor.ToggleCPU()
+		LoadOptions(True) ' reload options for PPC
+
+		BeginMake
+
+		Local buildManager:TBuildManager = New TBuildManager
+		buildManager.MakeApp(Main, makelib)
+		buildManager.DoBuild(True)
+
+		processor.ToggleCPU()
+		LoadOptions(True)
+	End If
+
 Rem
 	If opt_universal
 

+ 3 - 3
bmk_config.bmx

@@ -6,7 +6,7 @@ Import BRL.StandardIO
 ?macos
 Import Pub.MacOS
 ?
-Const BMK_VERSION:String = "3.05"
+Const BMK_VERSION:String = "3.06"
 
 Const ALL_SRC_EXTS$="bmx;i;c;m;h;cpp;cxx;mm;hpp;hxx;s;cc"
 
@@ -189,7 +189,7 @@ Function ParseConfigArgs$[]( args$[] )
 			opt_appstub=args[n]
 		Case "i"
 ?macos
-			' this is mac only... pah!
+			' this is mac/ios only... pah!
 			opt_universal = True
 ?
 		Case "l"
@@ -304,7 +304,7 @@ Function Usage:String(fullUsage:Int = False)
 		s:+ "~t~t~tMacOS : x86, x64~n"
 		s:+ "~t~t~tWin32 : x86, x64~n"
 		s:+ "~t~t~tLinux : x86, x64~n"
-		s:+ "~t~t~tiOS : x86 (simulator), armv7, arm64~n"
+		s:+ "~t~t~tiOS : x86, x64 (simulator), armv7, arm64~n"
 		s:+ "~t~t~tAndroid : x86, x64, arm, armeabi, armeabiv7a, arm64v8a~n"
 		s:+ "~t~t~tRaspberryPi : arm~n"
 		s:+ "~t~t~tEmscripten : js~n"

+ 107 - 16
bmk_make.bmx

@@ -362,8 +362,13 @@ Type TBuildManager
 
 				' sort archives for app linkage
 				If m.modid Then
-					If Not arc_order.Contains(m.arc_path) Then
-						arc_order.AddFirst(m.arc_path)
+					Local path:String = m.arc_path
+					If processor.Platform() = "ios" Then
+						path = m.merge_path
+					End If
+					
+					If Not arc_order.Contains(path) Then
+						arc_order.AddFirst(path)
 					End If
 				End If
 
@@ -481,7 +486,7 @@ Type TBuildManager
 
 									m.arc_time = time_(Null)
 									m.obj_time = time_(Null)
-					
+									
 								End If
 							Else
 								' this probably should never happen.
@@ -497,7 +502,7 @@ Type TBuildManager
 									If Not opt_quiet Then
 										Print ShowPct(m.pct) + "Linking:" + StripDir(opt_outfile)
 									End If
-									
+
 									Local links:TList = New TList
 									Local opts:TList = New TList
 									m.GetLinks(links, opts)
@@ -517,6 +522,24 @@ Type TBuildManager
 
 							End If
 
+						Case STAGE_MERGE
+
+							' a module?
+							If m.modid Then
+								Local max_obj_time:Int = m.MaxObjTime()
+
+								If max_obj_time > m.merge_time And Not m.dontbuild Then
+		
+									If Not opt_quiet Then
+										Print ShowPct(m.pct) + "Merging:" + StripDir(m.merge_path)
+									End If
+
+									CreateMergeArc m.merge_path, m.arc_path
+
+									m.merge_time = time_(Null)
+									
+								End If
+							End If
 					End Select
 
 				Else If Match(m.ext, "s") Then
@@ -569,10 +592,10 @@ Type TBuildManager
 		Next
 	
 		If app_build Then
-		
+
 			' post process
 			LoadBMK(ExtractDir(app_main) + "/post.bmk")
-		
+
 			If processor.Platform() = "android"
 				' create the apk
 				
@@ -827,8 +850,14 @@ Type TBuildManager
 		Return source
 	End Method
 
-	Method GetISourceFile:TSourceFile(arc_path:String, arc_time:Int, iface_path:String, iface_time:Int)
-		Local source:TSourceFile = TSourceFile(sources.ValueForKey(arc_path))
+	Method GetISourceFile:TSourceFile(arc_path:String, arc_time:Int, iface_path:String, iface_time:Int, merge_path:String, merge_time:Int)
+		Local source:TSourceFile
+		
+		If processor.Platform() = "ios" Then
+			source = TSourceFile(sources.ValueForKey(merge_path))
+		Else 
+			source = TSourceFile(sources.ValueForKey(arc_path))
+		End If
 
 		If Not source Then
 			source = ParseISourceFile(iface_path)
@@ -838,8 +867,13 @@ Type TBuildManager
 				source.arc_time = arc_time
 				source.iface_path = iface_path
 				source.iface_time = iface_time
+				source.merge_time = merge_time
 
-				sources.Insert(arc_path, source)
+				If processor.Platform() = "ios" Then
+					sources.Insert(merge_path, source)
+				Else
+					sources.Insert(arc_path, source)
+				End If
 			End If
 		End If
 		
@@ -847,7 +881,7 @@ Type TBuildManager
 	End Method
 	
 	Method GetMod:TSourceFile(m:String, rebuild:Int = False)
-	
+
 		If (opt_all And ((opt_modfilter And ((m).Find(opt_modfilter) = 0)) Or (Not opt_modfilter)) And Not app_main) Or (app_main And opt_standalone) Then
 			rebuild = True
 		End If
@@ -860,13 +894,24 @@ Type TBuildManager
 		Local arc_time:Int = FileTime(arc_path)
 		Local iface_path:String = path + "/" + id + opt_configmung + processor.CPU() + ".i"
 		Local iface_time:Int = FileTime(iface_path)
+		Local merge_path:String
+		Local merge_time:Int
+		
+		If processor.Platform() = "ios" Then
+			If processor.CPU() = "x86" Or processor.CPU() = "x64" Then
+				merge_path = path + "/" + id + opt_configmung + "sim.a"
+			Else
+				merge_path = path + "/" + id + opt_configmung + "dev.a"
+			End If
+			merge_time = FileTime(merge_path)
+		End If
 
 		Local source:TSourceFile
 		Local link:TSourceFile
 
 		If arc_time And iface_time And opt_quickscan Then
 
-			source = GetISourceFile(arc_path, arc_time, iface_path, iface_time)
+			source = GetISourceFile(arc_path, arc_time, iface_path, iface_time, merge_path, merge_time)
 			
 			If Not source Then
 				Return Null
@@ -880,12 +925,19 @@ Type TBuildManager
 				source.iface_path = iface_path
 				source.iface_time = iface_time
 				source.obj_path = arc_path
+				source.merge_path = merge_path
+				source.merge_time = merge_time
 				
 				CalculateDependencies(source, True, rebuild)
 
 				source.dontbuild = True
-				source.stage = STAGE_LINK
-				sources.Insert(source.arc_path, source)
+				If processor.Platform() = "ios" Then
+					source.stage = STAGE_MERGE
+					sources.Insert(source.merge_path, source)
+				Else
+					source.stage = STAGE_LINK
+					sources.Insert(source.arc_path, source)
+				End If
 
 			End If
 			
@@ -911,6 +963,8 @@ Type TBuildManager
 			source.arc_time = arc_time
 			source.iface_path = iface_path
 			source.iface_time = iface_time
+			source.merge_path = merge_path
+			source.merge_time = merge_time
 			
 			Local cc_opts:String = " -I" + CQuote(path)
 			cc_opts :+ " -I" + CQuote(ModulePath(""))
@@ -965,9 +1019,20 @@ Type TBuildManager
 				gen = CreateGenStage(source)
 			End If
 			
-			link = CreateLinkStage(gen)
+			If processor.Platform() <> "ios" Then
+				link = CreateLinkStage(gen)
+			Else
+				Local realLink:TSourceFile = CreateLinkStage(gen)
+				
+				' create a fat archive
+				link = CreateMergeStage(realLink)
+			End If
 		Else
-			link = TSourceFile(sources.ValueForKey(source.arc_path))
+			If processor.Platform() = "ios" Then
+				link = TSourceFile(sources.ValueForKey(source.merge_path))
+			Else
+				link = TSourceFile(sources.ValueForKey(source.arc_path))
+			End If
 			If Not link Then
 				Throw "Can't find link for : " + source.path
 			End If
@@ -1024,12 +1089,34 @@ Type TBuildManager
 		link.depsList = New TList
 		link.depsList.AddLast(source)		
 
-		sources.Insert(link.arc_path, link)
+		If processor.Platform() = "ios" Then
+			sources.Insert(link.obj_path, link)
+		Else
+			sources.Insert(link.arc_path, link)
+		End If
 
 		Return link
 	End Method
 	
+	Method CreateMergeStage:TSourceFile(source:TSourceFile)
+
+		Local merge:TSourceFile = New TSourceFile
+		
+		source.CopyInfo(merge)
+		
+		merge.deps.Insert(merge.obj_path, source)
+		merge.stage = STAGE_MERGE
+		merge.processed = True
+		merge.depsList = New TList
+		merge.depsList.AddLast(source)		
+
+		sources.Insert(merge.merge_path, merge)
+
+		Return merge
+	End Method
+	
 	Method CalculateBatches:TList(files:TList)
+
 		Local batches:TList = New TList
 	
 		Local count:Int
@@ -1061,6 +1148,10 @@ Type TBuildManager
 			If noDeps.IsEmpty() Then
 				' circular dependency!
 				' TODO : dump current list for user to work out?
+				Print "REMAINING :"
+				For Local depName:String = EachIn dependencies.Keys()
+					Print "  " + depName
+				Next
 				Throw "circular dependency!"
 			End If
 		

+ 37 - 0
bmk_modutil.bmx

@@ -21,6 +21,7 @@ Const STAGE_GENERATE:Int = 0
 Const STAGE_FASM2AS:Int = 1
 Const STAGE_OBJECT:Int = 2
 Const STAGE_LINK:Int = 3
+Const STAGE_MERGE:Int = 4
 
 Type TSourceFile
 	Field ext$		'one of: "bmx", "i", "c", "cpp", "m", "s", "h"
@@ -54,6 +55,9 @@ Type TSourceFile
 	Field depsList:TList
 	Field ext_files:TList
 	
+	Field merge_path:String
+	Field merge_time:Int
+	
 	Field cc_opts:String
 	Field bcc_opts:String
 	
@@ -125,6 +129,27 @@ Type TSourceFile
 
 		Return t
 	End Method
+	
+	Method MakeFatter(list:TList, o_path:String)
+		Local ext:String = ExtractExt(o_path)
+		If ext = "o" Then
+			Local file:String = StripExt(o_path)
+			Local fp:String = StripExt(file)
+			Select file.ExtractExt(file)
+				Case "arm64"
+					fp :+ ".armv7.o"
+				Case "armv7"
+					fp :+ ".arm64.o"
+				Case "x86"
+					fp :+ ".x64.o"
+				Case "x64"
+					fp :+ ".x86.o"
+			End Select
+			If Not list.Contains(fp) Then
+				list.AddLast(fp)
+			End If
+		End If
+	End Method
 
 	Method GetLinks(list:TList, opts:TList, modsOnly:Int = False)
 
@@ -132,6 +157,10 @@ Type TSourceFile
 			If Not modid Then
 				If Not list.Contains(obj_path) Then
 					list.AddLast(obj_path)
+					
+					If opt_universal And processor.Platform() = "ios" Then
+						MakeFatter(list, obj_path)
+					End If
 				End If
 			End If
 		End If
@@ -143,6 +172,10 @@ Type TSourceFile
 						If Not s.modid Then
 							If s.obj_path And Not list.Contains(s.obj_path) Then
 								list.AddLast(s.obj_path)
+								
+								If opt_universal And processor.Platform() = "ios" Then
+									MakeFatter(list, s.obj_path)
+								End If
 							End If
 						End If
 					End If
@@ -212,6 +245,8 @@ Type TSourceFile
 		source.dontBuild = dontBuild
 		source.cc_opts = cc_opts
 		source.bcc_opts = bcc_opts
+		source.merge_path = merge_path
+		source.merge_time = merge_time
 	End Method
 	
 	Method GetSourcePath:String()
@@ -225,6 +260,8 @@ Type TSourceFile
 				p = StripExt(obj_path) + ".c"
 			Case STAGE_LINK
 				p = obj_path
+			Case STAGE_MERGE
+				p = arc_path
 		End Select
 		Return p
 	End Method

+ 19 - 5
bmk_ng.bmx

@@ -306,11 +306,25 @@ Type TBMK
 	
 	Method ToggleCPU()
 		If opt_universal Then
-			If opt_arch = "ppc" Then
-				opt_arch = "x86"
-			Else
-				opt_arch = "ppc"
-			End If
+			Select Platform()
+				Case "macos"
+					If opt_arch = "ppc" Then
+						opt_arch = "x86"
+					Else
+						opt_arch = "ppc"
+					End If
+				Case "ios"
+					Select CPU()
+						Case "x86"
+							opt_arch = "x64"
+						Case "x64"
+							opt_arch = "x86"
+						Case "armv7"
+							opt_arch = "arm64"
+						Case "arm64"
+							opt_arch = "armv7"
+					End Select
+			End Select
 		End If
 	End Method
 	

+ 42 - 1
bmk_util.bmx

@@ -123,6 +123,46 @@ Function CompileBMX( src$,obj$,opts$ )
 
 End Function
 
+Function CreateMergeArc( path$ , arc_path:String )
+	Local cmd$
+
+	If processor.Platform() = "ios" Then
+		Local proc:String = processor.CPU()
+		Local opp:String
+		Select proc
+			Case "x86"
+				proc = "i386"
+				opp = "x86_64"
+			Case "x64"
+				proc = "x86_64"
+				opp = "i386"
+			Case "armv7"
+				opp = "arm64"
+			Case "arm64"
+				opp = "armv7"
+		End Select
+		
+		cmd = "lipo "
+
+		If Not FileType(path) Then
+			cmd :+ "-create -arch_blank " + opp + " -arch "
+		Else
+			cmd :+ CQuote(path)
+			cmd :+ " -replace "
+		End If
+	
+		cmd :+ proc + " " + CQuote(arc_path)
+	
+		cmd :+ " -output " + CQuote(path)
+	End If
+
+	If cmd And processor.MultiSys( cmd, path )
+		DeleteFile path
+		Throw "Build Error: Failed to merge archive " + path
+	EndIf
+
+End Function
+
 Function CreateArc( path$ , oobjs:TList )
 	DeleteFile path
 	Local cmd$,t$
@@ -190,7 +230,9 @@ End Function
 Function LinkApp( path$,lnk_files:TList,makelib,opts$ )
 
 	If processor.Platform() = "ios" Then
+
 		PackageIOSApp(path, lnk_files, opts)
+
 		Return
 	End If
 
@@ -781,7 +823,6 @@ Function PackageIOSApp( path$, lnk_files:TList, opts$ )
 	
 	iOSCopyDefaultFiles(templatePath, appPath)
 	
-	End
 End Function
 
 Function iOSCopyDefaultFiles(templatePath:String, appPath:String)