xref: /freebsd/contrib/libfido2/fuzz/build-coverage (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1#!/bin/sh -eux
2
3# Copyright (c) 2019 Yubico AB. All rights reserved.
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file.
6
7LIBCBOR="$1"
8LIBFIDO2="$2"
9
10CC="${CC:-clang}"
11CXX="${CXX:-clang++}"
12PKG_CONFIG_PATH="${PKG_CONFIG_PATH:-${LIBCBOR}/install/lib/pkgconfig}"
13export CC PKG_CONFIG_PATH
14
15# Clean up.
16rm -rf "${LIBCBOR}/build" "${LIBCBOR}/install" "${LIBFIDO2}/build"
17
18# Patch, build, and install libcbor.
19(cd "${LIBCBOR}" && patch -N -l -s -p0 < "${LIBFIDO2}/fuzz/README") || true
20mkdir "${LIBCBOR}/build" "${LIBCBOR}/install"
21(cd "${LIBCBOR}/build" && cmake -DBUILD_SHARED_LIBS=ON \
22	-DCMAKE_INSTALL_PREFIX="${LIBCBOR}/install" ..)
23make -C "${LIBCBOR}/build" VERBOSE=1 all install
24
25# Build libfido2.
26mkdir -p "${LIBFIDO2}/build"
27export CFLAGS="-fprofile-instr-generate -fcoverage-mapping"
28export LDFLAGS="${CFLAGS}"
29(cd "${LIBFIDO2}/build" && cmake -DFUZZ=ON -DLIBFUZZER=ON \
30    -DCMAKE_BUILD_TYPE=Debug ..)
31make -C "${LIBFIDO2}/build"
32