

all: prerequest mtmms.so mtscra.so libmtusdk.a mtusdk_test samples rms_mms rms_scra

prerequest:
	sudo apt-get update
	sudo apt-get install git libusb-1.0-0-dev libssl-dev libtool -y
	sudo apt install cmake
	sudo apt install g++

mtmms.so: mtmms.zip
	unzip mtmms.zip -d mtmms
	#sudo apt-get install libusb-1.0-0-dev -y
	$(MAKE) -C mtmms
	
mtscra.so : mtscra.zip
	unzip mtscra.zip -d mtscra
	# sudo apt-get install libusb-1.0-0-dev
	$(MAKE) -C mtscra	
	
libmtusdk.a : mtusdk.zip
	unzip mtusdk.zip -d mtusdk
	#sudo apt install libssl-dev -y
	$(MAKE) -C mtusdk
	
libmtusdkj.so : mtusdkj.zip
	cp ./mtusdk/libmtusdk.a ./mtusdkj/
	unzip mtusdkj.zip -d mtusdkj
	#sudo apt install libssl-dev -y
	$(MAKE) -C mtusdkj
	

mtusdk_test : mtusdk_test.zip restclient
	unzip mtusdk_test.zip -d mtusdk_test
	cp ./mtusdk/libmtusdk.a ./mtusdk_test/
	#sudo apt install libssl-dev
	$(MAKE) -C mtusdk_test
	rm mtusdk_test/obj -f -r
	$(MAKE) -C mtusdk_test -f makefile.mms
	cp ./mtscra/libmtscra.so ./mtusdk_test/
	cp ./mtmms/libmtmms.so ./mtusdk_test/
	
	cp ./mtscra/libmtscra.so ./
	cp ./mtmms/libmtmms.so ./
	cp ./mtusdk_test/mtusdk_test ./mtusdk_test.out
	
samples : samples.zip restclient
	unzip samples.zip -d .
	cp ./mtusdk/libmtusdk.a ./update_firmware_rs2/
	#sudo apt install libssl-dev
	$(MAKE) -C update_firmware_rs2
	cp ./mtscra/libmtscra.so ./update_firmware_rs2/
	cp ./mtmms/libmtmms.so ./update_firmware_rs2/
	
	cp ./mtusdk/libmtusdk.a ./emvconfiguration/
	#sudo apt install libssl-dev
	$(MAKE) -C emvconfiguration
	cp ./mtscra/libmtscra.so ./emvconfiguration/
	cp ./mtmms/libmtmms.so ./emvconfiguration/
	
	cp ./mtusdk/libmtusdk.a ./update_firmware/
	#sudo apt install libssl-dev
	$(MAKE) -C update_firmware
	cp ./mtscra/libmtscra.so ./update_firmware/
	cp ./mtmms/libmtmms.so ./update_firmware/
	
	cp ./update_firmware/update_firmware ./update_firmware.out 
	cp ./emvconfiguration/emvconfiguration ./emvconfiguration.out 
	cp ./update_firmware_rs2/update_cfg_rs2 ./update_cfg_rs2.out 
	cp ./update_firmware_rs2/update_firmware_rs2cmds ./update_firmware_rs2cmds.out 
	cp ./update_firmware_rs2/update_firmware_rs2mut ./update_firmware_rs2mut.out 
	
rms_mms : rms_mms.zip restclient
	unzip rms_mms.zip -d rms_mms
	cp ./mtusdk/libmtusdk.a ./rms_mms/
	#sudo apt install libssl-dev
	$(MAKE) -C rms_mms
	cp ./mtscra/libmtscra.so ./rms_mms/
	cp ./mtmms/libmtmms.so ./rms_mms/

rms_scra : rms_scra.zip restclient
	unzip rms_scra.zip -d rms_scra
	cp ./mtusdk/libmtusdk.a ./rms_scra/
	#sudo apt install libssl-dev
	$(MAKE) -C rms_scra
	cp ./mtscra/libmtscra.so ./rms_scra/
	cp ./mtmms/libmtmms.so ./rms_scra/

restclient : 
	sudo apt-get install libcurl4-openssl-dev libjsoncpp-dev -y
ifeq ($(wildcard restclient-cpp/*), )
	@echo "Download and build restclient-cpp"
	#sudo apt install libjsoncpp-dev -y
	#sudo apt install libcurl4-openssl-dev -y
	git clone https://github.com/mrtazz/restclient-cpp
	#sudo apt install libtool -y
	(cd restclient-cpp;./autogen.sh)
	sudo $(MAKE) -C restclient-cpp install 
else
	@echo "restclient-cpp is ready!"
endif
	sudo /sbin/ldconfig

clean:
	rm mtmms -f -r
	rm mtscra -f -r
	rm mtusdk -f -r
	rm mtusdk_test -f -r	
	rm update_firmware -f -r
	rm update_firmware_rs2 -f -r 
	rm send_file -f -r
	rm rms_mms -f -r
	rm rms_scra -f -r	
	rm *.so
	
