cleanup specfile for packaging
[profile/ivi/gpsd.git] / setup.py
1 # This file is Copyright (c) 2010 by the GPSD project
2 # BSD terms apply: see the file COPYING in the distribution root for details.
3 #
4 # Creates build/lib.linux-${arch}-${pyvers}/gpspacket.so,
5 # where ${arch} is an architecture and ${pyvers} is a Python version.
6
7 from distutils.core import setup, Extension
8
9 import os
10 import sys
11
12 # For VPATH builds, this script must be run from $(srcdir) with the
13 # abs_builddir environment variable set to the location of the build
14 # directory.  This is necessary because Python's distutils package
15 # does not have built-in support for VPATH builds.
16
17 # These dependencies are enforced here and not in the Makefile to make
18 # it easier to build the Python parts without building everything else
19 # (the user can run 'python setup.py' without having to run 'make').
20 needed_files = ['gpsd.h', 'packet_names.h']
21 created_files = []
22
23 manpages = []
24 try:
25     where = sys.argv.index('--mangenerator')
26     # Doesn't matter what it is, just that we have one
27     if sys.argv[where+1]:
28         manpages=[('share/man/man1', ['gpscat.1', 'gpsfake.1','gpsprof.1',
29                                       'xgps.1', 'xgpsspeed.1'])]
30         print("Installing manual pages, generator is %s" %( sys.argv[where+1]))
31     sys.argv = sys.argv[:where] + sys.argv[where+2:]
32 except ValueError:
33     pass
34 if not manpages:
35     print("No XML processor, omitting manual-page installation.")
36
37 MAKE = ("MAKE" in os.environ) and os.environ["MAKE"] or "make"
38 if not 'clean' in sys.argv:
39     abs_builddir = ("abs_builddir" in os.environ) and os.environ["abs_builddir"] or ""
40     if not os.path.exists(os.path.join(abs_builddir, 'gpsd_config.h')):
41         sys.stderr.write('\nPlease run configure first!\n')
42         sys.exit(1)
43
44     cdcmd = abs_builddir and ("cd '" + abs_builddir + "' && ") or ""
45     for f_name in needed_files:
46         # TODO:  Shouldn't make be run unconditionally in case a
47         # dependency of f_name has been updated?
48         if not os.path.exists(os.path.join(abs_builddir, f_name)):
49             cmd = cdcmd + MAKE + " '" + f_name + "'"
50             print(cmd)
51             make_out = os.popen(cmd)
52             print(make_out.read())
53             if make_out.close():
54                 sys.exit(1)
55             created_files.append(f_name)
56
57 gpspacket_sources = ["gpspacket.c", "packet.c", "isgps.c",
58             "driver_rtcm2.c", "strl.c", "hex.c", "crc24q.c"]
59 include_dirs = [ os.path.realpath(os.path.dirname(__file__)) ]
60 version_out = os.popen(MAKE + " -s version")
61 version = version_out.read()
62 print(version)
63 if version_out.close():
64     sys.exit(1)
65 version = version.split('\n')[-2]
66 version = version.strip()
67
68 setup( name="gps",
69        version=version,
70        description='Python libraries for the gpsd service daemon',
71        url="http://gpsd.berlios.de/",
72        author='the GPSD project',
73        author_email="gpsd-dev@lists.berlios.de",
74        license="BSD",
75        ext_modules=[
76         Extension("gps.packet", gpspacket_sources, include_dirs=include_dirs),
77         Extension("gps.clienthelpers", ["gpsclient.c", "geoid.c", "gpsdclient.c", "strl.c"], include_dirs=include_dirs)
78         ],
79        packages = ['gps'],
80        scripts = ['gpscat','gpsfake','gpsprof', 'xgps', 'xgpsspeed'],
81        data_files= manpages
82      )