Add configurable buffer times to timetable automation and make ticks_per_minute a...
[openttd-joker.git] / projects / generate.vbs
blob4870c07da52bf5d96cb863ecf5129824bc81521b
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_vs100.sln is for MSVC 2010
23 ' openttd_vs100.vcxproj is for MSVC 2010
24 ' openttd_vs100.vcxproj.filters is for MSVC 2010
25 ' langs_vs100.vcxproj is for MSVC 2010
26 ' strgen_vs100.vcxproj is for MSVC 2010
27 ' strgen_vs100.vcxproj.filters is for MSVC 2010
28 ' generate_vs100.vcxproj is for MSVC 2010
29 ' version_vs100.vcxproj is for MSVC 2010
31 ' openttd_vs90.sln is for MSVC 2008
32 ' openttd_vs90.vcproj is for MSVC 2008
33 ' langs_vs90.vcproj is for MSVC 2008
34 ' strgen_vs90.vcproj is for MSVC 2008
35 ' generate_vs90.vcproj is for MSVC 2008
36 ' version_vs90.vcproj is for MSVC 2008
38 ' openttd_vs80.sln is for MSVC 2005
39 ' openttd_vs80.vcproj is for MSVC 2005
40 ' langs_vs80.vcproj is for MSVC 2005
41 ' strgen_vs80.vcproj is for MSVC 2005
42 ' generate_vs80.vcproj is for MSVC 2005
43 ' version_vs80.vcproj is for MSVC 2005
45 Sub safety_check(filename)
46 Dim file, line, regexp, list
48 ' Define regexp
49 Set regexp = New RegExp
50 regexp.Pattern = "#|ottdres.rc|win32.cpp|win32_v.cpp"
51 regexp.Global = True
53 ' We use a dictionary to check duplicates
54 Set list = CreateObject("Scripting.Dictionary")
56 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
57 While Not file.AtEndOfStream
58 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
59 If Len(line) > 0 And Not regexp.Test(line) Then
60 line = FSO.GetFileName(line)
61 if list.Exists(line) Then
62 WScript.Echo " !! ERROR !!" _
63 & vbCrLf & "" _
64 & vbCrLf & "The filename '" & line & "' is already used in this project." _
65 & vbCrLf & "Because MSVC uses one single directory for all object files, it" _
66 & vbCrLf & "cannot handle filenames with the same name inside the same project." _
67 & vbCrLf & "Please rename either one of the file and try generating again." _
68 & vbCrLf & "" _
69 & vbCrLf & " !! ERROR !!"
70 WScript.Quit(1)
71 End If
72 list.Add line, line
73 End If
74 Wend
75 file.Close
76 End Sub
78 Sub get_files(srcdir, dir, list)
79 Dim file, filename
80 Dim rekeep, reskip
82 ' pattern for files to keep
83 Set rekeep = New RegExp
84 rekeep.Pattern = "\.h(pp)?$"
85 rekeep.Global = True
87 ' pattern for files to exclude
88 Set reskip = New RegExp
89 reskip.Pattern = "\.svn"
90 reskip.Global = True
92 For Each file in dir.Files
93 filename = Replace(file.path, srcdir, "") ' Remove */src/
94 filename = Replace(filename, "\", "/") ' Replace separators
95 If rekeep.Test(filename) And Not reskip.Test(filename) Then
96 list.Add filename, filename
97 End If
98 Next
99 End Sub
101 Sub get_dir_files(srcdir, dir, list)
102 Dim folder
103 ' Get files
104 get_files srcdir, dir, list
106 ' Recurse in subfolders
107 For Each folder in dir.SubFolders
108 get_dir_files srcdir, folder, list
109 Next
110 End Sub
112 Sub headers_check(filename, dir)
113 Dim source_list_headers, src_dir_headers, regexp, line, file, str
115 ' Define regexp for source.list parsing
116 Set regexp = New RegExp
117 regexp.Pattern = "\.h"
118 regexp.Global = True
120 ' Parse source.list and store headers in a dictionary
121 Set source_list_headers = CreateObject("Scripting.Dictionary")
122 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
123 While Not file.AtEndOfStream
124 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
125 If Len(line) > 0 And regexp.Test(line) And line <> "../objs/langs/table/strings.h" And line <> "../objs/settings/table/settings.h" Then
126 source_list_headers.Add line, line
127 End If
128 Wend
129 file.Close()
131 ' Get header files in /src/
132 Set src_dir_headers = CreateObject("Scripting.Dictionary")
133 get_dir_files dir, FSO.GetFolder(dir), src_dir_headers
135 ' Finding files in source.list but not in /src/
136 For Each line In source_list_headers
137 If Not src_dir_headers.Exists(line) Then
138 str = str & "< " & line & vbCrLf
139 End If
140 Next
142 ' Finding files in /src/ but not in source.list
143 For Each line In src_dir_headers
144 If Not source_list_headers.Exists(line) Then
145 str = str & "> " & line & vbCrLf
146 End If
147 Next
149 ' Display the missing files if any
150 If str <> "" Then
151 str = "The following headers are missing in source.list and not in /src/ or vice versa." _
152 & vbCrLf & str
153 WScript.Echo str
154 End If
155 End Sub
157 Function load_main_data(filename, ByRef vcxproj, ByRef filters, ByRef files)
158 Dim res, file, line, deep, skip, first_filter, first_file, filter, cltype, index
159 res = ""
160 index = 0
161 ' Read the source.list and process it
162 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
163 While Not file.AtEndOfStream
164 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
165 If Len(line) > 0 Then
166 Select Case Split(line, " ")(0)
167 Case "#end"
168 If deep = skip Then skip = skip - 1
169 deep = deep - 1
170 Case "#else"
171 If deep = skip Then
172 skip = skip - 1
173 ElseIf deep - 1 = skip Then
174 skip = skip + 1
175 End If
176 Case "#if"
177 line = Replace(line, "#if ", "")
178 If deep = skip And ( _
179 line = "SDL" Or _
180 line = "PNG" Or _
181 line = "WIN32" Or _
182 line = "MSVC" Or _
183 line = "DIRECTMUSIC" Or _
184 line = "AI" Or _
185 line = "SSE" Or _
186 line = "HAVE_THREAD" _
187 ) Then skip = skip + 1
188 deep = deep + 1
189 Case "#"
190 if deep = skip Then
191 line = Replace(line, "# ", "")
192 if first_filter <> 0 Then
193 res = res & " </Filter>" & vbCrLf
194 filters = filters & vbCrLf
195 Else
196 first_filter = 1
197 End If
198 filter = line
199 res = res & _
200 " <Filter" & vbCrLf & _
201 " Name=" & Chr(34) & filter & Chr(34) & vbCrLf & _
202 " >" & vbCrLf
203 filters = filters & _
204 " <Filter Include="& Chr(34) & filter & Chr(34) & ">" & vbCrLf & _
205 " <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-" & String(12 - Len(CStr(index)), "0") & index & "}</UniqueIdentifier>" & vbCrLf & _
206 " </Filter>"
207 index = index + 1
208 End If
209 Case Else
210 If deep = skip Then
211 line = Replace(line, "/" ,"\")
212 if first_file <> 0 Then
213 vcxproj = vcxproj & vbCrLf
214 files = files & vbCrLf
215 Else
216 first_file = 1
217 End If
218 res = res & _
219 " <File" & vbCrLf & _
220 " RelativePath=" & Chr(34) & ".\..\src\" & line & Chr(34) & vbCrLf & _
221 " >" & vbCrLf & _
222 " </File>" & vbCrLf
223 Select Case Split(Line, ".")(1)
224 Case "cpp"
225 cltype = "ClCompile"
226 Case "rc"
227 cltype = "ResourceCompile"
228 Case Else
229 cltype = "ClInclude"
230 End Select
231 vcxproj = vcxproj & " <" & cltype & " Include="& Chr(34) & "..\src\" & line & Chr(34) & " />"
232 files = files & _
233 " <" & cltype & " Include="& Chr(34) & "..\src\" & line & Chr(34) & ">" & vbCrLf & _
234 " <Filter>" & filter & "</Filter>" & vbCrLf & _
235 " </" & cltype & ">"
236 End If
237 End Select
238 End If
239 Wend
240 res = res & " </Filter>"
241 file.Close()
242 load_main_data = res
243 End Function
245 Function load_lang_data(dir, ByRef vcxproj, ByRef files)
246 Dim res, folder, file, first_time
247 res = ""
248 Set folder = FSO.GetFolder(dir)
249 For Each file In folder.Files
250 file = FSO.GetFileName(file)
251 If file <> "english.txt" And FSO.GetExtensionName(file) = "txt" Then
252 file = Left(file, Len(file) - 4)
253 If first_time <> 0 Then
254 res = res & vbCrLf
255 vcxproj = vcxproj & vbCrLf
256 files = files & vbCrLf
257 Else
258 first_time = 1
259 End If
260 res = res & _
261 " <File" & vbCrLf & _
262 " RelativePath=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & vbCrLf & _
263 " >" & vbCrLf & _
264 " <FileConfiguration" & vbCrLf & _
265 " Name=" & Chr(34) & "Debug|Win32" & Chr(34) & vbCrLf & _
266 " >" & vbCrLf & _
267 " <Tool" & vbCrLf & _
268 " Name=" & Chr(34) & "VCCustomBuildTool" & Chr(34) & vbCrLf & _
269 " Description=" & Chr(34) & "Generating " & file & " language file" & Chr(34) & vbCrLf & _
270 " 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 & _
271 " AdditionalDependencies=" & Chr(34) & "..\src\lang\english.txt;..\objs\strgen\strgen.exe" & Chr(34) & vbCrLf & _
272 " Outputs=" & Chr(34) & "..\bin\lang\" & file & ".lng" & Chr(34) & vbCrLf & _
273 " />" & vbCrLf & _
274 " </FileConfiguration>" & vbCrLf & _
275 " </File>"
276 vcxproj = vcxproj & _
277 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & ">" & vbCrLf & _
278 " <Message Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">Generating " & file & " language file</Message>" & vbCrLf & _
279 " <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 & _
280 " <AdditionalInputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\src\lang\english.txt;..\objs\strgen\strgen.exe;%(AdditionalInputs)</AdditionalInputs>" & vbCrLf & _
281 " <Outputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\bin\lang\" & file & ".lng;%(Outputs)</Outputs>" & vbCrLf & _
282 " </CustomBuild>"
283 files = files & _
284 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & ">" & vbCrLf & _
285 " <Filter>Translations</Filter>" & vbCrLf & _
286 " </CustomBuild>"
287 End If
288 Next
289 load_lang_data = res
290 End Function
292 Function load_settings_data(dir, ByRef vcxproj, ByRef command, ByRef files)
293 Dim res, folder, file, first_time
294 res = ""
295 command = "..\objs\settings\settings_gen.exe -o ..\objs\settings\table\settings.h -b ..\src\table\settings.h.preamble -a ..\src\table\settings.h.postamble"
296 Set folder = FSO.GetFolder(dir)
297 For Each file In folder.Files
298 file = FSO.GetFileName(file)
299 If FSO.GetExtensionName(file) = "ini" Then
300 if first_time <> 0 Then
301 res = res & vbCrLf
302 vcxproj = vcxproj & vbCrLf
303 files = files & vbCrLf
304 Else
305 first_time = 1
306 End If
307 res = res & _
308 " <File" & vbCrLf & _
309 " RelativePath=" & Chr(34) & "..\src\table\" & file & Chr(34) & vbCrLf & _
310 " >" & vbCrLf & _
311 " </File>"
312 vcxproj = vcxproj & _
313 " <None Include=" & Chr(34) & "..\src\table\" & file & Chr(34) & " />"
314 command = command & " ..\src\table\" & file
315 files = files & _
316 " <None Include=" & Chr(34) & "..\src\table\" & file & Chr(34) & ">" & vbCrLf & _
317 " <Filter>INI</Filter>" & vbCrLf & _
318 " </None>"
319 End If
320 Next
321 load_settings_data = res
322 End Function
324 Sub generate(data, dest, data2)
325 Dim srcfile, destfile, line
326 WScript.Echo "Generating " & FSO.GetFileName(dest) & "..."
327 Set srcfile = FSO.OpenTextFile(dest & ".in", 1, 0, 0)
328 Set destfile = FSO.CreateTextFile(dest, -1, 0)
330 If Not IsNull(data2) Then
331 ' Everything above the !!FILTERS!! marker
332 line = srcfile.ReadLine()
333 While line <> "!!FILTERS!!"
334 If len(line) > 0 Then destfile.WriteLine(line)
335 line = srcfile.ReadLine()
336 Wend
338 ' Our generated content
339 destfile.WriteLine(data2)
340 End If
342 ' Everything above the !!FILES!! marker
343 line = srcfile.ReadLine()
344 While line <> "!!FILES!!"
345 If len(line) > 0 Then destfile.WriteLine(line)
346 line = srcfile.ReadLine()
347 Wend
349 ' Our generated content
350 destfile.WriteLine(data)
352 ' Everything below the !!FILES!! marker
353 While Not srcfile.AtEndOfStream
354 line = srcfile.ReadLine()
355 If len(line) > 0 Then destfile.WriteLine(line)
356 Wend
357 srcfile.Close()
358 destfile.Close()
359 End Sub
361 Dim ROOT_DIR
362 ROOT_DIR = FSO.GetFolder("..").Path
363 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
364 ROOT_DIR = FSO.GetFolder(".").Path
365 End If
366 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
367 WScript.Echo "Can't find source.list, needed in order to make this run." _
368 & vbCrLf & "Please go to either the project dir, or the root dir of a clean SVN checkout."
369 WScript.Quit(1)
370 End If
372 safety_check ROOT_DIR & "/source.list"
373 headers_check ROOT_DIR & "/source.list", ROOT_DIR & "\src\" ' Backslashes needed for DoFiles
375 Dim openttd, openttdvcxproj, openttdfilters, openttdfiles
376 openttd = load_main_data(ROOT_DIR & "/source.list", openttdvcxproj, openttdfilters, openttdfiles)
377 generate openttd, ROOT_DIR & "/projects/openttd_vs80.vcproj", Null
378 generate openttd, ROOT_DIR & "/projects/openttd_vs90.vcproj", Null
379 generate openttdvcxproj, ROOT_DIR & "/projects/openttd_vs100.vcxproj", Null
380 generate openttdfiles, ROOT_DIR & "/projects/openttd_vs100.vcxproj.filters", openttdfilters
381 generate openttdvcxproj, ROOT_DIR & "/projects/openttd_vs141.vcxproj", Null
382 generate openttdfiles, ROOT_DIR & "/projects/openttd_vs141.vcxproj.filters", openttdfilters
384 Dim lang, langvcxproj, langfiles
385 lang = load_lang_data(ROOT_DIR & "/src/lang", langvcxproj, langfiles)
386 generate lang, ROOT_DIR & "/projects/langs_vs80.vcproj", Null
387 generate lang, ROOT_DIR & "/projects/langs_vs90.vcproj", Null
388 generate langvcxproj, ROOT_DIR & "/projects/langs_vs100.vcxproj", Null
389 generate langfiles, ROOT_DIR & "/projects/langs_vs100.vcxproj.filters", Null
390 generate langvcxproj, ROOT_DIR & "/projects/langs_vs141.vcxproj", Null
391 generate langfiles, ROOT_DIR & "/projects/langs_vs141.vcxproj.filters", Null
393 Dim settings, settingsvcxproj, settingscommand, settingsfiles
394 settings = load_settings_data(ROOT_DIR & "/src/table", settingsvcxproj, settingscommand, settingsfiles)
395 generate settings, ROOT_DIR & "/projects/settings_vs80.vcproj", settingscommand
396 generate settings, ROOT_DIR & "/projects/settings_vs90.vcproj", settingscommand
397 generate settingsvcxproj, ROOT_DIR & "/projects/settings_vs100.vcxproj", settingscommand
398 generate settingsfiles, ROOT_DIR & "/projects/settings_vs100.vcxproj.filters", Null
399 generate settingsvcxproj, ROOT_DIR & "/projects/settings_vs141.vcxproj", settingscommand
400 generate settingsfiles, ROOT_DIR & "/projects/settings_vs141.vcxproj.filters", Null