Factor out setting of the depot vehicle list icon string
[openttd/fttd.git] / projects / generate.vbs
blobd8f6792174824bceb76fac5ef40678adc94f43c5
1 Option Explicit
3 ' $Id$
5 ' This file is part of OpenTTD.
6 ' OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
7 ' OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 ' See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 Dim FSO
11 Set FSO = CreateObject("Scripting.FileSystemObject")
13 ' openttd_vs141.sln is for MSVC 2017
14 ' openttd_vs141.vcxproj is for MSVC 2017
15 ' openttd_vs141.vcxproj.filters is for MSVC 2017
16 ' langs_vs141.vcxproj is for MSVC 2017
17 ' strgen_vs141.vcxproj is for MSVC 2017
18 ' strgen_vs141.vcxproj.filters is for MSVC 2017
19 ' generate_vs141.vcxproj is for MSVC 2017
20 ' version_vs141.vcxproj is for MSVC 2017
22 ' openttd_vs140.sln is for MSVC 2015
23 ' openttd_vs140.vcxproj is for MSVC 2015
24 ' openttd_vs140.vcxproj.filters is for MSVC 2015
25 ' langs_vs140.vcxproj is for MSVC 2015
26 ' strgen_vs140.vcxproj is for MSVC 2015
27 ' strgen_vs140.vcxproj.filters is for MSVC 2015
28 ' generate_vs140.vcxproj is for MSVC 2015
29 ' version_vs140.vcxproj is for MSVC 2015
31 ' openttd_vs100.sln is for MSVC 2010
32 ' openttd_vs100.vcxproj is for MSVC 2010
33 ' openttd_vs100.vcxproj.filters is for MSVC 2010
34 ' langs_vs100.vcxproj is for MSVC 2010
35 ' strgen_vs100.vcxproj is for MSVC 2010
36 ' strgen_vs100.vcxproj.filters is for MSVC 2010
37 ' generate_vs100.vcxproj is for MSVC 2010
38 ' version_vs100.vcxproj is for MSVC 2010
40 ' openttd_vs90.sln is for MSVC 2008
41 ' openttd_vs90.vcproj is for MSVC 2008
42 ' langs_vs90.vcproj is for MSVC 2008
43 ' strgen_vs90.vcproj is for MSVC 2008
44 ' generate_vs90.vcproj is for MSVC 2008
45 ' version_vs90.vcproj is for MSVC 2008
47 ' openttd_vs80.sln is for MSVC 2005
48 ' openttd_vs80.vcproj is for MSVC 2005
49 ' langs_vs80.vcproj is for MSVC 2005
50 ' strgen_vs80.vcproj is for MSVC 2005
51 ' generate_vs80.vcproj is for MSVC 2005
52 ' version_vs80.vcproj is for MSVC 2005
54 Sub get_files(srcdir, dir, list)
55 Dim file, filename
56 Dim rekeep, reskip
58 ' pattern for files to keep
59 Set rekeep = New RegExp
60 rekeep.Pattern = "\.h(pp)?$"
61 rekeep.Global = True
63 ' pattern for files to exclude
64 Set reskip = New RegExp
65 reskip.Pattern = "\.svn"
66 reskip.Global = True
68 For Each file in dir.Files
69 filename = Replace(file.path, srcdir, "") ' Remove */src/
70 filename = Replace(filename, "\", "/") ' Replace separators
71 If rekeep.Test(filename) And Not reskip.Test(filename) Then
72 list.Add filename, filename
73 End If
74 Next
75 End Sub
77 Sub get_dir_files(srcdir, dir, list)
78 Dim folder
79 ' Get files
80 get_files srcdir, dir, list
82 ' Recurse in subfolders
83 For Each folder in dir.SubFolders
84 get_dir_files srcdir, folder, list
85 Next
86 End Sub
88 Sub headers_check(filename, dir)
89 Dim source_list_headers, src_dir_headers, regexp, line, file, str
91 ' Define regexp for source.list parsing
92 Set regexp = New RegExp
93 regexp.Pattern = "\.h"
94 regexp.Global = True
96 ' Parse source.list and store headers in a dictionary
97 Set source_list_headers = CreateObject("Scripting.Dictionary")
98 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
99 While Not file.AtEndOfStream
100 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
101 If Len(line) > 0 And regexp.Test(line) And line <> "../objs/langs/table/strings.h" And line <> "../objs/settings/table/settings.h" Then
102 source_list_headers.Add line, line
103 End If
104 Wend
105 file.Close()
107 ' Get header files in /src/
108 Set src_dir_headers = CreateObject("Scripting.Dictionary")
109 get_dir_files dir, FSO.GetFolder(dir), src_dir_headers
111 ' Finding files in source.list but not in /src/
112 For Each line In source_list_headers
113 If Not src_dir_headers.Exists(line) Then
114 str = str & "< " & line & vbCrLf
115 End If
116 Next
118 ' Finding files in /src/ but not in source.list
119 For Each line In src_dir_headers
120 If Not source_list_headers.Exists(line) Then
121 str = str & "> " & line & vbCrLf
122 End If
123 Next
125 ' Display the missing files if any
126 If str <> "" Then
127 str = "The following headers are missing in source.list and not in /src/ or vice versa." _
128 & vbCrLf & str
129 WScript.Echo str
130 End If
131 End Sub
133 Function load_main_data(filename, ByRef vcxproj, ByRef filters, ByRef files)
134 Dim res, file, line, deep, skip, first_filter, first_file, filter, cltype, index, ext, pathelems, outdir, config
135 Dim configs(3)
136 configs(0) = "Release|Win32"
137 configs(1) = "Debug|Win32"
138 configs(2) = "Release|x64"
139 configs(3) = "Debug|x64"
140 res = ""
141 index = 0
142 ' Read the source.list and process it
143 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
144 While Not file.AtEndOfStream
145 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
146 If Len(line) > 0 Then
147 Select Case Split(line, " ")(0)
148 Case "#end"
149 If deep = skip Then skip = skip - 1
150 deep = deep - 1
151 Case "#else"
152 If deep = skip Then
153 skip = skip - 1
154 ElseIf deep - 1 = skip Then
155 skip = skip + 1
156 End If
157 Case "#if"
158 line = Replace(line, "#if ", "")
159 If deep = skip And ( _
160 line = "SDL" Or _
161 line = "PNG" Or _
162 line = "WIN32" Or _
163 line = "MSVC" Or _
164 line = "DIRECTMUSIC" Or _
165 line = "AI" Or _
166 line = "SSE" Or _
167 line = "HAVE_THREAD" _
168 ) Then skip = skip + 1
169 deep = deep + 1
170 Case "#"
171 if deep = skip Then
172 line = Replace(line, "# ", "")
173 if first_filter <> 0 Then
174 res = res & " </Filter>" & vbCrLf
175 filters = filters & vbCrLf
176 Else
177 first_filter = 1
178 End If
179 filter = line
180 res = res & _
181 " <Filter" & vbCrLf & _
182 " Name=" & Chr(34) & filter & Chr(34) & vbCrLf & _
183 " >" & vbCrLf
184 filters = filters & _
185 " <Filter Include="& Chr(34) & filter & Chr(34) & ">" & vbCrLf & _
186 " <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-" & String(12 - Len(CStr(index)), "0") & index & "}</UniqueIdentifier>" & vbCrLf & _
187 " </Filter>"
188 index = index + 1
189 End If
190 Case Else
191 If deep = skip Then
192 line = Replace(line, "/" ,"\")
193 if first_file <> 0 Then
194 vcxproj = vcxproj & vbCrLf
195 files = files & vbCrLf
196 Else
197 first_file = 1
198 End If
199 ext = Split(Line, ".")(1)
200 pathelems = Split(Line, "\")
201 If UBound(pathelems) > 0 Then
202 ReDim Preserve pathelems(UBound(pathelems) - 1)
203 outdir = "$(IntDir)\" & Join(pathelems, "\") & "\"
204 Else
205 outdir = ""
206 End If
207 res = res & _
208 " <File" & vbCrLf & _
209 " RelativePath=" & Chr(34) & ".\..\src\" & line & Chr(34) & vbCrLf & _
210 " >" & vbCrLf
211 If ext = "cpp" And outdir <> "" Then
212 For Each config In configs
213 res = res & _
214 " <FileConfiguration" & vbCrLf & _
215 " Name=" & Chr(34) & config & Chr(34) & vbCrLf & _
216 " >" & vbCrLf & _
217 " <Tool" & vbCrLf & _
218 " Name=" & Chr(34) & "VCCLCompilerTool" & Chr(34) & vbCrLf & _
219 " AssemblerListingLocation=" & Chr(34) & outdir & Chr(34) & vbCrLf & _
220 " ObjectFile=" & Chr(34) & outdir & Chr(34) & vbCrLf & _
221 " XMLDocumentationFileName=" & Chr(34) & outdir & Chr(34) & vbCrLf & _
222 " />" & vbCrLf & _
223 " </FileConfiguration>" & vbCrLf
224 Next
225 End If
226 res = res & _
227 " </File>" & vbCrLf
228 Select Case ext
229 Case "cpp"
230 cltype = "ClCompile"
231 Case "rc"
232 cltype = "ResourceCompile"
233 Case Else
234 cltype = "ClInclude"
235 End Select
236 If ext = "cpp" And outdir <> "" Then
237 vcxproj = vcxproj & _
238 " <ClCompile Include=" & Chr(34) & "..\src\" & line & Chr(34) & ">" & vbCrLf & _
239 " <AssemblerListingLocation>" & outdir & "</AssemblerListingLocation>" & vbCrLf & _
240 " <ObjectFileName>" & outdir & "</ObjectFileName>" & vbCrLf & _
241 " <XMLDocumentationFileName>" & outdir & "</XMLDocumentationFileName>" & vbCrLf & _
242 " </ClCompile>"
243 Else
244 vcxproj = vcxproj & " <" & cltype & " Include="& Chr(34) & "..\src\" & line & Chr(34) & " />"
245 End If
246 files = files & _
247 " <" & cltype & " Include="& Chr(34) & "..\src\" & line & Chr(34) & ">" & vbCrLf & _
248 " <Filter>" & filter & "</Filter>" & vbCrLf & _
249 " </" & cltype & ">"
250 End If
251 End Select
252 End If
253 Wend
254 res = res & " </Filter>"
255 file.Close()
256 load_main_data = res
257 End Function
259 Function load_lang_data(dir, ByRef vcxproj, ByRef files)
260 Dim res, folder, file, first_time
261 res = ""
262 Set folder = FSO.GetFolder(dir)
263 For Each file In folder.Files
264 file = FSO.GetFileName(file)
265 If file <> "english.txt" And FSO.GetExtensionName(file) = "txt" Then
266 file = Left(file, Len(file) - 4)
267 If first_time <> 0 Then
268 res = res & vbCrLf
269 vcxproj = vcxproj & vbCrLf
270 files = files & vbCrLf
271 Else
272 first_time = 1
273 End If
274 res = res & _
275 " <File" & vbCrLf & _
276 " RelativePath=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & vbCrLf & _
277 " >" & vbCrLf & _
278 " <FileConfiguration" & vbCrLf & _
279 " Name=" & Chr(34) & "Debug|Win32" & Chr(34) & vbCrLf & _
280 " >" & vbCrLf & _
281 " <Tool" & vbCrLf & _
282 " Name=" & Chr(34) & "VCCustomBuildTool" & Chr(34) & vbCrLf & _
283 " Description=" & Chr(34) & "Generating " & file & " language file" & Chr(34) & vbCrLf & _
284 " CommandLine=" & Chr(34) & "..\objs\strgen\strgen.exe -s ..\src\lang -d ..\bin\lang &quot;$(InputPath)&quot;&#x0D;&#x0A;exit 0&#x0D;&#x0A;" & Chr(34) & vbCrLf & _
285 " AdditionalDependencies=" & Chr(34) & "..\src\lang\english.txt;..\objs\strgen\strgen.exe" & Chr(34) & vbCrLf & _
286 " Outputs=" & Chr(34) & "..\bin\lang\" & file & ".lng" & Chr(34) & vbCrLf & _
287 " />" & vbCrLf & _
288 " </FileConfiguration>" & vbCrLf & _
289 " </File>"
290 vcxproj = vcxproj & _
291 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & ">" & vbCrLf & _
292 " <Message Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">Generating " & file & " language file</Message>" & vbCrLf & _
293 " <Command Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\objs\strgen\strgen.exe -s ..\src\lang -d ..\bin\lang " & Chr(34) & "%(FullPath)" & Chr(34) & "</Command>" & vbCrLf & _
294 " <AdditionalInputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\src\lang\english.txt;..\objs\strgen\strgen.exe;%(AdditionalInputs)</AdditionalInputs>" & vbCrLf & _
295 " <Outputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\bin\lang\" & file & ".lng;%(Outputs)</Outputs>" & vbCrLf & _
296 " </CustomBuild>"
297 files = files & _
298 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & ">" & vbCrLf & _
299 " <Filter>Translations</Filter>" & vbCrLf & _
300 " </CustomBuild>"
301 End If
302 Next
303 load_lang_data = res
304 End Function
306 Function load_settings_data(dir, ByRef vcxproj, ByRef command, ByRef files)
307 Dim res, folder, file, first_time
308 res = ""
309 command = "..\objs\settings\settings_gen.exe -o ..\objs\settings\table\settings.h -b ..\src\table\settings.h.preamble -a ..\src\table\settings.h.postamble"
310 Set folder = FSO.GetFolder(dir)
311 For Each file In folder.Files
312 file = FSO.GetFileName(file)
313 If FSO.GetExtensionName(file) = "ini" Then
314 if first_time <> 0 Then
315 res = res & vbCrLf
316 vcxproj = vcxproj & vbCrLf
317 files = files & vbCrLf
318 Else
319 first_time = 1
320 End If
321 res = res & _
322 " <File" & vbCrLf & _
323 " RelativePath=" & Chr(34) & "..\src\table\" & file & Chr(34) & vbCrLf & _
324 " >" & vbCrLf & _
325 " </File>"
326 vcxproj = vcxproj & _
327 " <None Include=" & Chr(34) & "..\src\table\" & file & Chr(34) & " />"
328 command = command & " ..\src\table\" & file
329 files = files & _
330 " <None Include=" & Chr(34) & "..\src\table\" & file & Chr(34) & ">" & vbCrLf & _
331 " <Filter>INI</Filter>" & vbCrLf & _
332 " </None>"
333 End If
334 Next
335 load_settings_data = res
336 End Function
338 Sub generate(data, dest, data2)
339 Dim srcfile, destfile, line
340 WScript.Echo "Generating " & FSO.GetFileName(dest) & "..."
341 Set srcfile = FSO.OpenTextFile(dest & ".in", 1, 0, 0)
342 Set destfile = FSO.CreateTextFile(dest, -1, 0)
344 If Not IsNull(data2) Then
345 ' Everything above the !!FILTERS!! marker
346 line = srcfile.ReadLine()
347 While line <> "!!FILTERS!!"
348 If len(line) > 0 Then destfile.WriteLine(line)
349 line = srcfile.ReadLine()
350 Wend
352 ' Our generated content
353 destfile.WriteLine(data2)
354 End If
356 ' Everything above the !!FILES!! marker
357 line = srcfile.ReadLine()
358 While line <> "!!FILES!!"
359 If len(line) > 0 Then destfile.WriteLine(line)
360 line = srcfile.ReadLine()
361 Wend
363 ' Our generated content
364 destfile.WriteLine(data)
366 ' Everything below the !!FILES!! marker
367 While Not srcfile.AtEndOfStream
368 line = srcfile.ReadLine()
369 If len(line) > 0 Then destfile.WriteLine(line)
370 Wend
371 srcfile.Close()
372 destfile.Close()
373 End Sub
375 Dim ROOT_DIR
376 ROOT_DIR = FSO.GetFolder("..").Path
377 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
378 ROOT_DIR = FSO.GetFolder(".").Path
379 End If
380 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
381 WScript.Echo "Can't find source.list, needed in order to make this run." _
382 & vbCrLf & "Please go to either the project dir, or the root dir of a clean SVN checkout."
383 WScript.Quit(1)
384 End If
386 headers_check ROOT_DIR & "/source.list", ROOT_DIR & "\src\" ' Backslashes needed for DoFiles
388 Dim openttd, openttdvcxproj, openttdfilters, openttdfiles
389 openttd = load_main_data(ROOT_DIR & "/source.list", openttdvcxproj, openttdfilters, openttdfiles)
390 generate openttd, ROOT_DIR & "/projects/openttd_vs80.vcproj", Null
391 generate openttd, ROOT_DIR & "/projects/openttd_vs90.vcproj", Null
392 generate openttdvcxproj, ROOT_DIR & "/projects/openttd_vs100.vcxproj", Null
393 generate openttdfiles, ROOT_DIR & "/projects/openttd_vs100.vcxproj.filters", openttdfilters
394 generate openttdvcxproj, ROOT_DIR & "/projects/openttd_vs140.vcxproj", Null
395 generate openttdfiles, ROOT_DIR & "/projects/openttd_vs140.vcxproj.filters", openttdfilters
396 generate openttdvcxproj, ROOT_DIR & "/projects/openttd_vs141.vcxproj", Null
397 generate openttdfiles, ROOT_DIR & "/projects/openttd_vs141.vcxproj.filters", openttdfilters
399 Dim lang, langvcxproj, langfiles
400 lang = load_lang_data(ROOT_DIR & "/src/lang", langvcxproj, langfiles)
401 generate lang, ROOT_DIR & "/projects/langs_vs80.vcproj", Null
402 generate lang, ROOT_DIR & "/projects/langs_vs90.vcproj", Null
403 generate langvcxproj, ROOT_DIR & "/projects/langs_vs100.vcxproj", Null
404 generate langfiles, ROOT_DIR & "/projects/langs_vs100.vcxproj.filters", Null
405 generate langvcxproj, ROOT_DIR & "/projects/langs_vs140.vcxproj", Null
406 generate langfiles, ROOT_DIR & "/projects/langs_vs140.vcxproj.filters", Null
407 generate langvcxproj, ROOT_DIR & "/projects/langs_vs141.vcxproj", Null
408 generate langfiles, ROOT_DIR & "/projects/langs_vs141.vcxproj.filters", Null
410 Dim settings, settingsvcxproj, settingscommand, settingsfiles
411 settings = load_settings_data(ROOT_DIR & "/src/table", settingsvcxproj, settingscommand, settingsfiles)
412 generate settings, ROOT_DIR & "/projects/settings_vs80.vcproj", settingscommand
413 generate settings, ROOT_DIR & "/projects/settings_vs90.vcproj", settingscommand
414 generate settingsvcxproj, ROOT_DIR & "/projects/settings_vs100.vcxproj", settingscommand
415 generate settingsfiles, ROOT_DIR & "/projects/settings_vs100.vcxproj.filters", Null
416 generate settingsvcxproj, ROOT_DIR & "/projects/settings_vs140.vcxproj", settingscommand
417 generate settingsfiles, ROOT_DIR & "/projects/settings_vs140.vcxproj.filters", Null
418 generate settingsvcxproj, ROOT_DIR & "/projects/settings_vs141.vcxproj", settingscommand
419 generate settingsfiles, ROOT_DIR & "/projects/settings_vs141.vcxproj.filters", Null