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.
 
 
 
 
 

243 lines
8.8 KiB

  1. @echo off
  2. REM Change your executable name here
  3. set GAME_NAME=metro.exe
  4. REM Set your sources here (relative paths!)
  5. REM Example with two source folders:
  6. REM set SOURCES=src\*.c src\submodule\*.c
  7. set SOURCES=src\*.c
  8. REM Set your raylib/src location here (relative path!)
  9. set RAYLIB_SRC=vendor\raylib
  10. set RESOURCE_SOURCES=resources\windows\favicon.rc
  11. REM About this build script: it does many things, but in essence, it's
  12. REM very simple. It has 3 compiler invocations: building raylib (which
  13. REM is not done always, see logic by searching "Build raylib"), building
  14. REM src/*.c files, and linking together those two. Each invocation is
  15. REM wrapped in an if statement to make the -qq flag work, it's pretty
  16. REM verbose, sorry.
  17. REM To skip to the actual building part of the script, search for ":BUILD"
  18. REM For the ! variable notation
  19. setlocal EnableDelayedExpansion
  20. REM For shifting, which the command line argument parsing needs
  21. setlocal EnableExtensions
  22. :ARG_LOOP
  23. set ARG=%1
  24. if "!ARG!" == "" ( goto PREPARE )
  25. IF NOT "x!ARG!" == "x!ARG:h=!" (
  26. goto HELP
  27. )
  28. IF NOT "x!ARG!" == "x!ARG:d=!" (
  29. set BUILD_DEBUG=1
  30. )
  31. IF NOT "x!ARG!" == "x!ARG:u=!" (
  32. set UPX_IT=1
  33. )
  34. IF NOT "x!ARG!" == "x!ARG:r=!" (
  35. set RUN_AFTER_BUILD=1
  36. )
  37. IF NOT "x!ARG!" == "x!ARG:c=!" (
  38. set BUILD_ALL=1
  39. )
  40. IF NOT "x!ARG!" == "x!ARG:qq=!" (
  41. set QUIET=1
  42. set REALLY_QUIET=1
  43. ) ELSE IF NOT "x!ARG!" == "x!ARG:q=!" (
  44. IF DEFINED QUIET (
  45. set REALLY_QUIET=1
  46. ) ELSE (
  47. set QUIET=1
  48. )
  49. )
  50. IF NOT "x!ARG!" == "x!ARG:v=!" (
  51. set VERBOSE=1
  52. )
  53. IF NOT "%1" == "" (
  54. shift /1
  55. goto ARG_LOOP
  56. )
  57. :HELP
  58. echo Usage: windows-build.bat [-hdurcqqv]
  59. echo -h Show this information
  60. echo -d Faster builds that have debug symbols, and enable warnings
  61. echo -u Run upx* on the executable after compilation (before -r)
  62. echo -r Run the executable after compilation
  63. echo -c Remove the temp\{debug,release} directory, ie. full recompile
  64. echo -q Suppress this script's informational prints
  65. echo -qq Suppress all prints, complete silence
  66. echo -v cl.exe normally prints out a lot of superficial information, as
  67. echo well as the MSVC build environment activation scripts, but these are
  68. echo mostly suppressed by default. If you do want to see everything, use
  69. echo this flag.
  70. echo.
  71. echo * This is mostly here to make building simple "shipping" versions
  72. echo easier, and it's a very small bit in the build scripts. The option
  73. echo requires that you have upx installed and on your path, of course.
  74. echo.
  75. echo Examples:
  76. echo Build a release build: windows-build.bat
  77. echo Build a release build, full recompile: windows-build.bat -c
  78. echo Build a debug build and run: windows-build.bat -d -r
  79. echo Build in debug, run, don't print at all: windows-build.bat -drqq
  80. exit /B
  81. :PREPARE
  82. REM Activate the msvc build environment
  83. IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" (
  84. set VC_INIT="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"
  85. ) ELSE IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" (
  86. set VC_INIT="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat"
  87. ) ELSE IF EXIST "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat" (
  88. set VC_INIT="C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
  89. ) ELSE (
  90. REM Initialize your vc environment here if the defaults don't work
  91. REM set VC_INIT="C:\your\path\here\vcvarsall.bat"
  92. REM And then remove/comment out the following two lines
  93. echo "Couldn't find vcvarsall.bat or vcbuildtools.bat, please set it manually."
  94. exit /B
  95. )
  96. IF DEFINED VERBOSE (
  97. call !VC_INIT! x86
  98. ) ELSE (
  99. call !VC_INIT! x86 > NUL 2>&1
  100. )
  101. :BUILD
  102. REM Directories
  103. set "ROOT_DIR=%CD%"
  104. set "SOURCES=!ROOT_DIR!\!SOURCES!"
  105. set "RAYLIB_SRC=!ROOT_DIR!\!RAYLIB_SRC!"
  106. set "RESOURCE_SOURCES=!ROOT_DIR!\!RESOURCE_SOURCES!"
  107. REM Flags
  108. set OUTPUT_FLAG=/Fe: "!GAME_NAME!"
  109. set COMPILATION_FLAGS=/O1 /GL
  110. set WARNING_FLAGS=
  111. set SUBSYSTEM_FLAGS=/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup
  112. set LINK_FLAGS=/link /LTCG kernel32.lib user32.lib shell32.lib winmm.lib gdi32.lib opengl32.lib
  113. set OUTPUT_DIR=builds\windows-msvc
  114. REM Debug changes to flags
  115. IF DEFINED BUILD_DEBUG (
  116. set OUTPUT_FLAG=/Fe: "!GAME_NAME!"
  117. REM _CRT_SECURE_NO_WARNINGS is defined because the CRT has deprecated some C standard functions for safety reasons
  118. set COMPILATION_FLAGS=/Od /Zi /D_CRT_SECURE_NO_WARNINGS
  119. REM Removed warnings (because the thing being warned about has been taken into account):
  120. REM - 4204 is C89 specific, so not relevant.
  121. REM - 5045 is an informational warning about Spectre mitigation, not relevant
  122. REM - 4668 is some warning in the Windows ucrt\corecrt.h >.>
  123. REM - 4710 is about not inlining a function marked inline, and it seems snprintf will always trigger this
  124. REM - 4774 is about not using a string literal as the formatting string in snprintf. I think it's safe to use a const char*?
  125. REM - 4127 "conditional expression is constant" yeah, thanks, I know.
  126. set WARNING_FLAGS=/Wall /wd4204 /wd5045 /wd4668 /wd4710 /wd4774 /wd4127
  127. set SUBSYSTEM_FLAGS=
  128. set LINK_FLAGS=/link kernel32.lib user32.lib shell32.lib winmm.lib gdi32.lib opengl32.lib
  129. set OUTPUT_DIR=builds-debug\windows-msvc
  130. )
  131. IF NOT DEFINED VERBOSE (
  132. set VERBOSITY_FLAG=/nologo
  133. )
  134. REM Display what we're doing
  135. IF DEFINED BUILD_DEBUG (
  136. IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling in debug mode, flags: !COMPILATION_FLAGS! !WARNING_FLAGS!
  137. ) ELSE (
  138. IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling in release mode, flags: !COMPILATION_FLAGS! /link /LTCG
  139. )
  140. REM Create the temp directory for raylib
  141. set "TEMP_DIR=temp\release"
  142. IF DEFINED BUILD_DEBUG (
  143. set "TEMP_DIR=temp\debug"
  144. )
  145. IF DEFINED BUILD_ALL (
  146. IF EXIST !TEMP_DIR!\ (
  147. IF NOT DEFINED QUIET echo COMPILE-INFO: Found cached raylib, rebuilding.
  148. del /Q !TEMP_DIR!
  149. rmdir !TEMP_DIR!
  150. )
  151. )
  152. REM Build raylib if it hasn't been cached in TEMP_DIR
  153. IF NOT EXIST !TEMP_DIR!\ (
  154. mkdir !TEMP_DIR!
  155. cd !TEMP_DIR!
  156. set RAYLIB_DEFINES=/D_DEFAULT_SOURCE /DPLATFORM_DESKTOP /DGRAPHICS_API_OPENGL_33
  157. set 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"
  158. set RAYLIB_INCLUDE_FLAGS=/I"!RAYLIB_SRC!" /I"!RAYLIB_SRC!\external\glfw\include"
  159. IF DEFINED REALLY_QUIET (
  160. cl.exe /w /c !RAYLIB_DEFINES! !RAYLIB_INCLUDE_FLAGS! !COMPILATION_FLAGS! !RAYLIB_C_FILES! > NUL 2>&1 || exit /B
  161. ) ELSE (
  162. cl.exe /w /c !VERBOSITY_FLAG! !RAYLIB_DEFINES! !RAYLIB_INCLUDE_FLAGS! !COMPILATION_FLAGS! !RAYLIB_C_FILES! || exit /B
  163. )
  164. IF NOT DEFINED QUIET echo COMPILE-INFO: Raylib compiled into object files in: !TEMP_DIR!\
  165. REM Out of the temp directory
  166. cd !ROOT_DIR!
  167. )
  168. REM Move to the build directory
  169. IF NOT EXIST !OUTPUT_DIR! mkdir !OUTPUT_DIR!
  170. cd !OUTPUT_DIR!
  171. REM Build the actual game
  172. IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling game code.
  173. IF DEFINED REALLY_QUIET (
  174. cl.exe !VERBOSITY_FLAG! !COMPILATION_FLAGS! !WARNING_FLAGS! /c /I"!RAYLIB_SRC!" !SOURCES! > NUL 2>&1 || exit /B
  175. rc.exe !VERBOSITY_FLAG! !RESOURCE_SOURCES! > NUL 2>&1 || exit /B
  176. cl.exe !VERBOSITY_FLAG! !OUTPUT_FLAG! "!ROOT_DIR!\!TEMP_DIR!\*.obj" "!ROOT_DIR!\resources\windows\*.res" *.obj !LINK_FLAGS! !SUBSYSTEM_FLAGS! > NUL 2>&1 || exit /B
  177. ) ELSE (
  178. cl.exe !VERBOSITY_FLAG! !COMPILATION_FLAGS! !WARNING_FLAGS! /c /I"!RAYLIB_SRC!" !SOURCES! || exit /B
  179. rc.exe !VERBOSITY_FLAG! !RESOURCE_SOURCES! || exit /B
  180. cl.exe !VERBOSITY_FLAG! !OUTPUT_FLAG! "!ROOT_DIR!\!TEMP_DIR!\*.obj" "!ROOT_DIR!\resources\windows\*.res" *.obj !LINK_FLAGS! !SUBSYSTEM_FLAGS! || exit /B
  181. )
  182. del *.obj
  183. del "!ROOT_DIR!\resources\windows\*.res"
  184. IF NOT DEFINED QUIET echo COMPILE-INFO: Game compiled into an executable in: !OUTPUT_DIR!\
  185. REM Copy resources
  186. IF NOT EXIST metro_assets mkdir metro_assets
  187. cd metro_assets
  188. IF NOT EXIST "icon.png" cp !ROOT_DIR!\resources\icon.png icon.png
  189. IF NOT EXIST shaders mkdir shaders
  190. IF EXIST "shaders\sdf_shader.glsl" del shaders\sdf_shader.glsl
  191. cp !ROOT_DIR!\src\shaders\sdf.glsl shaders\sdf.glsl
  192. IF NOT EXIST fonts mkdir fonts
  193. IF NOT EXIST "fonts\open_sans.ttf" cp !ROOT_DIR!\vendor\open-sans\open_sans.ttf fonts\open_sans.ttf
  194. IF NOT EXIST "fonts\vt323.ttf" cp !ROOT_DIR!\vendor\vt323\vt323.ttf fonts\vt323.ttf
  195. cd ..
  196. IF NOT DEFINED QUIET echo COMPILE-INFO: Game resources copied into: !OUTPUT_DIR!\
  197. REM Run upx
  198. IF DEFINED UPX_IT (
  199. IF NOT DEFINED QUIET echo COMPILE-INFO: Packing !GAME_NAME! with upx.
  200. upx !GAME_NAME! > NUL 2>&1
  201. )
  202. REM Finally, run the produced executable
  203. IF DEFINED RUN_AFTER_BUILD (
  204. IF NOT DEFINED QUIET echo COMPILE-INFO: Running.
  205. IF DEFINED REALLY_QUIET (
  206. !GAME_NAME! > NUL 2>&1
  207. ) ELSE (
  208. !GAME_NAME!
  209. )
  210. )
  211. REM Back to development directory
  212. cd !ROOT_DIR!
  213. IF NOT DEFINED QUIET echo COMPILE-INFO: All done.