HOST=${NODE}
APP_DIR=/root/SDRAPP


TARGET_EXEC ?= sdrapp

BUILD_DIR ?= ./build
SRC_DIRS ?= ./

SRCS := $(shell find $(SRC_DIRS) -name '*.cpp')
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)

INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))

CPPFLAGS ?= $(INC_FLAGS) -MMD -MP -Ofast --fast-math -finline-functions -std=c++11


LIBDIR=-L/usr/local/lib/x86_64-linux-gnu
LDFLAGS=-lboost_program_options -lboost_system -lboost_thread -lpthread -lfftw3f -lrt -luhd -loml2 -locomm


$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
	$(CXX) $(OBJS) -o $@ $(LDFLAGS)

# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
	$(MKDIR_P) $(dir $@)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@


.PHONY: clean

clean:
	$(RM) -r $(BUILD_DIR) *.o

-include $(DEPS)

MKDIR_P ?= mkdir -p



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

remote-clean :
	ssh root@$(HOST) 'cd $(APP_DIR) && make clean'

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



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

remote-install-oml :
	ssh root@$(HOST) 'apt -y install gnulib libxml2-dev libpopt-dev pkg-config libxml2-utils libsqlite3-dev'
#	scp .INSTALL/oml2-2.11.1rc.tar.gz root@$(HOST):/root/.
#	ssh root@$(HOST) 'tar -zxvf oml2-2.11.1rc.tar.gz'
	ssh root@$(HOST) 'git clone --branch v2.11.1rc  https://github.com/mytestbed/oml.git'
	ssh root@$(HOST) 'cd oml/; ./autogen.sh; ./configure;, make -j 8; make install'
	ssh root@$(HOST) 'rm -rf oml'
	ssh root@$(HOST) 'ldconfig'



remote-install-deps :
	ssh root@$(HOST) 'apt update'
#	ssh root@$(HOST) 'apt -y install zlib1g-dev libssl-dev'
#	ssh root@$(HOST) 'apt -y install libpugixml1 libpugixml-dev'
	ssh root@$(HOST) 'apt -y install libboost-all-dev'
	ssh root@$(HOST) 'apt -y install libfftw3-dev'
#	ssh root@$(HOST) 'apt -y install net-tools cmake'
#	ssh root@$(HOST) 'apt -y install liboml2 liboml2-dev liblog4cxx-dev octave'

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=2500000'

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=5000000'

remote-config-netw :
	ssh root@$(HOST) 'ip -c link set enp6s0 down'
	ssh root@$(HOST) 'ip -c link set enp6s0 up'
	ssh root@$(HOST) 'ip -c a add 192.168.10.1/24 dev enp6s0'
	ssh root@$(HOST) 'ip -c link set enp6s0 mtu 8000'
	ssh root@$(HOST) 'sysctl -w net.core.rmem_max=50000000'
	ssh root@$(HOST) 'sysctl -w net.core.wmem_max=1048576'
