1
0

compile 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 [[ "$CPP" == "clang++" && "$MACHINE" == "Windows" ]]; then
  28. msvc_version="2022"
  29. wk_version="10.0.19041.0"
  30. EXTRA_ARGS=" -I\"$TESTS_DIR/lib/msvc-$msvc_version-include\""
  31. for s in cppwinrt shared ucrt um winrt; do
  32. EXTRA_ARGS="$EXTRA_ARGS -I\"$TESTS_DIR/lib/windows-kit-$wk_version-include/$s\""
  33. done
  34. fi
  35. if [[ "$CPP" == "cl.exe" ]]; then
  36. echo "Compiling $src_file, running:" "$CPP" "$CPP_STANDARD" "-F268435456" "-EHsc" "-O2" -I"${CPP_INCLUDE_DIR}" -Fe"$exe_file" "$src_file"
  37. "$CPP" "$CPP_STANDARD" "-F268435456" "-EHsc" "-O2" -I"${CPP_INCLUDE_DIR}" -Fe"$exe_file" "$src_file"
  38. else
  39. "$CPP" -v
  40. echo "Compiling $src_file, running:" "$CPP" "$CPP_OPTS" "$CPP_STANDARD" -Wpedantic -Werror -I"${CPP_INCLUDE_DIR}""$EXTRA_ARGS" -o"$exe_file" -O2 "$src_file"
  41. dir=$(dirname "$CPP")
  42. if [[ "$dir" == *"/bin" ]]; then
  43. EXTRA_ARGS="${EXTRA_ARGS} -static"
  44. fi
  45. eval "$CPP" "$CPP_OPTS" "$CPP_STANDARD" -Wpedantic -Werror -I"${CPP_INCLUDE_DIR}""$EXTRA_ARGS" -o"$exe_file" -O2 "$src_file"
  46. fi
  47. rm -f ./*.o ./*.obj
  48. if [ ! -f "$exe_file" ]; then
  49. echo "Compilation failed: file $exe_file not found"
  50. exit 1
  51. fi
  52. echo -e "${SUCCESS_TXT} $src_file compiled\n"
  53. if [[ "$2" == "--check-only" ]]; then
  54. rm -rf "$exe_file"
  55. fi