#install binaries in this directory:
INSTALL_PREFIX = /usr
INSTALL_SBIN = $(INSTALL_PREFIX)/sbin

#directory where ip_resend may create unix domain sockets 
SOCKET_DIR = /var/ip_resend

PROGRAMS = ip_resend ip_resend_wakeup
all: $(PROGRAMS)

.PHONY: all install clean test

ip_resend: ip_resend.c 
	cc ip_resend.c -D 'SOCK_DIR_PREFIX="$(SOCKET_DIR)"' -lm -o ip_resend

ip_resend_wakeup: ip_resend_wakeup.c
	cc ip_resend_wakeup.c -D 'SOCK_DIR_PREFIX="$(SOCKET_DIR)"' -o ip_resend_wakeup

install: $(PROGRAMS)
	cp $(PROGRAMS) $(INSTALL_SBIN)
	if [ ! -d $(SOCKET_DIR) ]; then mkdir $(SOCKET_DIR); fi

clean:
	rm -f $(PROGRAMS) socket

test:  $(PROGRAMS)
	./ip_resend -o lo -c socket & sleep 2; ping -c 3 -i 3 -w 3 127.0.0.1 &\
	 sleep 1; ./ip_resend_wakeup -m 127.0.0.1 -o lo -c socket

