-#!/bin/bash
+#!/bin/bash -eu
-set -e
-set -x
+MAGICK_COMPILER=$CC
+MAGICK_COMPILER_FLAGS="-DBUILD_TRAVIS=1"
+MAGICK_INCLUDE="appdir/usr/include/ImageMagick-7"
+MAGICK_SRC="Magick++/fuzz"
+MAGICK_LIBS="-Lappdir/usr/lib -lz -lpng -lfontconfig -lxcb -lX11 -lXext -lbz2 -ljpeg -ljbig -lIlmImf -ldjvulibre -ltiff -llqr-1 -lwmf -lwmflite -lraqm -lxml2 -llzma -llcms2 -lpthread -lfreetype -lMagick++-7.Q16 -lMagickWand-7.Q16 -lMagickCore-7.Q16"
+MAGICK_OUTPUT="Magick++/fuzz"
-MAGICKINCLUDE="appdir/usr/include/ImageMagick-7"
-MAGICKFUZZERLIBS="-Lappdir/usr/lib -lz -lpng -lfontconfig -lxcb -lX11 -lXext -lbz2 -ljpeg -ljbig -lIlmImf -ldjvulibre -ltiff -llqr-1 -lwmf -lwmflite -lraqm -lxml2 -llzma -llcms2 -lpthread -lfreetype -lMagick++-7.Q16 -lMagickWand-7.Q16 -lMagickCore-7.Q16"
-
-$CC -std=c++11 -I$MAGICKINCLUDE "Magick++/fuzz/encoder_list.cc" \
- -o "encoder_list" \
- -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -DBUILD_TRAVIS=1 $MAGICKFUZZERLIBS
-
-for f in Magick++/fuzz/*_fuzzer.cc; do
- fuzzer=$(basename "$f" _fuzzer.cc)
- # encoder_fuzzer is special
- if [ "$fuzzer" = "encoder" ]; then
- continue
- fi
- $CC -std=c++11 -I$MAGICKINCLUDE \
- "$f" -o "${fuzzer}_fuzzer" \
- -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -DBUILD_TRAVIS=1 $MAGICKFUZZERLIBS
-done
-
-# Build one encoder to confirm it works
-$CC -std=c++11 -I$MAGICKINCLUDE \
- "Magick++/fuzz/encoder_fuzzer.cc" -o "encoder_wmf_fuzzer" \
- -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -DBUILD_TRAVIS=1 \
- "-DFUZZ_IMAGEMAGICK_ENCODER=WMF" $MAGICKFUZZERLIBS
+. $MAGICK_SRC/build_fuzzers.sh
\ No newline at end of file
--- /dev/null
+#!/bin/bash -eu
+
+MAGICK_COMPILER_FLAGS="$MAGICK_COMPILER_FLAGS -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16"
+
+$MAGICK_COMPILER $MAGICK_COMPILER_FLAGS -std=c++11 -I$MAGICK_INCLUDE "$MAGICK_SRC/encoder_list.cc" \
+ -o "$MAGICK_SRC/encoder_list" $MAGICK_LIBS
+
+for f in $MAGICK_SRC/*_fuzzer.cc; do
+ fuzzer=$(basename "$f" _fuzzer.cc)
+ # encoder_fuzzer is special
+ if [ "$fuzzer" = "encoder" ]; then
+ continue
+ fi
+ $MAGICK_COMPILER $MAGICK_COMPILER_FLAGS -std=c++11 -I$MAGICK_INCLUDE \
+ "$f" -o "$MAGICK_OUTPUT/${fuzzer}_fuzzer" $MAGICK_LIBS
+done
+
+for encoder in $("$MAGICK_SRC/encoder_list"); do
+ encoder_flags="-DFUZZ_IMAGEMAGICK_ENCODER=$encoder"
+ $MAGICK_COMPILER $MAGICK_COMPILER_FLAGS -std=c++11 -I$MAGICK_INCLUDE \
+ "$MAGICK_SRC/encoder_fuzzer.cc" -o "$MAGICK_OUTPUT/encoder_${encoder,,}_fuzzer" \
+ $encoder_flags $MAGICK_LIBS
+done
\ No newline at end of file