###########################################################################
#
# FairCom Corporation makefile for c-treeEDGE nodejs.sql 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.sql 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/\
	libctsqlapi.so\
	test.js\
	msg

../../node_modules/:
	npm install ../..
package.json:
	npm init -y
node_modules/: 
	npm install ../..
libctsqlapi.so:
	cp ../../../ctree.drivers/lib/libctsqlapi.so .
test.js:
	cp ../test.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 test.js

clean:
	rm -f package.json
	rm -f package-lock.json
	rm -rf node_modules
	rm -rf ../../node_modules
	rm -f libctsqlapi.so
	rm -f test.js
