From 9ca8c0e77fb7ad095c6e596dc041129fe7259b76 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Fri, 6 Jun 2025 12:56:43 +0800
Subject: [PATCH] Fix flags and linking

diff --git scripts/make-config.sh scripts/make-config.sh
index d50bf3a1f..526c230c0 100755
--- scripts/make-config.sh
+++ scripts/make-config.sh
@@ -619,7 +619,7 @@ elif [[ -n $DRAGONFLYBSD ]]; then
     LDFLAGS_LINKER="-Wl,--as-needed,-z,origin,-rpath,'\$\$ORIGIN',-z,noexecstack"
     SOFLAGS='-Wl,-soname=$(notdir $@),-z,noexecstack'
 elif [[ -n $MACOS ]]; then
-    LDFLAGS_LINKER="-Wl,-rpath,@executable_path,-rpath,@executable_path/../lib,-no_warn_duplicate_libraries,-dead_strip_dylibs"
+    LDFLAGS_LINKER="-Wl,-rpath,@executable_path,-rpath,@executable_path/../lib,-dead_strip_dylibs"
     SOFLAGS="-Wl,-rpath,@loader_path -install_name '@rpath/\$(notdir \$@)'"
 fi
 
@@ -793,7 +793,7 @@ LIBTSDUCK_CXXFLAGS_INCLUDES="$LIBTSDUCK_CXXFLAGS_INCLUDES $CXXFLAGS_JAVA"
 LIBTSDUCK_LDLIBS="$LIBTSDUCK_LDLIBS $LDLIBS_PCSC"
 [[ -n $FREEBSD ]] && LIBTSCORE_LDLIBS="$LIBTSCORE_LDLIBS -lprocstat"
 [[ -n $OPENBSD$NETBSD$DRAGONFLYBSD ]] && LIBTSCORE_LDLIBS="$LIBTSCORE_LDLIBS -lkvm"
-[[ -n $LINUX ]] && LIBTSCORE_LDLIBS="$LIBTSCORE_LDLIBS -latomic"
+[[ -n $LINUX$MACOS ]] && LIBTSCORE_LDLIBS="$LIBTSCORE_LDLIBS -latomic"
 [[ -z $NOOPENSSL ]] && LIBTSCORE_LDLIBS="$LIBTSCORE_LDLIBS -lcrypto"
 [[ -n $NODTAPI ]] && LIBTSDUCK_CXXFLAGS_INCLUDES="$LIBTSDUCK_CXXFLAGS_INCLUDES -DTS_NO_DTAPI=1"
 [[ -n $NOHIDES ]] && LIBTSDUCK_CXXFLAGS_INCLUDES="$LIBTSDUCK_CXXFLAGS_INCLUDES -DTS_NO_HIDES=1"
diff --git src/libtscore/config/Makefile src/libtscore/config/Makefile
index d0fd5be4a..4fd933062 100644
--- src/libtscore/config/Makefile
+++ src/libtscore/config/Makefile
@@ -45,7 +45,7 @@ install-devel:
 	    -e 's| *{{STDCPP}} *| $(if $(NOPCSTD),,$(CXXFLAGS_STANDARD) )|g' \
 	    $(if $(OPENBSD)$(NETBSD),-e 's| *-ldl *| |g') \
 	    $(if $(MACOS)$(OPENBSD),-e 's| *-lrt *| |g') \
-	    $(if $(MACOS)$(BSD),-e 's| *-latomic *| |g') \
+	    $(if $(BSD),-e 's| *-latomic *| |g') \
 	    $(if $(FREEBSD),,-e 's| *-lprocstat *| |g') \
 	    $(if $(OPENBSD)$(NETBSD)$(DRAGONFLYBSD),,-e 's| *-lkvm *| |g') \
 	    -e 's|:[ ,][ ,]*|: |g' -e 's|,[ ,][ ,]*|, |g' -e 's|[ ,]*$$||' -e '/: *$$/d' \
diff --git src/libtscore/system/tsApplicationSharedLibrary.cpp src/libtscore/system/tsApplicationSharedLibrary.cpp
index 8c9f0f3b2..dfcf29d06 100644
--- src/libtscore/system/tsApplicationSharedLibrary.cpp
+++ src/libtscore/system/tsApplicationSharedLibrary.cpp
@@ -122,12 +122,9 @@ void ts::ApplicationSharedLibrary::GetSearchPath(UStringList& directories, const
         directories.push_back(u"/usr/lib64");
     }
 #endif
-#if defined(TS_MAC) && defined(TS_X86_64)
-    directories.push_back(u"/usr/local/lib/tsduck");
-    directories.push_back(u"/usr/local/lib");
-#elif defined(TS_MAC) && defined(TS_ARM64)
-    directories.push_back(u"/opt/homebrew/lib/tsduck");
-    directories.push_back(u"/opt/homebrew/lib");
+#if defined(TS_MAC)
+    directories.push_back(u"/opt/local/lib/tsduck");
+    directories.push_back(u"/opt/local/lib");
 #else
     directories.push_back(u"/usr/lib/tsduck");
     directories.push_back(u"/usr/lib");
diff --git src/libtsduck/config/Makefile src/libtsduck/config/Makefile
index 26b00404a..db6988421 100644
--- src/libtsduck/config/Makefile
+++ src/libtsduck/config/Makefile
@@ -69,7 +69,7 @@ install-devel:
 	    $(if $(NOVATEK),-e 's|libusb-1.0||g') \
 	    $(if $(OPENBSD)$(NETBSD),-e 's| *-ldl *| |g') \
 	    $(if $(MACOS)$(OPENBSD),-e 's| *-lrt *| |g') \
-	    $(if $(MACOS)$(BSD),-e 's| *-latomic *| |g') \
+	    $(if $(BSD),-e 's| *-latomic *| |g') \
 	    $(if $(FREEBSD),,-e 's| *-lprocstat *| |g') \
 	    $(if $(OPENBSD)$(NETBSD)$(DRAGONFLYBSD),,-e 's| *-lkvm *| |g') \
 	    -e 's|:[ ,][ ,]*|: |g' -e 's|,[ ,][ ,]*|, |g' -e 's|[ ,]*$$||' -e '/: *$$/d' \
diff --git src/libtsduck/java/src/io/tsduck/NativeLibrary.java src/libtsduck/java/src/io/tsduck/NativeLibrary.java
index 03eb58c86..6c662ec56 100644
--- src/libtsduck/java/src/io/tsduck/NativeLibrary.java
+++ src/libtsduck/java/src/io/tsduck/NativeLibrary.java
@@ -80,7 +80,7 @@ class NativeLibrary {
             path = searchLibraryInPath(System.getenv("TSPLUGINS_PATH"), libName);
             // Try various typical Unix directories
             if (path == null && !isWindows) {
-                path = searchLibraryInPath("/usr/local/lib:/usr/lib:/usr/lib64", libName);
+                path = searchLibraryInPath("/opt/local/lib:/usr/local/lib:/usr/lib:/usr/lib64", libName);
             }
             // Load the native library by explicit file name or using system search rules.
             if (path != null) {
