forked from fract4d/gnofract4d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·259 lines (222 loc) · 7.9 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
#!/usr/bin/env python3
from buildtools import my_install_lib
from distutils.core import setup, Extension
import distutils.sysconfig
import os
import shutil
import subprocess
import sys
gnofract4d_version = '4.0'
if sys.version_info < (3, 5):
print("Sorry, you need Python 3.5 or higher to run Gnofract 4D.")
print("You have version %s. Please upgrade." % sys.version)
sys.exit(1)
if not os.path.exists(os.path.join(distutils.sysconfig.get_python_inc(), "Python.h")):
print("Python header files are required.")
print("Please install libpython3-dev")
sys.exit(1)
# by default python uses all the args which were used to compile it. But Python is C and some
# extension files are C++, resulting in annoying '-Wstrict-prototypes is not supported' messages.
# tweak the cflags to override
os.environ["CFLAGS"] = distutils.sysconfig.get_config_var(
"CFLAGS").replace("-Wstrict-prototypes", "")
os.environ["OPT"] = distutils.sysconfig.get_config_var(
"OPT").replace("-Wstrict-prototypes", "")
# 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'''
try:
cp = subprocess.run(["pkg-config", package, option],
universal_newlines=True, stdout=subprocess.PIPE)
except FileNotFoundError:
print("Unable to check for %s, pkg-config not installed" %
package, file=sys.stderr)
if optional:
return []
else:
sys.exit(1)
if cp.returncode != 0:
if optional:
print("Can't find '%s'" % package, file=sys.stderr)
print("Some functionality will be disabled", file=sys.stderr)
return []
else:
print("Development files not found for: '%s'." %
package, file=sys.stderr)
sys.exit(1)
return cp.stdout.split()
png_flags = call_package_config("libpng", "--cflags")
png_libs = call_package_config("libpng", "--libs")
extra_macros = [('PNG_ENABLED', 1)]
jpg_lib = "jpeg"
for path in "/usr/include/jpeglib.h", "/usr/local/include/jpeglib.h":
if os.path.isfile(path):
extra_macros.append(('JPG_ENABLED', 1))
jpg_libs = [jpg_lib]
break
else:
raise SystemExit("NO JPEG HEADERS FOUND, you need to install libjpeg-dev")
fract4d_sources = [
'fract4d/c/fract4dmodule.cpp',
'fract4d/c/fract4dc/colormaps.cpp',
'fract4d/c/fract4dc/loaders.cpp',
'fract4d/c/fract4dc/sites.cpp',
'fract4d/c/fract4dc/images.cpp',
'fract4d/c/fract4dc/calcs.cpp',
'fract4d/c/fract4dc/workers.cpp',
'fract4d/c/fract4dc/functions.cpp',
'fract4d/c/fract4dc/arenas.cpp',
'fract4d/c/fract4dc/utils.cpp',
'fract4d/c/model/calcargs.cpp',
'fract4d/c/model/calcfunc.cpp',
'fract4d/c/model/fractfunc.cpp',
'fract4d/c/model/site.cpp',
'fract4d/c/model/image.cpp',
'fract4d/c/model/imagewriter.cpp',
'fract4d/c/model/imagereader.cpp',
'fract4d/c/model/colormap.cpp',
'fract4d/c/model/worker.cpp',
'fract4d/c/model/STFractWorker.cpp',
'fract4d/c/model/MTFractWorker.cpp',
'fract4d/c/model/pointfunc.cpp',
'fract4d/c/model/stats.cpp',
'fract4d/c/colorutils.cpp',
'fract4d/c/fract_stdlib.cpp'
]
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
]
libraries = ['stdc++']
extra_compile_args = ['-Wall', '-O0'] + png_flags
define_macros = defines + extra_macros
module_fract4dc = Extension(
name='fract4d.fract4dc',
sources=fract4d_sources,
include_dirs=['fract4d/c', 'fract4d/c/fract4dc', 'fract4d/c/model'],
libraries=libraries + jpg_libs,
extra_compile_args=extra_compile_args,
extra_link_args=png_libs,
define_macros=define_macros,
#undef_macros = [ 'NDEBUG'],
)
module_cmap = Extension(
'fract4d.fract4d_stdlib',
sources=[
'fract4d/c/colorutils.cpp',
'fract4d/c/model/colormap.cpp',
'fract4d/c/model/image.cpp',
'fract4d/c/fract_stdlib.cpp'
],
include_dirs=['fract4d/c', 'fract4d/c/model'],
libraries=libraries,
define_macros=[('_REENTRANT', 1)]
)
modules = [module_fract4dc, module_cmap]
def get_files(dir, ext):
return [os.path.join(dir, x) for x in os.listdir(dir) if x.endswith(ext)]
so_extension = distutils.sysconfig.get_config_var("EXT_SUFFIX")
with open("fract4d/c/cmap_name.h", "w") as fh:
fh.write("""
#ifndef CMAP_NAME
#define CMAP_NAME "/fract4d_stdlib%s"
#endif
""" % so_extension)
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='Edwin Young',
author_email='[email protected]',
maintainer='Edwin Young',
maintainer_email='[email protected]',
keywords="[email protected]",
url='http://github.com/edyoung/gnofract4d/',
packages=['fract4d_compiler', 'fract4d', 'fract4dgui'],
package_data={'fract4dgui': ['shortcuts-gnofract4d.ui', 'ui.xml']},
ext_modules=modules,
scripts=['gnofract4d'],
data_files=[
# style CSS
('share/gnofract4d', ['gnofract4d.css']),
# 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/gnofract4d/pixmaps',
[
'pixmaps/improve_now.png',
'pixmaps/explorer_mode.png',
'pixmaps/mail-forward.png',
'pixmaps/draw-brush.png',
'pixmaps/face-sad.png',
'pixmaps/autozoom.png',
'pixmaps/randomize_colors.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/', ['LICENSE', 'README.md']),
],
cmdclass={
"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
lib_targets = {
"fract4dc" + so_extension: "fract4d",
"fract4d_stdlib" + so_extension: "fract4d",
}
def copy_libs(root, dirlist, namelist):
for name in namelist:
target = lib_targets.get(name)
if target is not None:
shutil.copy(os.path.join(root, name), target)
for root, dirs, files in os.walk("build"):
copy_libs(root, dirs, files)