From: Sophie Brun <sophie@offensive-security.com>
Date: Tue, 15 Jun 2021 12:05:11 +0200
Subject: Install private lib correctly and set RPATH

Last-Update: 2022-08-26

The shared lib are private modules only used by dd_rescue binary. They
don't have SONAME:
 - Install *.so in /usr/lib/ddrescue instead of usr/lib/
 - Set RPATH in binary dd_rescue
---
 Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 4a33b8d..eff3399 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ INSTALLFLAGS = -s
 prefix = $(DESTDIR)/usr
 INSTALLDIR = $(prefix)/bin
 #INSTALLDIR = $(DESTDIR)/bin
-INSTALLLIBDIR = $(prefix)/$(LIB)
+INSTALLLIBDIR = $(prefix)/$(LIB)/ddrescue
 #INSTALLLIBDIR = $(DESTDIR)/$(LIBDIR)
 MANDIR = $(prefix)/share/man
 #MYDIR = dd_rescue-$(VERSION)
@@ -89,7 +89,7 @@ ifeq ($(MACH),i386)
 endif
 ifeq ($(MACH),x86_64)
   ISX86 := 1
-  LIB = lib64
+  LIB = lib
 endif
 
 ifeq ($(ISX86), 1)
@@ -185,7 +185,7 @@ endif	# ARMv6
 endif	# ARMv7/8
 endif	# ARM
 ifeq ($(MACH),aarch64)
-	LIB = lib64
+	LIB = lib
 	OBJECTS2 = find_nonzero_arm64.o
 	#POBJECTS2 = find_nonzero.po find_nonzero_arm64.po
 	AES_ARM64_O = aes_arm64.o
@@ -364,7 +364,7 @@ libfalloc-static: $(SRCDIR)/dd_rescue.c $(DDR_HEADERS) $(OBJECTS) $(OBJECTS2)
 
 # This is the default built
 dd_rescue: $(SRCDIR)/dd_rescue.c $(DDR_HEADERS) $(OBJECTS) $(OBJECTS2)
-	$(CC) $(CFLAGS) $(PIE) $(LDPIE) $(DEFINES) $< $(OUT) $(OBJECTS) $(OBJECTS2) -ldl $(EXTRA_LDFLAGS) $(RDYNAMIC)
+	$(CC) $(CFLAGS) $(PIE) $(LDPIE) $(DEFINES) $< $(OUT) $(OBJECTS) $(OBJECTS2) -ldl $(EXTRA_LDFLAGS) -Wl,-rpath,/usr/lib/ddrescue $(RDYNAMIC)
 
 # Test programs 
 md5: $(SRCDIR)/md5.c $(SRCDIR)/md5.h $(SRCDIR)/hash.h config.h
