makefile: Support both .so and .a link libraries on Linux

For some strange reason, Ubuntu 21.10 delivers various libraries as
either direct link libraries (".a") or  shared objects (".so") where
historically essentially everything was shared objects..
This commit is contained in:
Mark Pizzolato 2021-10-24 18:41:08 -07:00
parent d0c7276dd7
commit db401a4dbe

View file

@ -178,7 +178,7 @@ ifneq ($(findstring Windows,${OS}),)
endif endif
find_exe = $(abspath $(strip $(firstword $(foreach dir,$(strip $(subst :, ,${PATH})),$(wildcard $(dir)/$(1)))))) find_exe = $(abspath $(strip $(firstword $(foreach dir,$(strip $(subst :, ,${PATH})),$(wildcard $(dir)/$(1))))))
find_lib = $(abspath $(strip $(firstword $(foreach dir,$(strip ${LIBPATH}),$(wildcard $(dir)/lib$(1).${LIBEXT}))))) find_lib = $(firstword $(abspath $(strip $(firstword $(foreach dir,$(strip ${LIBPATH}),$(foreach ext,$(strip ${LIBEXT}),$(wildcard $(dir)/lib$(1).$(ext))))))))
find_include = $(abspath $(strip $(firstword $(foreach dir,$(strip ${INCPATH}),$(wildcard $(dir)/$(1).h))))) find_include = $(abspath $(strip $(firstword $(foreach dir,$(strip ${INCPATH}),$(wildcard $(dir)/$(1).h)))))
ifneq (0,$(TESTS)) ifneq (0,$(TESTS))
find_test = RegisterSanityCheck $(abspath $(wildcard $(1)/tests/$(2)_test.ini)) </dev/null find_test = RegisterSanityCheck $(abspath $(wildcard $(1)/tests/$(2)_test.ini)) </dev/null
@ -378,7 +378,8 @@ ifeq (${WIN32},) #*nix Environments (&& cygwin)
LIBPATH := $(sort $(foreach lib,$(shell /sbin/ldconfig -p | grep ' => /' | sed 's/^.* => //'),$(dir $(lib)))) LIBPATH := $(sort $(foreach lib,$(shell /sbin/ldconfig -p | grep ' => /' | sed 's/^.* => //'),$(dir $(lib))))
endif endif
endif endif
LIBEXT = so LIBSOEXT = so
LIBEXT = $(LIBSOEXT) a
else else
ifeq (SunOS,$(OSTYPE)) ifeq (SunOS,$(OSTYPE))
OSNAME = Solaris OSNAME = Solaris
@ -482,6 +483,9 @@ ifeq (${WIN32},) #*nix Environments (&& cygwin)
endif endif
endif endif
endif endif
ifeq (,$(LIBSOEXT))
LIBSOEXT = $(LIBEXT)
endif
ifeq (,$(filter /lib/,$(LIBPATH))) ifeq (,$(filter /lib/,$(LIBPATH)))
ifeq (existlib,$(shell if $(TEST) -d /lib/; then echo existlib; fi)) ifeq (existlib,$(shell if $(TEST) -d /lib/; then echo existlib; fi))
LIBPATH += /lib/ LIBPATH += /lib/
@ -573,7 +577,7 @@ ifeq (${WIN32},) #*nix Environments (&& cygwin)
endif endif
ifneq (,$(call find_include,dlfcn)) ifneq (,$(call find_include,dlfcn))
ifneq (,$(call find_lib,dl)) ifneq (,$(call find_lib,dl))
OS_CCDEFS += -DHAVE_DLOPEN=${LIBEXT} OS_CCDEFS += -DHAVE_DLOPEN=$(LIBSOEXT)
OS_LDFLAGS += -ldl OS_LDFLAGS += -ldl
$(info using libdl: $(call find_lib,dl) $(call find_include,dlfcn)) $(info using libdl: $(call find_lib,dl) $(call find_include,dlfcn))
else else
@ -582,7 +586,7 @@ ifeq (${WIN32},) #*nix Environments (&& cygwin)
$(info using libdl: $(call find_include,dlfcn)) $(info using libdl: $(call find_include,dlfcn))
else else
ifneq (,$(call find_lib,dld)) ifneq (,$(call find_lib,dld))
OS_CCDEFS += -DHAVE_DLOPEN=${LIBEXT} OS_CCDEFS += -DHAVE_DLOPEN=$(LIBSOEXT)
OS_LDFLAGS += -ldld OS_LDFLAGS += -ldld
$(info using libdld: $(call find_lib,dld) $(call find_include,dlfcn)) $(info using libdld: $(call find_lib,dld) $(call find_include,dlfcn))
else else