2017-05-13 20:24:17 +00:00
|
|
|
# Copyright 2017 Google Inc. All Rights Reserved.
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
|
|
# Simple example of a build file that nicely integrates a fuzz target
|
|
|
|
# with the rest of the project.
|
|
|
|
#
|
|
|
|
# We use 'make' as the build system, but these ideas are applicable
|
|
|
|
# to any other build system
|
|
|
|
|
2017-06-01 15:44:52 +00:00
|
|
|
# By default, use our own standalone_fuzz_target_runner.
|
2017-05-13 20:24:17 +00:00
|
|
|
# This runner does no fuzzing, but simply executes the inputs
|
|
|
|
# provided via parameters.
|
|
|
|
# Run e.g. "make all LIB_FUZZING_ENGINE=/path/to/libFuzzer.a"
|
|
|
|
# to link the fuzzer(s) against a real fuzzing engine.
|
|
|
|
#
|
2018-08-10 22:22:43 +00:00
|
|
|
# OSS-Fuzz will define its own value for LIB_FUZZING_ENGINE.
|
2017-06-01 15:44:52 +00:00
|
|
|
LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o
|
2017-05-13 20:24:17 +00:00
|
|
|
|
|
|
|
# Values for CC, CFLAGS, CXX, CXXFLAGS are provided by OSS-Fuzz.
|
|
|
|
# Outside of OSS-Fuzz use the ones you prefer or rely on the default values.
|
2017-05-16 00:36:20 +00:00
|
|
|
# Do not use the -fsanitize=* flags by default.
|
|
|
|
# OSS-Fuzz will use different -fsanitize=* flags for different builds (asan, ubsan, msan, ...)
|
|
|
|
|
2017-05-13 20:24:17 +00:00
|
|
|
# You may add extra compiler flags like this:
|
|
|
|
CXXFLAGS += -std=c++11
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -fv *.a *.o *unittest *_fuzzer *_seed_corpus.zip crash-* *.zip
|
|
|
|
|
|
|
|
all: do_stuff_unittest do_stuff_fuzzer
|
|
|
|
|
|
|
|
# Continuos integration system should run "make clean && make check"
|
|
|
|
check: all
|
|
|
|
./do_stuff_unittest
|
|
|
|
./do_stuff_fuzzer do_stuff_test_data/*
|
|
|
|
|
|
|
|
# Unit tests
|
|
|
|
do_stuff_unittest: do_stuff_unittest.cpp my_api.a
|
|
|
|
${CXX} ${CXXFLAGS} $< my_api.a -o $@
|
|
|
|
|
|
|
|
# Fuzz target, links against $LIB_FUZZING_ENGINE, so that
|
|
|
|
# you may choose which fuzzing engine to use.
|
2017-06-01 15:44:52 +00:00
|
|
|
do_stuff_fuzzer: do_stuff_fuzzer.cpp my_api.a standalone_fuzz_target_runner.o
|
2017-05-13 20:24:17 +00:00
|
|
|
${CXX} ${CXXFLAGS} $< my_api.a ${LIB_FUZZING_ENGINE} -o $@
|
|
|
|
zip -q -r do_stuff_fuzzer_seed_corpus.zip do_stuff_test_data
|
|
|
|
|
|
|
|
|
|
|
|
# The library itself.
|
|
|
|
my_api.a: my_api.cpp my_api.h
|
|
|
|
${CXX} ${CXXFLAGS} $< -c
|
|
|
|
ar ruv my_api.a my_api.o
|
|
|
|
|
|
|
|
# The standalone fuzz target runner.
|
2017-06-01 15:44:52 +00:00
|
|
|
standalone_fuzz_target_runner.o: standalone_fuzz_target_runner.cpp
|