build-fuzzer.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. set -e
  3. NPROC=1
  4. # OS detection
  5. if [ "$(uname)" = "Linux" ]; then
  6. NPROC=$(nproc)
  7. CC=clang-12
  8. elif [ "$(uname)" = "Darwin" ]; then
  9. NPROC=$(sysctl -n hw.ncpu)
  10. CC=clang
  11. elif [ "$(uname)" = "FreeBSD" ]; then
  12. NPROC=$(sysctl -n hw.ncpu)
  13. CC=cc
  14. else
  15. echo "Error: $(uname) not supported, sorry!"
  16. exit 1
  17. fi
  18. # Check if we have a compiler
  19. if ! [ -x "$(command -v $CC)" ]; then
  20. echo "Error: $CC is not installed!" >&2
  21. exit 1
  22. fi
  23. echo "OS :" $(uname)
  24. echo "CC :" $CC
  25. echo "NP :" $NPROC
  26. # Go to script directory
  27. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
  28. cd "$SCRIPT_DIR"
  29. cd ".."
  30. pwd
  31. # Find and then delete all files under current directory (.) that:
  32. # 1. contains "cmake" (case-&insensitive) in its path (wholename)
  33. # 2. name is not CMakeLists.txt
  34. find . -iwholename '*cmake*' -not -name CMakeLists.txt -delete
  35. # Build with ASAN / MSAN
  36. cmake -Dsctp_build_fuzzer=1 -Dsctp_build_programs=0 -Dsctp_invariants=1 -Dsctp_sanitizer_address=1 -DCMAKE_LINKER="$CC" -DCMAKE_C_COMPILER="$CC" .
  37. #cmake -Dsctp_build_fuzzer=1 -Dsctp_build_programs=0 -Dsctp_invariants=1 -Dsctp_sanitizer_memory=1 -DCMAKE_LINKER="$CC" -DCMAKE_C_COMPILER="$CC" .
  38. make -j"$NPROC"