compile 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. set -eo pipefail
  3. SUCCESS_TXT="${GREEN}[SUCCESS]${NC}"
  4. src_file=$1
  5. exe_file=$(basename "${src_file%.*}")
  6. if [[ -z "$MACHINE" ]]; then
  7. echo "Must provide MACHINE for compile"
  8. exit 1
  9. fi
  10. if [[ "$MACHINE" == "Windows" ]]; then
  11. exe_file=$(basename "${src_file%.*}".exe)
  12. fi
  13. if [[ -z "$src_file" ]]; then
  14. echo "Must provide \$1 for compile"
  15. exit 1
  16. fi
  17. if [[ -z "$CPP_INCLUDE_DIR" ]]; then
  18. echo "Must provide CPP_INCLUDE_DIR in environment"
  19. exit 1
  20. fi
  21. if [[ -z "$CPP" ]]; then
  22. echo "Must provide CPP in environment"
  23. exit 1
  24. fi
  25. rm -f "$exe_file"
  26. EXTRA_ARGS=""
  27. if [[ -z "${TESTLIB_COMPILER_OPTIMIZATION_OPT}" ]]; then
  28. if [[ "$2" == "--check-only" ]]; then
  29. if [[ "$CPP" == "cl.exe" ]]; then
  30. OPTIMIZATION="d"
  31. else
  32. OPTIMIZATION="0"
  33. fi
  34. else
  35. OPTIMIZATION="2"
  36. fi
  37. else
  38. OPTIMIZATION="${TESTLIB_COMPILER_OPTIMIZATION_OPT}"
  39. fi
  40. if [[ "$CPP" == "cl.exe" ]]; then
  41. echo "Compiling $src_file, running:" "$CPP" "$CPP_STANDARD" "-F268435456" "-EHsc" "-O${OPTIMIZATION}" -I"${CPP_INCLUDE_DIR}" -Fe"$exe_file" "$src_file"
  42. "$CPP" "$CPP_STANDARD" "-F268435456" "-EHsc" "-O${OPTIMIZATION}" -I"${CPP_INCLUDE_DIR}" -Fe"$exe_file" "$src_file"
  43. else
  44. "$CPP" --version
  45. dir=$(dirname "$CPP")
  46. if [[ "$dir" == *"/bin" ]] || [[ "$MACHINE" == "Windows" ]]; then
  47. EXTRA_ARGS="${EXTRA_ARGS} -static"
  48. fi
  49. echo "Compiling $src_file, running:" "$CPP" "$CPP_OPTS" "$CPP_STANDARD" -Wpedantic -Werror -I"${CPP_INCLUDE_DIR}""$EXTRA_ARGS" -o"$exe_file" "-O${OPTIMIZATION}" "$src_file"
  50. eval "$CPP" "$CPP_OPTS" "$CPP_STANDARD" -Wpedantic -Werror -I"${CPP_INCLUDE_DIR}""$EXTRA_ARGS" -o"$exe_file" "-O${OPTIMIZATION}" "$src_file"
  51. fi
  52. rm -f ./*.o ./*.obj
  53. if [ ! -f "$exe_file" ]; then
  54. echo "Compilation failed: file $exe_file not found"
  55. exit 1
  56. fi
  57. echo -e "${SUCCESS_TXT} $src_file compiled\n"
  58. if [[ "$2" == "--check-only" ]]; then
  59. rm -rf "$exe_file"
  60. fi