Codechange: Use cached town, station, industry names for list window sorting
[openttd-github.git] / projects / generate.vbs
blob169f8b6890dab018e8dfe9866487d7ca9c3918a6
1 Option Explicit
3 ' This file is part of OpenTTD.
4 ' 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.
5 ' 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.
6 ' 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/>.
8 Dim FSO
9 Set FSO = CreateObject("Scripting.FileSystemObject")
11 ' openttd_vs142.sln is for MSVC 2019
12 ' openttd_vs142.vcxproj is for MSVC 2019
13 ' openttd_vs142.vcxproj.filters is for MSVC 2019
14 ' langs_vs142.vcxproj is for MSVC 2019
15 ' strgen_vs142.vcxproj is for MSVC 2019
16 ' strgen_vs142.vcxproj.filters is for MSVC 2019
17 ' generate_vs142.vcxproj is for MSVC 2019
18 ' version_vs142.vcxproj is for MSVC 2019
19 ' basesets_vs142.vcxproj is for MSVC 2019
21 ' openttd_vs141.sln is for MSVC 2017
22 ' openttd_vs141.vcxproj is for MSVC 2017
23 ' openttd_vs141.vcxproj.filters is for MSVC 2017
24 ' langs_vs141.vcxproj is for MSVC 2017
25 ' strgen_vs141.vcxproj is for MSVC 2017
26 ' strgen_vs141.vcxproj.filters is for MSVC 2017
27 ' generate_vs141.vcxproj is for MSVC 2017
28 ' version_vs141.vcxproj is for MSVC 2017
29 ' basesets_vs141.vcxproj is for MSVC 2017
31 ' openttd_vs140.sln is for MSVC 2015
32 ' openttd_vs140.vcxproj is for MSVC 2015
33 ' openttd_vs140.vcxproj.filters is for MSVC 2015
34 ' langs_vs140.vcxproj is for MSVC 2015
35 ' strgen_vs140.vcxproj is for MSVC 2015
36 ' strgen_vs140.vcxproj.filters is for MSVC 2015
37 ' generate_vs140.vcxproj is for MSVC 2015
38 ' version_vs140.vcxproj is for MSVC 2015
39 ' basesets_vs140.vcxproj is for MSVC 2015
41 Sub safety_check(filename)
42 Dim file, line, regexp, list
44 ' Define regexp
45 Set regexp = New RegExp
46 regexp.Pattern = "#|ottdres.rc|win32.cpp|win32_v.cpp"
47 regexp.Global = True
49 ' We use a dictionary to check duplicates
50 Set list = CreateObject("Scripting.Dictionary")
52 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
53 While Not file.AtEndOfStream
54 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
55 If Len(line) > 0 And Not regexp.Test(line) Then
56 line = FSO.GetFileName(line)
57 if list.Exists(line) Then
58 WScript.Echo " !! ERROR !!" _
59 & vbCrLf & "" _
60 & vbCrLf & "The filename '" & line & "' is already used in this project." _
61 & vbCrLf & "Because MSVC uses one single directory for all object files, it" _
62 & vbCrLf & "cannot handle filenames with the same name inside the same project." _
63 & vbCrLf & "Please rename either one of the file and try generating again." _
64 & vbCrLf & "" _
65 & vbCrLf & " !! ERROR !!"
66 WScript.Quit(1)
67 End If
68 list.Add line, line
69 End If
70 Wend
71 file.Close
72 End Sub
74 Sub get_files(srcdir, dir, list)
75 Dim file, filename
76 Dim rekeep, reskip
78 ' pattern for files to keep
79 Set rekeep = New RegExp
80 rekeep.Pattern = "\.h(pp)?$"
81 rekeep.Global = True
83 ' pattern for files to exclude
84 Set reskip = New RegExp
85 reskip.Pattern = "\.svn"
86 reskip.Global = True
88 For Each file in dir.Files
89 filename = Replace(file.path, srcdir, "") ' Remove */src/
90 filename = Replace(filename, "\", "/") ' Replace separators
91 If rekeep.Test(filename) And Not reskip.Test(filename) Then
92 list.Add filename, filename
93 End If
94 Next
95 End Sub
97 Sub get_dir_files(srcdir, dir, list)
98 Dim folder
99 ' Get files
100 get_files srcdir, dir, list
102 ' Recurse in subfolders
103 For Each folder in dir.SubFolders
104 get_dir_files srcdir, folder, list
105 Next
106 End Sub
108 Sub headers_check(filename, dir)
109 Dim source_list_headers, src_dir_headers, regexp, line, file, str
111 ' Define regexp for source.list parsing
112 Set regexp = New RegExp
113 regexp.Pattern = "\.h"
114 regexp.Global = True
116 ' Parse source.list and store headers in a dictionary
117 Set source_list_headers = CreateObject("Scripting.Dictionary")
118 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
119 While Not file.AtEndOfStream
120 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
121 If Len(line) > 0 And regexp.Test(line) And line <> "../objs/langs/table/strings.h" And line <> "../objs/settings/table/settings.h" Then
122 source_list_headers.Add line, line
123 End If
124 Wend
125 file.Close()
127 ' Get header files in /src/
128 Set src_dir_headers = CreateObject("Scripting.Dictionary")
129 get_dir_files dir, FSO.GetFolder(dir), src_dir_headers
131 ' Finding files in source.list but not in /src/
132 For Each line In source_list_headers
133 If Not src_dir_headers.Exists(line) Then
134 str = str & "< " & line & vbCrLf
135 End If
136 Next
138 ' Finding files in /src/ but not in source.list
139 For Each line In src_dir_headers
140 If Not source_list_headers.Exists(line) Then
141 str = str & "> " & line & vbCrLf
142 End If
143 Next
145 ' Display the missing files if any
146 If str <> "" Then
147 str = "The following headers are missing in source.list and not in /src/ or vice versa." _
148 & vbCrLf & str
149 WScript.Echo str
150 End If
151 End Sub
153 Sub load_main_data(filename, ByRef vcxproj, ByRef filters, ByRef files)
154 Dim file, line, deep, skip, first_filter, first_file, filter, cltype, index
155 index = 0
156 ' Read the source.list and process it
157 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
158 While Not file.AtEndOfStream
159 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
160 If Len(line) > 0 Then
161 Select Case Split(line, " ")(0)
162 Case "#end"
163 If deep = skip Then skip = skip - 1
164 deep = deep - 1
165 Case "#else"
166 If deep = skip Then
167 skip = skip - 1
168 ElseIf deep - 1 = skip Then
169 skip = skip + 1
170 End If
171 Case "#if"
172 line = Replace(line, "#if ", "")
173 If deep = skip And ( _
174 line = "SDL" Or _
175 line = "PNG" Or _
176 line = "WIN32" Or _
177 line = "MSVC" Or _
178 line = "DIRECTMUSIC" Or _
179 line = "AI" Or _
180 line = "USE_SSE" Or _
181 line = "USE_XAUDIO2" Or _
182 line = "USE_THREADS" _
183 ) Then skip = skip + 1
184 deep = deep + 1
185 Case "#"
186 if deep = skip Then
187 line = Replace(line, "# ", "")
188 if first_filter <> 0 Then
189 filters = filters & vbCrLf
190 Else
191 first_filter = 1
192 End If
193 filter = line
194 filters = filters & _
195 " <Filter Include="& Chr(34) & filter & Chr(34) & ">" & vbCrLf & _
196 " <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-" & String(12 - Len(CStr(index)), "0") & index & "}</UniqueIdentifier>" & vbCrLf & _
197 " </Filter>"
198 index = index + 1
199 End If
200 Case Else
201 If deep = skip Then
202 line = Replace(line, "/" ,"\")
203 if first_file <> 0 Then
204 vcxproj = vcxproj & vbCrLf
205 files = files & vbCrLf
206 Else
207 first_file = 1
208 End If
209 Select Case Split(Line, ".")(1)
210 Case "cpp"
211 cltype = "ClCompile"
212 Case "rc"
213 cltype = "ResourceCompile"
214 Case Else
215 cltype = "ClInclude"
216 End Select
217 vcxproj = vcxproj & " <" & cltype & " Include="& Chr(34) & "..\src\" & line & Chr(34) & " />"
218 files = files & _
219 " <" & cltype & " Include="& Chr(34) & "..\src\" & line & Chr(34) & ">" & vbCrLf & _
220 " <Filter>" & filter & "</Filter>" & vbCrLf & _
221 " </" & cltype & ">"
222 End If
223 End Select
224 End If
225 Wend
226 file.Close()
227 End Sub
229 Sub load_lang_data(dir, ByRef vcxproj, ByRef files)
230 Dim folder, file, first_time
231 Set folder = FSO.GetFolder(dir)
232 For Each file In folder.Files
233 file = FSO.GetFileName(file)
234 If file <> "english.txt" And FSO.GetExtensionName(file) = "txt" Then
235 file = Left(file, Len(file) - 4)
236 If first_time <> 0 Then
237 vcxproj = vcxproj & vbCrLf
238 files = files & vbCrLf
239 Else
240 first_time = 1
241 End If
242 vcxproj = vcxproj & _
243 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & ">" & vbCrLf & _
244 " <Message Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">Generating " & file & " language file</Message>" & vbCrLf & _
245 " <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 & _
246 " <AdditionalInputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\src\lang\english.txt;..\objs\strgen\strgen.exe;%(AdditionalInputs)</AdditionalInputs>" & vbCrLf & _
247 " <Outputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\bin\lang\" & file & ".lng;%(Outputs)</Outputs>" & vbCrLf & _
248 " </CustomBuild>"
249 files = files & _
250 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & ">" & vbCrLf & _
251 " <Filter>Translations</Filter>" & vbCrLf & _
252 " </CustomBuild>"
253 End If
254 Next
255 End Sub
257 Sub load_settings_data(dir, ByRef vcxproj, ByRef command, ByRef files)
258 Dim folder, file, first_time
259 command = "..\objs\settings\settings_gen.exe -o ..\objs\settings\table\settings.h -b ..\src\table\settings.h.preamble -a ..\src\table\settings.h.postamble"
260 Set folder = FSO.GetFolder(dir)
261 For Each file In folder.Files
262 file = FSO.GetFileName(file)
263 If FSO.GetExtensionName(file) = "ini" Then
264 if first_time <> 0 Then
265 vcxproj = vcxproj & vbCrLf
266 files = files & vbCrLf
267 Else
268 first_time = 1
269 End If
270 vcxproj = vcxproj & _
271 " <None Include=" & Chr(34) & "..\src\table\" & file & Chr(34) & " />"
272 command = command & " ..\src\table\" & file
273 files = files & _
274 " <None Include=" & Chr(34) & "..\src\table\" & file & Chr(34) & ">" & vbCrLf & _
275 " <Filter>INI</Filter>" & vbCrLf & _
276 " </None>"
277 End If
278 Next
279 End Sub
281 Sub load_baseset_data(dir, langdir, ByRef vcxproj, ByRef files, ByRef langs)
282 Dim folder, file, ext, first_time
283 Set folder = FSO.GetFolder(langdir)
284 langs = " <Langs>"
285 For Each file In folder.Files
286 If first_time <> 0 Then
287 langs = langs & ";"
288 Else
289 first_time = 1
290 End If
291 file = FSO.GetFileName(file)
292 ext = FSO.GetExtensionName(file)
293 langs = langs & "..\src\lang\" & file
294 Next
295 langs = langs & "</Langs>"
296 first_time = 0
297 Set folder = FSO.GetFolder(dir)
298 For Each file In folder.Files
299 file = FSO.GetFileName(file)
300 ext = FSO.GetExtensionName(file)
301 If ext = "obm" Or ext = "obg" Or ext = "obs" Then
302 If first_time <> 0 Then
303 vcxproj = vcxproj & vbCrLf
304 files = files & vbCrLf
305 Else
306 first_time = 1
307 End If
308 vcxproj = vcxproj & _
309 " <CustomBuild Include=" & Chr(34) & "..\media\baseset\" & file & Chr(34) & ">" & vbCrLf & _
310 " <Message Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">Generating " & file & " baseset metadata file</Message>" & vbCrLf & _
311 " <Command Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">cscript //nologo ..\media\baseset\translations.vbs " & Chr(34) & "%(FullPath)" & Chr(34) & " " & Chr(34) & "$(OutputPath)" & file & Chr(34) & " ..\src\lang ..\bin\baseset\orig_extra.grf</Command>" & vbCrLf & _
312 " <AdditionalInputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">$(Langs);..\bin\baseset\orig_extra.grf;%(AdditionalInputs)</AdditionalInputs>" & vbCrLf & _
313 " <Outputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\bin\baseset\" & file & ";%(Outputs)</Outputs>" & vbCrLf & _
314 " </CustomBuild>"
315 files = files & _
316 " <CustomBuild Include=" & Chr(34) & "..\media\baseset\" & file & Chr(34) & ">" & vbCrLf & _
317 " <Filter>Baseset Metadata</Filter>" & vbCrLf & _
318 " </CustomBuild>"
319 End If
320 Next
321 End Sub
323 Sub generate(data, dest, data2)
324 Dim srcfile, destfile, line
325 WScript.Echo "Generating " & FSO.GetFileName(dest) & "..."
326 Set srcfile = FSO.OpenTextFile(dest & ".in", 1, 0, 0)
327 Set destfile = FSO.CreateTextFile(dest, -1, 0)
329 If Not IsNull(data2) Then
330 ' Everything above the !!FILTERS!! marker
331 line = srcfile.ReadLine()
332 While line <> "!!FILTERS!!"
333 If len(line) > 0 Then destfile.WriteLine(line)
334 line = srcfile.ReadLine()
335 Wend
337 ' Our generated content
338 destfile.WriteLine(data2)
339 End If
341 ' Everything above the !!FILES!! marker
342 line = srcfile.ReadLine()
343 While line <> "!!FILES!!"
344 If len(line) > 0 Then destfile.WriteLine(line)
345 line = srcfile.ReadLine()
346 Wend
348 ' Our generated content
349 destfile.WriteLine(data)
351 ' Everything below the !!FILES!! marker
352 While Not srcfile.AtEndOfStream
353 line = srcfile.ReadLine()
354 If len(line) > 0 Then destfile.WriteLine(line)
355 Wend
356 srcfile.Close()
357 destfile.Close()
358 End Sub
360 Dim ROOT_DIR
361 ROOT_DIR = FSO.GetFolder("..").Path
362 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
363 ROOT_DIR = FSO.GetFolder(".").Path
364 End If
365 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
366 WScript.Echo "Can't find source.list, needed in order to make this run." _
367 & vbCrLf & "Please go to either the project dir, or the root dir of a clean SVN checkout."
368 WScript.Quit(1)
369 End If
371 safety_check ROOT_DIR & "/source.list"
372 headers_check ROOT_DIR & "/source.list", ROOT_DIR & "\src\" ' Backslashes needed for DoFiles
374 Dim openttdvcxproj, openttdfilters, openttdfiles
375 load_main_data ROOT_DIR & "/source.list", openttdvcxproj, openttdfilters, openttdfiles
376 generate openttdvcxproj, ROOT_DIR & "/projects/openttd_vs140.vcxproj", Null
377 generate openttdfiles, ROOT_DIR & "/projects/openttd_vs140.vcxproj.filters", openttdfilters
378 generate openttdvcxproj, ROOT_DIR & "/projects/openttd_vs141.vcxproj", Null
379 generate openttdfiles, ROOT_DIR & "/projects/openttd_vs141.vcxproj.filters", openttdfilters
380 generate openttdvcxproj, ROOT_DIR & "/projects/openttd_vs142.vcxproj", Null
381 generate openttdfiles, ROOT_DIR & "/projects/openttd_vs142.vcxproj.filters", openttdfilters
383 Dim langvcxproj, langfiles
384 load_lang_data ROOT_DIR & "/src/lang", langvcxproj, langfiles
385 generate langvcxproj, ROOT_DIR & "/projects/langs_vs140.vcxproj", Null
386 generate langfiles, ROOT_DIR & "/projects/langs_vs140.vcxproj.filters", Null
387 generate langvcxproj, ROOT_DIR & "/projects/langs_vs141.vcxproj", Null
388 generate langfiles, ROOT_DIR & "/projects/langs_vs141.vcxproj.filters", Null
389 generate langvcxproj, ROOT_DIR & "/projects/langs_vs142.vcxproj", Null
390 generate langfiles, ROOT_DIR & "/projects/langs_vs142.vcxproj.filters", Null
392 Dim settingsvcxproj, settingscommand, settingsfiles
393 load_settings_data ROOT_DIR & "/src/table", settingsvcxproj, settingscommand, settingsfiles
394 generate settingsvcxproj, ROOT_DIR & "/projects/settings_vs140.vcxproj", settingscommand
395 generate settingsfiles, ROOT_DIR & "/projects/settings_vs140.vcxproj.filters", Null
396 generate settingsvcxproj, ROOT_DIR & "/projects/settings_vs141.vcxproj", settingscommand
397 generate settingsfiles, ROOT_DIR & "/projects/settings_vs141.vcxproj.filters", Null
398 generate settingsvcxproj, ROOT_DIR & "/projects/settings_vs142.vcxproj", settingscommand
399 generate settingsfiles, ROOT_DIR & "/projects/settings_vs142.vcxproj.filters", Null
401 Dim basesetvcxproj, basesetfiles, basesetlangs
402 load_baseset_data ROOT_DIR & "/media/baseset", ROOT_DIR & "/src/lang", basesetvcxproj, basesetfiles, basesetlangs
403 generate basesetvcxproj, ROOT_DIR & "/projects/basesets_vs140.vcxproj", basesetlangs
404 generate basesetfiles, ROOT_DIR & "/projects/basesets_vs140.vcxproj.filters", Null
405 generate basesetvcxproj, ROOT_DIR & "/projects/basesets_vs141.vcxproj", basesetlangs
406 generate basesetfiles, ROOT_DIR & "/projects/basesets_vs141.vcxproj.filters", Null
407 generate basesetvcxproj, ROOT_DIR & "/projects/basesets_vs142.vcxproj", basesetlangs
408 generate basesetfiles, ROOT_DIR & "/projects/basesets_vs142.vcxproj.filters", Null