Mercurial > controlcenter
changeset 65:36053ecad688
Win: Add Clang/LLVM support on Windows.
author | Brian Smith <brian@dbsoft.org> |
---|---|
date | Sun, 04 Oct 2020 18:54:03 -0500 |
parents | 1f1072093321 |
children | 289a01642c2b |
files | makefile.vc winmain.c |
diffstat | 2 files changed, 130 insertions(+), 112 deletions(-) [+] |
line wrap: on
line diff
--- a/makefile.vc Tue Jun 30 23:49:40 2020 -0500 +++ b/makefile.vc Sun Oct 04 18:54:03 2020 -0500 @@ -7,6 +7,17 @@ TARGET=cc +# 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 @@ -39,15 +50,13 @@ !include Version -CC = cl -CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -D__TARGET__=\"$(TARGET)\" -I. -I$(DWINCDIR) -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) -DVER_MAJ=$(VER_MAJ) -D VER_MIN=$(VER_MIN) -DVER_REV=$(VER_REV) -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 iphlpapi.lib $(DWLIBDIR)\dw.lib $(DWLIBDIR)\dwcompat.lib RES = LINKFLAGS = -machine:$(TARGET_CPU) -manifest -debug -debugtype:cv DLLLINKFLAGS = -dll -LINK = link DEFFILE = cc.def OBJS = cc.obj statswin.obj winmain.obj @@ -93,7 +102,7 @@ $(LIBS) ccw.res << - mt.exe /manifest cc.exe.manifest win\cc.exe.$(TARGET_CPU).manifest /outputresource:cc.exe;1 + mt.exe -manifest cc.exe.manifest win\cc.exe.$(TARGET_CPU).manifest -outputresource:cc.exe;1 .c.obj: $(CC) $(CFLAGS) $(CFLAGS_DEBUG) $(CFLAGS_COMPILE) $*.c
--- a/winmain.c Tue Jun 30 23:49:40 2020 -0500 +++ b/winmain.c Sun Oct 04 18:54:03 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); +}