-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
420 lines (365 loc) · 15.1 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#!/usr/bin/env python
#
# Setup script for sK1 0.9.x
#
# Copyright (C) 2007-2015 Igor E. Novikov
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
"""
Usage:
--------------------------------------------------------------------------
to build package: python setup.py build
to install package: python setup.py install
to remove installation: python setup.py uninstall
--------------------------------------------------------------------------
to create source distribution: python setup.py sdist
--------------------------------------------------------------------------
to create binary RPM distribution: python setup.py bdist_rpm
--------------------------------------------------------------------------
to create binary DEB distribution: python setup.py bdist_deb
--------------------------------------------------------------------------.
Help on available distribution formats: --help-formats
"""
import os, sys
import libutils
from libutils import make_source_list, DEB_Builder
############################################################
#
# Flags
#
############################################################
UPDATE_MODULES = False
DEB_PACKAGE = False
CLEAR_BUILD = False
LCMS2 = True
############################################################
#
# Package description
#
############################################################
NAME = 'sk1'
VERSION = '0.9.3'
DESCRIPTION = 'Vector graphics editor for prepress'
AUTHOR = 'Igor E. Novikov'
AUTHOR_EMAIL = 'igor.e.novikov@gmail.com'
MAINTAINER = AUTHOR
MAINTAINER_EMAIL = AUTHOR_EMAIL
LICENSE = 'LGPL v2'
URL = 'http://sk1project.org'
DOWNLOAD_URL = URL
CLASSIFIERS = [
'Development Status :: 5 - Stable',
'Environment :: Desktop',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: LGPL v2',
'Operating System :: POSIX',
'Programming Language :: Python',
'Programming Language :: Tcl',
'Programming Language :: C',
"Topic :: Multimedia :: Graphics :: Editors :: Vector-Based",
]
LONG_DESCRIPTION = '''
sK1 is an open source vector graphics editor similar to CorelDRAW,
Adobe Illustrator, or Freehand. First of all sK1 is oriented for prepress
industry, therefore works with CMYK colorspace and produces CMYK-based PDF
and postscript output.
sK1 Project (http://sk1project.org),
Copyright (C) 2007-2015 by Igor E. Novikov
'''
LONG_DEB_DESCRIPTION = ''' .
sK1 is an open source vector graphics editor similar to CorelDRAW,
Adobe Illustrator, or Freehand. First of all sK1 is oriented for prepress
industry, therefore works with CMYK colorspace and produces CMYK-based PDF
and postscript output.
.
sK1 Project (http://sk1project.org),
Copyright (C) 2007-2015 by Igor E. Novikov
.
'''
############################################################
#
# Build data
#
############################################################
install_path = '/usr/lib/%s-tk-%s' % (NAME, VERSION)
os.environ["SK1_INSTALL_PATH"] = "%s" % (install_path,)
src_path = 'src'
include_path = '/usr/include'
modules = []
scripts = ['src/script/sk1', ]
deb_scripts = []
data_files = [
('/usr/share/applications', ['src/sk1.desktop', ]),
('/usr/share/pixmaps', ['src/sk1.png', 'src/sk1.xpm', ]),
]
deb_depends = 'libxcursor1, libxext6, python-tk, python-gtk2, python-imaging'
deb_depends += ', python-cairo, python-reportlab'
dirs = libutils.get_dirs_tree('src/sk1/share')
share_dirs = []
for item in dirs: share_dirs.append(os.path.join(item[8:], '*.*'))
share_dirs += ['GNU_GPL_v2', 'GNU_LGPL_v2', 'COPYRIGHTS']
dirs = libutils.get_dirs_tree('src/sk1sdk/tkstyle')
share_dirs_sdk = []
for item in dirs: share_dirs_sdk.append(os.path.join(item[11:], '*.*'))
share_dirs_sdk.append('tcl/*.*')
package_data = {
'sk1': share_dirs,
'sk1sdk.tkpng': ['pkgIndex.tcl', ],
'sk1sdk': share_dirs_sdk,
'uc':['cms/profiles/*.*'],
}
#Preparing start script
fileptr = open('src/script/sk1.tmpl', 'rb')
fileptr2 = open('src/script/sk1', 'wb')
while True:
line = fileptr.readline()
if line == '': break
if '$SK1_INSTALL_PATH' in line:
line = line.replace('$SK1_INSTALL_PATH', install_path)
fileptr2.write(line)
else:
fileptr2.write(line)
fileptr.close()
fileptr2.close()
#Fix for Debian based distros
tcl_include_dirs = []
tcl_ver = ''
if os.path.isdir('/usr/include/tcl8.5'):
tcl_include_dirs = ['/usr/include/tcl8.5']
tcl_ver = '8.5'
if os.path.isdir('/usr/include/tcl8.6'):
tcl_include_dirs = ['/usr/include/tcl8.6']
tcl_ver = '8.6'
#Fix for osx
if os.path.isdir('/usr/local/lib/tcl8.5'):
tcl_include_dirs = ['/usr/local/lib/tcl8.5']
tcl_ver = '8.5'
if os.path.isdir('/usr/local/lib/tcl8.6'):
tcl_include_dirs = ['/usr/local/lib/tcl8.6']
tcl_ver = '8.6'
#Fix for OpenSuse
if not tcl_ver:
if os.path.isfile('/usr/lib/libtcl8.5.so'):
tcl_ver = '8.5'
if os.path.isfile('/usr/lib/libtcl8.6.so'):
tcl_ver = '8.6'
#Fix for Fedora
if not tcl_ver:
if os.path.isfile('/usr/lib64/libtcl8.5.so'):
tcl_ver = '8.5'
if os.path.isfile('/usr/lib64/libtcl8.6.so'):
tcl_ver = '8.6'
if not tcl_ver:
print 'System tcl/tk =>8.5 libraries have not found!'
sys.exit(1)
############################################################
#
# Main build procedure
#
############################################################
if len(sys.argv) == 1:
print 'Please specify build options!'
print __doc__
sys.exit(0)
if len(sys.argv) > 1:
if sys.argv[1] == 'bdist_rpm':
CLEAR_BUILD = True
if sys.argv[1] == 'build_update':
UPDATE_MODULES = True
CLEAR_BUILD = True
sys.argv[1] = 'build'
if sys.argv[1] == 'bdist_deb':
DEB_PACKAGE = True
CLEAR_BUILD = True
sys.argv[1] = 'build'
if len(sys.argv) > 2 and '--lcms2' in sys.argv:
LCMS2 = True
sys.argv.remove('--lcms2')
if len(sys.argv) > 2 and '--lcms1' in sys.argv:
LCMS2 = False
sys.argv.remove('--lcms1')
if sys.argv[1] == 'uninstall':
if os.path.isdir(install_path):
#removing sk1 folder
print 'REMOVE: ' + install_path
os.system('rm -rf ' + install_path)
#removing scripts
for item in scripts:
filename = os.path.basename(item)
print 'REMOVE: /usr/bin/' + filename
os.system('rm -rf /usr/bin/' + filename)
#removing data files
for item in data_files:
location = item[0]
file_list = item[1]
for file_item in file_list:
filename = os.path.basename(file_item)
filepath = os.path.join(location, filename)
print 'REMOVE: ' + filepath
os.system('rm -rf ' + filepath)
print 'Desktop database update: ',
os.system('update-desktop-database')
print 'DONE!'
else:
print 'sK1 installation is not found!'
sys.exit(0)
from distutils.core import setup, Extension
macros = [('MAJOR_VERSION', '1'), ('MINOR_VERSION', '0')]
paxtkinter_src = os.path.join(src_path, 'extensions', 'paxtkinter')
files = make_source_list(paxtkinter_src, ['paxtkinter.c'])
paxtkinter_module = Extension('app.paxtkinter',
include_dirs=tcl_include_dirs,
libraries=['tk' + tcl_ver, 'tcl' + tcl_ver],
define_macros=macros, sources=files)
modules.append(paxtkinter_module)
filter_src = os.path.join(src_path, 'extensions', 'filter')
files = ['streamfilter.c', 'filterobj.c', 'linefilter.c',
'subfilefilter.c', 'base64filter.c', 'nullfilter.c',
'stringfilter.c', 'binfile.c', 'hexfilter.c']
files = make_source_list(filter_src, files)
filter_module = Extension('streamfilter',
define_macros=macros, sources=files)
modules.append(filter_module)
type1mod_src = os.path.join(src_path, 'extensions', 'type1mod')
files = make_source_list(type1mod_src, ['_type1module.c', ])
type1mod_module = Extension('app._type1module',
define_macros=macros, sources=files)
modules.append(type1mod_module)
skread_src = os.path.join(src_path, 'extensions', 'skread')
files = make_source_list(skread_src, ['skreadmodule.c', ])
skread_module = Extension('app.skreadmodule',
define_macros=macros, sources=files)
modules.append(skread_module)
pstokenize_src = os.path.join(src_path, 'extensions', 'pstokenize')
files = make_source_list(pstokenize_src, ['pstokenize.c', 'pschartab.c'])
pstokenize_module = Extension('app.pstokenize',
define_macros=macros, sources=files)
modules.append(pstokenize_module)
pax_src = os.path.join(src_path, 'extensions', 'pax')
pax_include_dirs = ['/usr/include/cairo'] + tcl_include_dirs
pax_libs = ['X11', 'Xext', 'tk' + tcl_ver, 'tcl' + tcl_ver, 'cairo']
files = ['borderobject.c', 'clipmask.c', 'cmapobject.c', 'fontobject.c',
'gcobject.c', 'imageobject.c', 'intl.c', 'paxmodule.c', 'paxutil.c',
'pixmapobject.c', 'regionobject.c', 'tkwinobject.c']
files = make_source_list(pax_src, files)
pax_module = Extension('paxmodule',
include_dirs=pax_include_dirs, libraries=pax_libs,
define_macros=macros, sources=files)
modules.append(pax_module)
skmod_src = os.path.join(src_path, 'extensions', 'skmod')
files = ['curvedraw.c', 'curvefunc.c', 'curvelow.c', 'curvemisc.c',
'curveobject.c', 'skaux.c', 'skcolor.c', 'skdither.c', '_sketchmodule.c',
'skfm.c', 'skimage.c', 'skpoint.c', 'skrect.c', 'sktrafo.c']
files = make_source_list(skmod_src, files)
skmod_module = Extension('app._sketchmodule',
include_dirs=['/usr/include/cairo'], libraries=['m', 'X11', 'cairo'],
define_macros=macros, sources=files)
modules.append(skmod_module)
#--- sk1sdk extensions
tkpng_src = os.path.join(src_path, 'sk1sdk', 'tkpng', 'libtkpng')
files = make_source_list(tkpng_src, ['tkImgPNG.c', 'tkImgPNGInit.c'])
tkpng_module = Extension('sk1sdk.tkpng.libtkpng',
include_dirs=tcl_include_dirs,
libraries=['tk' + tcl_ver, 'tcl' + tcl_ver, 'z'],
define_macros=macros, sources=files)
modules.append(tkpng_module)
tkXcursor_src = os.path.join(src_path, 'sk1sdk', 'tkXcursor')
files = make_source_list(tkXcursor_src, ['_tkXcursor.c'])
tkXcursor_module = Extension('sk1sdk.tkXcursor._tkXcursor',
include_dirs=['/usr/include/X11/Xcursor'] + tcl_include_dirs,
libraries=['tk' + tcl_ver, 'tcl' + tcl_ver, 'Xcursor'],
define_macros=macros, sources=files)
modules.append(tkXcursor_module)
tkcairo_src = os.path.join(src_path, 'sk1sdk', 'tkcairo')
files = make_source_list(tkcairo_src, ['_tkcairo.c'])
tkcairo_module = Extension('sk1sdk.tkcairo._tkcairo',
include_dirs=['/usr/include/cairo'] + tcl_include_dirs,
libraries=['tk' + tcl_ver, 'tcl' + tcl_ver, 'cairo'],
define_macros=macros, sources=files)
modules.append(tkcairo_module)
#--- uc extensions
cms_src = os.path.join(src_path, 'uc', 'cms')
libs = ['lcms2', ]
if LCMS2:
files = make_source_list(cms_src, ['_cms2.c', ])
deb_depends = 'liblcms2-2, ' + deb_depends
else:
files = make_source_list(cms_src, ['_cms.c', ])
deb_depends = 'liblcms1, ' + deb_depends
libs = ['lcms', ]
cms_module = Extension('uc.cms._cms',
define_macros=macros, sources=files,
libraries=libs, extra_compile_args=["-Wall"])
modules.append(cms_module)
cairo_src = os.path.join(src_path, 'uc', 'libcairo')
files = make_source_list(cairo_src, ['_libcairo.c', ])
include_dirs = make_source_list(include_path, ['cairo', 'pycairo'])
cairo_module = Extension('uc.libcairo._libcairo',
define_macros=[('MAJOR_VERSION', '1'), ('MINOR_VERSION', '0')],
sources=files, include_dirs=include_dirs,
libraries=['cairo'])
modules.append(cairo_module)
#---
setup(name=NAME,
version=VERSION,
description=DESCRIPTION,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
license=LICENSE,
url=URL,
download_url=DOWNLOAD_URL,
long_description=LONG_DESCRIPTION,
classifiers=CLASSIFIERS,
packages=libutils.get_source_structure(),
package_dir=libutils.get_package_dirs(),
package_data=package_data,
data_files=data_files,
scripts=scripts,
ext_modules=modules)
#################################################
# .py source compiling
#################################################
libutils.compile_sources()
##############################################
# This section for developing purpose only
# Command 'python setup.py build_update' allows
# automating build and native extension copying
# into package directory
##############################################
if UPDATE_MODULES: libutils.copy_modules(modules)
#################################################
# Implementation of bdist_deb command
#################################################
if DEB_PACKAGE:
bld = DEB_Builder(name=NAME,
version=VERSION,
maintainer='%s <%s>' % (AUTHOR, AUTHOR_EMAIL),
depends=deb_depends,
homepage=URL,
description=DESCRIPTION,
long_description=LONG_DEB_DESCRIPTION,
package_dirs=libutils.get_package_dirs(),
package_data=package_data,
scripts=scripts,
data_files=data_files,
deb_scripts=deb_scripts,
dst=install_path)
bld.build()
if CLEAR_BUILD:
libutils.clear_build()
os.system('rm -rf MANIFEST')