-
Notifications
You must be signed in to change notification settings - Fork 27
/
setup.py
executable file
·287 lines (247 loc) · 9.22 KB
/
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/usr/bin/env python
import shutil
from distutils.core import setup, Extension
import distutils.sysconfig
import os
import stat
import commands
import sys
gnofract4d_version = '3.13'
if float(sys.version[:3]) < 2.4:
print "Sorry, you need Python 2.4 or higher to run Gnofract 4D."
print "You have version %s. Please upgrade." % sys.version
sys.exit(1)
# hack to use a different Python for building if an env var is set
# I use this to build python-2.2 and 2.4 RPMs.
build_version = os.environ.get("BUILD_PYTHON_VERSION")
build_python = os.environ.get("BUILD_PYTHON")
if build_version and build_python and sys.version[:3] != build_version:
print sys.version[:3], build_version
args = ["/usr/bin/python"] + sys.argv
print "running other Python version %s with args: %s" % (build_python,args)
os.execv(build_python, args)
from buildtools import my_bdist_rpm, my_build, my_build_ext, my_install_lib
# Extensions need to link against appropriate libs
# We use pkg-config to find the appropriate set of includes and libs
def call_package_config(package,option,optional=False):
'''invoke pkg-config, if it exists, to find the appropriate
arguments for a library'''
cmd = "pkg-config %s %s" % (package, option)
(status,output) = commands.getstatusoutput(cmd)
if status != 0:
if optional:
print >>sys.stderr, "Can't find '%s'" % package
print >>sys.stderr, "Some functionality will be disabled"
return []
else:
print >>sys.stderr, "Can't set up. Error running '%s'." % cmd
print >>sys.stderr, output
print >>sys.stderr, "Possibly you don't have one of these installed: '%s'." % package
sys.exit(1)
return output.split()
extra_macros = []
png_flags = call_package_config("libpng", "--cflags", True)
if png_flags != []:
extra_macros.append(('PNG_ENABLED', 1))
else:
print "NO PNG HEADERS FOUND"
png_libs = call_package_config("libpng", "--libs", True)
jpg_lib = "jpeg"
if os.path.isfile("/usr/include/jpeglib.h"):
extra_macros.append(('JPG_ENABLED', 1))
jpg_libs = [ jpg_lib ]
else:
print "NO JPEG HEADERS FOUND"
jpg_libs = []
#not ready yet.
have_gmp = False # os.path.isfile("/usr/include/gmp.h")
# use currently specified compilers, not ones from when Python was compiled
# this is necessary for cross-compilation
compiler = os.environ.get("CC","gcc")
cxxcompiler = os.environ.get("CXX","g++")
fract4d_sources = [
'fract4d/c/fract4dmodule.cpp',
'fract4d/c/cmap.cpp',
'fract4d/c/pointFunc.cpp',
'fract4d/c/fractFunc.cpp',
'fract4d/c/STFractWorker.cpp',
'fract4d/c/MTFractWorker.cpp',
'fract4d/c/image.cpp',
'fract4d/c/imageIO.cpp',
'fract4d/c/fract_stdlib.cpp'
]
# this is a hack to build 2 versions of the same extension.
# we want to create a standard fract4dc which doesn't depend on gmp
# and a second fract4dcgmp which does. These are both built from the
# same source files but in the latter case with USE_GMP defined
# This is so I can ship a single binary for gnofract4d which supports
# both users with GMP and users without it, by conditionally loading
# the appropriate extension
fract4d_gmp_sources = []
if(have_gmp):
for sourcefile in fract4d_sources:
# this particular part of the hack is so that each file gets
# compiled twice
gmp_sourcefile = sourcefile.replace(".cpp","_gmp.cpp")
os.system("cp %s %s" % (sourcefile, gmp_sourcefile))
fract4d_gmp_sources.append(gmp_sourcefile)
module_gmp = Extension(
'fract4d.gmpy',
sources = [
'fract4d/gmpy/gmpy.c'
],
libraries = ['gmp']
)
defines = [ ('_REENTRANT',1),
('THREADS',1),
#('STATIC_CALC',1),
#('NO_CALC', 1), # set this to not calculate the fractal
#('DEBUG_CREATION',1), # debug spew for allocation of objects
#('DEBUG_ALLOCATION',1), # debug spew for array handling
]
module_fract4dgmp = Extension(
'fract4d.fract4dcgmp',
sources = fract4d_gmp_sources,
include_dirs = [
'fract4d/c'
],
libraries = [
'stdc++', 'gmp'
] + jpg_libs,
extra_compile_args = [
'-Wall', '-Wno-strict-prototypes'
] + png_flags,
extra_link_args = png_libs,
define_macros = defines + [('USE_GMP',1)] + extra_macros,
undef_macros = [ 'NDEBUG']
)
if "win" in sys.platform:
warnings = '/W3'
libs = [ 'pthreadVC2', 'libdl' ]
osdep = [ '/DWIN32', '/DWINDOWS', '/D_USE_MATH_DEFINES', '/D_CRT_SECURE_NO_WARNINGS', '/EHsc', '/Ox' ]
osdep += [ '/I"F:/Gamma/GTK+/Win32/include/glib-2.0/"', '/I"F:/Gamma/GTK+/Win32/lib/glib-2.0/include/"' ]
extra_source = [ 'fract4d/c/win32func.cpp', 'fract4d/c/fract4d_stdlib_exports.cpp' ]
extra_link = [ '/LIBPATH:"F:/Gamma/GTK+/Win32/lib"' ]
else:
warnings = '-Wall'
libs = [ 'stdc++' ]
osdep = []
extra_source = []
extra_link = []
fract4d_sources += extra_source
module_fract4dc = Extension(
'fract4d.fract4dc',
sources = fract4d_sources,
include_dirs = [
'fract4d/c'
],
libraries = libs + jpg_libs,
#library_dirs=['/home/edwin/gnofract4d'],
extra_compile_args = [
warnings,
] + osdep + png_flags,
extra_link_args = extra_link + png_libs,
define_macros = defines + extra_macros,
#undef_macros = [ 'NDEBUG'],
)
module_cmap = Extension(
'fract4d.fract4d_stdlib',
sources = [
'fract4d/c/cmap.cpp',
'fract4d/c/image.cpp',
'fract4d/c/fract_stdlib.cpp'
] + extra_source,
include_dirs = [
'fract4d/c'
],
libraries = libs,
extra_link_args = extra_link,
define_macros = [ ('_REENTRANT', 1)]
)
modules = [module_fract4dc, module_cmap]
if have_gmp:
modules.append(module_fract4dgmp)
modules.append(module_gmp)
def get_files(dir,ext):
return [ os.path.join(dir,x) for x in os.listdir(dir) if x.endswith(ext)]
setup (name = 'gnofract4d',
version = gnofract4d_version,
description = 'A program to draw fractals',
long_description = \
'''Gnofract 4D is a fractal browser. It can generate many different fractals,
including some which are hybrids between the Mandelbrot and Julia sets,
and includes a Fractint-compatible parser for your own fractal formulas.''',
author = 'Tim Whidbey',
author_email = '[email protected]',
maintainer = 'Tim whidbey',
maintainer_email = '[email protected]',
keywords = "fractal Mandelbrot Julia fractint chaos",
url = 'http://gnofract4d.sourceforge.net/',
packages = ['fract4d', 'fract4dgui', 'fractutils'],
package_data = { 'fract4dgui' : [ 'ui.xml'] },
ext_modules = modules,
scripts = ['gnofract4d'],
data_files = [
# color maps
('share/gnofract4d/maps',
get_files("maps",".map") +
get_files("maps",".cs") +
get_files("maps", ".ugr")),
# formulas
('share/gnofract4d/formulas',
get_files("formulas","frm") +
get_files("formulas", "ucl") +
get_files("formulas", "uxf")),
# documentation
('share/gnome/help/gnofract4d/C',
get_files("doc/gnofract4d-manual/C", "xml")),
('share/gnome/help/gnofract4d/C/figures',
get_files("doc/gnofract4d-manual/C/figures",".png")),
('share/gnome/help/gnofract4d/C',
get_files("doc/gnofract4d-manual/C", "html")),
('share/gnome/help/gnofract4d/C',
get_files("doc/gnofract4d-manual/C",".css")),
#internal pixmaps
('share/pixmaps/gnofract4d',
['pixmaps/improve_now.png',
'pixmaps/explorer_mode.png']),
# icon
('share/pixmaps',
['pixmaps/gnofract4d-logo.png']),
# .desktop file
('share/applications', ['gnofract4d.desktop']),
# MIME type registration
('share/mime/packages', ['gnofract4d-mime.xml']),
# doc files
('share/doc/gnofract4d/',
['COPYING', 'README']),
],
cmdclass={
"my_bdist_rpm": my_bdist_rpm.my_bdist_rpm,
"build" : my_build.my_build,
"my_build_ext" : my_build_ext.my_build_ext,
"install_lib" : my_install_lib.my_install_lib
}
)
# I need to find the file I just built and copy it up out of the build
# location so it's possible to run without installing. Can't find a good
# way to extract the actual target directory out of distutils, hence
# this egregious hack
so_extension = distutils.sysconfig.get_config_var("SO")
lib_targets = {
"fract4dc" + so_extension : "fract4d",
"fract4d_stdlib" + so_extension : "fract4d",
"fract4dcgmp" + so_extension : "fract4d",
"gmpy" + so_extension: "fract4d"
}
if 'win' in sys.platform:
lib_targets["fract4d_stdlib.lib"] = "fract4d"
def copy_libs(dummy,dirpath,namelist):
for name in namelist:
target = lib_targets.get(name)
if target != None:
name = os.path.join(dirpath, name)
shutil.copy(name, target)
os.path.walk("build",copy_libs,None)
if 'win' in sys.platform:
shutil.copy("fract4d/fract4d_stdlib.pyd", "fract4d_stdlib.pyd")