###########################################################################
#
# FairCom Corporation makefile for c-treeEDGE nodejs API Tutorials
#
###########################################################################

EXECUTABLES = node npm
NODEJS := $(foreach exec,$(EXECUTABLES),\
        $(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH consider install nodejs")))

NODEVER := $(shell node --version | sed 's/\..*$$//' | sed 's/v//')

ALL:
	@echo The nodejs.nav tutorials requires the following to build and run:
	@echo \* NodeJS Version 10 or newer
	@echo Detected NodeJS Version $(NODEVER)
	@echo Make sure your system cover the requirements then execute:
	@echo make build
	@echo to build the tutorial

build:\
	../../node_modules/\
	package.json\
	node_modules/\
	libmtclient.so\
	ctdb_tutorial1.js\
	addRecords.js\
	deleteRecords.js\
	msg

../../node_modules/:
	npm install ../..
package.json:
	npm init -y
node_modules/: 
	npm install ../..
libmtclient.so:
	cp ../../../ctree.drivers/lib/libmtclient.so .
ctdb_tutorial1.js:
	cp ../ctdb_tutorial1.js .
addRecords.js:
	cp ../addRecords.js .
deleteRecords.js:
	cp ../deleteRecords.js .
msg:
	@echo "Make sure your NodeJS and FairCom runtimes match. Both must be 32-bit or 64-bit\; otherwise, you will get the Dynamic Linking Error"
	@echo "Now execute make run to run the tutorial"

run:
	node ctdb_tutorial1.js

clean:
	rm -f package.json
	rm -f package-lock.json
	rm -rf node_modules
	rm -rf ../../node_modules
	rm -f libmtclient.so
	rm -f ctdb_tutorial1.js
	rm -f addRecords.js
	rm -f deleteRecords.js
