
PREFIX ?= /usr/local

AMQP_QUEUE ?= vlkbdevel
INST_PATH ?= $(PREFIX)
VERSION ?= $(shell git describe)


.PHONY: build install uninstall run stop clean

all : build

.PHONY: build
build:
	make -C src/common VERSION=$(VERSION)
	make -C src/vlkbd VERSION=$(VERSION)
	make -C src/vlkb-obscore VERSION=$(VERSION)
	make -C src/vlkb VERSION=$(VERSION)

.PHONY: clean
clean:
	make -C src/common clean
	make -C src/vlkbd clean
	make -C src/vlkb-obscore clean
	make -C src/vlkb clean



.PHONY: install
install:
	mkdir -p $(INST_PATH)/bin
	install ./src/vlkb/bin/vlkb $(INST_PATH)/bin
	install ./src/vlkb-obscore/bin/vlkb-obscore $(INST_PATH)/bin
	install ./src/vlkbd/bin/vlkbd $(INST_PATH)/bin
	install vlkbd_exec.sh $(INST_PATH)/bin

.PHONY: uninstall
uninstall:
	rm -f $(INST_PATH)/bin/vlkb
	rm -f $(INST_PATH)/bin/vlkb-obscore
	rm -f $(INST_PATH)/bin/vlkbd
	rm -f $(INST_PATH)/bin/vlkbd_exec.sh




# vlkb-devel site local
.PHONY: vlkb-devel
vlkb-devel: stop uninstall clean build install config start



.PHONY: config
config:
	mkdir -p $(INST_PATH)/etc/vlkb-obscore
	mkdir -p $(INST_PATH)/etc/vlkbd
	cp config/vlkb-obscore.datasets.conf $(INST_PATH)/etc/vlkb-obscore/datasets.conf
	cp config/vlkbd.datasets.conf $(INST_PATH)/etc/vlkbd/datasets.conf
	

.PHONY: start
start:
	vlkbd_exec.sh localhost $(AMQP_QUEUE) $(INST_PATH)/etc/vlkbd/datasets.conf

.PHONY: stop
stop:
	pkill -f 'vlkbd.* $(AMQP_QUEUE).*$(INST_PATH)/etc/vlkbd/datasets.conf'

.PHONY: status
status:
	ps ax | grep vlkbd

.PHONY: reload
reload: stop start



