Ver código fonte

More work on MSVC support.

Mark Sibly 8 anos atrás
pai
commit
c6327800bf

+ 1 - 2
bin/env_windows.txt

@@ -48,10 +48,9 @@ MX2_LD_OPTS_MSVC=
 MX2_LD_OPTS_MSVC_DEBUG=
 MX2_LD_OPTS_MSVC_RELEASE=
 
-'C Compiler options. Note: -D_WIN32_WINNT=0x0601 means headers for Windows 7, ie: Windows 7 is min SDK!
 MX2_CC_OPTS_MSVC=-EHs -W0 -MT
 MX2_CC_OPTS_MSVC_DEBUG=
-MX2_CC_OPTS_MSVC_RELEASE=
+MX2_CC_OPTS_MSVC_RELEASE=-Ox
 
 'C++ Compiler options
 MX2_CPP_OPTS_MSVC=-EHs -W0 -MT

+ 2 - 0
modules/assimp/assimp/contrib/zlib/gzguts.h

@@ -20,7 +20,9 @@
 
 #include <stdio.h>
 
+#if !_MSC_VER
 #include <unistd.h>
+#endif
 
 #include "zlib.h"
 #ifdef STDC

+ 5 - 0
modules/litehtml/litehtml/src/gumbo/attribute.c

@@ -19,7 +19,12 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+
+#if _MSC_VER
+#include "strings.h"
+#else
 #include <strings.h>
+#endif
 
 #include "util.h"
 

+ 5 - 0
modules/litehtml/litehtml/src/gumbo/parser.c

@@ -19,7 +19,12 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+
+#if _MSC_VER
+#include "strings.h"
+#else
 #include <strings.h>
+#endif
 
 #include "attribute.h"
 #include "error.h"

+ 5 - 0
modules/litehtml/litehtml/src/gumbo/string_buffer.c

@@ -19,7 +19,12 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+
+#if _MSC_VER
+#include "strings.h"
+#else
 #include <strings.h>
+#endif
 
 #include "string_piece.h"
 #include "util.h"

+ 5 - 0
modules/litehtml/litehtml/src/gumbo/string_piece.c

@@ -19,7 +19,12 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+
+#if _MSC_VER
+#include "strings.h"
+#else
 #include <strings.h>
+#endif
 
 #include "util.h"
 

+ 6 - 1
modules/litehtml/litehtml/src/gumbo/utf8.c

@@ -19,7 +19,12 @@
 #include <assert.h>
 #include <stdint.h>
 #include <string.h>
-#include <strings.h>  // For strncasecmp.
+
+#if _MSC_VER
+#include "strings.h"
+#else
+#include <strings.h>
+#endif
 
 #include "error.h"
 #include "gumbo.h"

+ 6 - 0
modules/litehtml/litehtml/src/gumbo/util.c

@@ -19,7 +19,13 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+
+#if _MSC_VER
+#include "strings.h"
+#else
 #include <strings.h>
+#endif
+
 #include <stdarg.h>
 #include <stdio.h>
 

+ 5 - 0
modules/litehtml/litehtml/src/gumbo/vector.c

@@ -19,7 +19,12 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+
+#if _MSC_VER
+#include "strings.h"
+#else
 #include <strings.h>
+#endif
 
 #include "util.h"
 

+ 4 - 1
modules/std/fiber/native/asm/jump_i386_ms_pe_masm.asm

@@ -24,7 +24,10 @@
 .model flat, c
 .code
 
-jump_fcontext PROC BOOST_CONTEXT_EXPORT
+jump_fcontext PROC 
+
+	;BOOST_CONTEXT_EXPORT
+	
     push  ebp  ; save EBP 
     push  ebx  ; save EBX 
     push  esi  ; save ESI 

+ 4 - 1
modules/std/fiber/native/asm/make_i386_ms_pe_masm.asm

@@ -26,7 +26,10 @@
 _exit PROTO, value:SDWORD
 .code
 
-make_fcontext PROC BOOST_CONTEXT_EXPORT
+make_fcontext PROC 
+
+	;BOOST_CONTEXT_EXPORT
+	
     ; first arg of make_fcontext() == top of context-stack
     mov  eax, [esp+04h]
 

+ 4 - 1
modules/std/fiber/native/asm/ontop_i386_ms_pe_masm.asm

@@ -24,7 +24,10 @@
 .model flat, c
 .code
 
-ontop_fcontext PROC BOOST_CONTEXT_EXPORT
+ontop_fcontext PROC 
+
+	;BOOST_CONTEXT_EXPORT
+	
     push  ebp  ; save EBP 
     push  ebx  ; save EBX 
     push  esi  ; save ESI 

