Skip to content

Commit

Permalink
Building on MinGW
Browse files Browse the repository at this point in the history
mkleehammer/pyodbc/mkleehammer#1168
  • Loading branch information
RoDuth committed Feb 19, 2023
1 parent 4829107 commit 56ceb65
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/pyodbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef unsigned long long UINT64;
#ifdef __MINGW32__
#include <windef.h>
#include <malloc.h>
#include <windows.h>
#else
inline int max(int lhs, int rhs) { return (rhs > lhs) ? rhs : lhs; }
#endif
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 56ceb65

Please sign in to comment.