tools: Rework linking options for ocaml binding libraries
authorAnthony PERARD <anthony.perard@citrix.com>
Thu, 13 Oct 2022 13:05:13 +0000 (14:05 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 14 Oct 2022 19:56:57 +0000 (20:56 +0100)
Using a full path to the C libraries when preparing one of the ocaml
binding for those libraries make the binding unusable by external
project. The full path is somehow embedded and reused by the external
project when linking against the binding.

Instead, we will use the proper way to link a library, by using '-l'.
For in-tree build, we also need to provide the search directory via
'-L'.

(The search path -L are still be embedded, but at least that doesn't
prevent the ocaml binding from been used.)

Related-to: xen-project/xen#96
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
tools/Rules.mk
tools/ocaml/libs/eventchn/Makefile
tools/ocaml/libs/xc/Makefile
tools/ocaml/libs/xentoollog/Makefile
tools/ocaml/libs/xl/Makefile

index a165dc4bdaabcd2df22f0bdf52511b49c497dda6..34d495fff7bbc29bf35d0fac083c214f31ad51f9 100644 (file)
@@ -113,6 +113,14 @@ define xenlibs-ldflags
     $(foreach lib,$(1),-L$(XEN_ROOT)/tools/libs/$(lib))
 endef
 
+# Flags for linking against all Xen libraries listed in $(1) but by making use
+# of -L and -l instead of providing a path to the shared library.
+define xenlibs-ldflags-ldlibs
+    $(call xenlibs-ldflags,$(1)) \
+    $(foreach lib,$(1), -l$(FILENAME_$(lib))) \
+    $(foreach lib,$(1),$(xenlibs-ldlibs-$(lib)))
+endef
+
 define LIB_defs
  FILENAME_$(1) ?= xen$(1)
  XEN_libxen$(1) = $$(XEN_ROOT)/tools/libs/$(1)
index 7362a28d9ef25bda7ebbca540ff730a7b5d17147..dc560ba49bdb5fdddbf9c7cc29e386859802bdd2 100644 (file)
@@ -8,7 +8,7 @@ OBJS = xeneventchn
 INTF = $(foreach obj, $(OBJS),$(obj).cmi)
 LIBS = xeneventchn.cma xeneventchn.cmxa
 
-LIBS_xeneventchn = $(LDLIBS_libxenevtchn)
+LIBS_xeneventchn = $(call xenlibs-ldflags-ldlibs,evtchn)
 
 all: $(INTF) $(LIBS) $(PROGRAMS)
 
index 67acc46bee4d7a5d5eb7a580d5c289a6c381304f..3b76e9ad7bbe0a5b238126be0fc955af95531c52 100644 (file)
@@ -10,7 +10,7 @@ OBJS = xenctrl
 INTF = xenctrl.cmi
 LIBS = xenctrl.cma xenctrl.cmxa
 
-LIBS_xenctrl = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest)
+LIBS_xenctrl = $(call xenlibs-ldflags-ldlibs,ctrl guest)
 
 xenctrl_OBJS = $(OBJS)
 xenctrl_C_OBJS = xenctrl_stubs
index 9ede2fd124579e023f59662b6c3dbc8b4b58865c..1645b40faf692c93315b3b16cb70ff5bb01abf41 100644 (file)
@@ -13,7 +13,7 @@ OBJS = xentoollog
 INTF = xentoollog.cmi
 LIBS = xentoollog.cma xentoollog.cmxa
 
-LIBS_xentoollog = $(LDLIBS_libxentoollog)
+LIBS_xentoollog = $(call xenlibs-ldflags-ldlibs,toollog)
 
 xentoollog_OBJS = $(OBJS)
 xentoollog_C_OBJS = xentoollog_stubs
index 7c1c4edcedb4f9971463b1180248209572c42def..22d6c93aae7a42d77aa3c9a06ce17f0f04570e6a 100644 (file)
@@ -15,7 +15,7 @@ LIBS = xenlight.cma xenlight.cmxa
 
 OCAMLINCLUDE += -I ../xentoollog
 
-LIBS_xenlight = $(LDLIBS_libxenlight)
+LIBS_xenlight = $(call xenlibs-ldflags-ldlibs,light)
 
 xenlight_OBJS = $(OBJS)
 xenlight_C_OBJS = xenlight_stubs