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:
Daniel Elstner 2015-08-29 01:54:17 +02:00 committed by Uwe Hermann
parent 5b869e978a
commit c05a0ba528
2 changed files with 32 additions and 21 deletions

View File

@ -561,7 +561,9 @@ if BINDINGS_PYTHON
PDIR = bindings/python
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)
$(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)"
python-clean:
-$(AM_V_at)$(setup_py) clean --all 2>/dev/null
-$(AM_V_at)rm -f $(PDIR)/timestamp
-$(AM_V_at)rm -fr $(PDIR)/doxy
-$(AM_V_at)$(setup_py) clean --all 2>/dev/null
python-doc:
$(AM_V_at)cd $(srcdir)/$(PDIR) && BUILDDIR="$(abs_builddir)/$(PDIR)/" doxygen Doxyfile 2>/dev/null

View File

@ -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_ext import build_ext as _build_ext
import numpy as np
import subprocess
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,) = [
subprocess.check_output(
["pkg-config", option, "glib-2.0", "glibmm-2.4", "pygobject-3.0"]
).decode().rstrip().split(' ')
for option in
("--cflags-only-I", "--libs-only-L", "--libs-only-l", "--modversion")]
# Override the default compile flags used by distutils.
os.environ['OPT'] = ''
# Parse the command line arguments for VAR=value assignments,
# and apply them as environment variables.
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 += [os.path.join(srcdir, path) for path in includes]
includes += ['../..']
includes += [i[2:] for i in sr_includes]
includes += [np.get_include(), ]
libdirs = ['../../.libs', '../cxx/.libs'] + [l[2:] for l in sr_lib_dirs]
libs = [l[2:] for l in sr_libs] + ['sigrokcxx']
includes += [os.path.normpath(os.path.join(srcdir, path)) for path in includes]
includes += ['../..', np.get_include()]
ldadd = shlex.split(os.environ.get('LDADD', ''))
libdirs = ['../../.libs', '../cxx/.libs'] + \
[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):
vfile = os.path.join(srcdir, file)
@ -70,17 +81,15 @@ setup(
name = 'libsigrok',
namespace_packages = ['sigrok'],
packages = find_packages(srcdir),
version = sr_version,
version = os.environ.get('VERSION'),
description = "libsigrok API wrapper",
zip_safe = False,
script_name = __file__,
ext_modules = [
Extension('sigrok.core._classes',
sources = [vpath('sigrok/core/classes.i')],
swig_opts = ['-c++', '-threads', '-Isigrok/core',
'-I..', '-I%s' % os.path.join(srcdir, '..')] +
swig_opts = ['-c++', '-threads', '-Isigrok/core', '-I..', '-I' + srcdir_parent] +
['-I%s' % i for i in includes],
extra_compile_args = ['-std=c++11', '-Wno-uninitialized'],
extra_compile_args = ['-Wno-uninitialized'],
include_dirs = includes,
library_dirs = libdirs,
libraries = libs)