aboutsummaryrefslogtreecommitdiffstats
path: root/setup.py
blob: d6f71ac72950012fba6960170f5af6dcbefc708a (plain) (blame)
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
#! /usr/bin/env python
# encoding: utf-8

import os
import sys
import subprocess
from distutils.core import setup, Command
from distutils.extension import Extension
from distutils.version import StrictVersion


script_path = os.path.dirname(os.path.abspath(__file__))


# XXX: Force default visibility. See phab T504
if os.getenv("CFLAGS") is not None and "-fvisibility=" in os.environ["CFLAGS"]:
    os.environ["CFLAGS"] += " -fvisibility=default"


# === Sphinx ===
try:
    from sphinx.setup_command import BuildDoc
except ImportError:
    class BuildDoc(Command):
        description = "build documentation using sphinx, that must be installed."
        user_options = []
        def initialize_options(self): pass
        def finalize_options(self): pass
        def run(self): print("Error: sphinx not found")


# === pkg-config ===
def pkg_config(name, require, min_vers=None):
    try:
        sys.stdout.write("Checking for " + name + ": ")

        call = subprocess.Popen(
            ["pkg-config", "--modversion", require], stdout=subprocess.PIPE)
        out, err = call.communicate()
        ver = out.decode("utf-8").strip()

        if min_vers is not None:
            assert 0 == subprocess.call(
                ["pkg-config", "--atleast-version", min_vers, require])

        call = subprocess.Popen(
            ["pkg-config", "--cflags", require], stdout=subprocess.PIPE)
        out, err = call.communicate()
        cflags = out.decode("utf-8").split()

        call = subprocess.Popen(
            ["pkg-config", "--libs", require], stdout=subprocess.PIPE)
        out, err = call.communicate()
        libs = out.decode("utf-8").split()

        sys.stdout.write("OK, found " + ver + "\n")

        return (cflags, libs)
    except (OSError, subprocess.CalledProcessError):
        print("Did not find " + name + " with 'pkg-config'.")
        return None
    except (AssertionError):
        print(name+" version mismatch. Found: "+ver+"  Needed: "+min_vers)
        return None


# use cython or pre-generated c files
if os.path.exists(os.path.join(script_path, "efl", "eo", "efl.eo.pyx")):
    module_suffix = ".pyx"
    min_ver = "0.17.0"
    try:
        from Cython.Distutils import build_ext
        from Cython.Build import cythonize
        import Cython.Compiler.Options

        assert StrictVersion(Cython.__version__) >= StrictVersion(min_ver)
        Cython.Compiler.Options.fast_fail = True # Stop compilation on first error
        Cython.Compiler.Options.annotate = False # Generates HTML files with annotated source
        Cython.Compiler.Options.docstrings = True # Set to False to disable docstrings

    except (ImportError, AssertionError):
        print("Requires Cython >= %s (http://cython.org/)" % min_ver)
        raise
else:
    module_suffix = ".c"
    from distutils.command.build_ext import build_ext
    def cythonize(modules, *args, **kwargs):
        return modules


class CleanGenerated(Command):
    description = "Clean C and html files generated by Cython"
    user_options = []
    def initialize_options(self): pass
    def finalize_options(self): pass
    def run(self):
        for lib in "eo", "evas", "ecore", "edje", "edje/edit", "emotion", "elementary", "utils":
            for root, dirs, files in os.walk(os.path.join(script_path, "efl", lib)):
                for f in files:
                    if f.endswith(".c") or f.endswith(".html"):
                        path = os.path.join(root, f)
                        os.remove(path)
        dbus_ml_path = os.path.join(script_path, "efl", "dbus_mainloop", "dbus_mainloop.c")
        if os.path.exists(dbus_ml_path):
            os.remove(dbus_ml_path)


modules = []
packages = ["efl"]
package_dirs = {}

