all : app_read_sdr_samples

CFLAGS=-Ofast --fast-math -finline-functions
HOST="sdr2-s1-lg1"
APP_DIR=/root/SPECTRUM_VIEW

app_read_sdr_samples : main.o common_utils.o rxtx_handlers.o
	g++ $(CFLAGS) -o app_read_sdr_samples main.o common_utils.o rxtx_handlers.o -L/usr/local/lib/x86_64-linux-gnu -lboost_program_options -lboost_system -lboost_thread -lpthread -lfftw3f -llog4cxx -lrt -luhd

main.o : main.cpp CRadio.hpp CDeviceStorage.hpp
	g++ $(CFLAGS) -c main.cpp -std=c++11

common_utils.o : common_utils.cpp UDPSimple.hpp
	g++ $(CFLAGS) -c common_utils.cpp -std=c++11

rxtx_handlers.o : rxtx_handlers.cpp CDeviceStorage.hpp C1DCorrelation.hpp
	g++ $(CFLAGS) -c rxtx_handlers.cpp -std=c++11

clean :
	rm app_read_sdr_samples *.o

websock :
	cd websocketpp; cmake . -DBUILD_EXAMPLES=ON -DBUILD_TESTS=ON; make -j 4; make install; cd ..

remote-clean :
	ssh root@$(HOST) 'rm -rf $(APP_DIR)'

remote-make :
	ssh root@$(HOST) 'mkdir -p $(APP_DIR)'
	rsync -ptr *      root@$(HOST):$(APP_DIR)
	ssh root@$(HOST) 'cd $(APP_DIR) && make'

remote-run-tx :
	ssh root@$(HOST) 'cd $(APP_DIR); ./cmd_play --cmd "make addr0=192.168.10.2" --cmd "txconfig 0 4400e6 20e6 30" --cmd "txstream start" --cmd "txsig ofdm_slp_data256.dat 10000 0 ALL" '

remote-run-rx :
	ssh root@$(HOST) 'cd $(APP_DIR); ./cmd_play --cmd "make addr0=192.168.10.2"  --cmd "rxconfig 0 4400e6 20e6 30" --cmd "rxstream start" '


remote-setup :
	scp ~/.bash_colors 	root@$(HOST):/root/.
	$(MAKE)	remote-install-deps
	$(MAKE)	remote-install-websocket
#	$(MAKE)	remote-install-oml

remote-install-deps :
	ssh root@$(HOST) 'apt-get update;  apt-get -y install libboost-all-dev liblog4cxx-dev cmake libfftw3-dev libxml2-dev libpopt-dev libsqlite3-dev pkg-config libxml2-utils gnulib'

remote-install-websocket :
	ssh root@$(HOST) 'git clone https://github.com/zaphoyd/websocketpp.git'
	ssh root@$(HOST) 'cd websocketpp; cmake . -DBUILD_EXAMPLES=ON -DBUILD_TESTS=ON; make -j 4; make install'

remote-install-oml :
	scp ~/CODE/OML/oml2-2.11.1rc.tar.gz 	root@$(HOST):/root/.
	ssh root@$(HOST) 'tar -zxvf oml2-2.11.1rc.tar.gz; '
	ssh root@$(HOST) 'cd oml2-2.11.1rc/; ./autogen.sh; ./configure; make -j 4; make install; ldconfig'

remote-config-eth1 :
	ssh root@$(HOST) 'ifconfig eth1 mtu 9000'
	ssh root@$(HOST) 'sysctl -w net.core.rmem_max=50000000'
	ssh root@$(HOST) 'sysctl -w net.core.wmem_max=1048576'

remote-config-eth2 :
	ssh root@$(HOST) 'ifconfig eth2 192.168.10.1 mtu 8000'
	ssh root@$(HOST) 'sysctl -w net.core.rmem_max=50000000'
	ssh root@$(HOST) 'sysctl -w net.core.wmem_max=1048576'

