Translations update
[openttd/fttd.git] / projects / generate.vbs
blob17b211706817c6b9c5e4d466c2ceeffef838cfcd
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_vs140.sln is for MSVC 2015
14 ' openttd_vs140.vcxproj is for MSVC 2015
15 ' openttd_vs140.vcxproj.filters is for MSVC 2015
16 ' langs_vs140.vcxproj is for MSVC 2015
17 ' strgen_vs140.vcxproj is for MSVC 2015
18 ' strgen_vs140.vcxproj.filters is for MSVC 2015
19 ' generate_vs140.vcxproj is for MSVC 2015
20 ' version_vs140.vcxproj is for MSVC 2015
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 get_files(srcdir, dir, list)
46 Dim file, filename
47 Dim rekeep, reskip
49 ' pattern for files to keep
50 Set rekeep = New RegExp
51 rekeep.Pattern = "\.h(pp)?$"
52 rekeep.Global = True
54 ' pattern for files to exclude
55 Set reskip = New RegExp
56 reskip.Pattern = "\.svn"
57 reskip.Global = True
59 For Each file in dir.Files
60 filename = Replace(file.path, srcdir, "") ' Remove */src/
61 filename = Replace(filename, "\", "/") ' Replace separators
62 If rekeep.Test(filename) And Not reskip.Test(filename) Then
63 list.Add filename, filename
64 End If
65 Next
66 End Sub
68 Sub get_dir_files(srcdir, dir, list)
69 Dim folder
70 ' Get files
71 get_files srcdir, dir, list
73 ' Recurse in subfolders
74 For Each folder in dir.SubFolders
75 get_dir_files srcdir, folder, list
76 Next
77 End Sub
79 Sub headers_check(filename, dir)
80 Dim source_list_headers, src_dir_headers, regexp, line, file, str
82 ' Define regexp for source.list parsing
83 Set regexp = New RegExp
84 regexp.Pattern = "\.h"
85 regexp.Global = True
87 ' Parse source.list and store headers in a dictionary
88 Set source_list_headers = CreateObject("Scripting.Dictionary")
89 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
90 While Not file.AtEndOfStream
91 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
92 If Len(line) > 0 And regexp.Test(line) And line <> "../objs/langs/table/strings.h" And line <> "../objs/settings/table/settings.h" Then
93 source_list_headers.Add line, line
94 End If
95 Wend
96 file.Close()
98 ' Get header files in /src/
99 Set src_dir_headers = CreateObject("Scripting.Dictionary")
100 get_dir_files dir, FSO.GetFolder(dir), src_dir_headers
102 ' Finding files in source.list but not in /src/
103 For Each line In source_list_headers
104 If Not src_dir_headers.Exists(line) Then
105 str = str & "< " & line & vbCrLf
106 End If
107 Next
109 ' Finding files in /src/ but not in source.list
110 For Each line In src_dir_headers
111 If Not source_list_headers.Exists(line) Then
112 str = str & "> " & line & vbCrLf
113 End If
114 Next
116 ' Display the missing files if any
117 If str <> "" Then
118 str = "The following headers are missing in source.list and not in /src/ or vice versa." _
119 & vbCrLf & str
120 WScript.Echo str
121 End If
122 End Sub
124 Function load_main_data(filename, ByRef vcxproj, ByRef filters, ByRef files)
125 Dim res, file, line, deep, skip, first_filter, first_file, filter, cltype, index, ext, pathelems, outdir, config
126 Dim configs(3)
127 configs(0) = "Release|Win32"
128 configs(1) = "Debug|Win32"
129 configs(2) = "Release|x64"
130 configs(3) = "Debug|x64"
131 res = ""
132 index = 0
133 ' Read the source.list and process it
134 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
135 While Not file.AtEndOfStream
136 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
137 If Len(line) > 0 Then
138 Select Case Split(line, " ")(0)
139 Case "#end"
140 If deep = skip Then skip = skip - 1
141 deep = deep - 1
142 Case "#else"
143 If deep = skip Then
144 skip = skip - 1
145 ElseIf deep - 1 = skip Then
146 skip = skip + 1
147 End If
148 Case "#if"
149 line = Replace(line, "#if ", "")
150 If deep = skip And ( _
151 line = "SDL" Or _
152 line = "PNG" Or _
153 line = "WIN32" Or _
154 line = "MSVC" Or _
155 line = "DIRECTMUSIC" Or _
156 line = "AI" Or _
157 line = "SSE" Or _
158 line = "HAVE_THREAD" _
159 ) Then skip = skip + 1
160 deep = deep + 1
161 Case "#"
162 if deep = skip Then
163 line = Replace(line, "# ", "")
164 if first_filter <> 0 Then
165 res = res & " </Filter>" & vbCrLf
166 filters = filters & vbCrLf
167 Else
168 first_filter = 1
169 End If
170 filter = line
171 res = res & _
172 " <Filter" & vbCrLf & _
173 " Name=" & Chr(34) & filter & Chr(34) & vbCrLf & _
174 " >" & vbCrLf
175 filters = filters & _
176 " <Filter Include="& Chr(34) & filter & Chr(34) & ">" & vbCrLf & _
177 " <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-" & String(12 - Len(CStr(index)), "0") & index & "}</UniqueIdentifier>" & vbCrLf & _
178 " </Filter>"
179 index = index + 1
180 End If
181 Case Else
182 If deep = skip Then
183 line = Replace(line, "/" ,"\")
184 if first_file <> 0 Then
185 vcxproj = vcxproj & vbCrLf
186 files = files & vbCrLf
187 Else
188 first_file = 1
189 End If
190 ext = Split(Line, ".")(1)
191 pathelems = Split(Line, "\")
192 If UBound(pathelems) > 0 Then
193 ReDim Preserve pathelems(UBound(pathelems) - 1)
194 outdir = "$(IntDir)\" & Join(pathelems, "\") & "\"
195 Else
196 outdir = ""
197 End If
198 res = res & _
199 " <File" & vbCrLf & _
200 " RelativePath=" & Chr(34) & ".\..\src\" & line & Chr(34) & vbCrLf & _
201 " >" & vbCrLf
202 If ext = "cpp" And outdir <> "" Then
203 For Each config In configs
204 res = res & _
205 " <FileConfiguration" & vbCrLf & _
206 " Name=" & Chr(34) & config & Chr(34) & vbCrLf & _
207 " >" & vbCrLf & _
208 " <Tool" & vbCrLf & _
209 " Name=" & Chr(34) & "VCCLCompilerTool" & Chr(34) & vbCrLf & _
210 " AssemblerListingLocation=" & Chr(34) & outdir & Chr(34) & vbCrLf & _
211 " ObjectFile=" & Chr(34) & outdir & Chr(34) & vbCrLf & _
212 " XMLDocumentationFileName=" & Chr(34) & outdir & Chr(34) & vbCrLf & _
213 " />" & vbCrLf & _
214 " </FileConfiguration>" & vbCrLf
215 Next
216 End If
217 res = res & _
218 " </File>" & vbCrLf
219 Select Case ext
220 Case "cpp"
221 cltype = "ClCompile"
222 Case "rc"
223 cltype = "ResourceCompile"
224 Case Else
225 cltype = "ClInclude"
226 End Select
227 If ext = "cpp" And outdir <> "" Then
228 vcxproj = vcxproj & _
229 " <ClCompile Include=" & Chr(34) & "..\src\" & line & Chr(34) & ">" & vbCrLf & _
230 " <AssemblerListingLocation>" & outdir & "</AssemblerListingLocation>" & vbCrLf & _
231 " <ObjectFileName>" & outdir & "</ObjectFileName>" & vbCrLf & _
232 " <XMLDocumentationFileName>" & outdir & "</XMLDocumentationFileName>" & vbCrLf & _
233 " </ClCompile>"
234 Else
235 vcxproj = vcxproj & " <" & cltype & " Include="& Chr(34) & "..\src\" & line & Chr(34) & " />"
236 End If
237 files = files & _
238 " <" & cltype & " Include="& Chr(34) & "..\src\" & line & Chr(34) & ">" & vbCrLf & _
239 " <Filter>" & filter & "</Filter>" & vbCrLf & _
240 " </" & cltype & ">"
241 End If
242 End Select
243 End If
244 Wend
245 res = res & " </Filter>"
246 file.Close()
247 load_main_data = res
248 End Function
250 Function load_lang_data(dir, ByRef vcxproj, ByRef files)
251 Dim res, folder, file, first_time
252 res = ""
253 Set folder = FSO.GetFolder(dir)
254 For Each file In folder.Files
255 file = FSO.GetFileName(file)
256 If file <> "english.txt" And FSO.GetExtensionName(file) = "txt" Then
257 file = Left(file, Len(file) - 4)
258 If first_time <> 0 Then
259 res = res & vbCrLf
260 vcxproj = vcxproj & vbCrLf
261 files = files & vbCrLf
262 Else
263 first_time = 1
264 End If
265 res = res & _
266 " <File" & vbCrLf & _
267 " RelativePath=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & vbCrLf & _
268 " >" & vbCrLf & _
269 " <FileConfiguration" & vbCrLf & _
270 " Name=" & Chr(34) & "Debug|Win32" & Chr(34) & vbCrLf & _
271 " >" & vbCrLf & _
272 " <Tool" & vbCrLf & _
273 " Name=" & Chr(34) & "VCCustomBuildTool" & Chr(34) & vbCrLf & _
274 " Description=" & Chr(34) & "Generating " & file & " language file" & Chr(34) & vbCrLf & _
275 " 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 & _
276 " AdditionalDependencies=" & Chr(34) & "..\src\lang\english.txt;..\objs\strgen\strgen.exe" & Chr(34) & vbCrLf & _
277 " Outputs=" & Chr(34) & "..\bin\lang\" & file & ".lng" & Chr(34) & vbCrLf & _
278 " />" & vbCrLf & _
279 " </FileConfiguration>" & vbCrLf & _
280 " </File>"
281 vcxproj = vcxproj & _
282 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & ">" & vbCrLf & _
283 " <Message Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">Generating " & file & " language file</Message>" & vbCrLf & _
284 " <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 & _
285 " <AdditionalInputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\src\lang\english.txt;..\objs\strgen\strgen.exe;%(AdditionalInputs)</AdditionalInputs>" & vbCrLf & _
286 " <Outputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\bin\lang\" & file & ".lng;%(Outputs)</Outputs>" & vbCrLf & _
287 " </CustomBuild>"
288 files = files & _
289 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & ">" & vbCrLf & _
290 " <Filter>Translations</Filter>" & vbCrLf & _
291 " </CustomBuild>"
292 End If
293 Next
294 load_lang_data = res
295 End Function
297 Function load_settings_data(dir, ByRef vcxproj, ByRef command, ByRef files)
298 Dim res, folder, file, first_time
299 res = ""
300 command = "..\objs\settings\settings_gen.exe -o ..\objs\settings\table\settings.h -b ..\src\table\settings.h.preamble -a ..\src\table\settings.h.postamble"
301 Set folder = FSO.GetFolder(dir)
302 For Each file In folder.Files
303 file = FSO.GetFileName(file)
304 If FSO.GetExtensionName(file) = "ini" Then
305 if first_time <> 0 Then
306 res = res & vbCrLf
307 vcxproj = vcxproj & vbCrLf
308 files = files & vbCrLf
309 Else
310 first_time = 1
311 End If
312 res = res & _
313 " <File" & vbCrLf & _
314 " RelativePath=" & Chr(34) & "..\src\table\" & file & Chr(34) & vbCrLf & _
315 " >" & vbCrLf & _
316 " </File>"
317 vcxproj = vcxproj & _
318 " <None Include=" & Chr(34) & "..\src\table\" & file & Chr(34) & " />"
319 command = command & " ..\src\table\" & file
320 files = files & _
321 " <None Include=" & Chr(34) & "..\src\table\" & file & Chr(34) & ">" & vbCrLf & _
322 " <Filter>INI</Filter>" & vbCrLf & _
323 " </None>"
324 End If
325 Next
326 load_settings_data = res
327 End Function
329 Sub generate(data, dest, data2)
330 Dim srcfile, destfile, line
331 WScript.Echo "Generating " & FSO.GetFileName(dest) & "..."
332 Set srcfile = FSO.OpenTextFile(dest & ".in", 1, 0, 0)
333 Set destfile = FSO.CreateTextFile(dest, -1, 0)
335 If Not IsNull(data2) Then
336 ' Everything above the !!FILTERS!! marker
337 line = srcfile.ReadLine()
338 While line <> "!!FILTERS!!"
339 If len(line) > 0 Then destfile.WriteLine(line)
340 line = srcfile.ReadLine()
341 Wend
343 ' Our generated content
344 destfile.WriteLine(data2)
345 End If
347 ' Everything above the !!FILES!! marker
348 line = srcfile.ReadLine()
349 While line <> "!!FILES!!"
350 If len(line) > 0 Then destfile.WriteLine(line)
351 line = srcfile.ReadLine()
352 Wend
354 ' Our generated content
355 destfile.WriteLine(data)
357 ' Everything below the !!FILES!! marker
358 While Not srcfile.AtEndOfStream
359 line = srcfile.ReadLine()
360 If len(line) > 0 Then destfile.WriteLine(line)
361 Wend
362 srcfile.Close()
363 destfile.Close()
364 End Sub
366 Dim ROOT_DIR
367 ROOT_DIR = FSO.GetFolder("..").Path
368 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
369 ROOT_DIR = FSO.GetFolder(".").Path
370 End If
371 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
372 WScript.Echo "Can't find source.list, needed in order to make this run." _
373 & vbCrLf & "Please go to either the project dir, or the root dir of a clean SVN checkout."
374 WScript.Quit(1)
375 End If
377 headers_check ROOT_DIR & "/source.list", ROOT_DIR & "\src\" ' Backslashes needed for DoFiles
379 Dim openttd, openttdvcxproj, openttdfilters, openttdfiles
380 openttd = load_main_data(ROOT_DIR & "/source.list", openttdvcxproj, openttdfilters, openttdfiles)
381 generate openttd, ROOT_DIR & "/projects/openttd_vs80.vcproj", Null
382 generate openttd, ROOT_DIR & "/projects/openttd_vs90.vcproj", Null
383 generate openttdvcxproj, ROOT_DIR & "/projects/openttd_vs100.vcxproj", Null
384 generate openttdfiles, ROOT_DIR & "/projects/openttd_vs100.vcxproj.filters", openttdfilters
385 generate openttdvcxproj, ROOT_DIR & "/projects/openttd_vs140.vcxproj", Null
386 generate openttdfiles, ROOT_DIR & "/projects/openttd_vs140.vcxproj.filters", openttdfilters
388 Dim lang, langvcxproj, langfiles
389 lang = load_lang_data(ROOT_DIR & "/src/lang", langvcxproj, langfiles)
390 generate lang, ROOT_DIR & "/projects/langs_vs80.vcproj", Null
391 generate lang, ROOT_DIR & "/projects/langs_vs90.vcproj", Null
392 generate langvcxproj, ROOT_DIR & "/projects/langs_vs100.vcxproj", Null
393 generate langfiles, ROOT_DIR & "/projects/langs_vs100.vcxproj.filters", Null
394 generate langvcxproj, ROOT_DIR & "/projects/langs_vs140.vcxproj", Null
395 generate langfiles, ROOT_DIR & "/projects/langs_vs140.vcxproj.filters", Null
397 Dim settings, settingsvcxproj, settingscommand, settingsfiles
398 settings = load_settings_data(ROOT_DIR & "/src/table", settingsvcxproj, settingscommand, settingsfiles)
399 generate settings, ROOT_DIR & "/projects/settings_vs80.vcproj", settingscommand
400 generate settings, ROOT_DIR & "/projects/settings_vs90.vcproj", settingscommand
401 generate settingsvcxproj, ROOT_DIR & "/projects/settings_vs100.vcxproj", settingscommand
402 generate settingsfiles, ROOT_DIR & "/projects/settings_vs100.vcxproj.filters", Null
403 generate settingsvcxproj, ROOT_DIR & "/projects/settings_vs140.vcxproj", settingscommand
404 generate settingsfiles, ROOT_DIR & "/projects/settings_vs140.vcxproj.filters", Null