-
Notifications
You must be signed in to change notification settings - Fork 26
/
pyglpk_setup.py
100 lines (86 loc) · 3.49 KB
/
pyglpk_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from distutils.core import setup, Extension
import sys, os, os.path, re
useparams = False
sources = 'glpk lp barcol bar obj util kkt tree environment'
source_roots = sources.split()
if useparams: source_roots.append('params')
# This build process will not work with anything prior to GLPK 4.16,
# since there were many notable changes in GLPK including,
# importantly, something which actually contains the version number.
libdirs, incdirs, extraobs = [], [], []
# The glpver argument is one which is used only for the purposes of
# PyGLPK development, and will be of no use or interest to the
# standard practitioner. In order to assure compatibility with the
# many GLPK versions which exist, it is helpful to build against one
# of many
# This is very dirty.
m = re.match('glpver=(\d+)', sys.argv[-1])
if m:
# We have defined that we want to build to a local GLPK version.
minor_version = int(m.group(1))
assert minor_version >= 16
sys.argv = sys.argv[:-1]
libdirs.append(os.path.join('locals', '4.%d'%minor_version, 'lib'))
incdirs.append(os.path.join('locals', '4.%d'%minor_version, 'include'))
if minor_version<37:
libs = ['glpk.0.%d.0'%(minor_version-15)]
else:
libs = ['glpk.0']
print (libdirs, incdirs)
else:
# Try to get which is the executable path, and infer additional
# library and include directories from there, based on a call to
# whatever glpsol we find.
glpsol_path = os.popen('which glpsol').read().strip()
# If we can't find it, just hope that the default libs are correct.
if glpsol_path:
glpsol_path = os.path.abspath(glpsol_path)
head, tail = os.path.split(glpsol_path)
head, tail = os.path.split(head)
libdirs.append(os.path.join(head, 'lib'))
incdirs.append(os.path.join(head, 'include'))
# USERS DO CUSTOM INSTRUCTIONS HERE
# Perhaps set your libdir manually in case neither system defaults,
# nor the cleverness does not work.
#libs = ['glpk.something']
#libdirs = ['/my/dirs/are/here/lib']
#incdirs = ['/my/dirs/are/here/include']
# If the user did not define libraries themselves, set that up. We
# require both glpk and gmp.
try:
libs
except NameError:
# The user nor test code did not set libs up yet.
libs = ['glpk', 'gmp']
incdirs.append('src')
macros = []
if useparams: macros.append(('USEPARAMS', None))
# Now, finally, define that module!
module1 = Extension(
'glpk',
sources = [os.path.join('src',r+'.c') for r in source_roots],
define_macros = macros, extra_compile_args=['-m64'], extra_link_args=['-m64'],
library_dirs = libdirs, include_dirs = incdirs,
libraries = libs, extra_objects = extraobs)
ld = """The PyGLPK module gives one access to the functionality
of the GNU Linear Programming Kit.
"""
setup(name = 'glpk',
version = '0.3',
description = 'PyGLPK, a Python module encapsulating GLPK.',
long_description = ld,
author = 'Thomas Finley',
author_email = '[email protected]',
url = 'http://tfinley.net/software/pyglpk/',
license = 'GPL',
classifiers = [
'Development Status :: 3 - Alpha',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Programming Language :: C',
'Programming Language :: Python',
'Operating System :: POSIX',
'Operating System :: MacOS :: MacOS X',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Software Development :: Libraries :: Python Modules' ],
ext_modules = [module1])