changeset 339:f5cf55a750ff

Win: Add Clang/LLVM support for Windows.
author Brian Smith <brian@dbsoft.org>
date Sun, 04 Oct 2020 18:56:40 -0500
parents 4f35d5ab70cb
children e8807eb607f2
files makefile.vc winmain.c
diffstat 2 files changed, 133 insertions(+), 119 deletions(-) [+]
line wrap: on
line diff
--- a/makefile.vc	Tue Jun 30 23:30:27 2020 -0500
+++ b/makefile.vc	Sun Oct 04 18:56:40 2020 -0500
@@ -9,6 +9,17 @@
 
 TARGET=dwib
 
+# 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
@@ -52,13 +63,11 @@
 
 !include Version
 
-CC = cl
-CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -D__TARGET__=\"$(TARGET)\" -I. -I$(DWINCDIR) -I$(XML2INCDIR) -DVER_MAJ=$(VER_MAJ) -D VER_MIN=$(VER_MIN) -DVER_REV=$(VER_REV)
+CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -D__TARGET__=\"$(TARGET)\" -I. -I$(DWINCDIR) -I$(XML2INCDIR) -DVER_MAJ=$(VER_MAJ) -D VER_MIN=$(VER_MIN) -DVER_REV=$(VER_REV) -D_CRT_SECURE_NO_WARNINGS
 LIBS = wsock32.lib kernel32.lib user32.lib comctl32.lib gdi32.lib advapi32.lib shell32.lib comdlg32.lib $(DWLIBDIR)\dw.lib $(XML2LIBDIR)\libxml2_a.lib
 RES = 
 LINKFLAGS = -machine:$(TARGET_CPU) -manifest $(LINK_DEBUG)
 DLLLINKFLAGS = -dll
-LINK = link
 DEFFILE = win\dwib.def
 
 OBJS =	dwib.obj \
@@ -107,7 +116,7 @@
 $(LIBS)
 win\dwib.res
 <<
-	mt.exe /manifest dwib.exe.manifest win\dwib.exe.$(TARGET_CPU).manifest /outputresource:dwib.exe;1
+	mt.exe -manifest dwib.exe.manifest win\dwib.exe.$(TARGET_CPU).manifest -outputresource:dwib.exe;1
  
 dwib.dll: $(LIBOBJS) $(DEFFILE)
 	$(LINK) @<<
@@ -116,8 +125,8 @@
 $(LIBOBJS) $(RES)
 $(LIBS)
 <<
-	lib /def:$(DEFFILE) /machine:$(TARGET_CPU) /out:dwib.lib
-	mt.exe /manifest dwib.dll.manifest win\dwib.dll.$(TARGET_CPU).manifest /outputresource:dwib.dll;2
+	$(WLIB) -def:$(DEFFILE) -machine:$(TARGET_CPU) -out:dwib.lib
+	mt.exe -manifest dwib.dll.manifest win\dwib.dll.$(TARGET_CPU).manifest -outputresource:dwib.dll;2
  
 example.exe: example.obj winmain.obj
 	$(LINK) @<<
@@ -127,7 +136,7 @@
 $(LIBS) dwib.lib
 
 <<
-	mt.exe /manifest example.exe.manifest win\example.exe.$(TARGET_CPU).manifest /outputresource:example.exe;1
+	mt.exe -manifest example.exe.manifest win\example.exe.$(TARGET_CPU).manifest -outputresource:example.exe;1
  
 .c.obj:
 	$(CC) $(CFLAGS) $(CFLAGS_DEBUG) $(CFLAGS_COMPILE) $*.c
--- a/winmain.c	Tue Jun 30 23:30:27 2020 -0500
+++ b/winmain.c	Sun Oct 04 18:56:40 2020 -0500
@@ -1,112 +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>
-
-#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);
-	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;
-
-#ifndef NODW
-	Win32_Set_Instance(hInstance);
-#endif
-
-	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);
+}