buildProject.sh 3.0 KB

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