BUILD: makefile: reference libdl only once

There used to be special cases where USE_DL was only for the SSL library,
then for Lua, then was used globally, but each of them kept their own copy
of -ldl. When building on a system supporting libdl, with SSL and Lua
enabled, no less than 3 -ldl are found on the linker's command line.

What matters is only that it's close to the end, so let's remove the old
specific ones and move the global one to the end. The option now uses its
own DL_LDFLAGS that is automatically collected into OPTIONS_LDFLAGS.
diff --git a/Makefile b/Makefile
index c464e78..803eb14 100644
--- a/Makefile
+++ b/Makefile
@@ -542,10 +542,6 @@
 OPTIONS_OBJS   += src/ev_evports.o
 endif
 
-ifneq ($(USE_DL),)
-OPTIONS_LDFLAGS += -ldl
-endif
-
 ifneq ($(USE_RT),)
 OPTIONS_LDFLAGS += -lrt
 endif
@@ -572,9 +568,6 @@
 OPTIONS_CFLAGS  += $(if $(SSL_INC),-I$(SSL_INC))
 OPTIONS_LDFLAGS += $(if $(SSL_LIB),-L$(SSL_LIB)) -lssl -lcrypto
 endif
-ifneq ($(USE_DL),)
-OPTIONS_LDFLAGS += -ldl
-endif
 OPTIONS_OBJS  += src/ssl_sock.o src/ssl_ckch.o src/ssl_sample.o src/ssl_crtlist.o src/cfgparse-ssl.o src/ssl_utils.o src/jwt.o src/ssl_ocsp.o
 endif
 
@@ -629,9 +622,6 @@
 endif
 
 OPTIONS_LDFLAGS += $(LUA_LD_FLAGS) -l$(LUA_LIB_NAME) -lm
-ifneq ($(USE_DL),)
-OPTIONS_LDFLAGS += -ldl
-endif
 OPTIONS_OBJS    += src/hlua.o src/hlua_fcn.o
 endif
 
@@ -804,6 +794,11 @@
 include addons/ot/Makefile
 endif
 
+# better keep this one close to the end, as several libs above may need it
+ifneq ($(USE_DL),)
+  DL_LDFLAGS = -ldl
+endif
+
 ifneq ($(USE_LIBATOMIC),)
   TARGET_LDFLAGS += -latomic
 endif