• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_unittest do_stuff_fuzzer
28
29clean:
30	rm -fv *.a *.o *unittest *_fuzzer *_seed_corpus.zip crash-* *.zip
31
32# Continuos integration system should run "make clean && make check"
33check: all
34	./do_stuff_unittest
35	./do_stuff_fuzzer do_stuff_test_data/*
36
37# Unit tests
38do_stuff_unittest: do_stuff_unittest.cpp my_api.a
39	${CXX} ${CXXFLAGS} $< my_api.a -o $@
40
41# Fuzz target, links against $LIB_FUZZING_ENGINE, so that
42# you may choose which fuzzing engine to use.
43do_stuff_fuzzer: do_stuff_fuzzer.cpp my_api.a standalone_fuzz_target_runner.o
44	${CXX} ${CXXFLAGS} $< my_api.a ${LIB_FUZZING_ENGINE} -o $@
45	zip -q -r do_stuff_fuzzer_seed_corpus.zip do_stuff_test_data
46
47
48# The library itself.
49my_api.a: my_api.cpp my_api.h
50	${CXX} ${CXXFLAGS} $< -c
51	ar ruv my_api.a my_api.o
52
53# The standalone fuzz target runner.
54standalone_fuzz_target_runner.o: standalone_fuzz_target_runner.cpp
55