+COBJS := libvirt.cmo libvirt_version.cmo
+OPTOBJS := libvirt.cmx libvirt_version.cmx
+
+ifneq ($(OCAMLMKLIB),)
+# Good, we can just use ocamlmklib
+mllibvirt.cma: libvirt_c.o $(COBJS)
+ $(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS) -lvirt
+
+mllibvirt.cmxa: libvirt_c.o $(OPTOBJS)
+ $(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS) -lvirt
+
+else
+ifeq ($(WIN32),yes)
+# Ugh, MinGW doesn't have ocamlmklib. This technique is copied from the
+# example in OCaml distribution, otherlibs/win32unix/Makefile.nt
+
+mllibvirt.cma: dllmllibvirt.dll libmllibvirt.a $(COBJS)
+ $(OCAMLC) -a -linkall -o $@ $(COBJS) \
+ -dllib -lmllibvirt -cclib -lmllibvirt -cclib "$(LDFLAGS) -lvirt"
+
+mllibvirt.cmxa: libmllibvirt.a $(OPTOBJS)
+ $(OCAMLOPT) -a -linkall -o $@ $(OPTOBJS) \
+ -cclib -lmllibvirt -cclib "$(LDFLAGS) -lvirt"
+
+dllmllibvirt.dll: libvirt_c.o
+ $(CC) -shared -o $@ $^ \
+ $(LDFLAGS) "$(shell ocamlc -where)"/ocamlrun.a -lvirt
+
+libmllibvirt.a: libvirt_c.o
+ ar rc $@ $^
+ ranlib $@