Explore floating-point errors and metro tunnels in one trip. https://nc.itch.io/metro
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

linux-build.sh 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #!/bin/sh
  2. # Change your executable name here
  3. GAME_NAME="metro"
  4. # Set your sources here (relative paths!)
  5. # Example with two source folders:
  6. # SOURCES="src/*.c src/submodule/*.c"
  7. SOURCES="src/*.c"
  8. # Set your raylib/src location here (relative path!)
  9. RAYLIB_SRC="vendor/raylib"
  10. # About this build script: it does many things, but in essence, it's
  11. # very simple. It has 3 compiler invocations: building raylib (which
  12. # is not done always, see logic by searching "Build raylib"), building
  13. # src/*.c files, and linking together those two. Each invocation is
  14. # wrapped in an if statement to make the -qq flag work, it's pretty
  15. # verbose, sorry.
  16. # Stop the script if a compilation (or something else?) fails
  17. set -e
  18. # Get arguments
  19. while getopts ":hdusrcq" opt; do
  20. case $opt in
  21. h)
  22. echo "Usage: ./linux-build.sh [-hdusrcqq]"
  23. echo " -h Show this information"
  24. echo " -d Faster builds that have debug symbols, and enable warnings"
  25. echo " -u Run upx* on the executable after compilation (before -r)"
  26. echo " -s Run strip on the executable after compilation (before -r)"
  27. echo " -r Run the executable after compilation"
  28. echo " -c Remove the temp/(debug|release) directory, ie. full recompile"
  29. echo " -q Suppress this script's informational prints"
  30. echo " -qq Suppress all prints, complete silence (> /dev/null 2>&1)"
  31. echo ""
  32. echo "* This is mostly here to make building simple \"shipping\" versions"
  33. echo " easier, and it's a very small bit in the build scripts. The option"
  34. echo " requires that you have upx installed and on your path, of course."
  35. echo ""
  36. echo "Examples:"
  37. echo " Build a release build: ./linux-build.sh"
  38. echo " Build a release build, full recompile: ./linux-build.sh -c"
  39. echo " Build a debug build and run: ./linux-build.sh -d -r"
  40. echo " Build in debug, run, don't print at all: ./linux-build.sh -drqq"
  41. exit 0
  42. ;;
  43. d)
  44. BUILD_DEBUG="1"
  45. ;;
  46. u)
  47. UPX_IT="1"
  48. ;;
  49. s)
  50. STRIP_IT="1"
  51. ;;
  52. r)
  53. RUN_AFTER_BUILD="1"
  54. ;;
  55. c)
  56. BUILD_ALL="1"
  57. ;;
  58. q)
  59. if [ -n "$QUIET" ]; then
  60. REALLY_QUIET="1"
  61. else
  62. QUIET="1"
  63. fi
  64. ;;
  65. \?)
  66. echo "Invalid option: -$OPTARG" >&2
  67. exit 1
  68. ;;
  69. esac
  70. done
  71. # Set CC if it's not set already
  72. if [ -z "$CC" ]; then
  73. CC=cc
  74. fi
  75. # Directories
  76. ROOT_DIR=$PWD
  77. SOURCES="$ROOT_DIR/$SOURCES"
  78. RAYLIB_SRC="$ROOT_DIR/$RAYLIB_SRC"
  79. # Flags
  80. OUTPUT_DIR="builds/linux"
  81. COMPILATION_FLAGS="-std=c99 -Os -flto"
  82. FINAL_COMPILE_FLAGS="-s"
  83. WARNING_FLAGS="-Wall -Wextra -Wpedantic"
  84. LINK_FLAGS="-flto -lm -ldl -lpthread -lX11 -lxcb -lGL -lGLX -lXext -lGLdispatch -lXau -lXdmcp"
  85. # Debug changes to flags
  86. if [ -n "$BUILD_DEBUG" ]; then
  87. OUTPUT_DIR="builds-debug/linux"
  88. COMPILATION_FLAGS="-std=c99 -O0 -g"
  89. FINAL_COMPILE_FLAGS=""
  90. LINK_FLAGS="-lm -ldl -lpthread -lX11 -lxcb -lGL -lGLX -lXext -lGLdispatch -lXau -lXdmcp"
  91. fi
  92. # Display what we're doing
  93. if [ -n "$BUILD_DEBUG" ]; then
  94. [ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling in debug mode. ($COMPILATION_FLAGS $WARNING_FLAGS)"
  95. else
  96. [ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling in release mode. ($COMPILATION_FLAGS $FINAL_COMPILE_FLAGS)"
  97. fi
  98. # Create the raylib cache directory
  99. TEMP_DIR="temp/release"
  100. if [ -n "$BUILD_DEBUG" ]; then
  101. TEMP_DIR="temp/debug"
  102. fi
  103. # If there's a -c flag, remove the cache
  104. if [ -d "$TEMP_DIR" ] && [ -n "$BUILD_ALL" ]; then
  105. [ -z "$QUIET" ] && echo "COMPILE-INFO: Found cached raylib, rebuilding."
  106. rm -r "$TEMP_DIR"
  107. fi
  108. # If temp directory doesn't exist, build raylib
  109. if [ ! -d "$TEMP_DIR" ]; then
  110. mkdir -p $TEMP_DIR
  111. cd $TEMP_DIR
  112. RAYLIB_DEFINES="-D_DEFAULT_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33"
  113. RAYLIB_C_FILES="$RAYLIB_SRC/core.c $RAYLIB_SRC/shapes.c $RAYLIB_SRC/textures.c $RAYLIB_SRC/text.c $RAYLIB_SRC/models.c $RAYLIB_SRC/utils.c $RAYLIB_SRC/raudio.c $RAYLIB_SRC/rglfw.c"
  114. RAYLIB_INCLUDE_FLAGS="-I$RAYLIB_SRC -I$RAYLIB_SRC/external/glfw/include"
  115. if [ -n "$REALLY_QUIET" ]; then
  116. $CC -c $RAYLIB_DEFINES $RAYLIB_INCLUDE_FLAGS $COMPILATION_FLAGS $RAYLIB_C_FILES > /dev/null 2>&1
  117. else
  118. $CC -c $RAYLIB_DEFINES $RAYLIB_INCLUDE_FLAGS $COMPILATION_FLAGS $RAYLIB_C_FILES
  119. fi
  120. [ -z "$QUIET" ] && echo "COMPILE-INFO: Raylib compiled into object files in: $TEMP_DIR/"
  121. cd $ROOT_DIR
  122. fi
  123. # Build the actual game
  124. mkdir -p $OUTPUT_DIR
  125. cd $OUTPUT_DIR
  126. [ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling game code."
  127. if [ -n "$REALLY_QUIET" ]; then
  128. $CC -c $COMPILATION_FLAGS $WARNING_FLAGS $SOURCES > /dev/null 2>&1
  129. $CC -o $GAME_NAME $ROOT_DIR/$TEMP_DIR/*.o *.o $LINK_FLAGS > /dev/null 2>&1
  130. else
  131. $CC -c $COMPILATION_FLAGS $WARNING_FLAGS $SOURCES
  132. $CC -o $GAME_NAME $ROOT_DIR/$TEMP_DIR/*.o *.o $LINK_FLAGS
  133. fi
  134. rm *.o
  135. [ -z "$QUIET" ] && echo "COMPILE-INFO: Game compiled into an executable in: $OUTPUT_DIR/"
  136. cp $ROOT_DIR/resources/linux/moe.neon.metro.desktop .
  137. mkdir -p metro_assets
  138. cd metro_assets
  139. cp $ROOT_DIR/resources/icon.png .
  140. cp -r $ROOT_DIR/src/shaders .
  141. mkdir -p fonts
  142. cp $ROOT_DIR/vendor/vt323/vt323.ttf fonts/
  143. cp $ROOT_DIR/vendor/open-sans/open_sans.ttf fonts/
  144. cd ..
  145. [ -z "$QUIET" ] && echo "COMPILE-INFO: Game resources copied into: $OUTPUT_DIR/"
  146. if [ -n "$STRIP_IT" ]; then
  147. [ -z "$QUIET" ] && echo "COMPILE-INFO: Stripping $GAME_NAME."
  148. strip $GAME_NAME
  149. fi
  150. if [ -n "$UPX_IT" ]; then
  151. [ -z "$QUIET" ] && echo "COMPILE-INFO: Packing $GAME_NAME with upx."
  152. upx $GAME_NAME > /dev/null 2>&1
  153. fi
  154. if [ -n "$RUN_AFTER_BUILD" ]; then
  155. [ -z "$QUIET" ] && echo "COMPILE-INFO: Running."
  156. if [ -n "$REALLY_QUIET" ]; then
  157. ./$GAME_NAME > /dev/null 2>&1
  158. else
  159. ./$GAME_NAME
  160. fi
  161. fi
  162. cd $ROOT_DIR
  163. [ -z "$QUIET" ] && echo "COMPILE-INFO: All done."