Makefile 4.1 KB

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