buildProject.sh 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Local build settings that should be configured before building for the first time.
  2. # Make sure to erase all objects in the temporary folder before changing compiler.
  3. # Compile using GCC's C++ compiler
  4. CPP_COMPILER_PATH="/usr/bin/g++"
  5. # Compile using CLANG (Needs a 'Link "stdc++"' command in each project)
  6. #CPP_COMPILER_PATH="/usr/bin/clang"
  7. echo "Change CPP_COMPILER_PATH in ${BUILDER_FOLDER}/buildProject.sh if you are not using ${CPP_COMPILER_PATH} as your compiler."
  8. # Change TEMPORARY_FOLDER if you don't want to recompile everything after each reboot, or your operating system has a different path to the temporary folder.
  9. TEMPORARY_FOLDER="/tmp"
  10. # Select build method. (Not generating a script requires having the full path of the compiler.)
  11. #GENERATE_SCRIPT="Yes"
  12. GENERATE_SCRIPT="No"
  13. # Using buildProject.sh
  14. # $1 must be the *.DsrProj path, which is relative to the caller location.
  15. # $2... are variable assignments sent as input to the given project file.
  16. # CPP_COMPILER_PATH should be modified if it does not already refer to an installed C++ compiler.
  17. echo "Running buildProject.sh $@"
  18. # Get the build system's folder, where the build system is located
  19. BUILDER_FOLDER=`dirname "$(realpath $0)"`
  20. echo "BUILDER_FOLDER = ${BUILDER_FOLDER}"
  21. BUILDER_EXECUTABLE="${BUILDER_FOLDER}/builder"
  22. echo "BUILDER_EXECUTABLE = ${BUILDER_EXECUTABLE}"
  23. # Check if the build system is compiled
  24. if [ -e "${BUILDER_EXECUTABLE}" ]; then
  25. echo "Found the build system's binary."
  26. else
  27. echo "Building the Builder build system for first time use."
  28. LIBRARY_PATH="$(realpath ${BUILDER_FOLDER}/../../DFPSR)"
  29. 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"
  30. "${CPP_COMPILER_PATH}" -o "${BUILDER_EXECUTABLE}" ${SOURCE_CODE} -std=c++14 -lstdc++
  31. if [ $? -eq 0 ]; then
  32. echo "Completed building the Builder build system."
  33. else
  34. echo "Failed building the Builder build system, which is needed to build your project!"
  35. exit 1
  36. fi
  37. fi
  38. chmod +x "${BUILDER_EXECUTABLE}"
  39. if [ "$GENERATE_SCRIPT" == "Yes" ]; then
  40. # Calling the build system with a script path will generate it with compiling and linking commands before executing the result.
  41. # Useful for debugging the output when something goes wrong.
  42. SCRIPT_PATH="${TEMPORARY_FOLDER}/dfpsr_compile.sh"
  43. echo "Generating ${SCRIPT_PATH} from $1"
  44. if [ -e "${SCRIPT_PATH}" ]; then
  45. rm "${SCRIPT_PATH}"
  46. fi
  47. "${BUILDER_EXECUTABLE}" "${SCRIPT_PATH}" "$@" "Compiler=${CPP_COMPILER_PATH}";
  48. if [ -e "${SCRIPT_PATH}" ]; then
  49. echo "Giving execution permission to ${SCRIPT_PATH}"
  50. chmod +x "${SCRIPT_PATH}"
  51. echo "Running ${SCRIPT_PATH}"
  52. "${SCRIPT_PATH}"
  53. fi
  54. else
  55. # Calling the build system with only the temporary folder will call the compiler directly from the build system.
  56. # A simpler solution that works with just a single line, once the build system itself has been compiled.
  57. echo "Generating objects to ${TEMPORARY_FOLDER} from $1"
  58. "${BUILDER_EXECUTABLE}" "${TEMPORARY_FOLDER}" "$@" "Compiler=${CPP_COMPILER_PATH}";
  59. fi