blob: b5f43495b692a5b22a90ab07b79e5d388862fdc8 [file] [log] [blame]
Nigel Tao4c1826a2018-08-05 21:55:50 +10001#!/bin/bash -eu
2# Copyright 2018 The Wuffs Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# ----------------
17
18# See build-all.sh for commentary.
19
Nigel Taoeb670342021-10-07 14:59:13 +110020if [ ! -e wuffs-root-directory.txt ]; then
Nigel Tao10ae7042018-08-18 12:13:36 +100021 echo "$0 should be run from the Wuffs root directory."
22 exit 1
23fi
24
Nigel Taob2d598a2018-12-26 12:38:15 +110025CC=${CC:-gcc}
26CXX=${CXX:-g++}
Nigel Taofeb050b2021-10-07 14:12:16 +110027LDFLAGS=${LDFLAGS:-}
28
29# The "-fdata-sections -ffunction-sections -Wl,--gc-sections" produces smaller
30# binaries. See commit 41fce8a8 "Strip examples of unused data and functions".
31CFLAGS=${CFLAGS:--O3 -fdata-sections -ffunction-sections -Wl,--gc-sections}
32CXXFLAGS=${CXXFLAGS:--O3 -fdata-sections -ffunction-sections -Wl,--gc-sections}
Nigel Taob2d598a2018-12-26 12:38:15 +110033
Nigel Tao10ae7042018-08-18 12:13:36 +100034mkdir -p gen/bin
35
36sources=$@
37if [ $# -eq 0 ]; then
Nigel Tao128d0382021-08-12 22:59:11 +100038 sources=fuzz/c/std/*_fuzzer.c*
Nigel Tao10ae7042018-08-18 12:13:36 +100039fi
40
41for f in $sources; do
42 f=${f%_fuzzer.c}
Nigel Tao128d0382021-08-12 22:59:11 +100043 f=${f%_fuzzer.cc}
Nigel Tao10ae7042018-08-18 12:13:36 +100044 f=${f%/}
45 f=${f##*/}
46 if [ -z $f ]; then
47 continue
48 fi
Nigel Tao10ae7042018-08-18 12:13:36 +100049
Nigel Tao128d0382021-08-12 22:59:11 +100050 if [ -e fuzz/c/std/${f}_fuzzer.c ]; then
51 echo "Building (C) gen/bin/fuzz-$f"
Nigel Taofeb050b2021-10-07 14:12:16 +110052 $CC $CFLAGS -DWUFFS_CONFIG__FUZZLIB_MAIN fuzz/c/std/${f}_fuzzer.c \
53 $LDFLAGS -o gen/bin/fuzz-$f
Nigel Tao128d0382021-08-12 22:59:11 +100054 elif [ -e fuzz/c/std/${f}_fuzzer.cc ]; then
55 echo "Building (C++) gen/bin/fuzz-$f"
Nigel Taofeb050b2021-10-07 14:12:16 +110056 $CXX $CXXFLAGS -DWUFFS_CONFIG__FUZZLIB_MAIN fuzz/c/std/${f}_fuzzer.cc \
57 $LDFLAGS -o gen/bin/fuzz-$f
Nigel Tao128d0382021-08-12 22:59:11 +100058 fi
Nigel Tao4c1826a2018-08-05 21:55:50 +100059done