Debian Codegraph @

projects/scripts/build-windows.bat

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