Nigel Tao | 4c1826a | 2018-08-05 21:55:50 +1000 | [diff] [blame] | 1 | #!/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 Tao | eb67034 | 2021-10-07 14:59:13 +1100 | [diff] [blame] | 20 | if [ ! -e wuffs-root-directory.txt ]; then |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 21 | echo "$0 should be run from the Wuffs root directory." |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
Nigel Tao | b2d598a | 2018-12-26 12:38:15 +1100 | [diff] [blame] | 25 | CC=${CC:-gcc} |
| 26 | CXX=${CXX:-g++} |
Nigel Tao | feb050b | 2021-10-07 14:12:16 +1100 | [diff] [blame] | 27 | LDFLAGS=${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". |
| 31 | CFLAGS=${CFLAGS:--O3 -fdata-sections -ffunction-sections -Wl,--gc-sections} |
| 32 | CXXFLAGS=${CXXFLAGS:--O3 -fdata-sections -ffunction-sections -Wl,--gc-sections} |
Nigel Tao | b2d598a | 2018-12-26 12:38:15 +1100 | [diff] [blame] | 33 | |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 34 | mkdir -p gen/bin |
| 35 | |
| 36 | sources=$@ |
| 37 | if [ $# -eq 0 ]; then |
Nigel Tao | 128d038 | 2021-08-12 22:59:11 +1000 | [diff] [blame] | 38 | sources=fuzz/c/std/*_fuzzer.c* |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 39 | fi |
| 40 | |
| 41 | for f in $sources; do |
| 42 | f=${f%_fuzzer.c} |
Nigel Tao | 128d038 | 2021-08-12 22:59:11 +1000 | [diff] [blame] | 43 | f=${f%_fuzzer.cc} |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 44 | f=${f%/} |
| 45 | f=${f##*/} |
| 46 | if [ -z $f ]; then |
| 47 | continue |
| 48 | fi |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 49 | |
Nigel Tao | 128d038 | 2021-08-12 22:59:11 +1000 | [diff] [blame] | 50 | if [ -e fuzz/c/std/${f}_fuzzer.c ]; then |
| 51 | echo "Building (C) gen/bin/fuzz-$f" |
Nigel Tao | feb050b | 2021-10-07 14:12:16 +1100 | [diff] [blame] | 52 | $CC $CFLAGS -DWUFFS_CONFIG__FUZZLIB_MAIN fuzz/c/std/${f}_fuzzer.c \ |
| 53 | $LDFLAGS -o gen/bin/fuzz-$f |
Nigel Tao | 128d038 | 2021-08-12 22:59:11 +1000 | [diff] [blame] | 54 | elif [ -e fuzz/c/std/${f}_fuzzer.cc ]; then |
| 55 | echo "Building (C++) gen/bin/fuzz-$f" |
Nigel Tao | feb050b | 2021-10-07 14:12:16 +1100 | [diff] [blame] | 56 | $CXX $CXXFLAGS -DWUFFS_CONFIG__FUZZLIB_MAIN fuzz/c/std/${f}_fuzzer.cc \ |
| 57 | $LDFLAGS -o gen/bin/fuzz-$f |
Nigel Tao | 128d038 | 2021-08-12 22:59:11 +1000 | [diff] [blame] | 58 | fi |
Nigel Tao | 4c1826a | 2018-08-05 21:55:50 +1000 | [diff] [blame] | 59 | done |