Only link with libdl on Linux

Requiring an extra library for dlopen is a Linux non-POSIX-compliance.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/programs/Makefile b/programs/Makefile
index 2a3fd6f..7b9c5dd 100644
--- a/programs/Makefile
+++ b/programs/Makefile
@@ -18,6 +18,12 @@
 		-lmbedx509$(SHARED_SUFFIX)	\
 		-lmbedcrypto$(SHARED_SUFFIX)
 
+ifeq ($(shell uname -s),Linux)
+DLOPEN_LDFLAGS ?= -ldl
+else
+DLOPEN_LDFLAGS ?=
+endif
+
 include ../3rdparty/Makefile.inc
 LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
 
@@ -328,7 +334,7 @@
 # Do not link any test objects (that would bring in a static dependency on
 # libmbedcrypto at least). Do not link with libmbed* (that would defeat the
 # purpose of testing dynamic loading).
-	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/dlopen.c $(LDFLAGS) -ldl -o $@
+	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/dlopen.c $(LDFLAGS) $(DLOPEN_LDFLAGS) -o $@
 endif
 
 test/query_config.o: test/query_config.c test/query_config.h $(DEP)