2
0

build.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. TEMP_SUB="${COMPILER_FLAGS// /_}"
  11. TEMP_SUB=$(echo $TEMP_SUB | tr "+" "p")
  12. TEMP_SUB=$(echo $TEMP_SUB | tr -d " =-")
  13. TEMP_DIR=${TEMP_ROOT}/${TEMP_SUB}
  14. echo "Building version ${TEMP_SUB}"
  15. # Allow calling other scripts
  16. chmod +x ${ROOT_PATH}/tools/clean.sh
  17. chmod +x ${ROOT_PATH}/tools/buildLibrary.sh
  18. # Make a clean folder
  19. ${ROOT_PATH}/tools/clean.sh ${TEMP_DIR}
  20. echo "Compiling renderer framework."
  21. ${ROOT_PATH}/tools/buildLibrary.sh g++ ${ROOT_PATH}/DFPSR ${TEMP_DIR} "dfpsr" "${COMPILER_FLAGS}" LAZY
  22. if [ $? -ne 0 ]
  23. then
  24. exit 1
  25. fi
  26. # Abort if the project folder is replaced with the NONE keyword
  27. if [ "${PROJECT_FOLDERS}" = "NONE" ]
  28. then
  29. exit 0
  30. fi
  31. echo "Compiling application."
  32. ${ROOT_PATH}/tools/buildLibrary.sh g++ "${PROJECT_FOLDERS}" ${TEMP_DIR} "application" "${COMPILER_FLAGS}" CLEAN
  33. if [ $? -ne 0 ]
  34. then
  35. exit 1
  36. fi
  37. # Select the base libraries needed by the framework itself
  38. BASELIBS="-lm -pthread"
  39. # Select window manager to compile and libraries to link
  40. if [ ${WINDOW_MANAGER} = "NONE" ]
  41. then
  42. # Embedded/terminal mode
  43. WINDOW_SOURCE=${ROOT_PATH}/windowManagers/NoWindow.cpp
  44. LIBS="${BASELIBS} ${LINKER_FLAGS}"
  45. else
  46. # Desktop GUI mode
  47. WINDOW_SOURCE=${ROOT_PATH}/windowManagers/${WINDOW_MANAGER}Window.cpp
  48. LIBS="${BASELIBS} ${LINKER_FLAGS} -l${WINDOW_MANAGER}"
  49. fi
  50. echo "Compiling window manager (${WINDOW_SOURCE})"
  51. g++ ${COMPILER_FLAGS} -Wall -c ${WINDOW_SOURCE} -o ${TEMP_DIR}/NativeWindow.o
  52. if [ $? -ne 0 ]
  53. then
  54. exit 1
  55. fi
  56. echo "Linking application with libraries (${LIBS})"
  57. # Main must exist in the first library when linking
  58. g++ ${TEMP_DIR}/application.a ${TEMP_DIR}/NativeWindow.o ${LIBS} ${TEMP_DIR}/dfpsr.a -o ${TARGET_FILE}
  59. if [ $? -ne 0 ]
  60. then
  61. exit 1
  62. fi