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.

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