FUZZ_CFLAGS =

ifdef LIBFUZZER
CC ?= clang
#FUZZ_FLAGS ?= -fsanitize=fuzzer,address,signed-integer-overflow,unsigned-integer-overflow
FUZZ_FLAGS ?= -fsanitize=fuzzer,address
ifndef CFLAGS
FUZZ_CFLAGS += $(FUZZ_FLAGS)
endif
endif

FUZZ_CFLAGS += -DCONFIG_NO_RANDOM_POOL -DTEST_FUZZ
export FUZZ_CFLAGS
CFLAGS ?= -MMD -O2 -Wall -g
CFLAGS += $(FUZZ_CFLAGS)
ifdef LIBFUZZER
CFLAGS += -DTEST_LIBFUZZER
LDFLAGS += $(FUZZ_FLAGS)
endif

ifndef CC
CC=gcc
endif

ifndef LDO
LDO=$(CC)
endif

WPAS_SRC=../../../wpa_supplicant
SRC=../../../src

CFLAGS += -I$(SRC) -I$(SRC)/utils -I$(WPAS_SRC)
OBJS += ../fuzzer-common.o

$(SRC)/ap/libap.a:
	$(MAKE) -C $(SRC)/ap TEST_FUZZ=y

$(SRC)/common/libcommon.a:
	$(MAKE) -C $(SRC)/common

$(SRC)/crypto/libcrypto.a:
	$(MAKE) -C $(SRC)/crypto TEST_FUZZ=y

$(SRC)/eapol_auth/libeapol_auth.a:
	$(MAKE) -C $(SRC)/eapol_auth

$(SRC)/eapol_supp/libeapol_supp.a:
	$(MAKE) -C $(SRC)/eapol_supp

$(SRC)/eap_common/libeap_common.a:
	$(MAKE) -C $(SRC)/eap_common

$(SRC)/eap_peer/libeap_peer.a:
	$(MAKE) -C $(SRC)/eap_peer

$(SRC)/eap_server/libeap_server.a:
	$(MAKE) -C $(SRC)/eap_server

$(SRC)/l2_packet/libl2_packet.a:
	$(MAKE) -C $(SRC)/l2_packet

$(SRC)/p2p/libp2p.a:
	$(MAKE) -C $(SRC)/p2p

$(SRC)/radius/libradius.a:
	$(MAKE) -C $(SRC)/radius

$(SRC)/rsn_supp/librsn_supp.a:
	$(MAKE) -C $(SRC)/rsn_supp TEST_FUZZ=y

$(SRC)/tls/libtls.a:
	$(MAKE) -C $(SRC)/tls TEST_FUZZ=y

$(SRC)/utils/libutils.a:
	$(MAKE) -C $(SRC)/utils TEST_FUZZ=y

$(SRC)/wps/libwps.a:
	$(MAKE) -C $(SRC)/wps

Q=@
E=echo
ifeq ($(V), 1)
Q=
E=true
endif
ifeq ($(QUIET), 1)
Q=@
E=true
endif

%.o: %.c
	$(Q)$(CC) -c -o $@ $(CFLAGS) $<
	@$(E) "  CC " $<