+ 85 - 49
src/mx2cc/builder.monkey2

@@ -126,6 +126,7 @@ Class BuilderInstance
 		End
 
 		profileName=opts.target+"_"+opts.config
+		If opts.target="windows" And Int( GetEnv( "MX2_USE_MSVC" ) ) profileName+="_msvc"
 		
 		MODULES_DIR=CurrentDir()+"modules/"
 		
@@ -607,19 +608,43 @@ Class BuilderInstance
 		
 		Select ext.ToLower()
 		Case ".a"
-
-			If name.StartsWith( "lib" ) name=name.Slice( 3 ) Else name=path
-			product.LD_SYSLIBS.Push( "-l"+name )
 			
-		Case ".lib",".dylib"
-		
-			product.LD_SYSLIBS.Push( "-l"+name )
+			If name.StartsWith( "lib" )
+				
+				name=name.Slice( 3 )
+				
+				If product.toolchain="msvc"
+					product.LIB_FILES.Push( name+".lib" )
+				Else
+					product.LIB_FILES.Push( "-l"+name )
+				Endif
+			
+			Else
+				
+				New BuildEx( "Import Error: "+path )
+			Endif
+			
+		Case ".lib"
+			
+			If product.toolchain="msvc"
+				product.LIB_FILES.Push( name )
+			Else
+				product.LIB_FILES.Push( "-l"+name )
+			Endif
+			
+		Case ".dylib"
+			
+			If product.toolchain="gcc"
+				product.LIB_FILES.Push( "-l"+name )
+			Endif
 			
 		Case ".framework"
-		
-			product.LD_SYSLIBS.Push( "-framework "+name )
 			
-		Case ".h",".hh",".hpp"
+			If product.toolchain="gcc"
+				product.LIB_FILES.Push( "-framework "+name )
+			Endif
+			
+		Case ".h",".hh",".hxx",".hpp"
 		
 '			STD_INCLUDES.Push( "<"+path+">" )
 			
@@ -674,17 +699,29 @@ Class BuilderInstance
 				product.CC_OPTS+=" -I"+qdir
 				product.CPP_OPTS+=" -I"+qdir
 				
-			Case ".hh",".hpp"
+			Case ".hh",".hpp",".hxx"
 			
 				product.CPP_OPTS+=" -I"+qdir
 				
-			Case ".a",".lib",".dylib"
-			
-				product.LD_OPTS+=" -L"+qdir
+			Case ".a",".lib"
+				
+				If product.toolchain="msvc"
+					product.LD_OPTS+=" -LIBPATH:"+qdir
+				Else
+					product.LD_OPTS+=" -L"+qdir
+				Endif
+				
+			Case ".dylib"
+				
+				If product.toolchain="gcc"
+					product.LD_OPTS+=" -L"+qdir
+				Endif
 				
 			Case ".framework"
-			
-				product.LD_OPTS+=" -F"+qdir
+				
+				If product.toolchain="gcc"
+					product.LD_OPTS+=" -F"+qdir
+				Endif
 				
 			Default
 			
@@ -699,9 +736,11 @@ Class BuilderInstance
 		Select ext
 		Case ".framework"
 			
-			If GetFileType( path )<>FileType.Directory
-				New BuildEx( "Framework "+qpath+" not found" )
-				Return
+			If product.toolchain="gcc"
+				If GetFileType( path )<>FileType.Directory
+					New BuildEx( "Framework "+qpath+" not found" )
+					Return
+				Endif
 			Endif
 			
 		Default
@@ -724,60 +763,57 @@ Class BuilderInstance
 		
 			MX2_SRCS.Push( path )
 			
-		Case ".h",".hh",".hpp"
+		Case ".h",".hh",".hxx",".hpp"
 		
 '			STD_INCLUDES.Push( qpath )
 			
 		Case ".c",".cc",".cxx",".cpp",".m",".mm",".asm",".s"
 		
-			If parsingModule=mainModule product.SRC_FILES.Push( path )
+			If parsingModule=mainModule 
+				product.SRC_FILES.Push( path )
+			Endif
 		
-'			If modules.Length=1
-'				SRC_FILES.Push( path )
-'			Endif
-
 		Case ".java"
-		
-'			If parsingModule=mainModule product.JAVA_FILES.Push( path )
-			product.JAVA_FILES.Push( path )
+			
+			If opts.target="android"
+				product.JAVA_FILES.Push( path )
+			Endif
 			
 		Case ".o"
 		
 			product.OBJ_FILES.Push( path )
 			
-		Case ".a",".lib"
-		
-			product.LD_SYSLIBS.Push( qpath )
+		Case ".lib"
 			
-		Case ".so"
+			product.LIB_FILES.Push( qpath )
 		
