From 534003bde29658e9a9dda7d78f7b40d76263f4c5 Mon Sep 17 00:00:00 2001 From: Daniele Date: Tue, 19 Dec 2023 10:13:41 +0100 Subject: [PATCH] Added some aid-compile option in autoconf * Trying to setup pycv into config * forgot to commit configure before pushig * redesigning the compilation with the new ac * changed behaviour of not finding cython * now if no python package is found also python_bin is not set * now configure understands if python is embeddable * moved the variables and added some comments for clarity * rerun autoconf * set up a cleaner instalation * forgot to push the compileconfiguration common sourced file * added some aid for maintainers --------- Co-authored-by: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> --- Makefile.conf.in | 5 ++ configure | 103 ++++++++++++++++++++++---- configure.ac | 71 ++++++++++++++---- plugins/pycv/.gitignore | 2 +- plugins/pycv/Makefile | 14 +++- plugins/pycv/astyle.sh | 11 ++- plugins/pycv/compileConfiguration.sh | 54 ++++++++++++++ plugins/pycv/prepareMakeForDevelop.sh | 32 ++++---- plugins/pycv/standaloneCompile.sh | 35 ++------- python/Makefile | 2 +- 10 files changed, 250 insertions(+), 79 deletions(-) create mode 100644 plugins/pycv/compileConfiguration.sh diff --git a/Makefile.conf.in b/Makefile.conf.in index 23da2f82f6..ef619496e9 100644 --- a/Makefile.conf.in +++ b/Makefile.conf.in @@ -38,6 +38,11 @@ datadir=@datadir@ docdir=@docdir@ htmldir=@htmldir@ python_bin=@PYTHON_BIN@ +plumed_found_cython=@CYTHON_FOUND@ +canPyCV=@PLUMED_CAN_PYCV@ +pybind11_cflags=@PYBIND11_CFLAGS@ +python_cf_embedded=@PYTHON_CFLAGS@ +python_ld_embedded=@PYTHON_LDFLAGS@ mpiexec=@MPIEXEC@ make_static_archive=@make_static_archive@ use_absolute_soname=@use_absolute_soname@ diff --git a/configure b/configure index deab2d6740..eab0c618a3 100755 --- a/configure +++ b/configure @@ -637,6 +637,11 @@ make_doc readelf LD_MAIN_RUNPATH use_debug_glibcxx +PYTHON_CFLAGS +PYTHON_LDFLAGS +PYBIND11_CFLAGS +PLUMED_CAN_PYCV +CYTHON_FOUND OPENMP_CXXFLAGS EGREP GREP @@ -742,6 +747,7 @@ enable_boost_graph enable_boost_serialization enable_fftw enable_python +enable_pycv enable_af_ocl enable_af_cuda enable_af_cpu @@ -1443,6 +1449,7 @@ Optional Features: enable search for boost serialization, default: no --enable-fftw enable search for fftw, default: yes --enable-python enable search for python, default: yes + --enable-pycv enable set up the pycv plugin, default: yes --enable-af_ocl enable search for arrayfire_ocl, default: no --enable-af_cuda enable search for arrayfire_cuda, default: no --enable-af_cpu enable search for arrayfire_cpu, default: no @@ -3143,6 +3150,24 @@ fi +pycv= +# Check whether --enable-pycv was given. +if test "${enable_pycv+set}" = set; then : + enableval=$enable_pycv; case "${enableval}" in + (yes) pycv=true ;; + (no) pycv=false ;; + (*) as_fn_error $? "wrong argument to --enable-pycv" "$LINENO" 5 ;; + esac +else + case "yes" in + (yes) pycv=true ;; + (no) pycv=false ;; + esac + +fi + + + af_ocl= # Check whether --enable-af_ocl was given. if test "${enable_af_ocl+set}" = set; then : @@ -3222,7 +3247,6 @@ fi - # by default use -O flag # we override the autoconf default (-g) because in release build we do not want to # include symbol information (obj files are huge) @@ -8945,11 +8969,21 @@ $as_echo "$as_me: WARNING: cannot enable __PLUMED_HAS_FFTW" >&2;} fi -if test $python = true ; then +# python executable: if any of CYTHON_FOUND or PLUMED_CAN_PYCV is on will store +# the python executable + +# set if PYTHON_BIN has Cython in its environment + +# definitions and variables related to pycv and in general embedding python + + + + + # if PYTHON_BIN is defined, it is expected to be the full path to python # Otherwise, search from a list of names: - if test -z "$PYTHON_BIN" ; then - for ac_prog in python +if test -z "$PYTHON_BIN" ; then + for ac_prog in python python3 do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 @@ -8991,14 +9025,54 @@ fi test -n "$PYTHON_BIN" && break done - fi - if test -n "$PYTHON_BIN" - then +fi +if test -n "$PYTHON_BIN" ; then { $as_echo "$as_me:${as_lineno-$LINENO}: Python executable is $PYTHON_BIN" >&5 $as_echo "$as_me: Python executable is $PYTHON_BIN" >&6;} - { $as_echo "$as_me:${as_lineno-$LINENO}: checking support for required python modules (python3, setuptools, cython)" >&5 -$as_echo_n "checking support for required python modules (python3, setuptools, cython)... " >&6; } -testimport=" + if test $pycv = true ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking pycv: support for required python modules (python3, pybind11, numpy)" >&5 +$as_echo_n "checking pycv: support for required python modules (python3, pybind11, numpy)... " >&6; } + testimport=" +import numpy +import pybind11 +#no need to check for python3, if you have python2, you don't have pybind11 (and vice-versa) +" + if echo "$testimport" | "$PYTHON_BIN" 1>/dev/null 2>/dev/null; then + + pyver=$($PYTHON_BIN -c "import sysconfig;print(sysconfig.get_config_var('VERSION'))") + python_config=python${pyver}-config + + if ${python_config} --ldflags --embed 1>/dev/null 2>/dev/null ;then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + PYBIND11_CFLAGS="$($PYTHON_BIN -m pybind11 --includes) -fvisibility=hidden" + PYTHON_CFLAGS=$(${python_config} --cflags --embed) + PYTHON_LDFLAGS=$(${python_config} --ldflags --embed) + #TODO: conda_fixup + PLUMED_CAN_PYCV=yes + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot enable pycv" >&5 +$as_echo "$as_me: WARNING: cannot enable pycv" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \"PyCV needs python to be embeddable, please rebuild python\"" >&5 +$as_echo "$as_me: WARNING: \"PyCV needs python to be embeddable, please rebuild python\"" >&2;} + fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot enable pycv" >&5 +$as_echo "$as_me: WARNING: cannot enable pycv" >&2;} + fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot enable pycv" >&5 +$as_echo "$as_me: WARNING: cannot enable pycv" >&2;} + fi + + if test $python = true ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking python wrapper: support for required python modules (python3, setuptools, cython)" >&5 +$as_echo_n "checking python wrapper: support for required python modules (python3, setuptools, cython)... " >&6; } + testimport=" from setuptools import setup from setuptools import Extension from Cython.Build import cythonize @@ -9011,12 +9085,12 @@ if sys.version_info < (3,): $as_echo "yes" >&6; } $as_echo "#define __PLUMED_HAS_PYTHON 1" >>confdefs.h + CYTHON_FOUND=yes else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot enable python interface" >&5 $as_echo "$as_me: WARNING: cannot enable python interface" >&2;} - PYTHON_BIN= fi else { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot enable python interface" >&5 @@ -9024,6 +9098,11 @@ $as_echo "$as_me: WARNING: cannot enable python interface" >&2;} fi fi +if test "${PLUMED_CAN_PYCV}" != yes && test "${CYTHON_FOUND}" != yes; then + #this deactivate python bin if no package was found + PYTHON_BIN= +fi + if test "$af_ocl" = true ; then found=ko @@ -10062,8 +10141,6 @@ $as_echo "#define _REENTRANT 1" >>confdefs.h # these are libraries that should be linked also to MD engines -# python executable - diff --git a/configure.ac b/configure.ac index 0e1f2014c4..dc444c6f9e 100644 --- a/configure.ac +++ b/configure.ac @@ -319,6 +319,7 @@ PLUMED_CONFIG_ENABLE([boost_graph],[search for boost graph],[no]) PLUMED_CONFIG_ENABLE([boost_serialization],[search for boost serialization],[no]) PLUMED_CONFIG_ENABLE([fftw],[search for fftw],[yes]) PLUMED_CONFIG_ENABLE([python],[search for python],[yes]) +PLUMED_CONFIG_ENABLE([pycv],[set up the pycv plugin],[yes]) PLUMED_CONFIG_ENABLE([af_ocl],[search for arrayfire_ocl],[no]) PLUMED_CONFIG_ENABLE([af_cuda],[search for arrayfire_cuda],[no]) PLUMED_CONFIG_ENABLE([af_cpu],[search for arrayfire_cpu],[no]) @@ -331,7 +332,6 @@ AC_ARG_VAR(PYTHON_BIN,[python executable (e.g. python2.7 or /opt/local/bin/pytho AC_ARG_VAR(BASH_COMPLETION_DIR,[path where bash completion will be installed - default: search with pkg-config]) AC_ARG_VAR(MPIEXEC,[command to run mpi programs in tests - default not specified, which means use PLUMED_MPIRUN env var at runtime for backward compatibility]) - # by default use -O flag # we override the autoconf default (-g) because in release build we do not want to # include symbol information (obj files are huge) @@ -838,17 +838,59 @@ if test $fftw = true ; then PLUMED_CHECK_PACKAGE([fftw3.h],[fftw_execute],[__PLUMED_HAS_FFTW],[fftw3]) fi -if test $python = true ; then +# python executable: if any of CYTHON_FOUND or PLUMED_CAN_PYCV is on will store +# the python executable +AC_SUBST(PYTHON_BIN) +# set if PYTHON_BIN has Cython in its environment +AC_SUBST(CYTHON_FOUND) +# definitions and variables related to pycv and in general embedding python +AC_SUBST(PLUMED_CAN_PYCV) +AC_SUBST(PYBIND11_CFLAGS) +AC_SUBST(PYTHON_LDFLAGS) +AC_SUBST(PYTHON_CFLAGS) + # if PYTHON_BIN is defined, it is expected to be the full path to python -# Otherwise, search from a list of names: - if test -z "$PYTHON_BIN" ; then - AC_CHECK_PROGS([PYTHON_BIN],[python]) - fi - if test -n "$PYTHON_BIN" - then +# Otherwise, search from a list of names: +if test -z "$PYTHON_BIN" ; then + AC_CHECK_PROGS([PYTHON_BIN],[python python3]) +fi +if test -n "$PYTHON_BIN" ; then AC_MSG_NOTICE([Python executable is $PYTHON_BIN]) - AC_MSG_CHECKING([support for required python modules (python3, setuptools, cython)]) -testimport=" + if test $pycv = true ; then + AC_MSG_CHECKING([pycv: support for required python modules (python3, pybind11, numpy)]) + testimport=" +import numpy +import pybind11 +#no need to check for python3, if you have python2, you don't have pybind11 (and vice-versa) +" + if echo "$testimport" | "$PYTHON_BIN" 1>/dev/null 2>/dev/null; then + + pyver=$($PYTHON_BIN -c "import sysconfig;print(sysconfig.get_config_var('VERSION'))") + python_config=python${pyver}-config + + if ${python_config} --ldflags --embed 1>/dev/null 2>/dev/null ;then + AC_MSG_RESULT([yes]) + PYBIND11_CFLAGS="$($PYTHON_BIN -m pybind11 --includes) -fvisibility=hidden" + PYTHON_CFLAGS=$(${python_config} --cflags --embed) + PYTHON_LDFLAGS=$(${python_config} --ldflags --embed) + #TODO: conda_fixup + PLUMED_CAN_PYCV=yes + else + AC_MSG_RESULT([no]) + AC_MSG_WARN([cannot enable pycv]) + AC_MSG_WARN(["PyCV needs python to be embeddable, please rebuild python"]) + fi + else + AC_MSG_RESULT([no]) + AC_MSG_WARN([cannot enable pycv]) + fi + else + AC_MSG_WARN([cannot enable pycv]) + fi + + if test $python = true ; then + AC_MSG_CHECKING([python wrapper: support for required python modules (python3, setuptools, cython)]) + testimport=" from setuptools import setup from setuptools import Extension from Cython.Build import cythonize @@ -859,16 +901,21 @@ if sys.version_info < (3,): if echo "$testimport" | "$PYTHON_BIN" 1>/dev/null 2>/dev/null; then AC_MSG_RESULT([yes]) AC_DEFINE([__PLUMED_HAS_PYTHON]) + CYTHON_FOUND=yes else AC_MSG_RESULT([no]) AC_MSG_WARN([cannot enable python interface]) - PYTHON_BIN= fi else AC_MSG_WARN([cannot enable python interface]) fi fi +if test "${PLUMED_CAN_PYCV}" != yes && test "${CYTHON_FOUND}" != yes; then + #this deactivate python bin if no package was found + PYTHON_BIN= +fi + if test "$af_ocl" = true ; then PLUMED_CHECK_PACKAGE([arrayfire.h],[af_is_double],[__PLUMED_HAS_ARRAYFIRE],[afopencl]) PLUMED_CHECK_PACKAGE([arrayfire.h],[af_is_double],[__PLUMED_HAS_ARRAYFIRE_OCL],[afopencl]) @@ -944,8 +991,6 @@ AC_SUBST(LDSHARED) AC_SUBST(LD_MAIN_RUNPATH) # these are libraries that should be linked also to MD engines AC_SUBST(STATIC_LIBS) -# python executable -AC_SUBST(PYTHON_BIN) AC_SUBST(MPIEXEC) diff --git a/plugins/pycv/.gitignore b/plugins/pycv/.gitignore index ce1d56103b..7df00fe885 100644 --- a/plugins/pycv/.gitignore +++ b/plugins/pycv/.gitignore @@ -1,4 +1,4 @@ -Make.inc +/Makefile.conf *.o *.so env diff --git a/plugins/pycv/Makefile b/plugins/pycv/Makefile index 3deac9c515..9e9ee703cf 100644 --- a/plugins/pycv/Makefile +++ b/plugins/pycv/Makefile @@ -1,4 +1,10 @@ -include Make.inc +# include the machine dependent configuration +ifneq ($(MAKECMDGOALS),clean) + -include ../../Makefile.conf + ifndef canPyCV + include ./Makefile.conf + endif +endif .PHONY: clean check all #Dependency tracking based on https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr @@ -6,7 +12,8 @@ include Make.inc DEPDIR := .deps DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d PYBIND11FLAG = - +ADDCPPFLAGS:=$(python_cf_embedded) $(pybind11_cflags) $(ADDCPPFLAGS) +ADDCLDFLAGS:=$(ADDCLDFLAGS) $(python_ld_embedded) OBJS = ActionWithPython.o PythonCVInterface.o PythonFunction.o PlumedPythonEmbeddedModule.o ifeq ($(SOEXT),dylib) @@ -18,6 +25,7 @@ endif all: PythonCVInterface.$(SOEXT) #-fvisibility=hidden is needed for pybind11 (to not conflict with different pybind11 versions) +#I think I enforced this nearly everywhere I set up a flag for the compiler ActionWithPython.o PythonCVInterface.o PythonFunction.o PlumedPythonEmbeddedModule.o: PYBIND11FLAG= -fvisibility=hidden %.o: %.cpp $(DEPDIR)/%.d | $(DEPDIR) @@ -35,7 +43,7 @@ include $(wildcard $(DEPFILES)) #TODO: seems that $PLUMED_KERNEL is not needed, check PythonCVInterface.$(SOEXT): $(OBJS) @echo Linking $@ - $(LDSHARED) $(SONAME_OPTION),"$(notdir $@)" $(DYNAMIC_LIBS) $(PLUMED_KERNEL) $(ADDCLDFLAGS) $^ -o $@ + $(LDSHARED) $(SONAME_OPTION),"$(notdir $@)" $(DYNAMIC_LIBS) $(PLUMED_KERNEL) $(ADDCLDFLAGS) $^ -o $@ clean: rm -f $(OBJS) PythonCVInterface.$(SOEXT) diff --git a/plugins/pycv/astyle.sh b/plugins/pycv/astyle.sh index 0338316fbe..51b0a7be36 100755 --- a/plugins/pycv/astyle.sh +++ b/plugins/pycv/astyle.sh @@ -1,20 +1,23 @@ #! /usr/bin/env bash +#formatted with shfmt https://github.com/mvdan/sh/releases +#checked with shellcheck + for file in *.c *.cpp *.h *.inc.in; do test -f "$file" || continue echo -n "astyle $file" - ../../astyle/astyle --options=../../.astyle.options <$file >$file.tmp && { - if cmp -s $file $file.tmp; then + ../../astyle/astyle --options=../../.astyle.options <"$file" >"${file}.tmp" && { + if cmp -s "$file" "${file}.tmp"; then echo else - cp $file.tmp $file + cp "${file}.tmp" "$file" echo " +++ PATCHED" fi } - rm $file.tmp + rm "${file}.tmp" done diff --git a/plugins/pycv/compileConfiguration.sh b/plugins/pycv/compileConfiguration.sh new file mode 100644 index 0000000000..ee27007cae --- /dev/null +++ b/plugins/pycv/compileConfiguration.sh @@ -0,0 +1,54 @@ +#!/bin/env bash + +#formatted with shfmt https://github.com/mvdan/sh/releases +#checked with shellcheck +# shellcheck disable=SC2034 # The unused variables will be used in sourcer files + +#please source this file + +#for some reason, on the WSL I need to compile with +# `export PYCV_EXTRA_LDFLAGS="-Wl,--no-as-needed"` +#-Wl,--no-as-needed forces the python library to be linked +#I do not undestand why, since -as-needed should be disabled by default + +plumed_program_name=${plumed_program_name:-plumed} + +#check if during config time the settings for compiling PyCV where got +plumed_canPyCV=$( + ${plumed_program_name} --no-mpi config makefile_conf | grep canPyCV | sed -e s/^canPyCV=// +) + +if [[ $plumed_canPyCV = yes ]]; then + pybind11_cflags=$(plumed --no-mpi config makefile_conf | grep pybind11_cflags | sed -e s/^pybind11_cflags=//) + python_cf_embedded=$(plumed --no-mpi config makefile_conf | grep python_cf_embedded | sed -e s/^python_cf_embedded=//) + python_ld_embedded=$(plumed --no-mpi config makefile_conf | grep python_ld_embedded | sed -e s/^python_ld_embedded=//) +else + #assign a default value to python bin and plumed + python_bin=${python_bin:-python} + #python3-config may be any python3.* version, this should avoid contamination from other environments + #and use pythonX.Y-config, as suggested in the manual + pyver=$($python_bin -c "import sysconfig;print(sysconfig.get_config_var('VERSION'))") + python_config=python${pyver}-config + + # Note that in conda libpython3xx is not found in the path returned by ldflags. IMHO it is a bug. + # The workaround is to -L appropriately. Will be fixed here. + conda_fixup=${CONDA_PREFIX+-L$CONDA_PREFIX/lib} + if [ -n "$conda_fixup" ]; then + echo "CONDA_PREFIX is set. Assuming conda and enabling a workaround for missing -L in ${python_config} --ldflags --embed" + fi + + if ! ${python_config} --embed >/dev/null 2>/dev/null; then + #TODO: verify that this does not give problems with conda + echo "PyCV needs python to be built to be embedable" + echo "(compiling python with --enable-shared should be enough)" + exit 1 + fi + if ! ${python_bin} -m pybind11 --includes >/dev/null; then + #python will automatically say that there is non pybind11 + exit 1 + fi + #-fvisibility=hidden is needed to correct the warnings for the visibility of some pybind11 functionalities + pybind11_cflags="$(${python_bin} -m pybind11 --includes) -fvisibility=hidden" + python_cf_embedded=$(${python_config} --cflags --embed) + python_ld_embedded=$(${python_config} --ldflags --embed) +fi \ No newline at end of file diff --git a/plugins/pycv/prepareMakeForDevelop.sh b/plugins/pycv/prepareMakeForDevelop.sh index 61a04e7c57..375851c5a9 100755 --- a/plugins/pycv/prepareMakeForDevelop.sh +++ b/plugins/pycv/prepareMakeForDevelop.sh @@ -1,12 +1,11 @@ #! /usr/bin/env bash -#assign a default value to python bin and plumed -python_bin=${python_bin:-python} -plumed_program_name=${plumed_program_name:-plumed} -#python3-config may be any python3.* version, this should avoid contamination from other environments -#and use pythonX.Y-config, as suggested in the manual -pyver=$($python_bin -c "import sysconfig;print(sysconfig.get_config_var('VERSION'))") -python_config=python${pyver}-config +#formatted with shfmt https://github.com/mvdan/sh/releases +#checked with shellcheck +# the SC2154 warnings are variables present in the sourced file + +source compileConfiguration.sh + if [[ -z $PLUMED_KERNEL ]]; then echo "$(basename $0) can work only if \"PLUMED_KERNEL\" is defined" @@ -14,16 +13,15 @@ if [[ -z $PLUMED_KERNEL ]]; then exit 1 fi -if ! ${python_config} --embed >/dev/null 2>/dev/null; then -#TODO: verify that this does not give problems with conda - echo "PyCV needs python to be built to be embedable" - echo "(compiling python with --enable-shared should be enough)" - exit 1 -fi - +plumed_include=$(${plumed_program_name} --no-mpi info --include-dir) { ${plumed_program_name} --no-mpi config makefile_conf echo "PLUMED_KERNEL=${PLUMED_KERNEL}" - echo "ADDCPPFLAGS=$(${python_config} --cflags --embed) $(${python_bin} -m pybind11 --includes) -I$(${plumed_program_name} --no-mpi info --include-dir)/plumed" - echo "ADDCLDFLAGS=${PYCV_EXTRA_LDFLAGS} $(${python_config} --ldflags --embed)" -} > Make.inc + if [[ ! $plumed_canPyCV = yes ]]; then + echo "pybind11_cflags=$pybind11_cflags" + echo "python_cf_embedded=$python_cf_embedded" + echo "python_ld_embedded=$python_ld_embedded" + fi + echo "ADDCPPFLAGS=-I${plumed_include}/plumed" + echo "ADDCLDFLAGS=${PYCV_EXTRA_LDFLAGS} ${conda_fixup}" +} > Makefile.conf diff --git a/plugins/pycv/standaloneCompile.sh b/plugins/pycv/standaloneCompile.sh index d42ef01b74..e5ce28ec29 100755 --- a/plugins/pycv/standaloneCompile.sh +++ b/plugins/pycv/standaloneCompile.sh @@ -1,35 +1,16 @@ #! /usr/bin/env bash -#assign a default value to python bin and plumed -python_bin=${python_bin:-python} -plumed_program_name=${plumed_program_name:-plumed} -#python3-config may be any python3.* version, this should avoid contamination from other environments -#and use pythonX.Y-config, as suggested in the manual -pyver=$($python_bin -c "import sysconfig;print(sysconfig.get_config_var('VERSION'))") -python_config=python${pyver}-config -# Note that in conda libpython3xx is not found in the path returned by ldflags. IMHO it is a bug. -# The workaround is to -L appropriately. Will be fixed here. -conda_fixup=${CONDA_PREFIX+-L$CONDA_PREFIX/lib} -if [ ! -z "$conda_fixup" ]; then - echo "CONDA_PREFIX is set. Assuming conda and enabling a workaround for missing -L in ${python_config} --ldflags --embed" -fi +#formatted with shfmt https://github.com/mvdan/sh/releases +#checked with shellcheck +# the SC2154 warnings are variables present in the sourced file -if ! ${python_config} --embed >/dev/null 2>/dev/null; then - #TODO: verify that this does not give problems with conda - echo "PyCV needs python to be built to be embedable" - echo "(compiling python with --enable-shared should be enough)" - exit 1 -fi +source compileConfiguration.sh -#for some reason, on the WSL I need to compile with `export PYCV_EXTRA_LDFLAGS="-Wl,--no-as-needed"` -#-Wl,--no-as-needed forces the python library to be linked, without this in a WSL does not work -#-fvisibility=hidden is needed to correct the warnings for the visibility of some pybind11 functionalities -export PLUMED_MKLIB_CFLAGS="$(${python_config} --cflags --embed) $(${python_bin} -m pybind11 --includes) -fvisibility=hidden" +export PLUMED_MKLIB_CFLAGS="${python_cf_embedded} ${pybind11_cflags}" +export PLUMED_MKLIB_LDFLAGS="${PYCV_EXTRA_LDFLAGS} ${python_ld_embedded} ${conda_fixup}" -export PLUMED_MKLIB_LDFLAGS="${PYCV_EXTRA_LDFLAGS} $(${python_config} --ldflags --embed) $conda_fixup" - -echo PLUMED_MKLIB_CFLAGS=$PLUMED_MKLIB_CFLAGS -echo PLUMED_MKLIB_LDFLAGS=$PLUMED_MKLIB_LDFLAGS +echo "PLUMED_MKLIB_CFLAGS=$PLUMED_MKLIB_CFLAGS" +echo "PLUMED_MKLIB_LDFLAGS=$PLUMED_MKLIB_LDFLAGS" ${plumed_program_name} mklib PythonCVInterface.cpp ActionWithPython.cpp PythonFunction.cpp PlumedPythonEmbeddedModule.cpp diff --git a/python/Makefile b/python/Makefile index 1ed692191b..ea96689808 100644 --- a/python/Makefile +++ b/python/Makefile @@ -9,7 +9,7 @@ VERSION = $(shell if test -f ../VERSION.txt ; then grep -v \\\# ../VERSION.txt ; plumed_compiled := $(wildcard ../src/lib/plumed) -ifdef python_bin +ifdef plumed_found_cython all: @echo Building python interface for PLUMED