Commit 5ce42539 authored by Denis Bilenko's avatar Denis Bilenko

fix setup.py to compile with libevent-2 on windows. Thanks to Luigi Pugnetti...

fix setup.py to compile with libevent-2 on windows. Thanks to Luigi Pugnetti for the original patch.

- Removed --static and --dynamic options
parent 5f35cab5
...@@ -6,30 +6,19 @@ gevent build & installation script ...@@ -6,30 +6,19 @@ gevent build & installation script
If you have more than one libevent installed or it is installed in a If you have more than one libevent installed or it is installed in a
non-standard location, use the options to point to the right dirs: non-standard location, use the options to point to the right dirs:
-Idir add include dir -IPATH add include PATH
-Ldir add library dir -LPATH add library PATH
--static link libevent statically (default on win32) --libevent PATH use libevent from PATH (implies -IPATH -IPATH/include -LPATH/.libs)
--dynamic link libevent dynamically (default on any platform other than win32)
Also,
setup.py build --libevent DIR
is a shortcut for
setup.py build -IDIR -IDIR/include LDIR/.libs
""" """
# XXX Options --static and --dynamic aren't tested for values other than theirs
# defaults (that is, --static on win32, --dynamic on everything else)
import sys import sys
import os import os
import re import re
import traceback import traceback
import glob
from distutils.command import build_ext
from distutils.core import Extension, setup from distutils.core import Extension, setup
from os.path import join, isdir, abspath, basename from os.path import join, isdir, abspath, basename, exists
__version__ = re.search("__version__\s*=\s*'(.*)'", open('gevent/__init__.py').read(), re.M).group(1) __version__ = re.search("__version__\s*=\s*'(.*)'", open('gevent/__init__.py').read(), re.M).group(1)
assert __version__ assert __version__
...@@ -39,7 +28,6 @@ include_dirs = [] # specified by -I ...@@ -39,7 +28,6 @@ include_dirs = [] # specified by -I
library_dirs = [] # specified by -L library_dirs = [] # specified by -L
libevent_source_path = None # specified by --libevent libevent_source_path = None # specified by --libevent
VERBOSE = '-v' in sys.argv VERBOSE = '-v' in sys.argv
static = sys.platform == 'win32' # set to True with --static; set to False with --dynamic
extra_compile_args = [] extra_compile_args = []
sources = ['gevent/core.c'] sources = ['gevent/core.c']
libraries = [] libraries = []
...@@ -118,7 +106,7 @@ def add_library_dir(path, must_exist=True): ...@@ -118,7 +106,7 @@ def add_library_dir(path, must_exist=True):
library_dirs.append(path) library_dirs.append(path)
# parse options: -I NAME / -INAME / -L NAME / -LNAME / --libevent DIR / --static / --dynamic # parse options: -I NAME / -INAME / -L NAME / -LNAME / --libevent DIR
# we're cutting out options from sys.path instead of using optparse # we're cutting out options from sys.path instead of using optparse
# so that these option can co-exists with distutils' options # so that these option can co-exists with distutils' options
i = 1 i = 1
...@@ -143,44 +131,59 @@ while i < len(sys.argv): ...@@ -143,44 +131,59 @@ while i < len(sys.argv):
if sys.platform == 'win32': if sys.platform == 'win32':
add_include_dir(join(libevent_source_path, 'compat'), must_exist=False) add_include_dir(join(libevent_source_path, 'compat'), must_exist=False)
add_include_dir(join(libevent_source_path, 'WIN32-Code'), must_exist=False) add_include_dir(join(libevent_source_path, 'WIN32-Code'), must_exist=False)
elif arg == '--static':
static = True
elif arg == '--dynamic':
static = False
else: else:
i += 1 i += 1
continue continue
del sys.argv[i] del sys.argv[i]
# sources used when building on windows; this includes sources of both libevent-1.4
# and libevent-2 combined, but will filter out the files that do not exist
libevent_sources = '''buffer.c
bufferevent_async.c
bufferevent.c
bufferevent_filter.c
bufferevent_pair.c
bufferevent_ratelim.c
bufferevent_sock.c
buffer_iocp.c
evbuffer.c
evdns.c
event.c
event_iocp.c
event_tagging.c
evmap.c
evrpc.c
evthread.c
evthread_win32.c
evutil.c
evutil_rand.c
http.c
listener.c
log.c
signal.c
strlcpy.c
WIN32-Code/win32.c
win32select.c'''.split()
if not sys.argv[1:] or '-h' in sys.argv or '--help' in ' '.join(sys.argv): if not sys.argv[1:] or '-h' in sys.argv or '--help' in ' '.join(sys.argv):
print __doc__ print __doc__
else: else:
if static: if sys.platform == 'win32':
if not libevent_source_path: if not libevent_source_path:
sys.exit('Please provide path to libevent source with --libevent DIR') sys.exit('Please provide path to libevent source with --libevent DIR')
extra_compile_args += ['-DHAVE_CONFIG_H'] extra_compile_args += ['-DHAVE_CONFIG_H']
libevent_sources = ['event.c', extra_compile_args += ['-DWIN32']
'buffer.c', libraries = ['wsock32', 'advapi32', 'ws2_32', 'shell32']
'evbuffer.c', include_dirs.extend([ join(libevent_source_path, 'WIN32-Code'),
'event_tagging.c', join(libevent_source_path, 'compat') ])
'evutil.c', libevent_sources = [join(libevent_source_path, filename) for filename in libevent_sources]
'log.c', libevent_sources = [filename for filename in libevent_sources if exists(filename)]
'signal.c', if not libevent_sources:
'evdns.c', sys.exit('No libevent sources found in %s' % libevent_source_path)
'http.c',
'strlcpy.c']
if sys.platform == 'win32':
libraries = ['wsock32', 'advapi32']
include_dirs.extend([ join(libevent_source_path, 'WIN32-Code'),
join(libevent_source_path, 'compat') ])
libevent_sources.append('WIN32-Code/win32.c')
extra_compile_args += ['-DWIN32']
else:
libevent_sources += ['select.c']
print 'XXX --static is not well supported on non-win32 platforms: only select is enabled'
for filename in libevent_sources: for filename in libevent_sources:
sources.append( join(libevent_source_path, filename) ) sources.append(filename)
else: else:
libraries = ['event'] libraries = ['event']
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment