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