changeset 39:683ab0f780e8

Win: Add Clang/LLVM support for Windows.
author Brian Smith <brian@dbsoft.org>
date Sun, 04 Oct 2020 18:57:53 -0500
parents a69dab167dd4
children 5bccf3ca5c4f
files dmail.c makefile.vc minimal/makefile.vc mysql/makefile.vc winmain.c
diffstat 5 files changed, 191 insertions(+), 155 deletions(-) [+]
line wrap: on
line diff
--- a/dmail.c	Tue Jun 30 23:44:35 2020 -0500
+++ b/dmail.c	Sun Oct 04 18:57:53 2020 -0500
@@ -1387,7 +1387,7 @@
             dw_window_set_style(tempbutton, DW_BS_NOBORDER, DW_BS_NOBORDER);
 
 			if(messageFunctions[z])
-				dw_signal_connect(tempbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(mainFunctions[z]), (void *)mainItems[z]);
+				dw_signal_connect(tempbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(mainFunctions[z]), DW_UINT_TO_POINTER(mainItems[z]));
 
 			dw_box_pack_start(toolbox, tempbutton, 30, 30, FALSE, FALSE, 0);
 		}
--- a/makefile.vc	Tue Jun 30 23:44:35 2020 -0500
+++ b/makefile.vc	Sun Oct 04 18:57:53 2020 -0500
@@ -7,6 +7,17 @@
 
 TARGET=dmail
 
+# Configure alternate compiler based on Clang/LLVM
+!if "$(CLANG)" == "Y"
+WLIB=llvm-lib.exe
+CC=clang-cl.exe
+LINK=lld-link.exe
+!else
+WLIB=lib.exe
+CC=cl.exe
+LINK=link.exe
+!endif
+
 #
 # Configure settings for the target platform
 #	Default to x86 if not specified
@@ -29,15 +40,13 @@
 PLATFORM_DEF = -DWIN64
 !endif
 
-CC = cl
-CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -D__TARGET__=\"$(TARGET)\" -I. -I$(DWINCDIR)
+CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -D__TARGET__=\"$(TARGET)\" -I. -I$(DWINCDIR) -D_CRT_SECURE_NO_WARNINGS
 CFLAGS_DEBUG = -Zi
 CFLAGS_COMPILE = -MTd
 LIBS = wsock32.lib kernel32.lib user32.lib comctl32.lib gdi32.lib advapi32.lib shell32.lib comdlg32.lib $(DWLIBDIR)\dw.lib $(DWLIBDIR)\dwcompat.lib
 RES = 
 LINKFLAGS = -machine:$(TARGET_CPU) -manifest -debug -debugtype:cv
 DLLLINKFLAGS = -dll
-LINK = link
 DEFFILE = dmail.def
 
 OBJS =	dmail.obj \
@@ -53,17 +62,17 @@
 
 clean:
 	-erase *.dll
-        -erase *.exe
-        -erase *.opt
-        -erase *.lib
-        -erase *.obj
-        -erase *.map
-        -erase *.pdb
-        -erase *.ilk
-        -erase *.exp
-        -erase *.res
-        -erase *~
-        
+	-erase *.exe
+	-erase *.opt
+	-erase *.lib
+	-erase *.obj
+	-erase *.map
+	-erase *.pdb
+	-erase *.ilk
+	-erase *.exp
+	-erase *.res
+	-erase *~
+	
 dmailw.res: dmailw.rc
 	rc -r dmailw.rc
 
@@ -75,7 +84,7 @@
 $(LIBS)
 dmailw.res
 <<
-	mt.exe /manifest dmail.exe.manifest win\dmail.exe.$(TARGET_CPU).manifest /outputresource:dmail.exe;1
-        
+	mt.exe -manifest dmail.exe.manifest win\dmail.exe.$(TARGET_CPU).manifest -outputresource:dmail.exe;1
+
 .c.obj:
 	$(CC) $(CFLAGS) $(CFLAGS_DEBUG) $(CFLAGS_COMPILE) $*.c
--- a/minimal/makefile.vc	Tue Jun 30 23:44:35 2020 -0500
+++ b/minimal/makefile.vc	Sun Oct 04 18:57:53 2020 -0500
@@ -5,6 +5,17 @@
 #DWLIBDIR=\netlabs\dwindows\lib
 #DWINCDIR=\netlabs\dwindows
 
+# Configure alternate compiler based on Clang/LLVM
+!if "$(CLANG)" == "Y"
+WLIB=llvm-lib.exe
+CC=clang-cl.exe
+LINK=lld-link.exe
+!else
+WLIB=lib.exe
+CC=cl.exe
+LINK=link.exe
+!endif
+
 #
 # Configure settings for the target platform
 #	Default to x86 if not specified
@@ -27,15 +38,13 @@
 PLATFORM_DEF = -DWIN64
 !endif
 
-CC = cl
-CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -DBUILD_DLL -I$(DWINCDIR) -I. -I..
+CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -DBUILD_DLL -I$(DWINCDIR) -I. -I.. -D_CRT_SECURE_NO_WARNINGS
 CFLAGS_DEBUG = -Zi
 CFLAGS_COMPILE = -MTd
 LIBS = $(DWLIBDIR)\dw.lib $(DWLIBDIR)\dwcompat.lib
 RES = 
 LINKFLAGS = -machine:$(TARGET_CPU) -manifest -debug -debugtype:cv
 DLLLINKFLAGS = -dll
-LINK = link
 DEFFILE = minimalw.def
 
 OBJS =	minimal.obj
@@ -44,16 +53,16 @@
 
 clean:
 	-erase *.dll
-        -erase *.exe
-        -erase *.opt
-        -erase *.lib
-        -erase *.obj
-        -erase *.map
-        -erase *.pdb
-        -erase *.ilk
-        -erase *.exp
-        -erase *~
-        
+	-erase *.exe
+	-erase *.opt
+	-erase *.lib
+	-erase *.obj
+	-erase *.map
+	-erase *.pdb
+	-erase *.ilk
+	-erase *.exp
+	-erase *~
+	
 minimal.dll: $(OBJS) $(DEFFILE)
 	$(LINK) @<<
 -out:$(@) -def:$(DEFFILE)
@@ -61,8 +70,8 @@
 $(OBJS) $(RES)
 $(LIBS)
 <<
-    mt.exe /manifest minimal.dll.manifest /outputresource:minimal.dll;2
-    copy minimal.dll ..
+	mt.exe -manifest minimal.dll.manifest -outputresource:minimal.dll;2
+	copy minimal.dll ..
 
 .c.obj:
 	$(CC) $(CFLAGS) $(CFLAGS_DEBUG) $(CFLAGS_COMPILE) $*.c
--- a/mysql/makefile.vc	Tue Jun 30 23:44:35 2020 -0500
+++ b/mysql/makefile.vc	Sun Oct 04 18:57:53 2020 -0500
@@ -5,6 +5,17 @@
 #DWLIBDIR=\netlabs\dwindows\lib
 #DWINCDIR=\netlabs\dwindows
 
+# Configure alternate compiler based on Clang/LLVM
+!if "$(CLANG)" == "Y"
+WLIB=llvm-lib.exe
+CC=clang-cl.exe
+LINK=lld-link.exe
+!else
+WLIB=lib.exe
+CC=cl.exe
+LINK=link.exe
+!endif
+
 #
 # Configure settings for the target platform
 #	Default to x86 if not specified
@@ -27,15 +38,13 @@
 PLATFORM_DEF = -DWIN64
 !endif
 
-CC = cl
-CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -DBUILD_DLL -I$(DWINCDIR) -I. -I..
+CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -DBUILD_DLL -I$(DWINCDIR) -I. -I.. -D_CRT_SECURE_NO_WARNINGS
 CFLAGS_DEBUG = -Zi
 CFLAGS_COMPILE = -MTd
 LIBS = $(DWLIBDIR)\dw.lib $(DWLIBDIR)\dwcompat.lib mysqlclient.lib wsock32.lib advapi32.lib user32.lib
 RES = 
 LINKFLAGS = -machine:$(TARGET_CPU) -manifest -debug -debugtype:cv
 DLLLINKFLAGS = -dll
-LINK = link
 DEFFILE = mysqlplgw.def
 
 OBJS =	mysqlplg.obj
@@ -44,16 +53,16 @@
 
 clean:
 	-erase *.dll
-        -erase *.exe
-        -erase *.opt
-        -erase *.lib
-        -erase *.obj
-        -erase *.map
-        -erase *.pdb
-        -erase *.ilk
-        -erase *.exp
-        -erase *~
-        
+	-erase *.exe
+	-erase *.opt
+	-erase *.lib
+	-erase *.obj
+	-erase *.map
+	-erase *.pdb
+	-erase *.ilk
+	-erase *.exp
+	-erase *~
+	
 mysqlplg.dll: $(OBJS) $(DEFFILE)
 	$(LINK) @<<
 -out:$(@) -def:$(DEFFILE)
@@ -61,8 +70,8 @@
 $(OBJS) $(RES)
 $(LIBS)
 <<
-    mt.exe /manifest mysqlplg.dll.manifest /outputresource:mysqlplg.dll;2
-    copy mysqlplg.dll ..
+	mt.exe -manifest mysqlplg.dll.manifest -outputresource:mysqlplg.dll;2
+	copy mysqlplg.dll ..
 
 .c.obj:
 	$(CC) $(CFLAGS) $(CFLAGS_DEBUG) $(CFLAGS_COMPILE) $*.c