-			If opts.target="android"		'probably all non-windows targets
-			
-				product.LD_SYSLIBS.Push( qpath )
+		Case ".a"
 			
+			If product.toolchain="gcc"
+				product.LIB_FILES.Push( qpath )
 			Endif
 			
-			product.DLL_FILES.Push( path )
+		Case ".so",".dylib"
 			
-		Case ".dll",".exe"
-		
-			product.DLL_FILES.Push( path )
+			If product.toolchain="gcc"
+				product.LIB_FILES.Push( qpath )
+				product.DLL_FILES.Push( path )
+			Endif
 			
-		Case ".dylib"
-		
-			product.LD_SYSLIBS.Push( qpath )
+		Case ".dll",".exe"
 			
-			product.DLL_FILES.Push( path )
+			If opts.target="windows"
+				product.DLL_FILES.Push( path )
+			Endif
 			
 		Case ".framework"
-		
-			'OK, this is ugly...
-		
-			ImportLocalFile( ExtractDir( path )+"*.framework" )
-			
-			ImportSystemFile( StripDir( path ) )
 			
-			product.DLL_FILES.Push( path )
+			If product.toolchain="gcc"
+				'OK, this is ugly...
+				ImportLocalFile( ExtractDir( path )+"*.framework" )
+				ImportSystemFile( StripDir( path ) )
+				product.DLL_FILES.Push( path )
+			Endif
 		
 		Default
 		

+ 16 - 25
src/mx2cc/buildproduct.monkey2

@@ -8,22 +8,27 @@ Class BuildProduct
 	Field imports:=New Stack<Module>
 	Field outputFile:String
 	
+	Field toolchain:String
+
 	Field CC_OPTS:String
 	Field CPP_OPTS:String
 	Field AS_OPTS:String
 	Field LD_OPTS:String
 	
-	Field SRC_FILES:=New StringStack
-	Field OBJ_FILES:=New StringStack
-	Field LD_SYSLIBS:=New StringStack
+	Field SRC_FILES:=New StringStack	'source code files
+	Field JAVA_FILES:=New StringStack	'java files
+	Field OBJ_FILES:=New StringStack	'object code files - added to module .a
+	Field LIB_FILES:=New StringStack	'library files - passed to linker.
+	Field DLL_FILES:=New StringStack	'dll/exe files, copied to app dir.
+	
 	Field ASSET_FILES:=New StringStack
-	Field JAVA_FILES:=New StringStack
-	Field DLL_FILES:=New StringStack
 	
 	Method New( module:Module,opts:BuildOpts )
 		Self.module=module
 		Self.opts=opts
 		
+		toolchain=opts.target="windows" And Int( GetEnv( "MX2_USE_MSVC" ) ) ? "msvc" Else "gcc"
+		
 		Local copts:=""
 		copts+=" -I~q"+MODULES_DIR+"~q"
 		copts+=" -I~q"+MODULES_DIR+"monkey/native~q"
@@ -256,8 +261,6 @@ End
 
 Class GccBuildProduct Extends BuildProduct
 	
-	Field toolchain:String
-
 	Field CC_CMD:=""
 	Field CXX_CMD:=""
 	Field AS_CMD:=""
@@ -267,8 +270,6 @@ Class GccBuildProduct Extends BuildProduct
 	Method New( module:Module,opts:BuildOpts )
 		Super.New( module,opts )
 		
-		toolchain=opts.target="windows" And Int( GetEnv( "MX2_USE_MSVC" ) ) ? "msvc" Else "gcc"
-		
 		Local target:="_"+opts.target.ToUpper()
 		Local config:="_"+opts.config.ToUpper()
 		
@@ -460,8 +461,6 @@ Class GccBuildProduct Extends BuildProduct
 			
 		Else If toolchain="msvc"
 			
-			'args="-out:~q"+output+"~q"+args
-
 			Local tmp:=AllocTmpFile( "libFiles" )
 			SaveString( args,tmp )
 			
@@ -479,7 +478,6 @@ Class GccBuildProduct Extends BuildProduct
 #Else
 			cmd=AR_CMD+" q ~q"+output+"~q"+args
 #Endif
-			
 		Endif
 		
 		Exec( cmd )
@@ -503,8 +501,8 @@ Class GccBuildProduct Extends BuildProduct
 			If ExtractExt( outputFile ).ToLower()<>".exe" outputFile+=".exe"
 				
 			If toolchain="msvc"
-				If opts.appType="gui" cmd+=" -subsystem:windows" Else cmd+=" -subsystem:console"
 '				cmd+=" -entry:main"
