From 6f9eaf9e67283e0335e5960bb65ce9705848d040 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Thu, 9 Jul 2015 16:24:33 -0700 Subject: [PATCH] Add support for compilation on Windows using mingw32. --- CMakeLists.txt | 5 ++++- Timer.c | 4 ++-- general.h | 2 +- lib/TH/THGeneral.c | 2 +- lib/TH/THGeneral.h.in | 2 +- lib/luaT/luaT.h | 4 ++-- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94589997..1c555d8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,10 +11,13 @@ SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}") IF (NOT MSVC) + IF (MINGW) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=format") + ELSE() SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=implicit-function-declaration -Werror=format") + ENDIF(MINGW) ENDIF(NOT MSVC) - # Flags # When using MSVC IF(MSVC) diff --git a/Timer.c b/Timer.c index 96f792a4..796190bc 100644 --- a/Timer.c +++ b/Timer.c @@ -1,6 +1,6 @@ #include "general.h" -#ifdef _MSC_VER +#if (defined(_MSC_VER) || defined(__MINGW32__)) #include #else #include @@ -19,7 +19,7 @@ typedef struct _Timer double startusertime; double startsystime; -#ifdef _MSC_VER +#if (defined(_MSC_VER) || defined(__MINGW32__)) time_t base_time; #endif diff --git a/general.h b/general.h index da439ca6..62b17d41 100644 --- a/general.h +++ b/general.h @@ -7,7 +7,7 @@ #include "luaT.h" #include "TH.h" -#ifdef _MSC_VER +#if (defined(_MSC_VER) || defined(__MINGW32__)) #define snprintf _snprintf #define popen _popen diff --git a/lib/TH/THGeneral.c b/lib/TH/THGeneral.c index f48f28ce..03dc24b0 100644 --- a/lib/TH/THGeneral.c +++ b/lib/TH/THGeneral.c @@ -150,7 +150,7 @@ void THFree(void *ptr) double THLog1p(const double x) { -#ifdef _MSC_VER +#if (defined(_MSC_VER) || defined(__MINGW32__)) volatile double y = 1 + x; return log(y) - ((y-1)-x)/y ; /* cancels errors with IEEE arithmetic */ #else diff --git a/lib/TH/THGeneral.h.in b/lib/TH/THGeneral.h.in index 9f118499..130feab2 100644 --- a/lib/TH/THGeneral.h.in +++ b/lib/TH/THGeneral.h.in @@ -89,7 +89,7 @@ do { \ #define THMin(X, Y) ((X) < (Y) ? (X) : (Y)) #define THMax(X, Y) ((X) > (Y) ? (X) : (Y)) -#ifdef _MSC_VER +#if (defined(_MSC_VER) || defined(__MINGW32__)) # define log1p(x) THLog1p(x) #define snprintf _snprintf #define popen _popen diff --git a/lib/luaT/luaT.h b/lib/luaT/luaT.h index 4c25fc1c..c144b6ef 100644 --- a/lib/luaT/luaT.h +++ b/lib/luaT/luaT.h @@ -18,7 +18,7 @@ extern "C" { # endif #endif -#ifdef _MSC_VER +#if (defined(_MSC_VER) || defined(__MINGW32__)) # define DLL_EXPORT __declspec(dllexport) # define DLL_IMPORT __declspec(dllimport) # ifdef luaT_EXPORTS @@ -108,7 +108,7 @@ LUAT_API int luaT_lua_pushudata(lua_State *L); /* comments show what function (that you should use) they call now */ #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) #define LUAT_DEPRECATED __attribute__((__deprecated__)) -#elif defined(_MSC_VER) +#elif (defined(_MSC_VER) || defined(__MINGW32__)) #define LUAT_DEPRECATED __declspec(deprecated) #else #define LUAT_DEPRECATED