XEN_ROOT = $(CURDIR)/../../..
include $(XEN_ROOT)/tools/Rules.mk

# Xen script dir and scripts to go there.
XEN_SCRIPTS := vif-bridge block

XEN_SCRIPT_DATA :=

XEN_RCD_PROG := rc.d/xencommons rc.d/xendriverdomain

IN_TARGETS := rc.d/xencommons
IN_TARGETS += rc.d/xendriverdomain

.PHONY: all
all:

$(foreach file,$(IN_TARGETS),$(eval $(call apply-build-vars,$(file))))

.PHONY: build
build: $(IN_TARGETS)

.PHONY: install
install: install-scripts install-rcd

.PHONY: uninstall
uninstall: uninstall-script uninstall-rcd

.PHONY: install-scripts
install-scripts: build
	$(INSTALL_DIR) $(DESTDIR)$(XEN_SCRIPT_DIR)
	set -e; for i in $(XEN_SCRIPTS); \
	   do \
	   $(INSTALL_PROG) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \
	done
	set -e; for i in $(XEN_SCRIPT_DATA); \
	   do \
	   $(INSTALL_DATA) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \
	done

.PHONY: uninstall-scripts
uninstall-scripts:
	rm -f $(addprefix $(DESTDIR)$(XEN_SCRIPT_DIR)/, $(XEN_SCRIPTS))
	rm -f $(addprefix $(DESTDIR)$(XEN_SCRIPT_DIR)/, $(XEN_SCRIPT_DATA))

.PHONY: install-rcd
install-rcd: build
	$(INSTALL_DIR) $(DESTDIR)$(INITD_DIR)
	set -e; for i in $(XEN_RCD_PROG); \
	   do \
	   $(INSTALL_PROG) $$i $(DESTDIR)$(INITD_DIR); \
	done

.PHONY: uninstall-rcd
uninstall-rcd:
	rm -f $(addprefix $(DESTDIR)$(INITD_DIR)/, $(XEN_RCD_PROG))

.PHONY: clean
clean:

.PHONY: distclean
distclean: clean
	$(RM) $(IN_TARGETS)
