From 0c4573d82a6b8bfd213e5eba34e713a678cb02da Mon Sep 17 00:00:00 2001 From: Dion Nicolaas Date: Thu, 16 Apr 2015 22:36:06 +0200 Subject: [PATCH] fix tile2bmp build under mingw. Provide alternatives for Microsoft-specific macros. Be consistent about slashes in gcc Makefile. Don't include shlwapi.h for any compiler. --- sys/winnt/Makefile.gcc | 8 ++++---- win/win32/mhmain.c | 44 ++++++++++++++++++++++++++++++++++++++++++ win/win32/winhack.c | 7 +++---- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/sys/winnt/Makefile.gcc b/sys/winnt/Makefile.gcc index 7aed22a50..f4d6e1972 100644 --- a/sys/winnt/Makefile.gcc +++ b/sys/winnt/Makefile.gcc @@ -595,7 +595,7 @@ $(GAMEFILE) : $(ALLOBJ) $(NHRES) $(O)gamedir.tag \ $(GAMEDIR)/nhdefkey.dll $(GAMEDIR)/nh340key.dll $(GAMEDIR)/nhraykey.dll endif @echo Linking.... - $(link) $(lflags) -o$@ $(ALLOBJ) $(NHRES) $(WINPLIBS) -lstdc++ + $(link) $(lflags) -o$@ $(ALLOBJ) $(NHRES) $(WINPLIBS) -static -lstdc++ $(subst /,\,@if exist $(O)install.tag del $(O)install.tag) @@ -686,10 +686,10 @@ $(SRC)/vis_tab.c: $(U)makedefs.exe $(DAT)/engrave: $(DAT)/engrave.txt $(U)makedefs.exe $(subst /,\,$(U)makedefs -s) -$(DAT)\epitaph: $(DAT)/epitaph.txt $(U)makedefs.exe +$(DAT)/epitaph: $(DAT)/epitaph.txt $(U)makedefs.exe $(subst /,\,$(U)makedefs -s) -$(DAT)\bogusmon: $(DAT)/bogusmon.txt $(U)makedefs.exe +$(DAT)/bogusmon: $(DAT)/bogusmon.txt $(U)makedefs.exe $(subst /,\,$(U)makedefs -s) @@ -999,7 +999,7 @@ $(U)til2bm32.exe: $(O)til2bm32.o $(TEXT_IO32) @$(link) $(LFLAGSU) -o$@ $(O)til2bm32.o $(TEXT_IO32) $(O)tile2bmp.o: $(WSHR)/tile2bmp.c $(HACK_H) $(TILE_H) $(INCL)/win32api.h - $(cc) $(CFLAGS) -I$(WSHR) -o$@ $(WSHR)/tile2bmp.c + $(cc) $(CFLAGS) -mno-ms-bitfields -I$(WSHR) -o$@ $(WSHR)/tile2bmp.c $(O)til2bm32.o: $(WSHR)/til2bm32.c $(HACK_H) $(TILE_H) $(INCL)/win32api.h $(cc) $(CFLAGS) -I$(WSHR) -DTILE_X=32 -DTILE_Y=32 -o$@ $(WSHR)/til2bm32.c diff --git a/win/win32/mhmain.c b/win/win32/mhmain.c index ae46fda31..889092240 100644 --- a/win/win32/mhmain.c +++ b/win/win32/mhmain.c @@ -16,6 +16,50 @@ #include "mhmsgwnd.h" #include "mhmap.h" + +#ifdef __MINGW32__ +/* Force a compilation error if condition is true, but also produce a + result (of value 0 and type size_t), so the expression can be used + e.g. in a structure initializer (or where-ever else comma expressions + aren't permitted). */ +#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) +/* &a[0] degrades to a pointer: a different type from an array */ +#define __must_be_array(a) \ + BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0]))) + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) +#define _countof(arr) ARRAY_SIZE(arr) + +int _stprintf_s( + TCHAR*buffer, + size_t sizeOfBuffer, + const TCHAR *format , + ... + ) +{ + int ret; + va_list args; + + va_start (args, format); + ret = _vstprintf( buffer, format, args); + va_end(args); + return ret; +} + +double _wtof( const wchar_t *string ) +{ + double ret; + size_t len = wcslen(string) + 1; + char* p = (char*) malloc(len); + + wcstombs(p,string,len); + ret = atof(p); + free(p); + return ret; +} + +#endif + typedef struct mswin_nethack_main_window { int mapAcsiiModeSave; } NHMainWindow, *PNHMainWindow; diff --git a/win/win32/winhack.c b/win/win32/winhack.c index c8498f08f..13e3a6a3e 100644 --- a/win/win32/winhack.c +++ b/win/win32/winhack.c @@ -15,9 +15,8 @@ #include "mhmain.h" #include "mhmap.h" -#ifndef __BORLANDC__ -#include -#else /* Borland redefines "boolean" in shlwapi.h so just use the little bit we need */ +/* Borland and MinGW redefine "boolean" in shlwapi.h, + so just use the little bit we need */ typedef struct _DLLVERSIONINFO { DWORD cbSize; @@ -34,7 +33,7 @@ typedef struct _DLLVERSIONINFO typedef HRESULT (CALLBACK* DLLGETVERSIONPROC)(DLLVERSIONINFO *); -#endif +/* en of shlwapi.h */ /* Minimal common control library version Version _WIN_32IE Platform/IE