1#!/usr/bin/env python
2
3from distutils.core import setup, Extension
4import os,sys
5
6attdict = dict(
7   sources = ['gribapi_swig_wrap.c','grib_interface.c'],
8   swig_opts = [],
9   include_dirs = ['.'],
10   library_dirs = ["%s/lib" % sys.prefix],
11   libraries = [],
12   extra_objects = [],
13   extra_link_args = [],    # See GRIB-616
14)
15
16add_attribute = lambda **args: [list.append(attdict[key],value) for key,value in args.items()]
17
18# assumes build_dir is same as source_dir -- not true for cmake builds
19build_dir = '@BUILD_DIR@'
20add_attribute(
21    include_dirs = os.path.join(build_dir,'src'),
22    extra_objects = os.path.join(build_dir, 'src', '.libs', 'libgrib_api.a')
23)
24
25with_jasper = '@LIB_JASPER@'
26if with_jasper:
27    jasper_dir = '@JASPER_DIR@'
28    if jasper_dir and jasper_dir != 'system':
29        add_attribute(
30            include_dirs = os.path.join(jasper_dir,'include'),
31            library_dirs = os.path.join(jasper_dir,'lib'),
32            extra_link_args = '-Wl,-rpath,' + os.path.join(jasper_dir,'lib')
33        )
34    add_attribute(libraries = 'jasper')
35
36with_openjpeg = '@LIB_OPENJPEG@'
37if with_openjpeg:
38    openjpeg_dir = '@OPENJPEG_DIR@'
39    if openjpeg_dir and openjpeg_dir != 'system':
40        add_attribute(
41            include_dirs = os.path.join(openjpeg_dir,'include'),
42            library_dirs = os.path.join(openjpeg_dir,'lib'),
43            extra_link_args = '-Wl,-rpath,' + os.path.join(openjpeg_dir,'lib')
44        )
45    add_attribute(libraries = 'openjpeg')
46
47# assumes png is supplied by system paths -- may not be true
48png = '@LIB_PNG@'
49if png:
50    add_attribute(libraries = 'png')
51
52
53with_aec = '@LIB_AEC@'
54if with_aec:
55    aec_dir = '@AEC_DIR@'
56    if aec_dir and aec_dir != 'system':
57        add_attribute(
58            include_dirs = os.path.join(aec_dir,'include'),
59            library_dirs = os.path.join(aec_dir,'lib'),
60            extra_link_args = '-Wl,-rpath,' + os.path.join(aec_dir,'lib')
61        )
62    add_attribute(libraries = 'aec')
63
64
65data_handler = '@DATA_HANDLER@'
66if data_handler == "numpy":
67    import numpy
68    # Obtain the numpy include directory.  This logic works across numpy versions.
69    try:
70        numpy_include = numpy.get_include()
71    except AttributeError:
72        numpy_include = numpy.get_numpy_include()
73
74    add_attribute(
75        include_dirs = numpy_include,
76    )
77
78gribapi_module = Extension('_gribapi_swig',**attdict)
79
80setup (name = 'gribapi',
81       version = '0.1',
82       author      = 'ECMWF',
83       description = """Grib API SWIG module""",
84       ext_modules = [gribapi_module],
85       py_modules = ['gribapi_swig','gribapi'],
86      )
87