if set(("build", "build_ext", "install", "bdist", "sdist")) & set(sys.argv):

    # === Eina ===
    eina_pkg_config = pkg_config('Eina', 'eina', "1.8.0")

    if eina_pkg_config is None:
        raise SystemExit("Eina required but not found!")
    else:
        eina_cflags, eina_libs = eina_pkg_config


    # === Eo ===
    eo_pkg_config = pkg_config('Eo', 'eo', "1.8.0")

    if eo_pkg_config is None:
        raise SystemExit("Eo required but not found!")
    else:
        eo_cflags, eo_libs = eo_pkg_config

        eo_ext = Extension("eo", ["efl/eo/efl.eo"+module_suffix],
                                define_macros = [('EFL_BETA_API_SUPPORT', None)],
                                include_dirs = ['include/'],
                                extra_compile_args = eo_cflags,
                                extra_link_args = eo_libs + eina_libs)
        modules.append(eo_ext)


    # === Utilities ===
    utils_ext = [
        Extension("utils.deprecated", ["efl/utils/deprecated"+module_suffix],
                            include_dirs = ['include/'],
                            extra_compile_args = eina_cflags,
                            extra_link_args = eina_libs),
        Extension("utils.conversions", ["efl/utils/conversions"+module_suffix],
                            include_dirs = ['include/'],
                            extra_compile_args = eo_cflags,
                            extra_link_args = eo_libs + eina_libs),
        Extension("utils.logger", ["efl/utils/logger"+module_suffix],
                            include_dirs = ['include/'],
                            extra_compile_args = eina_cflags,
                            extra_link_args = eina_libs),
        ]
    modules += utils_ext
    packages.append("efl.utils")


    # === Evas ===
    evas_pkg_config = pkg_config('Evas', 'evas', "1.8.0")

    if evas_pkg_config is not None:

        evas_cflags, evas_libs = evas_pkg_config

        evas_ext = Extension("evas", ["efl/evas/efl.evas"+module_suffix],
                                include_dirs = ['include/'],
                                extra_compile_args = evas_cflags,
                                extra_link_args = evas_libs + eina_libs)
        modules.append(evas_ext)

        # compatibility
        packages.append("evas")
        package_dirs["evas"] = "compat/evas"


    # === Ecore ===
    ecore_pkg_config = pkg_config('Ecore', 'ecore', "1.8.0")
    ecore_file_pkg_config = pkg_config('EcoreFile', 'ecore-file', "1.8.0")

    if ecore_pkg_config is not None and ecore_file_pkg_config is not None and evas_pkg_config is not None:

        ecore_cflags, ecore_libs = ecore_pkg_config
        ecore_file_cflags, ecore_file_libs = ecore_file_pkg_config

        ecore_ext = Extension("ecore", ["efl/ecore/efl.ecore"+module_suffix],
                                include_dirs = ['include/'],
                                extra_compile_args = ecore_cflags + ecore_file_cflags,
                                extra_link_args = ecore_libs + ecore_file_libs + eina_libs + evas_libs)
        modules.append(ecore_ext)

        # compatibility
        packages.append("ecore")
        package_dirs["ecore"] = "compat/ecore"


    # === Edje ===
    edje_pkg_config = pkg_config('Edje', 'edje', "1.8.0")

    if edje_pkg_config is not None and evas_pkg_config is not None:

        edje_cflags, edje_libs = edje_pkg_config

        edje_ext = Extension("edje", ["efl/edje/efl.edje"+module_suffix],
                                include_dirs = ['include/'],
                                extra_compile_args = edje_cflags,
                                extra_link_args = edje_libs + eina_libs + evas_libs)
        modules.append(edje_ext)

        # compatibility
        packages.append("edje")
        package_dirs["edje"] = "compat/edje"

    # === Edje_Edit ===
    # edje_edit_ext = Extension("edje_edit", ["efl/edje/efl.edje_edit"+module_suffix],
    #                         define_macros = [('EDJE_EDIT_IS_UNSTABLE_AND_I_KNOW_ABOUT_IT', None)],
    #                         include_dirs = ['include/'],
    #                         extra_compile_args = edje_cflags,
    #                         extra_link_args = edje_libs + eina_libs + evas_libs)
    # modules.append(edje_edit_ext)


    # Emotion
    emotion_pkg_config = pkg_config('Emotion', 'emotion', "1.8.0")

    if emotion_pkg_config is not None and evas_pkg_config is not None:

        emotion_cflags, emotion_libs = emotion_pkg_config

        emotion_ext = Extension("emotion", ["efl/emotion/efl.emotion"+module_suffix],
                                include_dirs = ['include/'],
                                extra_compile_args = emotion_cflags,
                                extra_link_args = emotion_libs + eina_libs + evas_libs)
        modules.append(emotion_ext)

        # compatibility
        packages.append("emotion")
        package_dirs["emotion"] = "compat/emotion"


    # === dbus mainloop integration ===
    dbus_pkg_config = pkg_config('DBus', 'dbus-python', "0.83.0")

    if dbus_pkg_config is not None and ecore_pkg_config is not None:
        dbus_cflags, dbus_libs = dbus_pkg_config

        dbus_ml_ext = Extension("dbus_mainloop",
                                ["efl/dbus_mainloop/dbus_mainloop"+module_suffix,
                                 "efl/dbus_mainloop/e_dbus.c"],
                                extra_compile_args = dbus_cflags + ecore_cflags,
                                extra_link_args = dbus_libs + ecore_libs)
        modules.append(dbus_ml_ext)

        # compatibility
        packages.append("e_dbus")
        package_dirs["e_dbus"] = "compat/e_dbus"


    # === Elementary ===
    elm_mods = (
        #"access",
        "actionslider",
        "background",
        "box",
        "bubble",
        "button",
        "calendar_elm",
        "check",
        "clock",
        "colorselector",
        "configuration",
        "conformant",
        "ctxpopup",
        "datetime_elm",
        "dayselector",
        "diskselector",
        "entry",
        "fileselector_button",
        "fileselector_entry",
        "fileselector",
        "flip",
        "flipselector",
        "frame",
        "general",
        "gengrid",
        "genlist",
        "gesture_layer",
        #"glview",
        "grid",
        "hover",
        "hoversel",
        "icon",
        "image",
        "index",
        "innerwindow",
        "label",
        "layout_class",
        "layout",
        "list",
        "mapbuf",
        "map",
        "menu",
        "multibuttonentry",
        "naviframe",
        "need",
        "notify",
        "object_item",
        "object",
        "panel",
        "panes",
        "photocam",
        "photo",
        "plug",
        "popup",
        "progressbar",
        "radio",
        "scroller",
        "segment_control",
        "separator",
        "slider",
        "slideshow",
        "spinner",
        #"store",
        "table",
        "theme",
        "thumb",
        "toolbar",
        "transit",
        "video",
        "web",
        "window",
    )

    elm_pkg_config = pkg_config('Elementary', 'elementary', "1.8.0")

    if elm_pkg_config is not None \
    and evas_pkg_config is not None \
    and ecore_pkg_config is not None \
    and emotion_pkg_config is not None:
        elm_cflags, elm_libs = elm_pkg_config

        for m in elm_mods:
            e = Extension(
                "elementary." + m,
                ["efl/elementary/" + m + module_suffix],
                include_dirs = ["include/"],
                extra_compile_args = elm_cflags,
                extra_link_args = elm_libs + eina_libs + evas_libs
                )
            modules.append(e)

        packages.append("efl.elementary")

        # compatibility
        packages.append("elementary")
        package_dirs["elementary"] = "compat/elementary"


setup(
    name = "python-efl",
    fullname = "Python bindings for Enlightenment Foundation Libraries",
    description = "Python bindings for Enlightenment Foundation Libraries",
    version = "1.8.0",
    author = "Gustavo Sverzut Barbieri, Simon Busch, Boris 'billiob' Faure, Davide 'davemds' Andreoli, Fabiano Fidêncio, Bruno Dilly, Tiago Falcão, Joost Albers, Kai Huuhko, Ulisses Furquim",
    author_email = "dave@gurumeditation.it, kai.huuhko@gmail.com",
    maintainer = "Kai Huuhko, Davide <davemds> Andreoli",
    maintainer_email = "kai.huuhko@gmail.com, dave@gurumeditation.it",
    contact = "Enlightenment developer mailing list",
    contact_email = "enlightenment-devel@lists.sourceforge.net",
    url = "http://www.enlightenment.org",
    license = "GNU Lesser General Public License (LGPL)",
    cmdclass = {
        'build_ext': build_ext,
        'build_doc': BuildDoc,
        'clean_generated_files': CleanGenerated
        },
    package_dir = package_dirs,
    packages = packages,
    ext_package = "efl", # The prefix for ext modules/packages
    ext_modules = cythonize(modules, include_path=["include"]),
)