+				If opts.appType="gui" cmd+=" -subsystem:windows" Else cmd+=" -subsystem:console"
 			Else
 				If opts.appType="gui" cmd+=" -mwindows"
 			Endif
@@ -565,7 +563,7 @@ Class GccBuildProduct Extends BuildProduct
 		If opts.verbose>=0 Print "Linking "+outputFile+"..."
 			
 		If toolchain="msvc"
-			cmd+=" -out:~q"+outputFile+"~q"
+			cmd+=" -entry:mainCRTStartup -out:~q"+outputFile+"~q"
 		Else
 			cmd+=" -o ~q"+outputFile+"~q"
 		Endif
@@ -582,14 +580,7 @@ Class GccBuildProduct Extends BuildProduct
 			lnkFiles+=" ~q"+afile+"~q"
 		Next
 
-		If toolchain="msvc"
-			For Local i:=0 Until LD_SYSLIBS.Length
-				Local lib:=LD_SYSLIBS[i]
-				If lib.StartsWith( "-l" ) LD_SYSLIBS[i]=lib.Slice( 2 )+".lib"
-			Next
-		endif
-
-		lnkFiles+=" "+LD_SYSLIBS.Join( " " )
+		lnkFiles+=" "+LIB_FILES.Join( " " )
 		
 #If __TARGET__="windows"
 		lnkFiles=lnkFiles.Replace( " -Wl,"," " )
@@ -599,7 +590,7 @@ Class GccBuildProduct Extends BuildProduct
 #Else
 		cmd+=lnkFiles
 #Endif
-CopyAssets( assetsDir )
+		CopyAssets( assetsDir )
 		
 		CopyDlls( dllsDir )
 		
@@ -650,7 +641,7 @@ Class IosBuildProduct Extends GccBuildProduct
 
 		If opts.wholeArchive cmd+=" -Wl,--no-whole-archive"
 		
-		For Local lib:=Eachin LD_SYSLIBS
+		For Local lib:=Eachin LIB_FILES
 			If lib.ToLower().EndsWith( ".a~q" ) cmd+=" "+lib
 		Next
 		
@@ -803,7 +794,7 @@ Class AndroidBuildProduct Extends BuildProduct
 			
 			buf.Push( "LOCAL_LDLIBS += -ldl" )
 			
-			For Local lib:=Eachin LD_SYSLIBS
+			For Local lib:=Eachin LIB_FILES
 				If lib.StartsWith( "-l" ) buf.Push( "LOCAL_LDLIBS += "+lib )
 			Next
 			

+ 13 - 1
src/mx2cc/mx2cc.monkey2

@@ -19,10 +19,18 @@ Using libc..
 Using std..
 Using mx2..
 
+#If __CONFIG__="debug"
+Const FORCE_MSVC:=False
+#Endif
+
 Global StartDir:String
 
+'Const TestArgs:="mx2cc makemods -clean"
+
 'Const TestArgs:="mx2cc makemods -clean monkey"
 
+'Const TestArgs:="mx2cc makemods -config=debug monkey libc miniz stb-image stb-image-write stb-vorbis std"
+
 Const TestArgs:="mx2cc makeapp -target=desktop -apptype=console -run src/mx2cc/test.monkey2"
 
 'To build with old mx2cc...
@@ -38,7 +46,7 @@ Const TestArgs:="mx2cc makeapp -target=desktop -apptype=console -run src/mx2cc/t
 'Const TestArgs:="mx2cc makeapp -build -clean -config=release -target=raspbian src/mx2cc/mx2cc.monkey2"
 
 Function Main()
-	
+
 	'Set aside 64M for GC!
 	GCSetTrigger( 64*1024*1024 )
 
@@ -60,6 +68,10 @@ Function Main()
 
 	LoadEnv( env )
 	
+#If __CONFIG__="debug"
+	If FORCE_MSVC libc.setenv( "MX2_USE_MSVC","1",1 )
+#Endif
+	
 	Local args:=AppArgs()
 	
 	If args.Length<2

+ 31 - 4
src/mx2cc/test.monkey2

@@ -1,9 +1,36 @@
+Namespace myapp
 
-Function Main()
+#Import "<std>"
+#Import "<mojo>"
+
+Using std..
+Using mojo..
+
+Class MyWindow Extends Window
+
+	Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )
+
+		Super.New( title,width,height,flags )
+		
+		New Fiber( Lambda()
+			Print "HERE"
+		End )
+	End
+
+	Method OnRender( canvas:Canvas ) Override
 	
-	Print ULong( ".1" )
+		App.RequestRender()
+	
+		canvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )
+	End
+	
+End
+
+Function Main()
+
+	New AppInstance
 	
-	Local x:Int=.1
-	Print x
+	New MyWindow
 	
+	App.Run()
 End