1TEST_NAME=test
2FUZZ=afl-fuzz
3COMPONENTS_DIR=../..
4COMPILER_ICLUDE_DIR=$(shell echo `which xtensa-esp32-elf-gcc | xargs dirname | xargs dirname`/xtensa-esp32-elf)
5
6CFLAGS=-g -Wno-unused-value -Wno-missing-declarations -Wno-pointer-bool-conversion -Wno-macro-redefined -Wno-int-to-void-pointer-cast -DHOOK_MALLOC_FAILED -DESP_EVENT_H_ -D__ESP_LOG_H__ \
7                 -I. -I.. -I../include -I../private_include -I ./build/config  \
8                 -I$(COMPONENTS_DIR) \
9                 -I$(COMPONENTS_DIR)/driver/include \
10                 -I$(COMPONENTS_DIR)/esp_common/include \
11                 -I$(COMPONENTS_DIR)/esp_event/include \
12                 -I$(COMPONENTS_DIR)/esp_eth/include \
13                 -I$(COMPONENTS_DIR)/esp_hw_support/include \
14                 -I$(COMPONENTS_DIR)/esp_netif/include \
15                 -I$(COMPONENTS_DIR)/esp_netif/private_include \
16                 -I$(COMPONENTS_DIR)/esp_netif/lwip \
17                 -I$(COMPONENTS_DIR)/esp_rom/include \
18                 -I$(COMPONENTS_DIR)/esp_system/include \
19                 -I$(COMPONENTS_DIR)/esp_timer/include \
20                 -I$(COMPONENTS_DIR)/esp_wifi/include \
21                 -I$(COMPONENTS_DIR)/freertos \
22                 -I$(COMPONENTS_DIR)/freertos/include \
23                 -I$(COMPONENTS_DIR)/freertos/port/xtensa/include \
24                 -I$(COMPONENTS_DIR)/hal/include \
25                 -I$(COMPONENTS_DIR)/hal/esp32/include \
26                 -I$(COMPONENTS_DIR)/heap/include \
27                 -I$(COMPONENTS_DIR)/log/include \
28                 -I$(COMPONENTS_DIR)/lwip/lwip/src/include \
29                 -I$(COMPONENTS_DIR)/lwip/port/esp32/include \
30                 -I$(COMPONENTS_DIR)/lwip/lwip/src/include/lwip/apps \
31                 -I$(COMPONENTS_DIR)/newlib/platform_include \
32                 -I$(COMPONENTS_DIR)/soc/include \
33                 -I$(COMPONENTS_DIR)/soc/include \
34                 -I$(COMPONENTS_DIR)/soc/esp32/include \
35                 -I$(COMPONENTS_DIR)/soc/src/esp32/include \
36                 -I$(COMPONENTS_DIR)/tcpip_adapter/include \
37                 -I$(COMPONENTS_DIR)/xtensa/include \
38                 -I$(COMPONENTS_DIR)/xtensa/esp32/include \
39                 -I$(COMPILER_ICLUDE_DIR)/include
40
41
42MDNS_C_DEPENDENCY_INJECTION=-include mdns_di.h
43ifeq ($(INSTR),off)
44    CC=gcc
45    CFLAGS+=-DINSTR_IS_OFF
46    TEST_NAME=test_sim
47else
48    CC=afl-clang-fast
49endif
50CPP=$(CC)
51LD=$(CC)
52OBJECTS=esp32_mock.o mdns.o test.o esp_netif_mock.o
53
54OS := $(shell uname)
55ifeq ($(OS),Darwin)
56  LDLIBS=
57else
58   LDLIBS=-lbsd
59   CFLAGS+=-DUSE_BSD_STRING
60endif
61
62all: $(TEST_NAME)
63
64%.o: %.c
65	@echo "[CC] $<"
66	@$(CC) $(CFLAGS) -c $< -o $@
67
68mdns.o: ../mdns.c
69	@echo "[CC] $<"
70	@$(CC) $(CFLAGS) -include mdns_mock.h $(MDNS_C_DEPENDENCY_INJECTION) -c $< -o $@
71
72$(TEST_NAME): $(OBJECTS)
73	@echo "[LD] $@"
74	@$(LD)  $(OBJECTS) -o $@ $(LDLIBS)
75
76fuzz: $(TEST_NAME)
77	@$(FUZZ) -i "in" -o "out" -- ./$(TEST_NAME)
78
79clean:
80	@rm -rf *.o *.SYM $(TEST_NAME) out
81