Use libnl to add/remove IPs on Linux
[oweals/nmrpflash.git] / Makefile
index c3dcb29843d0ff902c740af1ddf0e62550d309cf..79b1fbe914ac237ce13671127f6f0d23b20f3984 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,35 +1,52 @@
 CC ?= gcc
 PREFIX ?= /usr/local
-CFLAGS += -Wall -g
+VERSION = $(shell git describe --always | tail -c +2)
 LIBS = -lpcap
+CFLAGS += -Wall -g -DNMRPFLASH_VERSION=\"$(VERSION)\"
+LDFLAGS += $(LIBS)
 
-.PHONY: clean install release release/osx release/linux
+ifeq ($(shell uname -s),Linux)
+       CFLAGS += $(shell pkg-config libnl-route-3.0 --cflags)
+       LIBS += $(shell pkg-config libnl-route-3.0 --libs)
+endif
 
-nmrp-flash: nmrp.o tftp.o ethsock.o main.o
-       $(CC) $(CFLAGS) -o nmrp-flash nmrp.o tftp.o ethsock.o main.o $(LIBS)
+nmrpflash_OBJ = nmrp.o tftp.o ethsock.o main.o util.o
 
-nmrp.o: nmrp.c nmrpd.h
-       $(CC) $(CFLAGS) -c -o nmrp.o nmrp.c
+.PHONY: clean install release release/osx release/linux release/win32
 
-tftp.o: tftp.c nmrpd.h
-       $(CC) $(CFLAGS) -c -o tftp.o tftp.c
+nmrpflash: $(nmrpflash_OBJ)
+       $(CC) $(CFLAGS) -o nmrpflash $(nmrpflash_OBJ) $(LDFLAGS)
 
-ethsock.o: ethsock.c nmrpd.h
-       $(CC) $(CFLAGS) -c -o ethsock.o ethsock.c
+tftptest:
+       CFLAGS=-DNMRPFLASH_TFTP_TEST make clean nmrpflash
 
-main.o: main.c nmrpd.h
-       $(CC) $(CFLAGS) -c -o main.o main.c
+%.o: %.c nmrpd.h
+       $(CC) -c $(CFLAGS) $< -o $@
 
+fuzz: clean
+       CC=afl-gcc CFLAGS=-DNMRPFLASH_FUZZ make nmrpflash
+       mv nmrpflash fuzz
+
+dofuzz: fuzz
+       echo core | sudo tee /proc/sys/kernel/core_pattern
+       echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
+       afl-fuzz -i fuzzin -o fuzzout -- ./fuzz
+       echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
 clean:
-       rm -f nmrp.o tftp.o main.o ethsock.o nmrp-flash nmrp-flash.exe
+       rm -f $(nmrpflash_OBJ) nmrpflash
 
-install: nmrp-flash
-       install -m 755 nmrp-flash $(PREFIX)/bin
+install: nmrpflash
+       install -m 755 nmrpflash $(PREFIX)/bin
 
 release/osx:
-       make clean release CFLAGS="-arch i686 -arch x86_64"
+       CFLAGS="-arch i386 -arch x86_64 -mmacosx-version-min=10.6" make release
+       zip nmrpflash-$(VERSION)-osx.zip nmrpflash
 
 release/linux: release
+       zip nmrpflash-$(VERSION)-linux.zip nmrpflash
+
+release/win32:
+       zip nmrpflash-$(VERSION)-win32.zip nmrpflash.exe
 
-release: nmrp-flash
-       strip nmrp-flash
+release: clean nmrpflash
+       strip nmrpflash