Makefile 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. CC = $(CROSS)gcc
  2. STRIP = $(CROSS)strip
  3. PKG_CONFIG ?= pkg-config
  4. PREFIX ?= /usr/local
  5. VERSION := $(shell if [ -d .git ] && which git 2>&1 > /dev/null; then git describe --always | tail -c +2; else echo $$STANDALONE_VERSION; fi)
  6. CFLAGS += -Wall -g -DNMRPFLASH_VERSION=\"$(VERSION)\"
  7. SUFFIX ?=
  8. MACOS_SDK ?= macosx11.1
  9. ARCH := $(shell uname -m)
  10. LINUXDEPLOY = ./linuxdeploy-$(ARCH).AppImage
  11. TMP := $(shell mktemp -d)
  12. APPDIR = $(TMP)/AppDir
  13. AFL = afl-gcc
  14. nmrpflash_OBJ = nmrp.o tftp.o ethsock.o main.o util.o
  15. ifdef MINGW
  16. SUFFIX = .exe
  17. CC = $(MINGW)gcc
  18. STRIP = $(MINGW)strip
  19. WINDRES = $(MINGW)windres
  20. CFLAGS += -DWIN32_LEAN_AND_MEAN
  21. CFLAGS += -D_WIN32_WINNT=0x0600
  22. CFLAGS += -D__USE_MINGW_ANSI_STDIO
  23. CFLAGS += "-I./Npcap/Include"
  24. LDFLAGS += -lwpcap
  25. LDFLAGS += -lPacket
  26. LDFLAGS += -liphlpapi
  27. LDFLAGS += -lws2_32
  28. LDFLAGS += -ladvapi32
  29. LDFLAGS += "-L./Npcap/Lib"
  30. nmrpflash_OBJ += windres.o
  31. else ifeq ($(shell uname -s),Linux)
  32. CFLAGS += $(shell $(PKG_CONFIG) libnl-route-3.0 --cflags)
  33. CFLAGS += $(shell $(PKG_CONFIG) libpcap --cflags)
  34. LDFLAGS += $(shell $(PKG_CONFIG) libnl-route-3.0 --libs)
  35. LDFLAGS += $(shell $(PKG_CONFIG) libpcap --libs)
  36. AFL = afl-gcc
  37. else
  38. LDFLAGS += -lpcap
  39. ifeq ($(shell uname -s),Darwin)
  40. AFL=afl-clang
  41. SYSROOT ?= $(shell xcrun --sdk $(MACOS_SDK) --show-sdk-path)
  42. LDFLAGS += -framework CoreFoundation
  43. endif
  44. endif
  45. .PHONY: clean install release release/macos release/linux release/win32
  46. nmrpflash$(SUFFIX): $(nmrpflash_OBJ)
  47. $(CC) $(CFLAGS) -o nmrpflash$(SUFFIX) $(nmrpflash_OBJ) $(LDFLAGS)
  48. tftptest:
  49. CFLAGS=-DNMRPFLASH_TFTP_TEST make clean nmrpflash
  50. %.o: %.c nmrpd.h
  51. $(CC) -c $(CFLAGS) $< -o $@
  52. windres.o: nmrpflash.rc nmrpflash.manifest nmrpflash.ico
  53. $(WINDRES) $< -o $@
  54. fuzz_nmrp: tftp.c util.c nmrp.c fuzz.c
  55. $(AFL) $(CFLAGS) -DNMRPFLASH_FUZZ $^ -o $@
  56. fuzz_tftp: tftp.c util.c nmrp.c fuzz.c
  57. $(AFL) $(CFLAGS) -DNMRPFLASH_FUZZ -DNMRPFLASH_FUZZ_TFTP $^ -o $@
  58. dofuzz_tftp: fuzz_tftp
  59. echo core | sudo tee /proc/sys/kernel/core_pattern
  60. echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
  61. afl-fuzz -i fuzzin/tftp -o fuzzout/tftp -- ./fuzz_tftp fuzzin/tftp.bin
  62. echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
  63. clean:
  64. rm -f $(nmrpflash_OBJ) nmrpflash*.AppImage nmrpflash nmrpflash.exe fuzz_nmrp fuzz_tftp
  65. install: nmrpflash
  66. install -d $(PREFIX)/bin
  67. install -s -m 755 nmrpflash $(PREFIX)/bin/
  68. uninstall:
  69. rm -f $(PREFIX)/bin/nmrpflash
  70. $(LINUXDEPLOY):
  71. wget -O $@ https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/$(shell basename $@)
  72. chmod +x $@
  73. nmrpflash-$(ARCH).AppImage: $(LINUXDEPLOY) release
  74. rm -rf $(APPDIR)
  75. mkdir -p $(APPDIR)
  76. $(LINUXDEPLOY) --appdir $(APPDIR) -e nmrpflash -i nmrpflash.svg -o appimage --create-desktop-file
  77. release/macos:
  78. CFLAGS="-isysroot $(SYSROOT) -target arm64-apple-macos11" SUFFIX=".arm64" make release
  79. CFLAGS="-isysroot $(SYSROOT) -target x86_64-apple-macos10.8" SUFFIX=".x86_64" make release
  80. lipo -create -output nmrpflash nmrpflash.x86_64 nmrpflash.arm64
  81. zip nmrpflash-$(VERSION)-macos.zip nmrpflash
  82. rm -f nmrpflash.x86_64 nmrpflash.arm64
  83. release/linux: release
  84. zip nmrpflash-$(VERSION)-linux.zip nmrpflash
  85. release/linux-appimage: nmrpflash-$(ARCH).AppImage
  86. mv $< $(TMP)/nmrpflash
  87. cd $(TMP); zip release.zip nmrpflash
  88. mv $(TMP)/release.zip nmrpflash-$(VERSION)-linux-$(ARCH).zip
  89. release/win32:
  90. zip nmrpflash-$(VERSION)-win32.zip nmrpflash.exe
  91. release: clean nmrpflash$(SUFFIX)
  92. $(STRIP) nmrpflash$(SUFFIX)
  93. nmrpflash.ico: nmrpflash.svg
  94. convert -background transparent -define icon:auto-resize=256,64,48,32,16 $< $@
  95. build-release-with-docker:
  96. docker build -t nmrpflash .
  97. docker create --name dummy nmrpflash
  98. docker cp dummy:/usr/src/nmrpflash/nmrpflash-$(VERSION)-linux-$(ARCH).zip .
  99. docker cp dummy:/usr/src/nmrpflash/nmrpflash-$(VERSION)-win32.zip .
  100. docker rm -f dummy