--- a/winmain.c	Tue Jun 30 23:44:35 2020 -0500
+++ b/winmain.c	Sun Oct 04 18:57:53 2020 -0500
@@ -1,108 +1,117 @@
-/* Dynamic Windows stub file to allow Win32 applications
- * to use the main() entry point instead of WinMain().
- */
-
-#include <windows.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <process.h>
-
-void Win32_Set_Instance(HINSTANCE hInstance);
-
-char **_convertargs(int *count, char *start, HINSTANCE DWInstance)
-{
-	char *tmp, *argstart, **argv;
-	int loc = 0, inquotes = 0;
-
-	(*count) = 1;
-
-	tmp = start;
-
-	/* Count the number of entries */
-	if(*start)
-	{
-		(*count)++;
-
-		while(*tmp)
-		{
-			if(*tmp == '"' && inquotes)
-				inquotes = 0;
-			else if(*tmp == '"' && !inquotes)
-				inquotes = 1;
-			else if(*tmp == ' ' && !inquotes)
-			{
-				/* Push past any white space */
-				while(*(tmp+1) == ' ')
-					tmp++;
-				/* If we aren't at the end of the command
-				 * line increment the count.
-				 */
-				if(*(tmp+1))
-					(*count)++;
-			}
-			tmp++;
-		}
-	}
-
-	argv = (char **)malloc(sizeof(char *) * ((*count)+1));
-	argv[0] = malloc(260);
-	GetModuleFileName(DWInstance, argv[0], 260);
-
-	argstart = tmp = start;
-
-	if(*start)
-	{
-		loc = 1;
-
-		while(*tmp)
-		{
-			if(*tmp == '"' && inquotes)
-			{
-				*tmp = 0;
-				inquotes = 0;
-			}
-			else if(*tmp == '"' && !inquotes)
-			{
-				argstart = tmp+1;
-				inquotes = 1;
-			}
-			else if(*tmp == ' ' && !inquotes)
-			{
-				*tmp = 0;
-				argv[loc] = strdup(argstart);
-
-				/* Push past any white space */
-				while(*(tmp+1) == ' ')
-					tmp++;
-
-				/* Move the start pointer */
-				argstart = tmp+1;
-
-				/* If we aren't at the end of the command
-				 * line increment the count.
-				 */
-				if(*(tmp+1))
-					loc++;
-			}
-			tmp++;
-		}
-		if(*argstart)
-			argv[loc] = strdup(argstart);
-	}
-	argv[loc+1] = NULL;
-	return argv;
-}
-
-/* Ok this is a really big hack but what the hell ;) */
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
-{
-	char **argv;
-	int argc;
-
-	Win32_Set_Instance(hInstance);
-
-	argv = _convertargs(&argc, lpCmdLine, hInstance);
-
-	return main(argc, argv);
-}
+/* Dynamic Windows stub file to allow Win32 applications
+ * to use the main() entry point instead of WinMain().
+ *
+ * (C) 2000-2012 Brian Smith <brian@dbsoft.org>
+ */
+
+#include <windows.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <process.h>
+
+#ifndef NODW
+void Win32_Set_Instance(HINSTANCE hInstance);
+#endif
+
+char **_convertargs(int *count, char *start, HINSTANCE DWInstance)
+{
+   char *tmp, *argstart, **argv;
+   int loc = 0, inquotes = 0;
+
+   (*count) = 1;
+
+   tmp = start;
+
+   /* Count the number of entries */
+   if(*start)
+   {
+      (*count)++;
+
+      while(*tmp)
+      {
+         if(*tmp == '"' && inquotes)
+            inquotes = 0;
+         else if(*tmp == '"' && !inquotes)
+            inquotes = 1;
+         else if(*tmp == ' ' && !inquotes)
+         {
+            /* Push past any white space */
+            while(*(tmp+1) == ' ')
+               tmp++;
+            /* If we aren't at the end of the command
+             * line increment the count.
+             */
+            if(*(tmp+1))
+               (*count)++;
+         }
+         tmp++;
+      }
+   }
+
+   argv = (char **)malloc(sizeof(char *) * ((*count)+1));
+   argv[0] = malloc(260);
+   GetModuleFileNameA(DWInstance, argv[0], 260);
+
+   argstart = tmp = start;
+
+   if(*start)
+   {
+      loc = 1;
+
+      while(*tmp)
+      {
+         if(*tmp == '"' && inquotes)
+         {
+            *tmp = 0;
+            inquotes = 0;
+         }
+         else if(*tmp == '"' && !inquotes)
+         {
+            argstart = tmp+1;
+            inquotes = 1;
+         }
+         else if(*tmp == ' ' && !inquotes)
+         {
+            *tmp = 0;
+            argv[loc] = _strdup(argstart);
+
+            /* Push past any white space */
+            while(*(tmp+1) == ' ')
+               tmp++;
+
+            /* Move the start pointer */
+            argstart = tmp+1;
+
+            /* If we aren't at the end of the command
+             * line increment the count.
+             */
+            if(*(tmp+1))
+               loc++;
+         }
+         tmp++;
+      }
+      if(*argstart)
+         argv[loc] = _strdup(argstart);
+   }
+   argv[loc+1] = NULL;
+   return argv;
+}
+
+/* Protoype for the application entrypoint */
+int main(int argc, char **argv);
+
+/* Ok this is a really big hack but what the hell ;) */
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+   char **argv;
+   int argc;
+
+#ifndef NODW
+   Win32_Set_Instance(hInstance);
+#endif
+
+   argv = _convertargs(&argc, lpCmdLine, hInstance);
+
+   return main(argc, argv);
+}