1# Copyright 2017 Google Inc. All Rights Reserved. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3 4# Simple example of a build file that nicely integrates a fuzz target 5# with the rest of the project. 6# 7# We use 'make' as the build system, but these ideas are applicable 8# to any other build system 9 10# By default, use our own standalone_fuzz_target_runner. 11# This runner does no fuzzing, but simply executes the inputs 12# provided via parameters. 13# Run e.g. "make all LIB_FUZZING_ENGINE=/path/to/libFuzzer.a" 14# to link the fuzzer(s) against a real fuzzing engine. 15# 16# OSS-Fuzz will define its own value for LIB_FUZZING_ENGINE. 17LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o 18 19# Values for CC, CFLAGS, CXX, CXXFLAGS are provided by OSS-Fuzz. 20# Outside of OSS-Fuzz use the ones you prefer or rely on the default values. 21# Do not use the -fsanitize=* flags by default. 22# OSS-Fuzz will use different -fsanitize=* flags for different builds (asan, ubsan, msan, ...) 23 24# You may add extra compiler flags like this: 25CXXFLAGS += -std=c++11 26 27all: do_stuff_fuzzer 28 29clean: 30 rm -fv *.a *.o *_fuzzer crash-* *.zip 31 32# Fuzz target, links against $LIB_FUZZING_ENGINE, so that 33# you may choose which fuzzing engine to use. 34do_stuff_fuzzer: do_stuff_fuzzer.cpp my_api.a standalone_fuzz_target_runner.o 35 ${CXX} ${CXXFLAGS} $< my_api.a ${LIB_FUZZING_ENGINE} -o $@ 36 37 38# The library itself. 39my_api.a: my_api.cpp my_api.h 40 ${CXX} ${CXXFLAGS} $< -c 41 ar ruv my_api.a my_api.o 42 43# The standalone fuzz target runner. 44standalone_fuzz_target_runner.o: standalone_fuzz_target_runner.cpp 45