build.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # Load arguments into named variables in order
  3. PROJECT_FOLDERS=$1 # Where your code is as a space separated list of folders in a quote
  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. COMPILER_FLAGS=$6 # -DDEBUG/-DNDEBUG -std=c++14/-std=c++17 -O2/-O3
  9. LINKER_FLAGS=$7 # Additional linker flags for libraries and such
  10. # Replace space with underscore
  11. TEMP_SUB="${COMPILER_FLAGS// /_}"
  12. # Replace + with p
  13. TEMP_SUB=$(echo $TEMP_SUB | tr "+" "p")
  14. # Remove = and -
  15. TEMP_SUB=$(echo $TEMP_SUB | tr -d "=-")
  16. TEMP_DIR=${TEMP_ROOT}/${TEMP_SUB}
  17. echo "Building version ${TEMP_SUB}"
  18. # Allow calling other scripts
  19. chmod +x ${ROOT_PATH}/tools/buildScripts/clean.sh
  20. chmod +x ${ROOT_PATH}/tools/buildScripts/buildLibrary.sh
  21. # Make a clean folder
  22. ${ROOT_PATH}/tools/buildScripts/clean.sh ${TEMP_DIR}
  23. echo "Compiling renderer framework."
  24. ${ROOT_PATH}/tools/buildScripts/buildLibrary.sh g++ ${ROOT_PATH}/DFPSR ${TEMP_DIR} "dfpsr" "${COMPILER_FLAGS}" 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_FOLDERS}" = "NONE" ]
  31. then
  32. exit 0
  33. fi
  34. echo "Compiling application."
  35. ${ROOT_PATH}/tools/buildScripts/buildLibrary.sh g++ "${PROJECT_FOLDERS}" ${TEMP_DIR} "application" "${COMPILER_FLAGS}" 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++ ${COMPILER_FLAGS} -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}/NativeWindow.o ${LIBS} ${TEMP_DIR}/dfpsr.a -o ${TARGET_FILE}
  62. if [ $? -ne 0 ]
  63. then
  64. exit 1
  65. fi