NAME = arpscan
VERSION = 0.5
OUI = /usr/local/lib/arpscan/oui
CC = gcc
CFLAGS = -O2 -g -DVER=$(VERSION) -DOUI=$(OUI)
SRC = Makefile arpscan.c oui.c list.h oui.awk
OBJ = $(filter %.o,$(SRC:.c=.o))
EXE = arpscan

$(EXE): $(OBJ)
	$(CC) $(LDFLAGS) $(OBJ) -o $(EXE)

clean:
	rm -f $(OBJ) $(EXE) core oui

install: arpscan
	install -s arpscan /usr/local/sbin/
	@echo To download/install vendor database: make db-install

db: oui

oui: oui.txt
	awk -f oui.awk $^ >$@

ifeq (,$(wildcard oui.txt))
oui.txt: db-download
endif

db-download:
	wget -N http://standards.ieee.org/regauth/oui/oui.txt

db-update: db-download db-install

db-install: oui
	install -Dm 644 oui $(OUI)

dist:
	DIR=/tmp/$$$$; PKG=$(NAME)-$(VERSION); mkdir $$DIR; mkdir $$DIR/$$PKG; \
	cp $(SRC) $$DIR/$$PKG; \
	tar czf $$PKG.tar.gz -C $$DIR $$PKG; \
	rm -rf $$DIR

.PHONY: clean install dist db db-download db-install db-update
