From 56ceb65b683a849b7fbfe777997e83a2f7d6eb69 Mon Sep 17 00:00:00 2001 From: RoDuth Date: Mon, 20 Feb 2023 09:56:34 +1000 Subject: [PATCH] Building on MinGW mkleehammer/pyodbc/#1168 --- setup.py | 12 ++++++++++-- src/pyodbc.h | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 34215dbf..b5aa9ff9 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import sys, os, re, shlex +import sys, os, re, shlex, sysconfig from os.path import exists, abspath, dirname, join, isdir, relpath, expanduser try: @@ -153,7 +153,15 @@ def get_compiler_settings(version_str): except ValueError: pass - if os.name == 'nt': + if 'mingw' in sysconfig.get_platform(): + # Windows mingw (note that os.name == 'nt' is True) + settings['extra_compile_args'].extend([ + '-Wno-write-strings', + '-Wno-deprecated-declarations', + ]) + settings['libraries'].append('odbc32') + + elif os.name == 'nt': settings['extra_compile_args'].extend([ '/Wall', '/wd4514', # unreference inline function removed diff --git a/src/pyodbc.h b/src/pyodbc.h index d2de93b0..8c223dce 100644 --- a/src/pyodbc.h +++ b/src/pyodbc.h @@ -31,6 +31,7 @@ typedef unsigned long long UINT64; #ifdef __MINGW32__ #include #include + #include #else inline int max(int lhs, int rhs) { return (rhs > lhs) ? rhs : lhs; } #endif @@ -119,6 +120,11 @@ inline void _strlwr(char* name) #define CDECL #endif +#ifdef __MINGW32__ +#define min(X,Y) ((X) < (Y) ? (X) : (Y)) +#define max(X,Y) ((X) > (Y) ? (X) : (Y)) +#endif + #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x)