Clean up library-finding logic
diff --git a/Makefile.in b/Makefile.in
index 48f7c09..4ff511f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -14,11 +14,26 @@
 # distribution  cleans and builds a .tgz
 # tags          builds etags file from all .c and .h files
 
+DYNAMIC_PATH_VAR = @DYNAMIC_PATH_VAR@
 CRYPTO_LIBDIR = @CRYPTO_LIBDIR@
 USE_EXTERNAL_CRYPTO = @USE_EXTERNAL_CRYPTO@
 HAVE_PCAP = @HAVE_PCAP@
 
-FIND_LIBRARIES = DYLD_LIBRARY_PATH=$(CRYPTO_LIBDIR)
+# Specify how tests should find shared libraries on macOS and Linux
+#
+# macOS purges DYLD_LIBRARY_PATH when spawning subprocesses, so it's
+# not possible to pass this in from the outside; we have to specify
+# it for any subprocesses we call. No support for dynamic linked
+# tests on Windows.
+ifneq ($(OS),Windows_NT)
+	UNAME_S = $(shell uname -s)
+	ifeq ($(UNAME_S),Linux)
+		FIND_LIBRARIES = LD_LIBRARY_PATH=$(CRYPTO_LIBDIR)
+	endif
+	ifeq ($(UNAME_S),Darwin)
+		FIND_LIBRARIES = DYLD_LIBRARY_PATH=$(CRYPTO_LIBDIR)
+	endif
+endif
 
 .PHONY: all shared_library test
 
@@ -26,7 +41,6 @@
 
 runtest: test
 	@echo "running libsrtp2 test applications..."
-	# XXX(RLB): This is a hack
 	$(FIND_LIBRARIES) crypto/test/cipher_driver$(EXE) -v >/dev/null
 	$(FIND_LIBRARIES) crypto/test/kernel_driver$(EXE) -v >/dev/null
 	$(FIND_LIBRARIES) test/test_srtp$(EXE) >/dev/null
diff --git a/crypto/Makefile.in b/crypto/Makefile.in
index 0e3db61..b384a57 100644
--- a/crypto/Makefile.in
+++ b/crypto/Makefile.in
@@ -21,7 +21,21 @@
 
 RANLIB	= @RANLIB@
 
-FIND_LIBRARIES = DYLD_LIBRARY_PATH=../$(CRYPTO_LIBDIR)
+# Specify how tests should find shared libraries on macOS and Linux
+#
+# macOS purges DYLD_LIBRARY_PATH when spawning subprocesses, so it's
+# not possible to pass this in from the outside; we have to specify
+# it for any subprocesses we call. No support for dynamic linked
+# tests on Windows.
+ifneq ($(OS),Windows_NT)
+	UNAME_S = $(shell uname -s)
+	ifeq ($(UNAME_S),Linux)
+		FIND_LIBRARIES = LD_LIBRARY_PATH=../$(CRYPTO_LIBDIR)
+	endif
+	ifeq ($(UNAME_S),Darwin)
+		FIND_LIBRARIES = DYLD_LIBRARY_PATH=../$(CRYPTO_LIBDIR)
+	endif
+endif
 
 # EXE defines the suffix on executables - it's .exe for cygwin, and
 # null on linux, bsd, and OS X and other OSes.  we define this so that