Mercurial > HandyFTP
changeset 124:2f6065d271b0
Win: Add Clang/LLVM support for Windows.
author | Brian Smith <brian@dbsoft.org> |
---|---|
date | Sun, 04 Oct 2020 18:55:43 -0500 |
parents | f9502f068ac7 |
children | a68353fac6eb |
files | src/makefile.vc src/winmain.c |
diffstat | 2 files changed, 130 insertions(+), 116 deletions(-) [+] |
line wrap: on
line diff
--- a/src/makefile.vc Wed Jul 01 00:07:54 2020 -0500 +++ b/src/makefile.vc Sun Oct 04 18:55:43 2020 -0500 @@ -7,6 +7,17 @@ TARGET=handyftp +# 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 @@ -50,13 +61,11 @@ !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 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 $(LINK_DEBUG) DLLLINKFLAGS = -dll -LINK = link DEFFILE = handyftp.def OBJS = handyftp.obj \ @@ -106,7 +115,7 @@ $(LIBS) handyftpw.res << - mt.exe /manifest handyftp.exe.manifest win\handyftp.exe.$(TARGET_CPU).manifest /outputresource:handyftp.exe;1 + mt.exe -manifest handyftp.exe.manifest win\handyftp.exe.$(TARGET_CPU).manifest -outputresource:handyftp.exe;1 .c.obj: $(CC) $(CFLAGS) $(CFLAGS_DEBUG) $*.c
--- a/src/winmain.c Wed Jul 01 00:07:54 2020 -0500 +++ b/src/winmain.c Sun Oct 04 18:55:43 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); +}