mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-10 19:16:34 +03:00
mingw patch from Daniele Varazzo.
This commit is contained in:
parent
728b4788de
commit
4805a93569
|
@ -1,3 +1,7 @@
|
|||
2005-04-10 Federico Di Gregorio <fog@debian.org>
|
||||
|
||||
* Applied mingw patch from Daniele Varazzo.
|
||||
|
||||
2005-04-03 Federico Di Gregorio <fog@debian.org>
|
||||
|
||||
* lib/psycopg1.py (connection.autocommit): added compatibility
|
||||
|
|
59
INSTALL
59
INSTALL
|
@ -16,3 +16,62 @@ to build in the local directory; and:
|
|||
|
||||
to install system-wide.
|
||||
|
||||
|
||||
Compiling under Windows with mingw32
|
||||
************************************
|
||||
|
||||
You can compile psycopg under Windows platform with mingw32 compiler. The
|
||||
software required is:
|
||||
|
||||
* MinGW (http://www.mingw.org/). You also get MinGW installed by installing
|
||||
Dev-C++ IDE (http://www.bloodshed.net/devcpp.html);
|
||||
|
||||
* either:
|
||||
* a binary PostgreSQL installation with include and libary files, at least
|
||||
release 8.0 (http://www.postgresql.org/download/);
|
||||
* PostgreSQL sources. You will need to compile PostgreSQL, which also
|
||||
requires MSYS (http://www.mingw.org/msys.shtml) and Flex and Bison
|
||||
packages (http://gnuwin32.sourceforge.net/packages.html).
|
||||
|
||||
I assume all the software installed in the standard way. gcc compiler directory
|
||||
should be in your path.
|
||||
|
||||
Steps required to package your own version of psycopg:
|
||||
|
||||
1. if building from PostgreSQL binaries:
|
||||
|
||||
1.1. create the file libpqdll.a (you should already know how to build
|
||||
Python extensions with mingw: see
|
||||
http://starship.python.net/crew/kernr/mingw32/Notes.html for details):
|
||||
|
||||
1.1.1. cd C:\Program Files\PostgreSQL\8.0\lib
|
||||
|
||||
1.1.2. pexports C:\WINNT\system32\libpq.dll > libpqdll.def
|
||||
|
||||
1.1.3. dlltool --dllname libpq.dll --def libpqdll.def \
|
||||
--output-lib libpqdll.a
|
||||
|
||||
2. else, if building from PostgreSQL source:
|
||||
|
||||
2.1. compile it:
|
||||
|
||||
2.1.1. unpack postgresql source (ex. in c:\)
|
||||
|
||||
2.1.2. run MSYS
|
||||
|
||||
2.1.3. cd /c/postgresql-8.0
|
||||
|
||||
2.1.4. ./configure --without-zlib
|
||||
|
||||
2.1.5. make
|
||||
|
||||
2.2. create the file libpqdll.a (dlltool is part of MinGW):
|
||||
|
||||
2.2.1. cd postgresql-8.0\src\interfaces\libpq
|
||||
|
||||
2.2.2. dlltool --dllname libpq.dll --def libpqdll.def \
|
||||
--output-lib libpqdll.a
|
||||
|
||||
3. build psycopg:
|
||||
|
||||
3.1. python setup.py build_ext --compiler=mingw32 install
|
||||
|
|
|
@ -201,7 +201,7 @@ PyTypeObject asisType = {
|
|||
0, /*tp_dictoffset*/
|
||||
|
||||
asis_init, /*tp_init*/
|
||||
PyType_GenericAlloc, /*tp_alloc*/
|
||||
0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
|
||||
asis_new, /*tp_new*/
|
||||
(freefunc)asis_del, /*tp_free Low-level free-memory routine */
|
||||
0, /*tp_is_gc For PyObject_IS_GC */
|
||||
|
|
|
@ -315,7 +315,7 @@ PyTypeObject binaryType = {
|
|||
0, /*tp_dictoffset*/
|
||||
|
||||
binary_init, /*tp_init*/
|
||||
PyType_GenericAlloc, /*tp_alloc*/
|
||||
0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
|
||||
binary_new, /*tp_new*/
|
||||
(freefunc)binary_del, /*tp_free Low-level free-memory routine */
|
||||
0, /*tp_is_gc For PyObject_IS_GC */
|
||||
|
|
|
@ -233,7 +233,7 @@ PyTypeObject pydatetimeType = {
|
|||
0, /*tp_dictoffset*/
|
||||
|
||||
pydatetime_init, /*tp_init*/
|
||||
PyType_GenericAlloc, /*tp_alloc*/
|
||||
0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
|
||||
pydatetime_new, /*tp_new*/
|
||||
(freefunc)pydatetime_del, /*tp_free Low-level free-memory routine */
|
||||
0, /*tp_is_gc For PyObject_IS_GC */
|
||||
|
|
|
@ -202,7 +202,7 @@ PyTypeObject pbooleanType = {
|
|||
0, /*tp_dictoffset*/
|
||||
|
||||
pboolean_init, /*tp_init*/
|
||||
PyType_GenericAlloc, /*tp_alloc*/
|
||||
0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
|
||||
pboolean_new, /*tp_new*/
|
||||
(freefunc)pboolean_del, /*tp_free Low-level free-memory routine */
|
||||
0, /*tp_is_gc For PyObject_IS_GC */
|
||||
|
|
|
@ -343,7 +343,7 @@ PyTypeObject qstringType = {
|
|||
0, /*tp_dictoffset*/
|
||||
|
||||
qstring_init, /*tp_init*/
|
||||
PyType_GenericAlloc, /*tp_alloc*/
|
||||
0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
|
||||
qstring_new, /*tp_new*/
|
||||
(freefunc)qstring_del, /*tp_free Low-level free-memory routine */
|
||||
0, /*tp_is_gc For PyObject_IS_GC */
|
||||
|
|
|
@ -380,7 +380,7 @@ PyTypeObject connectionType = {
|
|||
0, /*tp_dictoffset*/
|
||||
|
||||
connection_init, /*tp_init*/
|
||||
PyType_GenericAlloc, /*tp_alloc*/
|
||||
0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
|
||||
connection_new, /*tp_new*/
|
||||
(freefunc)connection_del, /*tp_free Low-level free-memory routine */
|
||||
0, /*tp_is_gc For PyObject_IS_GC */
|
||||
|
|
|
@ -1365,7 +1365,7 @@ PyTypeObject cursorType = {
|
|||
0, /*tp_dictoffset*/
|
||||
|
||||
cursor_init, /*tp_init*/
|
||||
PyType_GenericAlloc, /*tp_alloc*/
|
||||
0, /*tp_alloc Will be set to PyType_GenericAlloc in module init*/
|
||||
cursor_new, /*tp_new*/
|
||||
(freefunc)cursor_del, /*tp_free Low-level free-memory routine */
|
||||
0, /*tp_is_gc For PyObject_IS_GC */
|
||||
|
|
|
@ -202,7 +202,7 @@ PyTypeObject isqlquoteType = {
|
|||
0, /*tp_dictoffset*/
|
||||
|
||||
isqlquote_init, /*tp_init*/
|
||||
PyType_GenericAlloc, /*tp_alloc*/
|
||||
0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
|
||||
isqlquote_new, /*tp_new*/
|
||||
(freefunc)isqlquote_del, /*tp_free Low-level free-memory routine */
|
||||
0, /*tp_is_gc For PyObject_IS_GC */
|
||||
|
|
|
@ -485,6 +485,16 @@ init_psycopg(void)
|
|||
/* create a standard set of exceptions and add them to the module's dict */
|
||||
psyco_errors_init();
|
||||
psyco_errors_fill(dict);
|
||||
|
||||
/* Solve win32 build issue about non-constant initializer element */
|
||||
cursorType.tp_alloc = PyType_GenericAlloc;
|
||||
binaryType.tp_alloc = PyType_GenericAlloc;
|
||||
isqlquoteType.tp_alloc = PyType_GenericAlloc;
|
||||
pbooleanType.tp_alloc = PyType_GenericAlloc;
|
||||
pydatetimeType.tp_alloc = PyType_GenericAlloc;
|
||||
connectionType.tp_alloc = PyType_GenericAlloc;
|
||||
asisType.tp_alloc = PyType_GenericAlloc;
|
||||
qstringType.tp_alloc = PyType_GenericAlloc;
|
||||
|
||||
Dprintf("initpsycopg: module initialization complete");
|
||||
}
|
||||
|
|
15
setup.cfg
15
setup.cfg
|
@ -3,6 +3,9 @@ define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3,P
|
|||
# PSYCOPG_DEBUG can be added to enable verbose debug information
|
||||
# PSYCOPG_OWN_QUOTING can be added above but it is deprecated
|
||||
|
||||
# Use Python datatime objects for date/time representation.
|
||||
use_pydatetime=1
|
||||
|
||||
# include_dirs is the preferred method for locating postgresql headers,
|
||||
# but some extra checks on sys.platform will still be done in setup.py
|
||||
include_dirs=.:/usr/include/postgresql:/usr/include/postgresql/server
|
||||
|
@ -10,4 +13,14 @@ include_dirs=.:/usr/include/postgresql:/usr/include/postgresql/server
|
|||
# if postgresql is installed somewhere weird, just addthe right path in
|
||||
# library_dir any extra libraries required to link in libraries
|
||||
#library_dirs=
|
||||
libraries=pq
|
||||
|
||||
# Windows-only definitions
|
||||
# ------------------------
|
||||
|
||||
# The postgresql directory. It can be either the root of a source tree or the
|
||||
# location of a binary installation
|
||||
pgdir=C:\Program files\PostgreSQL\8.0
|
||||
#pgdir=D:\postgresql-8.0.1
|
||||
|
||||
# Dynamically build against libpq.dll
|
||||
use_pg_dll=0
|
||||
|
|
207
setup.py
207
setup.py
|
@ -26,6 +26,9 @@ UPDATEs. psycopg 2 also provide full asycronous operations for the really
|
|||
brave programmer.
|
||||
"""
|
||||
|
||||
# Enable generators on Python 2.2
|
||||
from __future__ import generators
|
||||
|
||||
classifiers = """\
|
||||
Development Status :: 4 - Beta
|
||||
Intended Audience :: Developers
|
||||
|
@ -42,28 +45,164 @@ Operating System :: Microsoft :: Windows
|
|||
Operating System :: Unix
|
||||
"""
|
||||
|
||||
import sys, os.path
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
from distutils.core import setup, Extension
|
||||
from distutils.errors import DistutilsFileError
|
||||
from distutils.command.build_ext import build_ext
|
||||
from distutils.sysconfig import get_python_inc
|
||||
import distutils.ccompiler
|
||||
|
||||
PSYCOPG_VERSION = '1.99.13'
|
||||
version_flags = []
|
||||
|
||||
have_pydatetime = False
|
||||
have_mxdatetime = False
|
||||
use_pydatetime = True
|
||||
|
||||
# windows-only definitions (TODO: this should be moved to setup.cfg!)
|
||||
POSTGRESQLDIR = "D:\\POSTGRESQL-7.4.2"
|
||||
USE_PG_DLL = True
|
||||
|
||||
# to work around older distutil limitations
|
||||
if sys.version < '2.2.3':
|
||||
from distutils.dist import DistributionMetadata
|
||||
DistributionMetadata.classifiers = None
|
||||
DistributionMetadata.download_url = None
|
||||
|
||||
class psycopg_build_ext(build_ext):
|
||||
"""Conditionally complement the setup.cfg options file.
|
||||
|
||||
This class configures the include_dirs, libray_dirs, libraries options as
|
||||
required by the system. Most of the configuration happens in
|
||||
finalize_options() method.
|
||||
|
||||
If you want to set up the build step for a peculiar platform, add a method
|
||||
finalize_PLAT(), where PLAT matches your sys.platform.
|
||||
"""
|
||||
user_options = build_ext.user_options[:]
|
||||
user_options.extend([
|
||||
('pgdir=', None,
|
||||
"The postgresql directory, either source or bin"),
|
||||
('use-pg-dll', None,
|
||||
"Build against libpq.dll"),
|
||||
('use-pydatetime', None,
|
||||
"Use Python datatime objects for date and time representation.")
|
||||
])
|
||||
|
||||
boolean_options = build_ext.boolean_options[:]
|
||||
boolean_options.extend(('use-pg-dll', 'use-pydatetime'))
|
||||
|
||||
# libpq directory in win32 source distribution: compiler dependant.
|
||||
libpqdir = None
|
||||
|
||||
def initialize_options(self):
|
||||
build_ext.initialize_options(self)
|
||||
self.use_pydatetime = 1
|
||||
self.use_pg_dll = 1
|
||||
self.pgdir = None
|
||||
|
||||
def finalize_win32(self):
|
||||
"""Finalize build system configuration on win32 platform.
|
||||
|
||||
Address issues related to the different environmental configurations
|
||||
that can be met:
|
||||
* msvc or gcc derived (mingw, cygwin) compiler;
|
||||
* source or bin PostgreSQL installation
|
||||
* static or dynamic linking vs. libpq.dll
|
||||
"""
|
||||
self.include_dirs.append(".")
|
||||
self.libraries.append("ws2_32")
|
||||
|
||||
if self.build_from_src():
|
||||
self.include_dirs.append(os.path.join(
|
||||
self.pgdir, "src", "interfaces", "libpq"))
|
||||
self.include_dirs.append(os.path.join(
|
||||
self.pgdir, "src", "include"))
|
||||
|
||||
if self.compiler == "msvc":
|
||||
self.libpqdir = os.path.join(
|
||||
self.pgdir, "src", "interfaces", "libpq", "Release")
|
||||
else:
|
||||
self.libpqdir = os.path.join(
|
||||
self.pgdir, "src", "interfaces", "libpq")
|
||||
|
||||
self.library_dirs.append(self.libpqdir)
|
||||
|
||||
else:
|
||||
self.include_dirs.append(os.path.join(
|
||||
self.pgdir, "include"))
|
||||
self.library_dirs.append(os.path.join(
|
||||
self.pgdir, "lib"))
|
||||
|
||||
if self.use_pg_dll:
|
||||
self.libraries.append(self.get_lib("pqdll"))
|
||||
else:
|
||||
self.libraries.append("advapi32")
|
||||
|
||||
def finalize_darwin(self):
|
||||
"""Finalize build system configuration on darwin platform.
|
||||
|
||||
fink installs lots of goodies in /sw/... - make sure we check there
|
||||
"""
|
||||
self.include_dirs.append("/sw/include/postgresql")
|
||||
self.library_dirs.append("/sw/lib")
|
||||
self.include_dirs.append("/opt/local/include/postgresql")
|
||||
self.library_dirs.append("/opt/local/lib")
|
||||
self.library_dirs.append("/usr/lib")
|
||||
self.libraries.append('ssl')
|
||||
self.libraries.append('crypto')
|
||||
|
||||
def finalize_options(self):
|
||||
"""Complete the build system configuation."""
|
||||
build_ext.finalize_options(self)
|
||||
|
||||
self.libraries.append(self.get_lib("pq"))
|
||||
|
||||
if hasattr(self, "finalize_" + sys.platform):
|
||||
getattr(self, "finalize_" + sys.platform)()
|
||||
|
||||
def run(self):
|
||||
build_ext.run(self)
|
||||
|
||||
# Add libpq.dll to the lib directory. libpq.dll can be in a wide
|
||||
# variety of places. The easiest way to add it to the distribution is
|
||||
# to have a copy in a fixed place (lib).
|
||||
if sys.platform == 'win32' and self.use_pg_dll:
|
||||
shutil.copy(self.find_libpq_dll(), "lib")
|
||||
|
||||
def build_from_src(self):
|
||||
"""Detect if building from postgres source or bin on w32 platform"""
|
||||
return os.path.exists(os.path.join(self.pgdir, "src"))
|
||||
|
||||
def get_lib(self, name):
|
||||
"""Return the full library name given its suffix.
|
||||
|
||||
MS VC compiler doesn't assume a "lib" prefix as gcc derived ones do.
|
||||
Return the library name as required by the compiler.
|
||||
"""
|
||||
if sys.platform == 'win32' and self.compiler == "msvc":
|
||||
return "lib" + name
|
||||
else:
|
||||
return name
|
||||
|
||||
__libpqdll = None
|
||||
def find_libpq_dll(self, *dirs):
|
||||
"""Return the full libpq.dll path and name."""
|
||||
if self.__libpqdll:
|
||||
return self.__libpqdll
|
||||
|
||||
for path in self.__iter_libpq_dll():
|
||||
if os.path.exists(path):
|
||||
sys.stdout.write("libpq.dll found in %s\n"
|
||||
% os.path.dirname(path))
|
||||
self.__libpqdll = path
|
||||
return path
|
||||
|
||||
raise DistutilsFileError("Can't find libpq.dll on the system")
|
||||
|
||||
def __iter_libpq_dll(self):
|
||||
"""Iterate on the possible filenames for libpq.dll."""
|
||||
# in the build dir for src installation
|
||||
if self.libpqdir:
|
||||
yield os.path.join(self.libpqdir, "libpq.dll")
|
||||
|
||||
# somewhere in the path - probably in system32 - for bin dist
|
||||
for path in os.environ['PATH'].split(os.pathsep):
|
||||
yield os.path.join(path, "libpq.dll")
|
||||
|
||||
# let's start with macro definitions (the ones not already in setup.cfg)
|
||||
define_macros = []
|
||||
|
||||
|
@ -79,32 +218,6 @@ if sys.version_info[0] >= 2 and sys.version_info[1] >= 4:
|
|||
|
||||
# gather information to build the extension module
|
||||
ext = [] ; data_files = []
|
||||
library_dirs = [] ; libraries = [] ; include_dirs = []
|
||||
|
||||
if sys.platform == 'win32':
|
||||
include_dirs = ['.',
|
||||
POSTGRESQLDIR + "\\src\\interfaces\\libpq",
|
||||
POSTGRESQLDIR + "\\src\\include" ]
|
||||
library_dirs = [ POSTGRESQLDIR + "\\src\\interfaces\\libpq\\Release" ]
|
||||
libraries = ["ws2_32"]
|
||||
if USE_PG_DLL:
|
||||
data_files.append((".\\lib\site-packages\\",
|
||||
[POSTGRESQLDIR + "\\src\interfaces\\libpq\\Release\\libpq.dll"]))
|
||||
libraries.append("libpqdll")
|
||||
else:
|
||||
libraries.append("libpq")
|
||||
libraries.append("advapi32")
|
||||
|
||||
# extra checks on darwin
|
||||
if sys.platform == "darwin":
|
||||
# fink installs lots of goodies in /sw/... - make sure we check there
|
||||
include_dirs.append("/sw/include/postgresql")
|
||||
library_dirs.append("/sw/lib")
|
||||
include_dirs.append("/opt/local/include/postgresql")
|
||||
library_dirs.append("/opt/local/lib")
|
||||
library_dirs.append("/usr/lib")
|
||||
libraries.append('ssl')
|
||||
libraries.append('crypto')
|
||||
|
||||
# sources
|
||||
|
||||
|
@ -115,6 +228,15 @@ sources = [
|
|||
'adapter_qstring.c', 'adapter_pboolean.c', 'adapter_binary.c',
|
||||
'adapter_asis.c']
|
||||
|
||||
from ConfigParser import ConfigParser
|
||||
parser = ConfigParser()
|
||||
parser.read('setup.cfg')
|
||||
|
||||
# Choose a datetime module
|
||||
have_pydatetime = False
|
||||
have_mxdatetime = False
|
||||
use_pydatetime = int(parser.get('build_ext', 'use_pydatetime'))
|
||||
|
||||
# check for mx package
|
||||
mxincludedir = os.path.join(get_python_inc(plat_specific=1), "mx")
|
||||
if os.path.exists(mxincludedir):
|
||||
|
@ -144,9 +266,6 @@ else:
|
|||
sys.exit(1)
|
||||
|
||||
# generate a nice version string to avoid confusion when users report bugs
|
||||
from ConfigParser import ConfigParser
|
||||
parser = ConfigParser()
|
||||
parser.read('setup.cfg')
|
||||
for have in parser.get('build_ext', 'define').split(','):
|
||||
if have == 'PSYCOPG_EXTENSIONS':
|
||||
version_flags.append('ext')
|
||||
|
@ -163,16 +282,17 @@ else:
|
|||
define_macros.append(('PSYCOPG_VERSION', '\\"'+PSYCOPG_VERSION_EX+'\\"'))
|
||||
|
||||
|
||||
if sys.platform == 'win32' and int(parser.get('build_ext', 'use_pg_dll')):
|
||||
data_files.append((".\\lib\\site-packages\\psycopg\\",
|
||||
[ "lib\\libpq.dll" ]))
|
||||
|
||||
# build the extension
|
||||
|
||||
sources = map(lambda x: os.path.join('psycopg', x), sources)
|
||||
|
||||
ext.append(Extension("psycopg._psycopg", sources,
|
||||
include_dirs=include_dirs,
|
||||
library_dirs=library_dirs,
|
||||
define_macros=define_macros,
|
||||
undef_macros=[],
|
||||
libraries=libraries))
|
||||
undef_macros=[]))
|
||||
|
||||
setup(name="psycopg",
|
||||
version=PSYCOPG_VERSION,
|
||||
|
@ -190,4 +310,5 @@ setup(name="psycopg",
|
|||
data_files=data_files,
|
||||
package_dir={'psycopg':'lib'},
|
||||
packages=['psycopg'],
|
||||
cmdclass={ 'build_ext': psycopg_build_ext },
|
||||
ext_modules=ext)
|
||||
|
|
Loading…
Reference in New Issue
Block a user