Build: Pass compiler flags from make to setup.py
Extend setup.py to allow environment variables to be set on the command line. Use that functionality to replace the pkg-config invocations with flags passed on from make. Suppress the annoying -Wstrict-prototypes warning by overriding the OPT variable. Also move the "cd bindings/python" from Makefile.am to setup.py to side-step problems with "cd" in make rules. This also fixes bug #628.
This commit is contained in:
parent
5b869e978a
commit
c05a0ba528
|
@ -561,7 +561,9 @@ if BINDINGS_PYTHON
|
||||||
PDIR = bindings/python
|
PDIR = bindings/python
|
||||||
PDOC = bindings/python/sigrok/core/doc.i
|
PDOC = bindings/python/sigrok/core/doc.i
|
||||||
|
|
||||||
setup_py = cd $(PDIR) && $(PYTHON) "$(abs_srcdir)/$(PDIR)/setup.py" --quiet
|
setup_vars = VERSION='$(PACKAGE_VERSION)' CC='$(CXX)' CFLAGS='$(AM_CXXFLAGS) $(CXXFLAGS)' LDADD='$(PYSIGROK_LIBS)'
|
||||||
|
setup_quiet = --quiet
|
||||||
|
setup_py = $(PYTHON) $(srcdir)/$(PDIR)/setup.py $(setup_vars) $(setup_quiet)
|
||||||
|
|
||||||
$(PDOC): $(srcdir)/bindings/swig/doc.py $(CPPXMLDOC)
|
$(PDOC): $(srcdir)/bindings/swig/doc.py $(CPPXMLDOC)
|
||||||
$(AM_V_at)test -d $(PDIR)/sigrok/core || $(MKDIR_P) $(PDIR)/sigrok/core
|
$(AM_V_at)test -d $(PDIR)/sigrok/core || $(MKDIR_P) $(PDIR)/sigrok/core
|
||||||
|
@ -581,9 +583,9 @@ python-install:
|
||||||
$(setup_py) install --root "$(DESTDIR)/" --prefix "$(prefix)" --exec-prefix "$(exec_prefix)"
|
$(setup_py) install --root "$(DESTDIR)/" --prefix "$(prefix)" --exec-prefix "$(exec_prefix)"
|
||||||
|
|
||||||
python-clean:
|
python-clean:
|
||||||
-$(AM_V_at)$(setup_py) clean --all 2>/dev/null
|
|
||||||
-$(AM_V_at)rm -f $(PDIR)/timestamp
|
-$(AM_V_at)rm -f $(PDIR)/timestamp
|
||||||
-$(AM_V_at)rm -fr $(PDIR)/doxy
|
-$(AM_V_at)rm -fr $(PDIR)/doxy
|
||||||
|
-$(AM_V_at)$(setup_py) clean --all 2>/dev/null
|
||||||
|
|
||||||
python-doc:
|
python-doc:
|
||||||
$(AM_V_at)cd $(srcdir)/$(PDIR) && BUILDDIR="$(abs_builddir)/$(PDIR)/" doxygen Doxyfile 2>/dev/null
|
$(AM_V_at)cd $(srcdir)/$(PDIR) && BUILDDIR="$(abs_builddir)/$(PDIR)/" doxygen Doxyfile 2>/dev/null
|
||||||
|
|
|
@ -21,25 +21,36 @@ from setuptools import setup, find_packages, Extension
|
||||||
from distutils.command.build_py import build_py as _build_py
|
from distutils.command.build_py import build_py as _build_py
|
||||||
from distutils.command.build_ext import build_ext as _build_ext
|
from distutils.command.build_ext import build_ext as _build_ext
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import subprocess
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
import shlex
|
||||||
|
|
||||||
srcdir = os.path.split(__file__)[0]
|
srcdir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
os.chdir('bindings/python')
|
||||||
|
srcdir = os.path.relpath(srcdir)
|
||||||
|
srcdir_parent = os.path.normpath(os.path.join(srcdir, '..'))
|
||||||
|
|
||||||
sr_includes, sr_lib_dirs, sr_libs, (sr_version,) = [
|
# Override the default compile flags used by distutils.
|
||||||
subprocess.check_output(
|
os.environ['OPT'] = ''
|
||||||
["pkg-config", option, "glib-2.0", "glibmm-2.4", "pygobject-3.0"]
|
|
||||||
).decode().rstrip().split(' ')
|
# Parse the command line arguments for VAR=value assignments,
|
||||||
for option in
|
# and apply them as environment variables.
|
||||||
("--cflags-only-I", "--libs-only-L", "--libs-only-l", "--modversion")]
|
while len(sys.argv) > 1:
|
||||||
|
match = re.match(r'([A-Z]+)=(.*)', sys.argv[1])
|
||||||
|
if match is None:
|
||||||
|
break
|
||||||
|
os.environ[match.group(1)] = match.group(2)
|
||||||
|
del sys.argv[1]
|
||||||
|
|
||||||
includes = ['../../include', '../cxx/include']
|
includes = ['../../include', '../cxx/include']
|
||||||
includes += [os.path.join(srcdir, path) for path in includes]
|
includes += [os.path.normpath(os.path.join(srcdir, path)) for path in includes]
|
||||||
includes += ['../..']
|
includes += ['../..', np.get_include()]
|
||||||
includes += [i[2:] for i in sr_includes]
|
|
||||||
includes += [np.get_include(), ]
|
ldadd = shlex.split(os.environ.get('LDADD', ''))
|
||||||
libdirs = ['../../.libs', '../cxx/.libs'] + [l[2:] for l in sr_lib_dirs]
|
libdirs = ['../../.libs', '../cxx/.libs'] + \
|
||||||
libs = [l[2:] for l in sr_libs] + ['sigrokcxx']
|
[l[2:] for l in ldadd if l.startswith('-L')]
|
||||||
|
libs = [l[2:] for l in ldadd if l.startswith('-l')] + ['sigrokcxx']
|
||||||
|
|
||||||
def vpath(file):
|
def vpath(file):
|
||||||
vfile = os.path.join(srcdir, file)
|
vfile = os.path.join(srcdir, file)
|
||||||
|
@ -70,17 +81,15 @@ setup(
|
||||||
name = 'libsigrok',
|
name = 'libsigrok',
|
||||||
namespace_packages = ['sigrok'],
|
namespace_packages = ['sigrok'],
|
||||||
packages = find_packages(srcdir),
|
packages = find_packages(srcdir),
|
||||||
version = sr_version,
|
version = os.environ.get('VERSION'),
|
||||||
description = "libsigrok API wrapper",
|
description = "libsigrok API wrapper",
|
||||||
zip_safe = False,
|
zip_safe = False,
|
||||||
script_name = __file__,
|
|
||||||
ext_modules = [
|
ext_modules = [
|
||||||
Extension('sigrok.core._classes',
|
Extension('sigrok.core._classes',
|
||||||
sources = [vpath('sigrok/core/classes.i')],
|
sources = [vpath('sigrok/core/classes.i')],
|
||||||
swig_opts = ['-c++', '-threads', '-Isigrok/core',
|
swig_opts = ['-c++', '-threads', '-Isigrok/core', '-I..', '-I' + srcdir_parent] +
|
||||||
'-I..', '-I%s' % os.path.join(srcdir, '..')] +
|
|
||||||
['-I%s' % i for i in includes],
|
['-I%s' % i for i in includes],
|
||||||
extra_compile_args = ['-std=c++11', '-Wno-uninitialized'],
|
extra_compile_args = ['-Wno-uninitialized'],
|
||||||
include_dirs = includes,
|
include_dirs = includes,
|
||||||
library_dirs = libdirs,
|
library_dirs = libdirs,
|
||||||
libraries = libs)
|
libraries = libs)
|
||||||
|
|
Loading…
Reference in New Issue