[libvirt] [ocaml PATCH 3/6] Build C sources separately

Pino Toscano ptoscano at redhat.com
Tue Sep 3 08:43:03 UTC 2019


Instead of including everything in a single C source, build all the 3 C
sources separately.

Signed-off-by: Pino Toscano <ptoscano at redhat.com>
---
 libvirt/Makefile.in          | 14 +++++++-------
 libvirt/README               | 28 ++++++----------------------
 libvirt/generator.pl         |  4 ----
 libvirt/libvirt_c_epilogue.c |  2 ++
 libvirt/libvirt_c_oneoffs.c  |  2 ++
 5 files changed, 17 insertions(+), 33 deletions(-)

diff --git a/libvirt/Makefile.in b/libvirt/Makefile.in
index 8451c5d..ad56bb5 100644
--- a/libvirt/Makefile.in
+++ b/libvirt/Makefile.in
@@ -64,10 +64,10 @@ OPTOBJS := libvirt.cmx libvirt_version.cmx
 
 ifneq ($(OCAMLMKLIB),)
 # Good, we can just use ocamlmklib
-mllibvirt.cma: libvirt_c.o $(COBJS)
+mllibvirt.cma: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(COBJS)
 	$(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS)
 
-mllibvirt.cmxa: libvirt_c.o $(OPTOBJS)
+mllibvirt.cmxa: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(OPTOBJS)
 	$(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS)
 
 else
@@ -83,11 +83,11 @@ mllibvirt.cmxa: libmllibvirt.a $(OPTOBJS)
 	$(OCAMLOPT) -a -linkall -o $@ $(OPTOBJS) \
 	  -cclib -lmllibvirt -cclib "$(LDFLAGS)"
 
-dllmllibvirt.dll: libvirt_c.o
+dllmllibvirt.dll: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o
 	$(CC) -shared -o $@ $^ \
 	  $(LDFLAGS) "$(shell ocamlc -where)"/ocamlrun.a
 
-libmllibvirt.a: libvirt_c.o
+libmllibvirt.a: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o
 	ar rc $@ $^
 	ranlib $@
 
@@ -104,9 +104,9 @@ libvirt_c.c: generator.pl
 	$(PERL) -w $<
 
 # Extra dependencies.
-libvirt_c.c: libvirt_c.h
-libvirt_c.c: libvirt_c_oneoffs.c
-libvirt_c.c: libvirt_c_epilogue.c
+libvirt_c.o: libvirt_c.h
+libvirt_c_oneoffs.o: libvirt_c.h
+libvirt_c_epilogue.o: libvirt_c.h
 
 # Status of automatically generated bindings.
 autostatus: libvirt_c.c
diff --git a/libvirt/README b/libvirt/README
index 0109940..3fb8f53 100644
--- a/libvirt/README
+++ b/libvirt/README
@@ -7,12 +7,15 @@ documentation starting at html/index.html.
 
 'libvirt.ml' describes how OCaml functions map to C functions.
 
-'libvirt_c*.c' are the C functions which map OCaml objects to C
-objects and vice versa (see next section).
-
 'libvirt_c.h' contains prototypes of common functions defined
 in the epilogue (see below), and provides some general macros.
 
+'libvirt_c_epilogue.c' contains some standard functions (eg.) for
+wrapping and unwrapping libvirt objects.
+
+'libvirt_c_oneoffs.c' contains bindings which are too specialised or
+one-of-a-kind to be worth generating automatically.
+
 Generated code
 --------------
 
@@ -26,22 +29,3 @@ there are a few one-off bindings (eg. one-of-a-type functions,
 functions with particularly complex mappings).  Our eventual aim to is
 autogenerate as much as possible.  Use 'make autostatus' in this
 directory to find out how we're doing.
-
-The generated 'libvirt_c.c' #includes some other C files in this
-directory:
-
-  #include "libvirt_c_oneoffs.c"
-
-    One-off bindings: Bindings which are too specialised or one-of-a-kind
-    to be worth generating automatically.
-
-  [Followed by generated bindings, then ...]
-
-  #include "libvirt_c_epilogue.c"
-
-    An epilogue which defines some standard static functions (eg.) for
-    wrapping and unwrapping libvirt objects.
-
-The key to understanding the generator is to look at the generated
-code (libvirt_c.c) first, and go from there back to parts of the
-generator script.
diff --git a/libvirt/generator.pl b/libvirt/generator.pl
index 61526c0..eb329a0 100755
--- a/libvirt/generator.pl
+++ b/libvirt/generator.pl
@@ -234,8 +234,6 @@ print F <<'END';
 
 #include "libvirt_c.h"
 
-#include "libvirt_c_oneoffs.c"
-
 END
 
 #----------------------------------------------------------------------
@@ -880,8 +878,6 @@ END
 # Write the epilogue.
 
 print F <<'END';
-#include "libvirt_c_epilogue.c"
-
 /* EOF */
 END
 
diff --git a/libvirt/libvirt_c_epilogue.c b/libvirt/libvirt_c_epilogue.c
index e58f7bb..3baf290 100644
--- a/libvirt/libvirt_c_epilogue.c
+++ b/libvirt/libvirt_c_epilogue.c
@@ -20,6 +20,8 @@
 
 /* Please read libvirt/README file. */
 
+#include "libvirt_c.h"
+
 const char *
 Optstring_val (value strv)
 {
diff --git a/libvirt/libvirt_c_oneoffs.c b/libvirt/libvirt_c_oneoffs.c
index 0a9e485..6f56f10 100644
--- a/libvirt/libvirt_c_oneoffs.c
+++ b/libvirt/libvirt_c_oneoffs.c
@@ -19,6 +19,8 @@
 
 /* Please read libvirt/README file. */
 
+#include "libvirt_c.h"
+
 #ifdef __GNUC__
 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
 #endif
-- 
2.21.0




More information about the libvir-list mailing list