1# -*- python -*-
2# -*- coding: utf-8 -*-
3
4from waflib import Logs, Options
5
6def options(opt):
7    grp = opt.get_option_group("Guitarix Widget Library")
8    grp.add_option('--python-wrapper',
9                   action='store_const',
10                   default=False,
11                   const=True,
12                   help=('build python wrapper for library (Developers only!!)'),
13                   )
14
15def configure(conf):
16    if not Options.options.python_wrapper:
17        return
18    conf.env.GX_PYTHON_WRAPPER = True
19    conf.env.GXW_SHARED = True
20    conf.env.GXW_SHARED_INSTALL = True
21    conf.load('python')
22    conf.check_python_headers(features='pyext')
23    if conf.env.PYTHON_VERSION[0] != '3':
24        raise conf.errors.WafError(
25            'need Python version 3; please use "python3 waf configure ..."'
26            ' or supply the executable path in environment variable PYTHON')
27    conf.check_python_module("numpy")
28    conf.check_cfg(package='pygobject-2.0', args='--cflags --libs', uselib_store='PYGOBJECT', mandatory=True)
29    conf.check_cfg(package='pygobject-2.0', variables='codegendir', uselib_store='PYGOBJECT', mandatory=True, quiet=True)
30    conf.check_cfg(package='pygtk-2.0', args='--cflags --libs', uselib_store='PYGTK', mandatory=True)
31    conf.check_cfg(package='pygtk-2.0', variables='defsdir', uselib_store='PYGTK', mandatory=True, quiet=True)
32    conf.check_cfg(package='gobject-introspection-1.0', mandatory=True)
33    conf.find_program('g-ir-scanner', mandatory=True)
34    conf.find_program('g-ir-compiler', mandatory=True)
35
36def build(bld):
37    if not bld.env.GX_PYTHON_WRAPPER:
38        return
39    bld.add_group()
40    sources = ["GxTuner.h",
41               "GxFastMeter.h",
42               "GxWaveView.h",
43               "GxRegler.h",
44               "GxSelector.h",
45               "GxSwitch.h",
46               "GxToggleImage.h",
47               "GxControlParameter.h",
48               "GxIREdit.h",
49               "GxRadioButton.h",
50               "GxWheel.h",
51               "GxWheelVertical.h",
52               "GxKnob.h",
53               "GxBigKnob.h",
54               "GxSmallKnob.h",
55               "GxSmallKnobR.h",
56               "GxHSlider.h",
57               "GxMiniSlider.h",
58               "GxVSlider.h",
59               "GxEQSlider.h",
60               "GxLevelSlider.h",
61               "GxPaintBox.h",
62               "GxMeterScale.h",
63               "GxValueDisplay.h",
64               "GxRackTuner.h",
65               ]
66    glob = lambda n: bld.srcnode.ant_glob('libgxw/gxw/'+n)
67    bld.env.LIBRARY='libgxw/gxw/libgxw.so'
68    gir_name = "Gxw-0.1.gir"
69    bld(name = 'gxw_gir',
70        rule = (
71            "g-ir-scanner --namespace=Gxw --nsversion=0.1 --library ${LIBRARY}"
72	    "  --symbol-prefix=gx_ --symbol-prefix=gxw_ --identifier-prefix=Gx"
73	    "  $(pkg-config gtk+-3.0 --cflags --libs)"
74	    "  -Llibgxw/gxw -lgxw"
75	    "  --include Gtk-3.0"
76	    "  --output=${TGT}"
77            "  ${SRC}"
78            ),
79        source = glob('gxinit.*')+glob('Gx*.cpp')+glob('Gx*.h'),
80        target = gir_name,
81        )
82    bld(name = 'gxw_typelib',
83        rule = 'g-ir-compiler ${SRC} --output=${TGT}',
84        source = gir_name,
85        target = gir_name.replace('.gir','.typelib'),
86        )
87