xref: /freebsd/contrib/libfido2/fuzz/build-coverage (revision 2ccfa855b2fc331819953e3de1b1c15ce5b95a7e)
10afa8e06SEd Maste#!/bin/sh -eux
20afa8e06SEd Maste
30afa8e06SEd Maste# Copyright (c) 2019 Yubico AB. All rights reserved.
40afa8e06SEd Maste# Use of this source code is governed by a BSD-style
50afa8e06SEd Maste# license that can be found in the LICENSE file.
6*2ccfa855SEd Maste# SPDX-License-Identifier: BSD-2-Clause
70afa8e06SEd Maste
80afa8e06SEd MasteLIBCBOR="$1"
90afa8e06SEd MasteLIBFIDO2="$2"
100afa8e06SEd Maste
110afa8e06SEd MasteCC="${CC:-clang}"
120afa8e06SEd MasteCXX="${CXX:-clang++}"
130afa8e06SEd MastePKG_CONFIG_PATH="${PKG_CONFIG_PATH:-${LIBCBOR}/install/lib/pkgconfig}"
140afa8e06SEd Masteexport CC PKG_CONFIG_PATH
150afa8e06SEd Maste
160afa8e06SEd Maste# Clean up.
170afa8e06SEd Masterm -rf "${LIBCBOR}/build" "${LIBCBOR}/install" "${LIBFIDO2}/build"
180afa8e06SEd Maste
190afa8e06SEd Maste# Patch, build, and install libcbor.
200afa8e06SEd Maste(cd "${LIBCBOR}" && patch -N -l -s -p0 < "${LIBFIDO2}/fuzz/README") || true
210afa8e06SEd Mastemkdir "${LIBCBOR}/build" "${LIBCBOR}/install"
220afa8e06SEd Maste(cd "${LIBCBOR}/build" && cmake -DBUILD_SHARED_LIBS=ON \
230afa8e06SEd Maste	-DCMAKE_INSTALL_PREFIX="${LIBCBOR}/install" ..)
240afa8e06SEd Mastemake -C "${LIBCBOR}/build" VERBOSE=1 all install
250afa8e06SEd Maste
260afa8e06SEd Maste# Build libfido2.
270afa8e06SEd Mastemkdir -p "${LIBFIDO2}/build"
280afa8e06SEd Masteexport CFLAGS="-fprofile-instr-generate -fcoverage-mapping"
29*2ccfa855SEd Masteexport CFLAGS="${CFLAGS} -fsanitize=fuzzer-no-link"
300afa8e06SEd Masteexport LDFLAGS="${CFLAGS}"
31*2ccfa855SEd Masteexport FUZZ_LDFLAGS="${LDFLAGS} -fsanitize=fuzzer"
32*2ccfa855SEd Maste(cd "${LIBFIDO2}/build" && cmake -DFUZZ=ON -DFUZZ_LDFLAGS="${FUZZ_LDFLAGS}" \
330afa8e06SEd Maste	-DCMAKE_BUILD_TYPE=Debug ..)
340afa8e06SEd Mastemake -C "${LIBFIDO2}/build"
35