1#!/bin/bash -eu
2
3#  SPDX-License-Identifier: Apache-2.0
4#  ----------------------------------------------------------------------------
5#  Copyright 2020-2021 Arm Limited
6#  Copyright 2020 Google Inc.
7#
8#  Licensed under the Apache License, Version 2.0 (the "License"); you may not
9#  use this file except in compliance with the License. You may obtain a copy
10#  of the License at:
11#
12#      http://www.apache.org/licenses/LICENSE-2.0
13#
14#  Unless required by applicable law or agreed to in writing, software
15#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17#  License for the specific language governing permissions and limitations
18#  under the License.
19#  ----------------------------------------------------------------------------
20
21# This script is invoked by oss-fuzz from <root>/Source/
22
23# Generate a dummy version header (normally built by CMake variable expansion)
24echo "#pragma once" > astcenccli_version.h
25echo "#define VERSION_STRING \"0.0.0\"" >> astcenccli_version.h
26echo "#define YEAR_STRING \"2021\"" >> astcenccli_version.h
27
28# Build the core project for fuzz tests to link against
29for source in ./*.cpp; do
30  BASE="${source##*/}"
31  BASE="${BASE%.cpp}"
32  echo ${BASE}
33
34  $CXX $CXXFLAGS \
35      -c \
36      -DASTCENC_SSE=0 \
37      -DASTCENC_AVX=0 \
38      -DASTCENC_POPCNT=0 \
39      -I. -std=c++14 -mfpmath=sse -msse2 -fno-strict-aliasing -O0 -g \
40      $source \
41      -o ${BASE}.o
42done
43
44ar -qc libastcenc.a *.o
45
46# Build project local fuzzers
47for fuzzer in ./Fuzzers/fuzz_*.cpp; do
48  $CXX $CXXFLAGS \
49      -DASTCENC_SSE=0 \
50      -DASTCENC_AVX=0 \
51      -DASTCENC_POPCNT=0 \
52      -I. -std=c++14 $fuzzer $LIB_FUZZING_ENGINE ./libastcenc.a \
53      -o $OUT/$(basename -s .cpp $fuzzer)
54done
55
56# Cleanup temporary build files
57rm *.o
58rm *.a
59