Makefile 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. COMPONENTS_DIR=../..
  2. COMPILER_ICLUDE_DIR=$(shell echo `which xtensa-esp32-elf-gcc | xargs dirname | xargs dirname`/xtensa-esp32-elf)
  3. CFLAGS=-std=gnu99 -Og -ggdb -ffunction-sections -fdata-sections -nostdlib -Wall -Werror=all -Wno-int-to-pointer-cast -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-macro-redefined -Wno-constant-conversion -Wno-incompatible-pointer-types-discards-qualifiers -Wno-typedef-redefinition -Wno-incompatible-pointer-types -Wextra \
  4. -Wno-unused-parameter -Wno-sign-compare -Wno-address -Wno-unused-variable -DESP_PLATFORM -D IDF_VER=\"v3.1\" -MMD -MP -DWITH_POSIX -DLWIP_NO_CTYPE_H=1
  5. INC_DIRS=-I . -I ./build/config -I $(COMPONENTS_DIR)/newlib/platform_include -I $(COMPONENTS_DIR)/newlib/include -I $(COMPONENTS_DIR)/driver/include -I $(COMPONENTS_DIR)/esp32/include -I $(COMPONENTS_DIR)/ethernet/include -I $(COMPONENTS_DIR)/freertos/include/esp_additions -I $(COMPONENTS_DIR)/freertos/include/esp_additions/freertos -I $(COMPONENTS_DIR)/freertos/include -I $(COMPONENTS_DIR)/heap/include -I $(COMPONENTS_DIR)/lwip/lwip/src/include -I $(COMPONENTS_DIR)/lwip/include/apps -I $(COMPONENTS_DIR)/lwip/lwip/src/include/netif -I $(COMPONENTS_DIR)/lwip/lwip/src/include/posix -I $(COMPONENTS_DIR)/lwip/port/esp32/include -I $(COMPONENTS_DIR)/lwip/lwip/src/include/posix -I $(COMPONENTS_DIR)/lwip/include/apps/ping -I $(COMPONENTS_DIR)/lwip/include/apps/sntp -I $(COMPONENTS_DIR)/soc/esp32/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/tcpip_adapter/include -I $(COMPONENTS_DIR)/esp_rom/include -I $(COMPONENTS_DIR)/esp_common/include -I $(COMPONENTS_DIR)/esp_hw_support/include -I $(COMPONENTS_DIR)/xtensa/include -I $(COMPONENTS_DIR)/xtensa/esp32/include -I $(COMPONENTS_DIR)/esp_wifi/include -I $(COMPONENTS_DIR)/esp_event/include -I $(COMPONENTS_DIR)/freertos/port/xtensa/include -I $(COMPONENTS_DIR)/esp_system/include -I $(COMPONENTS_DIR)/esp_timer/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/soc/src/esp32/include -I $(COMPONENTS_DIR)/soc/esp32/include -I $(COMPONENTS_DIR)/esp_netif/include -I $(COMPONENTS_DIR)/esp_eth/include -I $(COMPONENTS_DIR)/esp_netif/lwip -I $(COMPONENTS_DIR)/hal/include -I $(COMPONENTS_DIR)/hal/esp32/include -I $(COMPILER_ICLUDE_DIR)/include
  6. TEST_NAME=test
  7. FUZZ=afl-fuzz
  8. GEN_CFG=generate_config
  9. LD=$(CC)
  10. ifeq ($(MODE),dhcp_client)
  11. DEPENDENCY_INJECTION=-include dhcp_di.h
  12. OBJECTS=dhcp.o def.o network_mock.o test_dhcp_client.o
  13. SAMPLE_PACKETS=in_dhcp_client
  14. else ifeq ($(MODE),dhcp_server)
  15. DEPENDENCY_INJECTION=-include dhcpserver_di.h
  16. OBJECTS=dhcpserver.o def.o test_dhcp_server.o network_mock.o esp_netif_loopback_mock.o
  17. SAMPLE_PACKETS=in_dhcp_server
  18. else ifeq ($(MODE),dns)
  19. CFLAGS+=-DNOT_MOCK_DNS
  20. DEPENDENCY_INJECTION=-include dns_di.h
  21. OBJECTS=dns.o def.o test_dns.o network_mock.o
  22. SAMPLE_PACKETS=in_dns
  23. else
  24. $(error Please specify MODE: dhcp_server, dhcp_client, dns)
  25. endif
  26. ifeq ($(INSTR),off)
  27. CC=gcc
  28. CFLAGS+=-DINSTR_IS_OFF
  29. TEST_NAME=test_sim
  30. else
  31. CC=afl-clang-fast
  32. endif
  33. CFLAGS+=$(INC_DIRS)
  34. all: $(TEST_NAME)
  35. def.o: ../lwip/src/core/def.c $(GEN_CFG)
  36. @echo "[CC] $<"
  37. @$(CC) $(CFLAGS) -D BUILDING_DEF $(DEPENDENCY_INJECTION) -c $< -o $@
  38. dns.o: ../lwip/src/core/dns.c $(GEN_CFG)
  39. @echo "[CC] $<"
  40. @$(CC) $(CFLAGS) $(DEPENDENCY_INJECTION) -c $< -o $@
  41. dhcp.o: ../lwip/src/core/ipv4/dhcp.c $(GEN_CFG)
  42. @echo "[CC] $<"
  43. @$(CC) $(CFLAGS) $(DEPENDENCY_INJECTION) -c $< -o $@
  44. dhcpserver.o: ../apps/dhcpserver/dhcpserver.c $(GEN_CFG)
  45. @echo "[CC] $<"
  46. @$(CC) $(CFLAGS) $(DEPENDENCY_INJECTION) -c $< -o $@
  47. %.o: %.c $(GEN_CFG)
  48. @echo "[CC] $<"
  49. @$(CC) $(CFLAGS) -c $< -o $@
  50. .PHONY: $(GEN_CFG)
  51. $(GEN_CFG):
  52. $(IDF_PATH)/tools/idf.py reconfigure
  53. $(TEST_NAME): $(OBJECTS)
  54. @echo "[LD] $@"
  55. @$(LD) $(OBJECTS) -o $@ $(LDLIBS)
  56. fuzz: $(TEST_NAME)
  57. @$(FUZZ) -t 5000+ -i "$(SAMPLE_PACKETS)" -o "out" -- ./$(TEST_NAME)