From 3cb27aa2cd543445dfd132d00a87912638043e0c Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Wed, 8 May 2019 19:41:40 +0200
Subject: [PATCH] Fix to allow finding indirect libraries on Linux

---
 conda/recipe/build.sh  | 24 ++++++++++++++++--------
 conda/recipe/meta.yaml |  3 +++
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/conda/recipe/build.sh b/conda/recipe/build.sh
index bd610a290..eb8bc15cd 100644
--- a/conda/recipe/build.sh
+++ b/conda/recipe/build.sh
@@ -3,8 +3,7 @@
 env | sort
 
 # GB: install xdrfile library
-if false; then
-    # TG - disabling because it fails to link for no rational cause
+if true; then
     wget http://ftp.gromacs.org/pub/contrib/xdrfile-1.1.4.tar.gz
     tar xzf xdrfile-1.1.4.tar.gz
     cd xdrfile-1.1.4
@@ -14,14 +13,23 @@ if false; then
     cd ../
 fi
 
-# TG: The "disabled" features are workaround for possible
-#     conda+configure bugs in library search: building is ok but
-#     linking with the .so doesn't find them (in
-#     conda-forge). Possibly the LD path needs tweaks.
+# TODO: install docs?
 
-# TODO: re-enable them and see. Also to do: install docs?
+# python wrapper is installed with pip
+# we temporarily use internal lapack/blas (should probably be fixed)
+# STATIC_LIBS is required on Linux for the following reason:
+# When using env modules the dependent libraries can be found through the
+# LD_LIBRARY_PATH or encoded configuring with -rpath.
+# Conda does not use LD_LIBRARY_PATH and it is thus necessary to suggest where libraries are.
+
+if test -n "$MACOSX_DEPLOYMENT_TARGET" ; then
+  opt=""
+else
+  opt=STATIC_LIBS=-Wl,-rpath-link,$PREFIX/lib
+fi
+
+./configure --prefix=$PREFIX --enable-shared --disable-python --disable-external-lapack --disable-external-blas $opt
 
-./configure --prefix=$PREFIX --enable-shared --disable-python --disable-zlib --disable-external-lapack --disable-external-blas 
 make -j4
 make install
 
diff --git a/conda/recipe/meta.yaml b/conda/recipe/meta.yaml
index a1e761c29..ee96692cd 100644
--- a/conda/recipe/meta.yaml
+++ b/conda/recipe/meta.yaml
@@ -43,6 +43,8 @@ requirements:
     - pip
     - cython
     - zlib
+# cannot link gsl on MacOS
+    - gsl # [linux]
     - m2w64-binutils  # [win]
     - m2w64-gcc  # [win]
     - m2w64-tools-git  # [win]
@@ -50,6 +52,7 @@ requirements:
   run:
     - python
     - zlib
+    - gsl # [linux]
 
 test:
   # TODO. In principle these could be the official regtests.
-- 
GitLab