diff --git a/cmake/modules/lcgsoft-macros.cmake b/cmake/modules/lcgsoft-macros.cmake
index d2cf094f38863a81e19565acba7120852583a34d..e6095454703d2132928bfdd152b71ebc4fa93c0b 100644
--- a/cmake/modules/lcgsoft-macros.cmake
+++ b/cmake/modules/lcgsoft-macros.cmake
@@ -568,16 +568,17 @@ function(LCG_expand_version_patterns version outvar input)
   string(REPLACE <NATIVE_VERSION> ${version} result "${input}")
   string(REPLACE <VERSION> ${version} result "${result}")
   #string(REPLACE <VOID> "" result "${result}")
-  set(knownvars SOURCE_DIR INSTALL_DIR)
+  set(knownvars SOURCE_DIR INSTALL_DIR VOID)
   foreach(iter 1 2 3)  # 3 nested replacements
-    string(REGEX MATCHALL "<[^ <>(){}]+>" vars ${result})
+    string(REGEX MATCHALL "[^$]<[^ <>(){}]+>" vars ${result})
     foreach(var ${vars})
+      string(SUBSTRING ${var} 1 -1 var)
       string(REPLACE "<" "" v ${var})
       string(REPLACE ">" "" v ${v})
       list(FIND knownvars ${v} index)
       if(DEFINED ${v})
         string(REPLACE ${var} ${${v}} result "${result}")
-      elseif(iter EQUAL 3 AND index EQUAL -1 AND NOT v STREQUAL VOID)
+      elseif(iter EQUAL 3 AND index EQUAL -1)
         message(FATAL_ERROR " Could not resolve variable '<${v}>' in 'LCGPackage_Add':\n ${result}")
       endif()
     endforeach()
diff --git a/externals/patches/openldap-2.4.39.patch b/externals/patches/openldap-2.4.39.patch
new file mode 100644
index 0000000000000000000000000000000000000000..ad20e8dbd4baac01eccc3ab84bbf412416eb58e1
--- /dev/null
+++ b/externals/patches/openldap-2.4.39.patch
@@ -0,0 +1,21 @@
+diff -r -u openldap-2.4.39/configure openldap/2.4.39/configure
+--- configure.orig	2014-01-25 14:36:15.000000000 +0100
++++ configure	2015-05-06 09:46:50.000000000 +0200
+@@ -20307,7 +20307,7 @@
+ __db_version DB_VERSION_MAJOR
+ 
+ _ACEOF
+-	set X `eval "$ac_cpp conftest.$ac_ext" | $EGREP __db_version` none none
++	set X `eval "$ac_cpp -P conftest.$ac_ext" | $EGREP __db_version` none none
+ 	ol_cv_bdb_major=${3}
+ 
+ fi
+@@ -20333,7 +20333,7 @@
+ __db_version DB_VERSION_MINOR
+ 
+ _ACEOF
+-	set X `eval "$ac_cpp conftest.$ac_ext" | $EGREP __db_version` none none
++	set X `eval "$ac_cpp -P conftest.$ac_ext" | $EGREP __db_version` none none
+ 	ol_cv_bdb_minor=${3}
+ 
+ fi