From 133d8b96cda0baff81042f120cbb15f955754063 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] mlvirsh can compile without extlib * mlvirsh/mlvirsh.ml: mlvirsh only needed three functions from extlib, so copy them in here to avoid the dependency. * configure.ac: No dependency on extlib for mlvirsh. * mlvirsh/Makefile.in: Changed so can build without ocamlfind. * README: Updated documentation. --- ChangeLog | 7 +++++++ README | 6 +----- configure.ac | 5 +---- mlvirsh/.depend | 2 -- mlvirsh/Makefile.in | 29 +++++++++++++++++++++++++---- mlvirsh/mlvirsh.ml | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 6 files changed, 78 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index e105e00..e1b99ca 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2008-01-05 Richard Jones + mlvirsh can compile without extlib + * mlvirsh/mlvirsh.ml: mlvirsh only needed three functions from + extlib, so copy them in here to avoid the dependency. + * configure.ac: No dependency on extlib for mlvirsh. + * mlvirsh/Makefile.in: Changed so can build without ocamlfind. + * README: Updated documentation. + Update documentation for Windows. * README: Update documentation for Windows. diff --git a/README b/README index 6be1cf4..06eb130 100755 --- a/README +++ b/README @@ -12,7 +12,7 @@ known functionality to OCaml programs. Requirements ---------------------------------------------------------------------- -To build the bindings (required): +To build the bindings, examples, and mlvirsh (required): GNU make, gcc libvirt >= 0.2.1 (from http://libvirt.org/, @@ -27,10 +27,6 @@ To build the OCaml interface documentation (optional): ocamldoc (part of OCaml itself) -To build mlvirsh (optional): - - Extlib (from http://ocaml-lib.sourceforge.net/) - To build virt-top (optional): ocaml-curses (from http://www.nongnu.org/ocaml-tmk/) diff --git a/configure.ac b/configure.ac index c90a2b0..a478198 100755 --- a/configure.ac +++ b/configure.ac @@ -132,10 +132,7 @@ else fi dnl Which subpackages (== subdirs) will we build? -subdirs="libvirt examples" -if test "x$pkg_extlib" != "xno"; then - subdirs="$subdirs mlvirsh" -fi +subdirs="libvirt examples mlvirsh" if test "x$pkg_lablgtk2" != "xno"; then subdirs="$subdirs mlvirtmanager" fi diff --git a/mlvirsh/.depend b/mlvirsh/.depend index a346edd..e69de29 100755 --- a/mlvirsh/.depend +++ b/mlvirsh/.depend @@ -1,2 +0,0 @@ -mlvirsh.cmo: ../libvirt/libvirt.cmi -mlvirsh.cmx: ../libvirt/libvirt.cmx diff --git a/mlvirsh/Makefile.in b/mlvirsh/Makefile.in index 6976e16..197f732 100755 --- a/mlvirsh/Makefile.in +++ b/mlvirsh/Makefile.in @@ -21,13 +21,23 @@ prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ -OCAMLCPACKAGES := -package extlib,unix -I ../libvirt +OCAMLFIND = @OCAMLFIND@ + +ifneq ($(OCAMLFIND),) +OCAMLCPACKAGES := -package unix -I ../libvirt OCAMLCFLAGS := -g OCAMLCLIBS := -linkpkg - OCAMLOPTPACKAGES := $(OCAMLCPACKAGES) OCAMLOPTFLAGS := OCAMLOPTLIBS := $(OCAMLCLIBS) +else +OCAMLCINCS := -I ../libvirt +OCAMLCFLAGS := -g +OCAMLCLIBS := unix.cma +OCAMLOPTINCS := $(OCAMLCINCS) +OCAMLOPTFLAGS := +OCAMLOPTLIBS := unix.cmxa +endif export LIBRARY_PATH=../libvirt export LD_LIBRARY_PATH=../libvirt @@ -39,14 +49,25 @@ all: $(BYTE_TARGETS) opt: $(OPT_TARGETS) +ifneq ($(OCAMLFIND),) mlvirsh: mlvirsh.cmo - ocamlfind ocamlc $(OCAMLCPACKAGES) $(OCAMLCFLAGS) $(OCAMLCLIBS) \ + $(OCAMLFIND) ocamlc $(OCAMLCPACKAGES) $(OCAMLCFLAGS) $(OCAMLCLIBS) \ ../libvirt/mllibvirt.cma -o $@ $< mlvirsh.opt: mlvirsh.cmx - ocamlfind ocamlopt \ + $(OCAMLFIND) ocamlopt \ $(OCAMLOPTPACKAGES) $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) \ ../libvirt/mllibvirt.cmxa -o $@ $< +else +mlvirsh: mlvirsh.cmo + $(OCAMLC) $(OCAMLCINCS) $(OCAMLCFLAGS) $(OCAMLCLIBS) \ + ../libvirt/mllibvirt.cma -o $@ $< + +mlvirsh.opt: mlvirsh.cmx + $(OCAMLOPT) \ + $(OCAMLOPTINCS) $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) \ + ../libvirt/mllibvirt.cmxa -o $@ $< +endif install: if [ -x mlvirsh.opt ]; then \ diff --git a/mlvirsh/mlvirsh.ml b/mlvirsh/mlvirsh.ml index 055f818..8052506 100755 --- a/mlvirsh/mlvirsh.ml +++ b/mlvirsh/mlvirsh.ml @@ -17,7 +17,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *) -open ExtString open Printf module C = Libvirt.Connect @@ -76,6 +75,48 @@ and input_all chan = done; Buffer.contents buf +(* Split a string at a separator. + * Functions copied from extlib Copyright (C) 2003 Nicolas Cannasse et al. + * to avoid the explicit dependency on extlib. + *) +let str_find str sub = + let sublen = String.length sub in + if sublen = 0 then + 0 + else + let found = ref 0 in + let len = String.length str in + try + for i = 0 to len - sublen do + let j = ref 0 in + while String.unsafe_get str (i + !j) = String.unsafe_get sub !j do + incr j; + if !j = sublen then begin found := i; raise Exit; end; + done; + done; + raise Not_found + with + Exit -> !found + +let str_split str sep = + let p = str_find str sep in + let len = String.length sep in + let slen = String.length str in + String.sub str 0 p, String.sub str (p + len) (slen - p - len) + +let str_nsplit str sep = + if str = "" then [] + else ( + let rec nsplit str sep = + try + let s1 , s2 = str_split str sep in + s1 :: nsplit s2 sep + with + Not_found -> [str] + in + nsplit str sep + ) + (* Hypervisor connection. *) type conn_t = No_connection | RO of Libvirt.ro C.t | RW of Libvirt.rw C.t let conn = ref No_connection @@ -224,7 +265,7 @@ let do_command = let cpumap = String.make (C.cpumaplen (C.maxcpus_of_node_info info)) '\000' in List.iter (C.use_cpu cpumap) - (List.map int_of_string (String.nsplit str ",")); + (List.map int_of_string (str_nsplit str ",")); cpumap in @@ -680,7 +721,7 @@ let rec interactive_mode () = | RW _ -> "mlvirsh# " in print_string prompt; let command = read_line () in - (match String.nsplit command " " with + (match str_nsplit command " " with | [] -> () | command :: args -> do_command command args -- 1.8.3.1