oss-fuzz-build.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash -eu
  2. # Copyright 2019 Google Inc.
  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. # http://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. cd "$SRC"/leptonica
  18. ./autogen.sh
  19. ./configure --disable-shared
  20. make SUBDIRS=src install -j"$(nproc)"
  21. ldconfig
  22. cd "$SRC"/tesseract
  23. ./autogen.sh
  24. CXXFLAGS="$CXXFLAGS -D_GLIBCXX_DEBUG" ./configure --disable-graphics --disable-shared
  25. make -j"$(nproc)"
  26. # Get the models which are needed for the fuzzers.
  27. mkdir -p "$OUT"/tessdata
  28. (
  29. cd "$OUT"/tessdata
  30. test -f eng.traineddata || \
  31. curl -sSL -O https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata
  32. )
  33. # OSS-Fuzz requires static linking for the project specific libraries,
  34. # so get the list of those libraries for Leptonica and TIFF.
  35. # Note that libm must be linker dynamically to avoid linker errors.
  36. LEPTONICA_CFLAGS=$(pkg-config --cflags lept)
  37. LEPTONICA_LIBS=$(pkg-config --static --libs lept)
  38. LIBTIFF_LIBS=$(pkg-config --static --libs libtiff-4 | sed 's/ -lm//')
  39. $CXX $CXXFLAGS \
  40. -I "$SRC"/tesseract/include \
  41. "$SRC"/tesseract/unittest/fuzzers/fuzzer-api.cpp -o "$OUT"/fuzzer-api \
  42. "$SRC"/tesseract/.libs/libtesseract.a \
  43. $LEPTONICA_CFLAGS \
  44. -Wl,-Bstatic $LEPTONICA_LIBS $LIBTIFF_LIBS -Wl,-Bdynamic \
  45. $LIB_FUZZING_ENGINE
  46. $CXX $CXXFLAGS \
  47. -DTESSERACT_FUZZER_WIDTH=512 \
  48. -DTESSERACT_FUZZER_HEIGHT=256 \
  49. -I "$SRC"/tesseract/include \
  50. "$SRC"/tesseract/unittest/fuzzers/fuzzer-api.cpp -o "$OUT"/fuzzer-api-512x256 \
  51. "$SRC"/tesseract/.libs/libtesseract.a \
  52. $LEPTONICA_CFLAGS \
  53. -Wl,-Bstatic $LEPTONICA_LIBS $LIBTIFF_LIBS -Wl,-Bdynamic \
  54. $LIB_FUZZING_ENGINE