buildAndRun.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # Load arguments into named variables in order
  3. PROJECT_FOLDER=$1 # Where your code is
  4. TARGET_FILE=$2 # Your executable to build
  5. ROOT_PATH=$3 # The parent folder of DFPSR, SDK and tools
  6. TEMP_ROOT=$4 # Where your temporary objects should be
  7. WINDOW_MANAGER=$5 # Which library to use for creating a window
  8. MODE=$6 # Use -DDEBUG for debug mode or -DNDEBUG for release mode
  9. CPP_VERSION=$7 # Default is -std=c++14
  10. O_LEVEL=$8 # Default is -O2
  11. LINKER_FLAGS=$9 # Additional linker flags for libraries and such
  12. TEMP_SUB="${MODE}_${CPP_VERSION}_${O_LEVEL}"
  13. TEMP_SUB=$(echo $TEMP_SUB | tr "+" "p")
  14. TEMP_SUB=$(echo $TEMP_SUB | tr -d " =-")
  15. TEMP_DIR=${TEMP_ROOT}/${TEMP_SUB}
  16. echo "Building version ${TEMP_SUB}"
  17. # Create a temporary folder
  18. mkdir -p ${TEMP_DIR}
  19. # Remove objects, but keep libraries
  20. rm -f ${TEMP_DIR}/*.o
  21. # Allow calling the build script
  22. chmod +x ${ROOT_PATH}/tools/buildLibrary.sh
  23. echo "Compiling renderer framework."
  24. ${ROOT_PATH}/tools/buildLibrary.sh g++ ${ROOT_PATH}/DFPSR ${TEMP_DIR} "dfpsr" ${CPP_VERSION} ${O_LEVEL} ${MODE} LAZY
  25. if [ $? -ne 0 ]
  26. then
  27. exit 1
  28. fi
  29. # Abort if the project folder is replaced with the NONE keyword
  30. if [ ${PROJECT_FOLDER} = "NONE" ]
  31. then
  32. exit 0
  33. fi
  34. echo "Compiling application."
  35. ${ROOT_PATH}/tools/buildLibrary.sh g++ ${PROJECT_FOLDER} ${TEMP_DIR} "application" ${CPP_VERSION} ${O_LEVEL} ${MODE} CLEAN
  36. if [ $? -ne 0 ]
  37. then
  38. exit 1
  39. fi
  40. # Select the base libraries needed by the framework itself
  41. BASELIBS="-lm -pthread"
  42. # Select window manager to compile and libraries to link
  43. if [ ${WINDOW_MANAGER} = "NONE" ]
  44. then
  45. # Embedded/terminal mode
  46. WINDOW_SOURCE=${ROOT_PATH}/windowManagers/NoWindow.cpp
  47. LIBS="${BASELIBS} ${LINKER_FLAGS}"
  48. else
  49. # Desktop GUI mode
  50. WINDOW_SOURCE=${ROOT_PATH}/windowManagers/${WINDOW_MANAGER}Window.cpp
  51. LIBS="${BASELIBS} ${LINKER_FLAGS} -l${WINDOW_MANAGER}"
  52. fi
  53. echo "Compiling window manager (${WINDOW_SOURCE})"
  54. g++ ${CPP_VERSION} ${O_LEVEL} ${MODE} -Wall -c ${WINDOW_SOURCE} -o ${TEMP_DIR}/NativeWindow.o
  55. if [ $? -ne 0 ]
  56. then
  57. exit 1
  58. fi
  59. echo "Linking application with libraries (${LIBS})"
  60. # Main must exist in the first library when linking
  61. g++ ${TEMP_DIR}/application.a ${TEMP_DIR}/dfpsr.a ${TEMP_DIR}/NativeWindow.o ${LIBS} -o ${TARGET_FILE}
  62. if [ $? -ne 0 ]
  63. then
  64. exit 1
  65. fi
  66. echo "Starting application at ${TARGET_FILE}"
  67. ${TARGET_FILE}