Setting version to 1.29.0.
[gammu.git] / python / setup.py
blob922ee512535a5fca987aaad60fa5148be2fae1a4
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 # vim: expandtab sw=4 ts=4 sts=4:
4 '''
5 python-gammu - Phone communication libary
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright © 2003 - 2010 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 '''
26 import distutils
27 import distutils.sysconfig
28 import distutils.cygwinccompiler
29 import distutils.command.build
30 import distutils.command.build_ext
31 import distutils.command.install
32 import distutils.command.bdist_wininst
33 from distutils.core import setup, Extension
34 from commands import getstatusoutput
35 import sys
36 import os
37 import os.path
38 import re
39 import datetime
40 import string
42 # some defines
43 VERSION = '1.29.0'
44 VERSION_TUPLE = tuple(map(int, VERSION.split('.')))
45 GAMMU_REQUIRED = VERSION_TUPLE
46 PYTHON_REQUIRED = (2,3)
48 ADDITIONAL_PARAMS = [
49 ('skip-deps', 's', 'skip checking for dependencies'),
50 ('pkgconfig=', 'p', 'path to pkg-config binary'),
51 ('pkgconfig-search-path=', 'P', 'path where pkg-config searches for installed packages'),
52 ('gammu-libs=', None, 'path to libGammu'),
53 ('gammu-incs=', None, 'path to gammu.h include'),
54 ('gammu-cfg=', None, 'path to gammu-config.h include'),
55 ('gammu-build=', None, 'path where gammu library has been built'),
58 class build_ext_gammu(distutils.command.build_ext.build_ext, object):
59 """
60 Custom build_ext command with dependency checking support.
61 """
62 user_options = distutils.command.build_ext.build_ext.user_options + ADDITIONAL_PARAMS
63 boolean_options = distutils.command.build_ext.build_ext.boolean_options + ['skip-deps']
64 linklibs = []
66 def initialize_options(self):
67 super(build_ext_gammu, self).initialize_options()
68 self.skip_deps = False
69 self.pkgconfig = 'pkg-config'
70 self.pkgconfig_search_path = None
71 self.gammu_libs = None
72 self.gammu_incs = None
73 self.gammu_cfg = None
74 self.gammu_build = None
76 def do_pkgconfig(self, cmd):
77 prefix = ''
78 if self.pkgconfig_search_path is not None:
79 prefix = 'PKG_CONFIG_PATH="%s" ' % self.pkgconfig_search_path
80 return getstatusoutput(prefix + 'pkg-config %s' % cmd)
82 def pkg_exists(self, name):
83 output = self.do_pkgconfig('--exists %s' % name)
84 if output[0] != 0:
85 if self.pkgconfig_search_path is None:
86 self.pkgconfig_search_path = '/usr/local/lib/pkgconfig'
87 print 'Package %s not found, adding %s to pkg-config search path' % \
88 (name, self.pkgconfig_search_path)
89 output = self.do_pkgconfig('--exists %s' % name)
90 if output[0] == 0:
91 return True
92 print 'ERROR: Could not find package %s!' % name
93 return False
95 def check_version(self, name, version):
96 output = self.do_pkgconfig('--modversion %s' % name)
97 distutils.log.info('found %s version %s' % (name, output[1]))
98 pkc_version = tuple(map(int, output[1].split('.')))
99 if pkc_version >= version:
100 return True
101 print 'ERROR: Package %s is too old!' % name
102 print ' You need version %s, but %s is installed' % \
103 ('.'.join(map(str, version)), '.'.join(map(str, pkc_version)))
104 return False
106 def get_pkg_include_dirs(self, name):
107 output = self.do_pkgconfig('--cflags-only-I %s' % name)
108 if output[0] != 0:
109 return None
110 return output[1].replace('-I', '').split()
112 def get_pkg_libraries(self, name):
113 output = self.do_pkgconfig('--libs-only-l %s' % name)
114 if output[0] != 0:
115 return None
116 return output[1].replace('-l', '').split()
118 def get_pkg_library_dirs(self, name):
119 output = self.do_pkgconfig('--libs-only-L %s' % name)
120 if output[0] != 0:
121 return None
122 return output[1].replace('-L', '').split()
124 def check_pkgconfig(self):
125 res = self.do_pkgconfig('--version')
126 if res[0] != 0:
127 print "ERROR: Could not find pkg-config!"
128 sys.exit(1)
130 def check_gammu(self):
131 if not self.pkg_exists('gammu') or not self.check_version('gammu', GAMMU_REQUIRED):
132 print '\nYou need installed gammu and enabled pkg-config to find it.'
133 print
134 print 'This is done by invoking make install in gammu sources.'
135 print
136 print 'If package was installed to other prefix, please use'
137 print '--pkgconfig-search-path=<install_prefix>/lib/pkgconfig'
138 print
139 print 'If you get this error when invoking setup.py install, you can'
140 print 'try to ignore this with --skip-deps'
141 print
142 sys.exit(1)
144 def read_gammu_version(self, path):
145 try:
146 distutils.log.info('checking for gammu-config.h in %s' % path)
147 config_h = os.path.join(path, 'gammu-config.h')
148 content = file(config_h).read()
149 return re.search('VERSION "([^"]*)"', content)
150 except IOError:
151 return None
153 def check_includedir(self):
154 self.gammu_incs = os.path.expanduser(self.gammu_incs)
156 found = None
158 if self.gammu_cfg is not None:
159 found = self.read_gammu_version(self.gammu_cfg)
160 if found is None:
161 self.gammu_cfg = None
163 if found is None:
164 found = self.read_gammu_version(self.gammu_incs)
166 # Old build system
167 if found is None:
168 found = self.read_gammu_version(os.path.join(self.gammu_incs, '..', 'cfg'))
170 if found == None:
171 print 'WARNING: Can not read version from gammu-config.h!'
172 self.gammu_incs = None
173 return False
175 found = found.groups()
177 if len(found) != 1:
178 print 'WARNING: Can not read version from gammu-config.h!'
179 self.gammu_incs = None
180 return False
182 cfg_version = tuple(map(int, found[0].split('.')))
184 if cfg_version < GAMMU_REQUIRED:
185 print "ERROR: Too old version of Gammu"
186 print " Need %s, but %s is installed" % \
187 ('.'.join(map(str, GAMMU_REQUIRED)),
188 ('.'.join(map(str, cfg_version))))
189 sys.exit(1)
191 return True
193 def check_libs(self):
194 self.gammu_libs = os.path.expanduser(self.gammu_libs)
195 self.linklibs.append('Gammu')
196 self.linklibs.append('gsmsd')
197 if sys.platform == 'win32':
198 self.linklibs.append('wsock32')
199 self.linklibs.append('ws2_32')
200 self.linklibs.append('setupapi')
201 self.linklibs.append('advapi32')
203 def process_build_tree(self):
204 if not os.path.exists(os.path.join(self.gammu_build, 'CMakeCache.txt')):
205 self.gammu_build = os.path.join(self.gammu_build, 'build-configure')
206 if not os.path.exists(os.path.join(self.gammu_build, 'CMakeCache.txt')):
207 distutils.log.info('Could not find CMake build files.')
208 distutils.log.info('You are probably using too old Gammu version!')
209 sys.exit(1)
211 distutils.log.info('Detected CMake style build tree')
212 # We will use pkgconfig for detecting rest.
213 self.pkgconfig_search_path = os.path.join(self.gammu_build, 'pkgconfig')
215 def check_requirements(self):
216 if sys.version_info < PYTHON_REQUIRED:
217 print 'You need python %s to compile this!' % '.'.join(map(str, PYTHON_REQUIRED))
218 sys.exit(1)
220 if self.gammu_build is not None:
221 self.process_build_tree()
223 if self.gammu_incs is not None:
224 if not self.check_includedir():
225 print "ERROR: Could not determine gammu sources version!"
226 sys.exit(1)
228 if self.gammu_libs is not None:
229 self.check_libs()
231 if self.gammu_libs is None or self.gammu_incs is None:
232 self.check_pkgconfig()
233 self.check_gammu()
234 if self.gammu_libs is None:
235 self.linklibs += self.get_pkg_libraries('gammu')
236 self.gammu_libs = self.get_pkg_library_dirs('gammu')
237 if self.gammu_incs is None:
238 self.gammu_incs = self.get_pkg_include_dirs('gammu')
240 if self.gammu_cfg is not None:
241 self.include_dirs.append(self.gammu_cfg)
243 if type(self.gammu_incs) is str:
244 self.include_dirs.append(self.gammu_incs)
245 else:
246 self.include_dirs += self.gammu_incs
248 self.include_dirs.append('./include')
250 if type(self.gammu_libs) is str:
251 self.library_dirs.append(self.gammu_libs)
252 else:
253 self.library_dirs += self.gammu_libs
255 if type(self.linklibs) is str:
256 self.libraries.append(self.linklibs)
257 else:
258 self.libraries += self.linklibs
260 def run (self):
261 if not self.skip_deps:
262 self.check_requirements()
263 super(build_ext_gammu, self).run()
265 gammumodule = Extension('gammu._gammu',
266 include_dirs = ['.'],
267 sources = [
268 'gammu/src/errors.c',
269 'gammu/src/data.c',
270 'gammu/src/misc.c',
271 'gammu/src/convertors/misc.c',
272 'gammu/src/convertors/string.c',
273 'gammu/src/convertors/time.c',
274 'gammu/src/convertors/base.c',
275 'gammu/src/convertors/sms.c',
276 'gammu/src/convertors/memory.c',
277 'gammu/src/convertors/todo.c',
278 'gammu/src/convertors/calendar.c',
279 'gammu/src/convertors/bitmap.c',
280 'gammu/src/convertors/ringtone.c',
281 'gammu/src/convertors/backup.c',
282 'gammu/src/convertors/file.c',
283 'gammu/src/convertors/call.c',
284 'gammu/src/convertors/wap.c',
285 'gammu/src/gammu.c',
286 'gammu/src/smsd.c',
289 setup (name = 'python-gammu',
290 version = VERSION,
291 description = 'Gammu bindings',
292 long_description = 'Bindings to libGammu, which allows access many phones.',
293 author = "Michal Cihar",
294 author_email = 'michal@cihar.com',
295 maintainer = "Michal Cihar",
296 maintainer_email = "michal@cihar.com",
297 platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME'],
298 keywords = ['mobile', 'phone', 'SMS', 'contact', 'gammu', 'calendar', 'todo'],
299 license = 'GPL',
300 url = 'http://wammu.eu/python-gammu/',
301 download_url = 'http://wammu.eu/download/gammu/',
302 classifiers = [
303 'Development Status :: 5 - Production/Stable',
304 'License :: OSI Approved :: GNU General Public License (GPL)',
305 'Operating System :: Microsoft :: Windows :: Windows 95/98/2000',
306 'Operating System :: Microsoft :: Windows :: Windows NT/2000',
307 'Operating System :: POSIX',
308 'Operating System :: Unix',
309 'Programming Language :: Python',
310 'Programming Language :: C',
311 'Topic :: Communications :: Telephony'
313 cmdclass = {
314 'build_ext': build_ext_gammu,
316 packages = ['gammu'],
317 ext_modules = [gammumodule]