Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

218 linhas
7.3 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 For the ! variable notation
  20. setlocal EnableDelayedExpansion
  21. REM For shifting, which the command line argument parsing needs
  22. setlocal EnableExtensions
  23. :ARG_LOOP
  24. set ARG=%1
  25. if "!ARG!" == "" ( goto PREPARE )
  26. IF NOT "x!ARG!" == "x!ARG:h=!" (
  27. goto HELP
  28. )
  29. IF NOT "x!ARG!" == "x!ARG:d=!" (
  30. set BUILD_DEBUG=1
  31. )
  32. IF NOT "x!ARG!" == "x!ARG:u=!" (
  33. set UPX_IT=1
  34. )
  35. IF NOT "x!ARG!" == "x!ARG:r=!" (
  36. set RUN_AFTER_BUILD=1
  37. )
  38. IF NOT "x!ARG!" == "x!ARG:c=!" (
  39. set BUILD_ALL=1
  40. )
  41. IF NOT "x!ARG!" == "x!ARG:qq=!" (
  42. set QUIET=1
  43. set REALLY_QUIET=1
  44. ) ELSE IF NOT "x!ARG!" == "x!ARG:q=!" (
  45. IF DEFINED QUIET (
  46. set REALLY_QUIET=1
  47. ) ELSE (
  48. set QUIET=1
  49. )
  50. )
  51. IF NOT "x!ARG!" == "x!ARG:v=!" (
  52. set VERBOSE=1
  53. )
  54. IF NOT "%1" == "" (
  55. shift /1
  56. goto ARG_LOOP
  57. )
  58. :HELP
  59. echo Usage: build-windows.bat [-hdurcqqv]
  60. echo -h Show this information
  61. echo -d Faster builds that have debug symbols, and enable warnings
  62. echo -u Run upx* on the executable after compilation (before -r)
  63. echo -r Run the executable after compilation
  64. echo -c Remove the temp\{debug,release} directory, ie. full recompile
  65. echo -q Suppress this script's informational prints
  66. echo -qq Suppress all prints, complete silence
  67. echo -v cl.exe normally prints out a lot of superficial information, as
  68. echo well as the MSVC build environment activation scripts, but these are
  69. echo mostly suppressed by default. If you do want to see everything, use
  70. echo this flag.
  71. echo.
  72. echo * This is mostly here to make building simple "shipping" versions
  73. echo easier, and it's a very small bit in the build scripts. The option
  74. echo requires that you have upx installed and on your path, of course.
  75. echo.
  76. echo Examples:
  77. echo Build a release build: build-windows.bat
  78. echo Build a release build, full recompile: build-windows.bat -c
  79. echo Build a debug build and run: build-windows.bat -d -r
  80. echo Build in debug, run, don't print at all: build-windows.bat -drqq
  81. exit /B
  82. :PREPARE
  83. REM Activate the msvc build environment
  84. IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" (
  85. set VC_INIT="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"
  86. ) ELSE IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" (
  87. set VC_INIT="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat"
  88. ) ELSE IF EXIST "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat" (
  89. set VC_INIT="C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
  90. ) ELSE (
  91. REM Initialize your vc environment here if the defaults don't work
  92. REM set VC_INIT="C:\your\path\here\vcvarsall.bat"
  93. REM And then remove/comment out the following two lines
  94. echo "Couldn't find vcvarsall.bat or vcbuildtools.bat, please set it manually."
  95. exit /B
  96. )
  97. IF DEFINED VERBOSE (
  98. call !VC_INIT! !TARGET_PLATFORM!
  99. ) ELSE (
  100. call !VC_INIT! !TARGET_PLATFORM! > NUL 2>&1
  101. )
  102. :BUILD
  103. REM Directories
  104. set "ROOT_DIR=%CD%"
  105. set "SOURCES=!ROOT_DIR!\!SOURCES!"
  106. set "RAYLIB_SRC=!ROOT_DIR!\!RAYLIB_SRC!"
  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. set COMPILATION_FLAGS=/Od /Zi
  118. set WARNING_FLAGS=/Wall
  119. set SUBSYSTEM_FLAGS=/DEBUG
  120. set LINK_FLAGS=/link kernel32.lib user32.lib shell32.lib winmm.lib gdi32.lib opengl32.lib
  121. set OUTPUT_DIR=builds-debug\windows-msvc
  122. )
  123. IF NOT DEFINED VERBOSE (
  124. set VERBOSITY_FLAG=/nologo
  125. )
  126. REM Display what we're doing
  127. IF DEFINED BUILD_DEBUG (
  128. IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling in debug mode, flags: !COMPILATION_FLAGS! !WARNING_FLAGS!
  129. ) ELSE (
  130. IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling in release mode, flags: !COMPILATION_FLAGS! /link /LTCG
  131. )
  132. REM Create the temp directory for raylib
  133. set "TEMP_DIR=temp\release"
  134. IF DEFINED BUILD_DEBUG (
  135. set "TEMP_DIR=temp\debug"
  136. )
  137. IF DEFINED BUILD_ALL (
  138. IF EXIST !TEMP_DIR!\ (
  139. IF NOT DEFINED QUIET echo COMPILE-INFO: Found cached raylib, rebuilding.
  140. del /Q !TEMP_DIR!
  141. rmdir !TEMP_DIR!
  142. )
  143. )
  144. REM Build raylib if it hasn't been cached in TEMP_DIR
  145. IF NOT EXIST !TEMP_DIR!\ (
  146. mkdir !TEMP_DIR!
  147. cd !TEMP_DIR!
  148. REM Raylib's src folder
  149. set "RAYLIB_DEFINES=/D_DEFAULT_SOURCE /DPLATFORM_DESKTOP /DGRAPHICS_API_OPENGL_33"
  150. 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"
  151. set RAYLIB_INCLUDE_FLAGS=/I"!RAYLIB_SRC!" /I"!RAYLIB_SRC!\external\glfw\include"
  152. IF DEFINED REALLY_QUIET (
  153. cl.exe /w /c !RAYLIB_DEFINES! !RAYLIB_INCLUDE_FLAGS! !COMPILATION_FLAGS! !RAYLIB_C_FILES! > NUL 2>&1 || exit /B
  154. ) ELSE (
  155. cl.exe /w /c !VERBOSITY_FLAG! !RAYLIB_DEFINES! !RAYLIB_INCLUDE_FLAGS! !COMPILATION_FLAGS! !RAYLIB_C_FILES! || exit /B
  156. )
  157. IF NOT DEFINED QUIET echo COMPILE-INFO: Raylib compiled into object files in: !TEMP_DIR!\
  158. REM Out of the temp directory
  159. cd !ROOT_DIR!
  160. )
  161. REM Move to the build directory
  162. IF NOT EXIST !OUTPUT_DIR! mkdir !OUTPUT_DIR!
  163. cd !OUTPUT_DIR!
  164. REM Build the actual game
  165. IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling game code.
  166. IF DEFINED REALLY_QUIET (
  167. cl.exe !VERBOSITY_FLAG! !COMPILATION_FLAGS! !WARNING_FLAGS! /c /I"!RAYLIB_SRC!" !SOURCES! > NUL 2>&1 || exit /B
  168. cl.exe !VERBOSITY_FLAG! !OUTPUT_FLAG! "!ROOT_DIR!\!TEMP_DIR!\*.obj" *.obj !LINK_FLAGS! !SUBSYSTEM_FLAGS! > NUL 2>&1 || exit /B
  169. ) ELSE (
  170. cl.exe !VERBOSITY_FLAG! !COMPILATION_FLAGS! !WARNING_FLAGS! /c /I"!RAYLIB_SRC!" !SOURCES! || exit /B
  171. cl.exe !VERBOSITY_FLAG! !OUTPUT_FLAG! "!ROOT_DIR!\!TEMP_DIR!\*.obj" *.obj !LINK_FLAGS! !SUBSYSTEM_FLAGS! || exit /B
  172. )
  173. del *.obj
  174. IF NOT DEFINED QUIET echo COMPILE-INFO: Game compiled into an executable in: !OUTPUT_DIR!\
  175. REM Run upx
  176. IF DEFINED UPX_IT (
  177. IF NOT DEFINED QUIET echo COMPILE-INFO: Packing !GAME_NAME! with upx.
  178. upx !GAME_NAME! > NUL 2>&1
  179. )
  180. REM Finally, run the produced executable
  181. IF DEFINED RUN_AFTER_BUILD (
  182. IF NOT DEFINED QUIET echo COMPILE-INFO: Running.
  183. IF DEFINED REALLY_QUIET (
  184. !GAME_NAME! > NUL 2>&1
  185. ) ELSE (
  186. !GAME_NAME!
  187. )
  188. )
  189. REM Back to development directory
  190. cd !ROOT_DIR!
  191. IF NOT DEFINED QUIET echo COMPILE-INFO: All done.