From cc864a15ce9707035e1052834e27707e5980d029 Mon Sep 17 00:00:00 2001 From: Xiang Zhong Date: Fri, 14 Jun 2024 20:43:43 +0800 Subject: [PATCH] dynamically resolve envs --- patches/patch.sh | 9 +++++++-- src/lib/Makefile | 28 ++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/patches/patch.sh b/patches/patch.sh index 4a454077d0..908ddf248a 100755 --- a/patches/patch.sh +++ b/patches/patch.sh @@ -284,14 +284,19 @@ case "$action" in test -n "$quiet" || echo "Executing plumed_before_patch function" plumed_before_patch fi + if test -f "$PLUMED_INCLUDEDIR/$PLUMED_PROGRAM_NAME/wrapper/Plumed.h"; then + header="$PLUMED_INCLUDEDIR/$PLUMED_PROGRAM_NAME/wrapper/Plumed.h" + else + header=`realpath "$PLUMED_ROOT/../../include/plumed/wrapper/Plumed.h"` + fi if test -n "$include" ; then test -n "$quiet" || echo "Including Plumed.h, Plumed.inc, and Plumed.cmake ($mode mode)" - echo "#include \"$PLUMED_INCLUDEDIR/$PLUMED_PROGRAM_NAME/wrapper/Plumed.h\"" > Plumed.h + echo "#include \"$header\"" > Plumed.h echo "include $PLUMED_ROOT/src/lib/Plumed.inc.$mode" > Plumed.inc echo "include($PLUMED_ROOT/src/lib/Plumed.cmake.$mode)" > Plumed.cmake else test -n "$quiet" || echo "Linking Plumed.h, Plumed.inc, and Plumed.cmake ($mode mode)" - ln -fs "$PLUMED_INCLUDEDIR/$PLUMED_PROGRAM_NAME/wrapper/Plumed.h" Plumed.h + ln -fs "$header" Plumed.h ln -fs "$PLUMED_ROOT/src/lib/Plumed.inc.$mode" Plumed.inc ln -fs "$PLUMED_ROOT/src/lib/Plumed.cmake.$mode" Plumed.cmake fi diff --git a/src/lib/Makefile b/src/lib/Makefile index c28dfe2260..5967b04f39 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -446,16 +446,36 @@ ifeq ($(PLUMED_INSTALL),Install) # If plumed is installed, single paths can be overridden using env vars @echo "export PLUMED_IS_INSTALLED=yes" >> $@ @echo "export PLUMED_ROOT=\"\$${PLUMED_ROOT-$(libdir)/$(program_name)}\"" >> $@ - @echo "export PLUMED_INCLUDEDIR=\"\$${PLUMED_INCLUDEDIR-$(includedir)}\"" >> $@ - @echo "export PLUMED_HTMLDIR=\"\$${PLUMED_HTMLDIR=$(htmldir)}\"" >> $@ + @echo "PLUMED_INCLUDEDIR=\"\$${PLUMED_INCLUDEDIR-$(includedir)}\"" >> $@ + @echo "if test -d \"\$$PLUMED_INCLUDEDIR/plumed\"; then" >> $@ + @echo " export PLUMED_INCLUDEDIR=\$$PLUMED_INCLUDEDIR" >> $@ + @echo "else" >> $@ + @echo " export PLUMED_INCLUDEDIR=\$$PLUMED_ROOT/../../include" >> $@ + @echo "fi" >> $@ + @echo "PLUMED_HTMLDIR=\"\$${PLUMED_HTMLDIR=$(htmldir)}\"" >> $@ + @echo "if test -d \"\$$PLUMED_HTMLDIR\"; then" >> $@ + @echo " export PLUMED_HTMLDIR=\$$PLUMED_HTMLDIR" >> $@ + @echo "else" >> $@ + @echo " export PLUMED_HTMLDIR=\$$PLUMED_ROOT/../../share/doc/plumed" >> $@ + @echo "fi" >> $@ @echo "export PLUMED_PROGRAM_NAME=\"\$${PLUMED_PROGRAM_NAME-$(program_name)}\"" >> $@ @echo "export PLUMED_VERSION=$(VERSION)" >> $@ @echo "source \"\$$PLUMED_ROOT\"/scripts/$(subst plumed-,,$(@F)).sh" >> $@ else @echo "export PLUMED_IS_INSTALLED=no" >> $@ @echo "export PLUMED_ROOT=\"\$${PLUMED_ROOT-$(realpath ../../)}\"" >> $@ - @echo "export PLUMED_INCLUDEDIR=\"\$${PLUMED_ROOT}/src/include\"" >> $@ - @echo "export PLUMED_HTMLDIR=\"\$${PLUMED_ROOT}\"" >> $@ + @echo "PLUMED_INCLUDEDIR=\"\$${PLUMED_INCLUDEDIR-$(includedir)}\"" >> $@ + @echo "if test -d \"\$$PLUMED_INCLUDEDIR/plumed\"; then" >> $@ + @echo " export PLUMED_INCLUDEDIR=\$$PLUMED_INCLUDEDIR" >> $@ + @echo "else" >> $@ + @echo " export PLUMED_INCLUDEDIR=\$$PLUMED_ROOT/../../include" >> $@ + @echo "fi" >> $@ + @echo "PLUMED_HTMLDIR=\"\$${PLUMED_HTMLDIR=$(htmldir)}\"" >> $@ + @echo "if test -d \"\$$PLUMED_HTMLDIR\"; then" >> $@ + @echo " export PLUMED_HTMLDIR=\$$PLUMED_HTMLDIR" >> $@ + @echo "else" >> $@ + @echo " export PLUMED_HTMLDIR=\$$PLUMED_ROOT/../../share/doc/plumed" >> $@ + @echo "fi" >> $@ @echo "export PLUMED_PROGRAM_NAME=plumed" >> $@ @echo "export PLUMED_VERSION=$(VERSION)" >> $@ @echo "source \"\$$PLUMED_ROOT\"/scripts/$(subst plumed-,,$(@F)).sh" >> $@