# Add the fuzzer only if everything was built with the fuzzing flags.
#
ifneq "$(findstring -fsanitize=fuzzer,${CFLAGS})" ""
-SUBMAKEFILES += fuzzer.mk
+
+#
+# Define a function to do all of the same thing.
+#
+define FUZZ_PROTOCOL
+src/bin/fuzzer_${1}.mk: src/bin/fuzzer.mk
+ $${Q}echo "PROTOCOL=${1}" > $$@
+ $${Q}cat $$^ >> $$@
+
+SUBMAKEFILES += fuzzer_${1}.mk
+endef
+
+#
+# Add the list of protocols to be fuzzed here Each protocol needs to
+# have a test point for packet decoding. See
+# src/protocols/radius/decode.c for an example.
+#
+PROTOCOLS = radius
+
+$(foreach X,${PROTOCOLS},$(eval $(call FUZZ_PROTOCOL,${X})))
endif
#
# FR_LIBRARY_PATH=./build/lib/ FR_LIBRARY_FUZZ_PROTOCOL=radius FR_DICTIONARY_DIR=./share/dictionary/ ./build/make/jlibtool --mode=execute ./build/bin/local/fuzzer /path/to/corpus/directory/
#
-# Command-line option parsing will be added later.
+
+#
+# The libraries to be fuzzed MUST be explicitly linked to the protocol libraries.
+# Dynamic loading will NOT work. In order to simplify the process, the protocol
+# libraries export a common test point. We have one source / make file, which
+# then magically turns into different fuzzers.
#
-TARGET := fuzzer
+# However, because the *test point* functions are loaded dynamically,
+# you still have to tell the fuzzer which library it's supposed to
+# load.
+#
+
+TARGET := fuzzer_$(PROTOCOL)
SOURCES := fuzzer.c
-TGT_PREREQS := libfreeradius-util.a libfreeradius-radius.a
+TGT_PREREQS := libfreeradius-util.a libfreeradius-$(PROTOCOL).a
SRC_CFLAGS := -fsanitize=fuzzer
TGT_LDFLAGS := -fsanitize=fuzzer