1
0

compile 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. set -eo pipefail
  3. src_file=$1
  4. exe_file=$(basename "${src_file%.*}")
  5. if [[ -z "$MACHINE" ]]; then
  6. echo "Must provide MACHINE for compile"
  7. exit 1
  8. fi
  9. if [[ "$MACHINE" == "Windows" ]]; then
  10. exe_file=$(basename "${src_file%.*}".exe)
  11. fi
  12. if [[ -z "$src_file" ]]; then
  13. echo "Must provide \$1 for compile"
  14. exit 1
  15. fi
  16. if [[ -z "$CPP_INCLUDE_DIR" ]]; then
  17. echo "Must provide CPP_INCLUDE_DIR in environment"
  18. exit 1
  19. fi
  20. if [[ -z "$CPP" ]]; then
  21. echo "Must provide CPP in environment"
  22. exit 1
  23. fi
  24. rm -f "$exe_file"
  25. EXTRA_ARGS=""
  26. if [[ "$CPP" == "clang++" && "$MACHINE" == "Windows" ]]; then
  27. msvc_version="2022"
  28. wk_version="10.0.19041.0"
  29. EXTRA_ARGS=" -I\"$TESTS_DIR/lib/msvc-$msvc_version-include\""
  30. for s in cppwinrt shared ucrt um winrt; do
  31. EXTRA_ARGS="$EXTRA_ARGS -I\"$TESTS_DIR/lib/windows-kit-$wk_version-include/$s\""
  32. done
  33. fi
  34. if [[ "$CPP" == "cl.exe" ]]; then
  35. echo "Compiling $src_file, running:" "$CPP" "$CPP_STANDARD" "-F268435456" "-EHsc" "-O2" -I"${CPP_INCLUDE_DIR}" -Fe"$exe_file" "$src_file"
  36. "$CPP" "$CPP_STANDARD" "-F268435456" "-EHsc" "-O2" -I"${CPP_INCLUDE_DIR}" -Fe"$exe_file" "$src_file" &>/dev/null
  37. else
  38. echo "Compiling $src_file, running:" "$CPP" "$CPP_OPTS" "$CPP_STANDARD" -Wpedantic -Werror -I"${CPP_INCLUDE_DIR}""$EXTRA_ARGS" -o"$exe_file" -O2 "$src_file"
  39. eval "$CPP" "$CPP_OPTS" "$CPP_STANDARD" -Wpedantic -Werror -I"${CPP_INCLUDE_DIR}""$EXTRA_ARGS" -o"$exe_file" -O2 "$src_file"
  40. fi
  41. rm -f ./*.o ./*.obj
  42. if [ ! -f "$exe_file" ]; then
  43. echo "Compilation failed: file $exe_file not found"
  44. exit 1
  45. fi
  46. echo "[SUCCESS] $src_file compiled"
  47. if [[ "$2" == "--check-only" ]]; then
  48. rm -rf "$exe_file"
  49. fi