#!/bin/sh

# http://www.openwall.com/lists/musl/2015/03/21/17

set -xue

fuzzdir=fuzz

mkdir -p $fuzzdir
cd $fuzzdir
[ -e libfuzz.a ] && exit 0

svn co http://llvm.org/svn/llvm-project/llvm/trunk/lib/Fuzzer
cat <<EOF >cov-minimal-rt.c
static long counter;
void __sanitizer_cov_with_check(int *guard) {
if (*guard == 0) {
counter++;
*guard=1;
}
}
long __sanitizer_get_total_unique_coverage() { return counter; }
void __sanitizer_cov_module_init() {}
void __sanitizer_reset_coverage(){}
void __sanitizer_get_coverage_guards(){}
void __sanitizer_get_number_of_counters(){}
void __sanitizer_update_counter_bitset_and_clear_counters(){}
void __sanitizer_set_death_callback(){}
EOF

clang -std=c++11 -c Fuzzer/Fuzzer*.cpp -I Fuzzer
clang -c cov-minimal-rt.c
ar rc libfuzz.a *.o
ranlib libfuzz.a
