OCAMLINCLUDES    = ../xapi ../util
OCAML_LIBS       = ../util/stats
OCAML_CLIBS     += $(XEN_OCAML_CLIBS)
# XXX: these should all be specified in the ocamlfind META file:
XENLIGHT_LINK_FLAGS= -cclib -lxlutil -cclib -luuid -cclib -lblktapctl -cclib -lutil -cclib -lxenlight -cclib -lxenstore
OCAML_LINK_FLAGS+= $(XEN_OCAML_LINK_FLAGS) $(XENLIGHT_LINK_FLAGS)

CFLAGS          += $(XEN_CFLAGS)

OCAMLPACKS     = threads xenctrl xenstore stdext log cdrom netdev xenlight
OCAMLFLAGS    += -thread

LIBFILES = table xenops_helpers xenbus_utils balloon xenguestHelper domain hotplug device io statdev xal netman memory watch device_common squeeze squeeze_xen squeezed_rpc squeezed_state squeezed_rpc device_number stubdom

StaticCLibrary(statdev_stubs, statdev_stubs)
OCamlLibraryClib(xenops, $(LIBFILES), statdev_stubs)
OCamlDocLibrary(xenops, $(LIBFILES))

OCAML_LIBS += ../util/version ../idl/ocaml_backend/common xenops

OCamlProgram(list_domains, list_domains)
OCamlDocProgram(list_domains, list_domains)
OCamlProgram(memory_breakdown, memory_breakdown)
OCamlProgram(memory_summary, memory_summary)
OCamlProgram(freemem, freemem)
OCamlProgram(squeezed, squeezed)
OCamlDocProgram(squeezed, squeezed)
OCamlProgram(squeezed_client, squeezed_client)

OCamlProgram(device_number_test, device_number_test device_number)

# legacy
OCamlProgram(create_domain, xenops)
OCamlProgram(destroy_domain, xenops)
OCamlProgram(build_domain, xenops)
OCamlProgram(build_hvm, xenops)
OCamlProgram(restore_domain, xenops)
OCamlProgram(suspend_domain, xenops)
OCamlProgram(add_vbd, xenops)
OCamlProgram(add_vif, xenops)
OCamlProgram(shutdown_domain, xenops)
OCamlProgram(unpause_domain, xenops)
OCamlProgram(pause_domain, xenops)

OCamlProgram(xenops, xenops)
OCamlProgram(fence, fence)
OCamlProgram(dbgring, dbgring)

section
	OCAMLINCLUDES   = ../idl/ocaml_backend ../idl
	OCAMLFLAGS = -dtypes -warn-error F -cclib -static
	OCAMLPACKS = xenctrl xenstore
	OCamlProgram(xs, xenstore_readdir)

OCamlProgram(xal, xal_main)
OCamlProgram(watch_test, watch_test)
OCamlProgram(squeeze_test, squeeze_test squeeze_test_main)

BIN_PROGS=list_domains squeezed_client
DEBUG_PROGS=xs xal xenops watch_test memory_breakdown memory_summary
SYMLINK_PROGS=destroy_domain shutdown_domain create_domain build_domain build_hvm add_vbd add_vif unpause_domain pause_domain suspend_domain restore_domain
OTHER_PROGS=fence dbgring squeezed

.PHONY: allxenops
allxenops: $(DEBUG_PROGS) $(BIN_PROGS) $(OTHER_PROGS)

.PHONY: install
install:
	mkdir -p $(DEBUGDIST)
	cp -f $(DEBUG_PROGS) $(DEBUGDIST)
	sh -c 'for i in $(SYMLINK_PROGS); do ln -nfs xenops $(DEBUGDIST)/$$i; done'
	mkdir -p $(BIN_PATH)
	$(IPROG) $(BIN_PROGS) $(BIN_PATH)
	mkdir -p $(LIBEXEC)
	$(IPROG) fence $(LIBEXEC)/fence.bin
	$(IPROG) squeezed $(LIBEXEC)/squeezed

.PHONY: sdk-install
sdk-install: install

.PHONY: clean
clean:
	rm -f *.cmi *.cmx *.cmo *.a *.cma *.cmxa *.o *.annot *.run *.opt $(DEBUG_PROGS) $(BIN_PROGS) $(SYMLINK_PROGS) $(OTHER_PROGS)
