build.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. MANAGERS=$5 # Which libraries to use for creating windows and playing sounds
  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 [ ${MANAGERS} = "NONE" ]
  44. then
  45. # Embedded/terminal mode
  46. WINDOW_SOURCE=${ROOT_PATH}/windowManagers/NoWindow.cpp
  47. SOUND_SOURCE=${ROOT_PATH}/soundManagers/NoSound.cpp
  48. LIBS="${BASELIBS} ${LINKER_FLAGS}"
  49. elif [ ${MANAGERS} = "X11" ]
  50. then
  51. # Desktop GUI mode without sound
  52. WINDOW_SOURCE=${ROOT_PATH}/windowManagers/X11Window.cpp
  53. SOUND_SOURCE=${ROOT_PATH}/soundManagers/NoSound.cpp
  54. LIBS="${BASELIBS} ${LINKER_FLAGS} -lX11"
  55. elif [ ${MANAGERS} = "X11&ALSA" ]
  56. then
  57. # Desktop GUI mode with sound
  58. WINDOW_SOURCE=${ROOT_PATH}/windowManagers/X11Window.cpp
  59. SOUND_SOURCE=${ROOT_PATH}/soundManagers/AlsaSound.cpp
  60. LIBS="${BASELIBS} ${LINKER_FLAGS} -lX11 -lasound"
  61. else
  62. echo "Unrecognized argument ${MANAGERS} for sound and window managers!"
  63. exit 1
  64. fi
  65. echo "Compiling sound manager (${SOUND_SOURCE})"
  66. g++ ${COMPILER_FLAGS} -Wall -c ${SOUND_SOURCE} -o ${TEMP_DIR}/NativeSound.o
  67. if [ $? -ne 0 ]
  68. then
  69. exit 1
  70. fi
  71. echo "Compiling window manager (${WINDOW_SOURCE})"
  72. g++ ${COMPILER_FLAGS} -Wall -c ${WINDOW_SOURCE} -o ${TEMP_DIR}/NativeWindow.o
  73. if [ $? -ne 0 ]
  74. then
  75. exit 1
  76. fi
  77. echo "Linking application with libraries (${LIBS})"
  78. # Main must exist in the first library when linking
  79. g++ ${TEMP_DIR}/application.a ${TEMP_DIR}/NativeWindow.o ${TEMP_DIR}/NativeSound.o ${LIBS} ${TEMP_DIR}/dfpsr.a -o ${TARGET_FILE}
  80. if [ $? -ne 0 ]
  81. then
  82. exit 1
  83. fi