1set -e
2SOURCES=(dgif_lib.c egif_lib.c getarg.c gifalloc.c gif_err.c gif_font.c \
3        gif_hash.c openbsd-reallocarray.c qprintf.c quantize.c)
4cd $SRC/giflib-code
5rm -f *.o
6for file in ${SOURCES[@]};
7do
8    name=$(basename $file .c)
9    $CC -c -I . $CFLAGS $file -o $name.o
10done
11ar rc libgif.a *.o
12
13cd $SRC
14$CXX $CFLAGS -Wall -c -I giflib-code dgif_target.cc -o dgif_target.o
15$CXX $CXXFLAGS $LIB_FUZZING_ENGINE -std=c++11  -I giflib-code dgif_fuzz_common.cc dgif_target.o  \
16        -o $OUT/dgif_target giflib-code/libgif.a
17
18$CXX $CXXFLAGS -Wall -c -I giflib-code egif_target.cc -o egif_target.o
19$CXX $CXXFLAGS $LIB_FUZZING_ENGINE -std=c++11  -I giflib-code egif_fuzz_common.cc egif_target.o  \
20        -o $OUT/egif_target giflib-code/libgif.a
21
22rm -rf genfiles && mkdir genfiles && LPM/external.protobuf/bin/protoc gif_fuzz_proto.proto --cpp_out=genfiles
23
24$CXX $CXXFLAGS -Wall -c -I giflib-code dgif_protobuf_target.cc -I libprotobuf-mutator/ \
25-I genfiles \
26-I LPM/external.protobuf/include \
27 -o dgif_protobuf_target.o
28
29$CXX $CXXFLAGS $LIB_FUZZING_ENGINE -std=c++11 -I. -I giflib-code dgif_protobuf_target.o dgif_fuzz_common.cc genfiles/gif_fuzz_proto.pb.cc \
30ProtoToGif.cpp \
31-I LPM/external.protobuf/include \
32-I genfiles \
33LPM/src/libfuzzer/libprotobuf-mutator-libfuzzer.a \
34LPM/src/libprotobuf-mutator.a \
35LPM/external.protobuf/lib/libprotobuf.a \
36        -o $OUT/dgif_protobuf_target giflib-code/libgif.a
37
38
39# Place dict and config in OUT
40wget -O $OUT/gif.dict \
41  https://raw.githubusercontent.com/mirrorer/afl/master/dictionaries/gif.dict \
42  &> /dev/null
43cp $SRC/*.options $OUT/
44find $SRC/giflib-code -iname "*.gif" -exec \
45  zip -ujq $OUT/dgif_target_seed_corpus.zip "{}" \;
46