From 09823dd6a038952c5685998254c3f71bee8bc773 Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 20 Aug 2021 15:21:49 +0300 Subject: [PATCH] more portable build of the Python extension module with HDF5 paths propagated from configure script --- Makefile.am | 11 ++++++++--- python/install_pytrexio.sh | 5 ++++- python/setup.py | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index bc6fa1e..c3402cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -157,6 +157,10 @@ $(HTML_FILES): docs/index.html # =============== DEVELOPER MODE =============== # +SWIG = @SWIG@ +HDF5_LDFLAGS = @HDF5_LDFLAGS@ +HDF5_CFLAGS = @HDF5_CFLAGS@ + if TREXIO_DEVEL CLEANFILES += $(SOURCES) $(trexio_f) $(trexio_h) @@ -183,7 +187,6 @@ cppcheck.out: $(trexio_h) --language=c --std=c99 -rp --platform=unix64 \ -I../include *.c *.h 2>../$@ - setup_py = $(srcdir)/python/setup.py setup_cfg = $(srcdir)/python/setup.cfg pytrexio_py = $(srcdir)/python/pytrexio/pytrexio.py @@ -199,7 +202,8 @@ python-test: $(TEST_PY) $(RM) -r -- __pycache__ python-install: $(pytrexio_py) $(setup_py) $(setup_cfg) - cd python && ./install_pytrexio.sh + cd python && \ + ./install_pytrexio.sh $(HDF5_LDFLAGS) $(HDF5_CFLAGS) $(pytrexio_py): $(pytrexio_c) cd tools && ./prepare_python.sh @@ -208,7 +212,8 @@ $(pytrexio_py): $(pytrexio_c) # [?] swig -python -threads pytrexio.i ----> Add thread support for all the interface $(pytrexio_c): $(ORG_FILES) $(trexio_h) $(pytrexio_i) $(numpy_i) cp $(trexio_h) src/ - cd src/ && swig -python -py3 -o pytrexio_wrap.c pytrexio.i + cd src/ && \ + $(SWIG) -python -py3 -o pytrexio_wrap.c pytrexio.i $(RM) -- src/trexio.h $(numpy_i): diff --git a/python/install_pytrexio.sh b/python/install_pytrexio.sh index d85b8a3..148ef9d 100755 --- a/python/install_pytrexio.sh +++ b/python/install_pytrexio.sh @@ -3,6 +3,9 @@ set -x set -e +H5_LDFLAGS_LOCAL=$1 +H5_CFLAGS_LOCAL=$2 + # This script should update the version of the Python package #source version.py @@ -11,7 +14,7 @@ python3 -m pip install --upgrade setuptools wheel twine # Create build directory and compile extension files (*.c) # --no-user-cfg disables custom .cfg files of the user machine, so that only setup.cfg is used -python3 -s setup.py --no-user-cfg build +H5_LDFLAGS=${H5_LDFLAGS_LOCAL} H5_CFLAGS=${H5_CFLAGS_LOCAL} python3 -s setup.py --no-user-cfg build # Local inplace build of the .so module with SWIG-produced pytrexio_wrap.c (from the SWIG documentation) #python3 setup.py build_ext --inplace --swig-opts="-modern" diff --git a/python/setup.py b/python/setup.py index 6967a1c..367adbe 100644 --- a/python/setup.py +++ b/python/setup.py @@ -14,13 +14,16 @@ c_files = ['trexio.c', 'trexio_hdf5.c', 'trexio_text.c', 'pytrexio_wrap.c'] with open("README.md", "r") as fh: long_description = fh.read() +h5_ldflags = str(os.environ.get("H5_LDFLAGS", None )) +h5_cflags_withI = str(os.environ.get("H5_CFLAGS", None )) +h5_cflags = h5_cflags_withI.replace("-I","") pytrexio_module = Extension('pytrexio._pytrexio', sources = [os.path.join(srcpath, code) for code in c_files], - include_dirs = ['/usr/include/hdf5/serial', srcpath], + include_dirs = [h5_cflags, srcpath], libraries = ['hdf5', 'hdf5_hl'], extra_compile_args = ['-Wno-discarded-qualifiers'], - extra_link_args = ['-L/usr/lib/x86_64-linux-gnu/hdf5/serial'] + extra_link_args = [h5_ldflags] )