aboutsummaryrefslogtreecommitdiffhomepage
path: root/projects/example/my-api-repo/Makefile
blob: 144ff27a6ea333d530699e3c4d4bd59dce64311d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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

# By default, use our own standalone_fuzz_taget_runner.
# 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.
#
# OSS-Fuzz will define it's own value for LIB_FUZZING_ENGINE.
LIB_FUZZING_ENGINE ?= standalone_fuzz_taget_runner.o

# 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.
# 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.
do_stuff_fuzzer: do_stuff_fuzzer.cpp my_api.a standalone_fuzz_taget_runner.o
	${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.
standalone_fuzz_taget_runner.o: standalone_fuzz_taget_runner.cpp