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