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/>.
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
45 Set regexp
= New RegExp
46 regexp
.Pattern
= "#|ottdres.rc|win32.cpp|win32_v.cpp"
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 !!" _
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." _
65 & vbCrLf
& " !! ERROR !!"
74 Sub get_files(srcdir
, dir
, list
)
78 ' pattern for files to keep
79 Set rekeep
= New RegExp
80 rekeep
.Pattern
= "\.h(pp)?$"
83 ' pattern for files to exclude
84 Set reskip = New RegExp
85 reskip.Pattern = "\
.svn
"
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
97 Sub get_dir_files(srcdir, dir, list)
100 get_files srcdir, dir, list
102 ' Recurse in subfolders
103 For Each folder in dir.SubFolders
104 get_dir_files srcdir, folder, list
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
"
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
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
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
145 ' Display the missing files if any
147 str = "The following headers are missing
in source
.list
and not in /src
/ or vice versa
." _
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
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)
163 If deep = skip Then skip = skip - 1
168 ElseIf deep - 1 = skip Then
172 line = Replace(line, "#
if ", "")
173 If deep = skip And ( _
178 line = "DIRECTMUSIC
" Or _
180 line = "USE_SSE
" Or _
181 line = "USE_XAUDIO2
" Or _
182 line = "USE_THREADS
" _
183 ) Then skip = skip + 1
187 line = Replace(line, "#
", "")
188 if first_filter <> 0 Then
189 filters = filters & vbCrLf
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 & _
202 line = Replace(line, "/" ,"\
")
203 if first_file <> 0 Then
204 vcxproj = vcxproj & vbCrLf
205 files = files & vbCrLf
209 Select Case Split(Line, ".")(1)
213 cltype = "ResourceCompile
"
217 vcxproj = vcxproj & " <" & cltype & " Include
="& Chr(34) & "..\src\
" & line & Chr(34) & " />"
219 " <" & cltype & " Include
="& Chr(34) & "..\src\
" & line & Chr(34) & ">" & vbCrLf & _
220 " <Filter
>" & filter & "</Filter
>" & vbCrLf & _
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
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 & _
250 " <CustomBuild Include
=" & Chr(34) & "..\src\lang\
" & file & ".txt
" & Chr(34) & ">" & vbCrLf & _
251 " <Filter
>Translations
</Filter
>" & vbCrLf & _
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
270 vcxproj = vcxproj & _
271 " <None Include
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & " />"
272 command = command & " ..\src\table\
" & file
274 " <None Include
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & ">" & vbCrLf & _
275 " <Filter
>INI
</Filter
>" & vbCrLf & _
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)
285 For Each file In folder.Files
286 If first_time <> 0 Then
291 file = FSO.GetFileName(file)
292 ext = FSO.GetExtensionName(file)
293 langs = langs & "..\src\lang\
" & file
295 langs = langs & "</Langs
>"
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
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 & _
316 " <CustomBuild Include
=" & Chr(34) & "..\media\baseset\
" & file & Chr(34) & ">" & vbCrLf & _
317 " <Filter
>Baseset Metadata
</Filter
>" & vbCrLf & _
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()
337 ' Our generated content
338 destfile.WriteLine(data2)
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()
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)
361 ROOT_DIR = FSO.GetFolder("..").Path
362 If Not FSO.FileExists(ROOT_DIR & "/source
.list
") Then
363 ROOT_DIR = FSO.GetFolder(".").Path
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."
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