From cc8131feac011954b6b1cc1a9bfde6172d359a05 Mon Sep 17 00:00:00 2001
From: Orgad Shaneh <orgad.shaneh@audiocodes.com>
Date: Mon, 12 Apr 2021 18:12:30 +0300
Subject: [PATCH 1/2] Fix symlinking with DESTDIR

make install DESTDIR=/path/inst failed on symlink.
---
 CMakeLists.txt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 50bf1713..2b258564 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2504,20 +2504,20 @@ function(install_manpage_symlink SOURCE TARGET MANDIR)
         # If we haven't found an ln executable with MinGW, we don't try
         # generating and installing the man pages, so if we get here,
         # we've found that executable.
-        set(LINK_COMMAND "\"${LINK_EXECUTABLE}\" \"-s\" \"${SOURCE}\" \"${TARGET}\"")
+        set(LINK_COMMAND "\"${LINK_EXECUTABLE}\" \"-s\" \$ENV{DESTDIR}\"${SOURCE}\" \"${TARGET}\"")
     else(MINGW)
-        set(LINK_COMMAND "\"${CMAKE_COMMAND}\" \"-E\" \"create_symlink\" \"${SOURCE}\" \"${TARGET}\"")
+        set(LINK_COMMAND "\"${CMAKE_COMMAND}\" \"-E\" \"create_symlink\" \$ENV{DESTDIR}\"${SOURCE}\" \"${TARGET}\"")
     endif(MINGW)
 
     install(CODE
         "message(STATUS \"Symlinking: ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
          execute_process(
             COMMAND \"${CMAKE_COMMAND}\" \"-E\" \"remove\" \"${TARGET}\"
-            WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
+            WORKING_DIRECTORY \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${MANDIR}
           )
          execute_process(
             COMMAND ${LINK_COMMAND}
-            WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
+            WORKING_DIRECTORY \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${MANDIR}
             RESULT_VARIABLE EXIT_STATUS
           )
           if(NOT EXIT_STATUS EQUAL 0)
-- 
2.31.0.windows.1

