buildProject.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # Local build settings that should be configured before building for the first time.
  3. # Make sure to erase all objects in the temporary folder before changing compiler.
  4. # Select build method. (Not generating a script requires having the full path of the compiler.)
  5. #GENERATE_SCRIPT="Yes"
  6. GENERATE_SCRIPT="No"
  7. # Change TEMPORARY_FOLDER if you do not want to recompile everything after each reboot.
  8. TEMPORARY_FOLDER="/tmp"
  9. COMPILER_NAME="g++"
  10. # Find the compiler.
  11. CPP_COMPILER_PATH=$(which "${COMPILER_NAME}")
  12. if [ -n "$CPP_COMPILER_PATH" ]; then
  13. echo "Found ${COMPILER_NAME} at ${CPP_COMPILER_PATH}."
  14. else
  15. echo "Could not find ${COMPILER_NAME}."
  16. exit 1
  17. fi
  18. # Get the script's folder.
  19. BUILDER_FOLDER=$(dirname "$0")
  20. echo "BUILDER_FOLDER = ${BUILDER_FOLDER}"
  21. # Ask for permission to access the temporary folder.
  22. if ! ( [ -d "${TEMPORARY_FOLDER}" ] && [ -r "${TEMPORARY_FOLDER}" ] && [ -w "${TEMPORARY_FOLDER}" ] && [ -x "${TEMPORARY_FOLDER}" ] ); then
  23. echo "Can not access the ${TEMPORARY_FOLDER} folder."
  24. TEMPORARY_FOLDER="${BUILDER_FOLDER}/temporary"
  25. mkdir "${TEMPORARY_FOLDER}"
  26. if ! ( [ -d "${TEMPORARY_FOLDER}" ] && [ -r "${TEMPORARY_FOLDER}" ] && [ -w "${TEMPORARY_FOLDER}" ] && [ -x "${TEMPORARY_FOLDER}" ] ); then
  27. echo "Failed not create a new folder at ${TEMPORARY_FOLDER}, aborting!"
  28. exit 1
  29. else
  30. echo "Got read, write and execution rights to the ${TEMPORARY_FOLDER} folder, so we can use it to store temporary files."
  31. fi
  32. else
  33. echo "Got read, write and execution rights to the ${TEMPORARY_FOLDER} folder, so we can use it to store temporary files."
  34. fi
  35. # Using buildProject.sh
  36. # $1 must be the *.DsrProj path, which is relative to the caller location.
  37. # $2... are variable assignments sent as input to the given project file.
  38. echo "Running buildProject.sh $@"
  39. # Get the build system's folder, where the build system is located
  40. BUILDER_FOLDER=`dirname "$(realpath $0)"`
  41. echo "BUILDER_FOLDER = ${BUILDER_FOLDER}"
  42. BUILDER_EXECUTABLE="${BUILDER_FOLDER}/builder"
  43. echo "BUILDER_EXECUTABLE = ${BUILDER_EXECUTABLE}"
  44. # Check if the build system is compiled
  45. if [ -e "${BUILDER_EXECUTABLE}" ]; then
  46. echo "Found the build system's binary."
  47. else
  48. echo "Building the Builder build system for first time use."
  49. LIBRARY_PATH="$(realpath ${BUILDER_FOLDER}/../../DFPSR)"
  50. SOURCE_CODE="${BUILDER_FOLDER}/code/main.cpp ${BUILDER_FOLDER}/code/Machine.cpp ${BUILDER_FOLDER}/code/generator.cpp ${BUILDER_FOLDER}/code/analyzer.cpp ${BUILDER_FOLDER}/code/expression.cpp ${LIBRARY_PATH}/collection/collections.cpp ${LIBRARY_PATH}/api/fileAPI.cpp ${LIBRARY_PATH}/api/bufferAPI.cpp ${LIBRARY_PATH}/api/stringAPI.cpp ${LIBRARY_PATH}/api/timeAPI.cpp ${LIBRARY_PATH}/base/SafePointer.cpp ${LIBRARY_PATH}/base/virtualStack.cpp ${LIBRARY_PATH}/base/heap.cpp"
  51. "${CPP_COMPILER_PATH}" -o "${BUILDER_EXECUTABLE}" ${SOURCE_CODE} -std=c++14 -lstdc++
  52. if [ $? -eq 0 ]; then
  53. echo "Completed building the Builder build system."
  54. else
  55. echo "Failed building the Builder build system, which is needed to build your project!"
  56. exit 1
  57. fi
  58. fi
  59. chmod +x "${BUILDER_EXECUTABLE}"
  60. if [ "$GENERATE_SCRIPT" == "Yes" ]; then
  61. # Calling the build system with a script path will generate it with compiling and linking commands before executing the result.
  62. # Useful for debugging the output when something goes wrong.
  63. SCRIPT_PATH="${TEMPORARY_FOLDER}/dfpsr_compile.sh"
  64. echo "Generating ${SCRIPT_PATH} from $1"
  65. if [ -e "${SCRIPT_PATH}" ]; then
  66. rm "${SCRIPT_PATH}"
  67. fi
  68. "${BUILDER_EXECUTABLE}" "${SCRIPT_PATH}" "$@" "Compiler=${CPP_COMPILER_PATH}";
  69. if [ -e "${SCRIPT_PATH}" ]; then
  70. echo "Giving execution permission to ${SCRIPT_PATH}"
  71. chmod +x "${SCRIPT_PATH}"
  72. echo "Running ${SCRIPT_PATH}"
  73. "${SCRIPT_PATH}"
  74. fi
  75. else
  76. # Calling the build system with only the temporary folder will call the compiler directly from the build system.
  77. # A simpler solution that works with just a single line, once the build system itself has been compiled.
  78. echo "Generating objects to ${TEMPORARY_FOLDER} from $1"
  79. "${BUILDER_EXECUTABLE}" "${TEMPORARY_FOLDER}" "$@" "Compiler=${CPP_COMPILER_PATH}";
  80. if [ $? -eq 0 ]; then
  81. echo "Finished building."
  82. else
  83. echo "Failed building the project!"
  84. exit 1
  85. fi
  86. fi