Makefile 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. CC ?= gcc
  2. PKG_CONFIG ?= pkg-config
  3. PREFIX ?= /usr/local
  4. VERSION := $(shell if [ -d .git ] && which git 2>&1 > /dev/null; then git describe --always | tail -c +2; else echo $$STANDALONE_VERSION; fi)
  5. CFLAGS += -Wall -g -DNMRPFLASH_VERSION=\"$(VERSION)\"
  6. SUFFIX ?=
  7. ifeq ($(shell uname -s),Linux)
  8. CFLAGS += $(shell $(PKG_CONFIG) libnl-route-3.0 --cflags)
  9. LDFLAGS += $(shell $(PKG_CONFIG) libnl-route-3.0 --libs) -lpcap
  10. else
  11. LDFLAGS += -lpcap
  12. endif
  13. ifeq ($(shell uname -s),Darwin)
  14. AFL=afl-clang
  15. else
  16. AFL=afl-gcc
  17. endif
  18. nmrpflash_OBJ = nmrp.o tftp.o ethsock.o main.o util.o
  19. .PHONY: clean install release release/macos release/linux release/win32
  20. nmrpflash$(SUFFIX): $(nmrpflash_OBJ)
  21. $(CC) $(CFLAGS) -o nmrpflash$(SUFFIX) $(nmrpflash_OBJ) $(LDFLAGS)
  22. tftptest:
  23. CFLAGS=-DNMRPFLASH_TFTP_TEST make clean nmrpflash
  24. %.o: %.c nmrpd.h
  25. $(CC) -c $(CFLAGS) $< -o $@
  26. fuzz_nmrp: tftp.c util.c nmrp.c fuzz.c
  27. $(AFL) $(CFLAGS) -DNMRPFLASH_FUZZ $^ -o $@
  28. fuzz_tftp: tftp.c util.c nmrp.c fuzz.c
  29. $(AFL) $(CFLAGS) -DNMRPFLASH_FUZZ -DNMRPFLASH_FUZZ_TFTP $^ -o $@
  30. dofuzz_tftp: fuzz_tftp
  31. echo core | sudo tee /proc/sys/kernel/core_pattern
  32. echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
  33. afl-fuzz -i fuzzin/tftp -o fuzzout/tftp -- ./fuzz_tftp fuzzin/tftp.bin
  34. echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
  35. clean:
  36. rm -f $(nmrpflash_OBJ) nmrpflash nmrpflash.exe fuzz_nmrp fuzz_tftp
  37. install: nmrpflash
  38. install -m 755 nmrpflash $(PREFIX)/bin
  39. release/macos:
  40. CFLAGS="-target arm64-apple-macos11" SUFFIX=".arm64" make release
  41. CFLAGS="-target x86_64-apple-macos10.8" SUFFIX=".x86_64" make release
  42. lipo -create -output nmrpflash nmrpflash.x86_64 nmrpflash.arm64
  43. zip nmrpflash-$(VERSION)-macos.zip nmrpflash
  44. rm -f nmrpflash.x86_64 nmrpflash.arm64
  45. release/linux: release
  46. zip nmrpflash-$(VERSION)-linux.zip nmrpflash
  47. release/win32:
  48. zip nmrpflash-$(VERSION)-win32.zip nmrpflash.exe
  49. release: clean nmrpflash$(SUFFIX)
  50. strip nmrpflash$(SUFFIX)
  51. nmrpflash.ico: nmrpflash.svg
  52. convert -background transparent -define icon:auto-resize=256,64,48,32,16 $< $@