ethermess/Makefile

73 lines
2.1 KiB
Makefile

DESTDIR ?=
PREFIX ?= /usr/local
EXEC_PREFIX ?= $(PREFIX)
BINDIR ?= $(EXEC_PREFIX)/bin
LIBEXECDIR ?= $(EXEC_PREFIX)/libexec
DATAROOTDIR ?= $(PREFIX)/share
MANDIR ?= $(DATAROOTDIR)/man
CFLAGS += -Os -g -Wall -Wextra -pedantic
CPPFLAGS +=
LDFLAGS +=
SED ?= sed
BINS := ethermess
LIBEXECS := ethermess-backend
TOOLS := ethertype-dump arp-request
MAN1S := ethermess.1
MAN7S := ethermess.7
.SUFFIXES:
.SUFFIXES: .c .o
.PHONY: default all install uninstall clean distclean
default: $(BINS) $(LIBEXECS)
all: $(BINS) $(LIBEXECS) $(TOOLS)
ethertype-dump: ethertype-dump.o
$(CC) -o $@ $< $(LDFLAGS)
arp-request: arp-request.o
$(CC) -o $@ $< $(LDFLAGS)
ethermess: ethermess.py
# I'm not sure you can make this work 100% with traditional make
$(SED) "2s/__LIBEXECDIR__/'`printf "%s" "$(LIBEXECDIR)" | sed "s,\\\\\\\\,\\\\\\\\\\\\\\\\,g;s,/,\\\\\\\\/,g;s,"'"'",\\\\\\\\"'"'",g"`'/" < $< > $@
chmod +x $@
ethermess-backend: ethermess-backend.o
$(CC) -o $@ $< $(LDFLAGS)
.c.o:
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
install: $(BINS) $(LIBEXECS) $(MAN1S) $(MAN7S)
install -D -m 755 -t '$(DESTDIR)$(BINDIR)' $(BINS)
install -D -m 755 -t '$(DESTDIR)$(LIBEXECDIR)' $(LIBEXECS)
install -D -m 644 -t '$(DESTDIR)$(MANDIR)/man1' $(MAN1S)
install -D -m 644 -t '$(DESTDIR)$(MANDIR)/man7' $(MAN7S)
@echo
@echo '--------------------------------------------------------------------------------'
@echo 'To finish the installation, set the CAP_NET_RAW on $(LIBEXECDIR)/ethermess-backend with'
@echo
@echo ' # setcap CAP_NET_RAW=ep $(LIBEXECDIR)/ethermess-backend'
@echo
@echo 'ethermess-backend needs to be able to create a raw ethernet packet socket, which'
@echo 'is a privileged operation. CAP_NET_RAW allows it to do so without needing to run'
@echo 'with root privileges.'
@echo '--------------------------------------------------------------------------------'
uninstall:
cd $(DESTDIR)$(BINDIR) && rm $(BINS)
cd $(DESTDIR)$(LIBEXECDIR) && rm $(LIBEXECS)
cd $(DESTDIR)$(MANDIR)/man1 && rm $(MAN1S)
cd $(DESTDIR)$(MANDIR)/man7 && rm $(MAN7S)
clean:
rm -f $(BINS) $(LIBEXECS) $(TOOLS) *.o
distclean: clean