您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

219 行
7.7 KiB

  1. @echo off
  2. REM Change your executable name here
  3. set GAME_NAME=game.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=core_basic_window.c
  8. REM Set your raylib\src location here (relative path!)
  9. set RAYLIB_SRC=..\..\src
  10. REM Set the target platform for the compiler (Ex: x86 or x64)
  11. set TARGET_PLATFORM=x86
  12. REM About this build script: it does many things, but in essence, it's
  13. REM very simple. It has 3 compiler invocations: building raylib (which
  14. REM is not done always, see logic by searching "Build raylib"), building
  15. REM src/*.c files, and linking together those two. Each invocation is
  16. REM wrapped in an if statement to make the -qq flag work, it's pretty
  17. REM verbose, sorry.
  18. REM To skip to the actual building part of the script, search for ":BUILD"
  19. REM Checks if cl is available and skips to the argument loop if it is
  20. REM (Prevents calling vcvarsall every time you run this script)
  21. WHERE cl >nul 2>nul
  22. IF %ERRORLEVEL% == 0 goto READ_ARGS
  23. REM Activate the msvc build environment if cl isn't available yet
  24. IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" (
  25. set VC_INIT="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"
  26. ) ELSE IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" (
  27. set VC_INIT="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat"
  28. ) ELSE IF EXIST "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat" (
  29. set VC_INIT="C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
  30. ) ELSE (
  31. REM Initialize your vc environment here if the defaults don't work
  32. REM set VC_INIT="C:\your\path\here\vcvarsall.bat"
  33. REM And then remove/comment out the following two lines
  34. echo "Couldn't find vcvarsall.bat or vcbuildtools.bat, please set it manually."
  35. exit /B
  36. )
  37. echo Setting up the msvc build environment, this could take some time but the next builds should be faster
  38. REM Remove everything after %TARGET_PLATFORM% if you want to see
  39. REM the vcvarsall.bat or vcbuildtools.bat output
  40. call %VC_INIT% %TARGET_PLATFORM% > NUL 2>&1
  41. :READ_ARGS
  42. REM For the ! variable notation
  43. setlocal EnableDelayedExpansion
  44. REM For shifting, which the command line argument parsing needs
  45. setlocal EnableExtensions
  46. :ARG_LOOP
  47. set ARG=%1
  48. if "!ARG!" == "" ( goto BUILD )
  49. IF NOT "x!ARG!" == "x!ARG:h=!" (
  50. goto HELP
  51. )
  52. IF NOT "x!ARG!" == "x!ARG:d=!" (
  53. set BUILD_DEBUG=1
  54. )
  55. IF NOT "x!ARG!" == "x!ARG:u=!" (
  56. set UPX_IT=1
  57. )
  58. IF NOT "x!ARG!" == "x!ARG:r=!" (
  59. set RUN_AFTER_BUILD=1
  60. )
  61. IF NOT "x!ARG!" == "x!ARG:c=!" (
  62. set BUILD_ALL=1
  63. )
  64. IF NOT "x!ARG!" == "x!ARG:qq=!" (
  65. set QUIET=1
  66. set REALLY_QUIET=1
  67. ) ELSE IF NOT "x!ARG!" == "x!ARG:q=!" (
  68. IF DEFINED QUIET (
  69. set REALLY_QUIET=1
  70. ) ELSE (
  71. set QUIET=1
  72. )
  73. )
  74. IF NOT "x!ARG!" == "x!ARG:v=!" (
  75. set VERBOSE=1
  76. )
  77. IF NOT "%1" == "" (
  78. shift /1
  79. goto ARG_LOOP
  80. )
  81. :HELP
  82. echo Usage: build-windows.bat [-hdurcqqv]
  83. echo -h Show this information
  84. echo -d Faster builds that have debug symbols, and enable warnings
  85. echo -u Run upx* on the executable after compilation (before -r)
  86. echo -r Run the executable after compilation
  87. echo -c Remove the temp\{debug,release} directory, ie. full recompile
  88. echo -q Suppress this script's informational prints
  89. echo -qq Suppress all prints, complete silence
  90. echo -v cl.exe normally prints out a lot of superficial information, as
  91. echo well as the MSVC build environment activation scripts, but these are
  92. echo mostly suppressed by default. If you do want to see everything, use
  93. echo this flag.
  94. echo.
  95. echo * This is mostly here to make building simple "shipping" versions
  96. echo easier, and it's a very small bit in the build scripts. The option
  97. echo requires that you have upx installed and on your path, of course.
  98. echo.
  99. echo Examples:
  100. echo Build a release build: build-windows.bat
  101. echo Build a release build, full recompile: build-windows.bat -c
  102. echo Build a debug build and run: build-windows.bat -d -r
  103. echo Build in debug, run, don't print at all: build-windows.bat -drqq
  104. exit /B
  105. :BUILD
  106. REM Directories
  107. set "ROOT_DIR=%CD%"
  108. set "SOURCES=!ROOT_DIR!\!SOURCES!"
  109. set "RAYLIB_SRC=!ROOT_DIR!\!RAYLIB_SRC!"
  110. REM Flags
  111. set OUTPUT_FLAG=/Fe: "!GAME_NAME!"
  112. set COMPILATION_FLAGS=/std:c11 /O1 /GL /favor:blend /utf-8 /validate-charset /EHsc
  113. set WARNING_FLAGS=/W3 /sdl
  114. set SUBSYSTEM_FLAGS=/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup
  115. set LINK_FLAGS=/link /LTCG kernel32.lib user32.lib shell32.lib winmm.lib gdi32.lib opengl32.lib
  116. set OUTPUT_DIR=builds\windows-msvc
  117. REM Debug changes to flags
  118. IF DEFINED BUILD_DEBUG (
  119. set OUTPUT_FLAG=/Fe: "!GAME_NAME!"
  120. set COMPILATION_FLAGS=/std:c11 /Od /Zi /utf-8 /validate-charset /EHsc
  121. set WARNING_FLAGS=/W3 /sdl
  122. set SUBSYSTEM_FLAGS=/DEBUG
  123. set LINK_FLAGS=/link kernel32.lib user32.lib shell32.lib winmm.lib gdi32.lib opengl32.lib
  124. set OUTPUT_DIR=builds-debug\windows-msvc
  125. )
  126. IF NOT DEFINED VERBOSE (
  127. set VERBOSITY_FLAG=/nologo
  128. )
  129. REM Display what we're doing
  130. IF DEFINED BUILD_DEBUG (
  131. IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling in debug mode, flags: !COMPILATION_FLAGS! !WARNING_FLAGS!
  132. ) ELSE (
  133. IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling in release mode, flags: !COMPILATION_FLAGS! /link /LTCG
  134. )
  135. REM Create the temp directory for raylib
  136. set "TEMP_DIR=temp\release"
  137. IF DEFINED BUILD_DEBUG (
  138. set "TEMP_DIR=temp\debug"
  139. )
  140. IF DEFINED BUILD_ALL (
  141. IF EXIST !TEMP_DIR!\ (
  142. IF NOT DEFINED QUIET echo COMPILE-INFO: Found cached raylib, rebuilding.
  143. del /Q !TEMP_DIR!
  144. rmdir !TEMP_DIR!
  145. )
  146. )
  147. REM Build raylib if it hasn't been cached in TEMP_DIR
  148. IF NOT EXIST !TEMP_DIR!\ (
  149. mkdir !TEMP_DIR!
  150. cd !TEMP_DIR!
  151. REM raylib source folder
  152. set "RAYLIB_DEFINES=/D_DEFAULT_SOURCE /DPLATFORM_DESKTOP /DGRAPHICS_API_OPENGL_33"
  153. set RAYLIB_C_FILES="!RAYLIB_SRC!\rcore.c" "!RAYLIB_SRC!\rshapes.c" "!RAYLIB_SRC!\rtextures.c" "!RAYLIB_SRC!\rtext.c" "!RAYLIB_SRC!\rmodels.c" "!RAYLIB_SRC!\utils.c" "!RAYLIB_SRC!\raudio.c" "!RAYLIB_SRC!\rglfw.c"
  154. set RAYLIB_INCLUDE_FLAGS=/I"!RAYLIB_SRC!" /I"!RAYLIB_SRC!\external\glfw\include"
  155. IF DEFINED REALLY_QUIET (
  156. cl.exe /w /c !RAYLIB_DEFINES! !RAYLIB_INCLUDE_FLAGS! !COMPILATION_FLAGS! !RAYLIB_C_FILES! > NUL 2>&1 || exit /B
  157. ) ELSE (
  158. cl.exe /w /c !VERBOSITY_FLAG! !RAYLIB_DEFINES! !RAYLIB_INCLUDE_FLAGS! !COMPILATION_FLAGS! !RAYLIB_C_FILES! || exit /B
  159. )
  160. IF NOT DEFINED QUIET echo COMPILE-INFO: raylib compiled into object files in: !TEMP_DIR!\
  161. REM Out of the temp directory
  162. cd !ROOT_DIR!
  163. )
  164. REM Move to the build directory
  165. IF NOT EXIST !OUTPUT_DIR! mkdir !OUTPUT_DIR!
  166. cd !OUTPUT_DIR!
  167. REM Build the actual game
  168. IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling game code.
  169. IF DEFINED REALLY_QUIET (
  170. cl.exe !VERBOSITY_FLAG! !COMPILATION_FLAGS! !WARNING_FLAGS! /c /I"!RAYLIB_SRC!" !SOURCES! > NUL 2>&1 || exit /B
  171. cl.exe !VERBOSITY_FLAG! !OUTPUT_FLAG! "!ROOT_DIR!\!TEMP_DIR!\*.obj" *.obj !LINK_FLAGS! !SUBSYSTEM_FLAGS! > NUL 2>&1 || exit /B
  172. ) ELSE (
  173. cl.exe !VERBOSITY_FLAG! !COMPILATION_FLAGS! !WARNING_FLAGS! /c /I"!RAYLIB_SRC!" !SOURCES! || exit /B
  174. cl.exe !VERBOSITY_FLAG! !OUTPUT_FLAG! "!ROOT_DIR!\!TEMP_DIR!\*.obj" *.obj !LINK_FLAGS! !SUBSYSTEM_FLAGS! || exit /B
  175. )
  176. del *.obj
  177. IF NOT DEFINED QUIET echo COMPILE-INFO: Game compiled into an executable in: !OUTPUT_DIR!\
  178. REM Run upx
  179. IF DEFINED UPX_IT (
  180. IF NOT DEFINED QUIET echo COMPILE-INFO: Packing !GAME_NAME! with upx.
  181. upx !GAME_NAME! > NUL 2>&1
  182. )
  183. REM Finally, run the produced executable
  184. IF DEFINED RUN_AFTER_BUILD (
  185. IF NOT DEFINED QUIET echo COMPILE-INFO: Running.
  186. IF DEFINED REALLY_QUIET (
  187. !GAME_NAME! > NUL 2>&1
  188. ) ELSE (
  189. !GAME_NAME!
  190. )
  191. )
  192. REM Back to development directory
  193. cd !ROOT_DIR!
  194. IF NOT DEFINED QUIET echo COMPILE-INFO: All done.