From df57ccdc366fd1736c22a3b0179dd374599c2485 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 | 11 +++++++++-- src/pyodbc.h | 5 +++-- src/pyodbcmodule.cpp | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index be5ac895..dcaa8ac9 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import sys, os, shlex, re +import sys, os, re, shlex, sysconfig from os.path import exists, join, isdir, relpath, expanduser from pathlib import Path from inspect import cleandoc @@ -83,7 +83,14 @@ def get_compiler_settings(): 'define_macros': [('PYODBC_VERSION', VERSION)] } - 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', + ]) + 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 febcc677..98cad7f8 100644 --- a/src/pyodbc.h +++ b/src/pyodbc.h @@ -28,7 +28,8 @@ typedef long long INT64; typedef unsigned long long UINT64; #define _strcmpi strcasecmp #define _strdup strdup - inline int max(int lhs, int rhs) { return (rhs > lhs) ? rhs : lhs; } +inline int max(int lhs, int rhs) { return (rhs > lhs) ? rhs : lhs; } +inline int min(int lhs, int rhs) { return (rhs < lhs) ? rhs : lhs; } #endif #ifdef __SUN__ @@ -45,7 +46,7 @@ typedef unsigned long long UINT64; #include #include -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MINGW32__) #include #endif diff --git a/src/pyodbcmodule.cpp b/src/pyodbcmodule.cpp index 82eb01e5..2a1645fb 100644 --- a/src/pyodbcmodule.cpp +++ b/src/pyodbcmodule.cpp @@ -303,6 +303,7 @@ static bool AllocateEnv() } SQLPOINTER defaultVersion = (SQLPOINTER)SQL_OV_ODBC3; + #ifdef SQL_OV_ODBC3_80 PyObject* odbcversion = PyObject_GetAttrString(pModule, "odbcversion"); if (PyObject_TypeCheck(odbcversion, &PyUnicode_Type)) { if (PyUnicode_CompareWithASCIIString(odbcversion, "3.8") == 0) @@ -311,7 +312,7 @@ static bool AllocateEnv() } } Py_DECREF(odbcversion); - + #endif if (!SQL_SUCCEEDED(SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, defaultVersion, sizeof(int)))) { PyErr_SetString(PyExc_RuntimeError, "Unable to set SQL_ATTR_ODBC_VERSION attribute.");