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/>.
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
58 Set regexp
= New RegExp
59 regexp
.Pattern
= "#|ottdres.rc|win32.cpp|win32_v.cpp"
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 !!" _
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." _
78 & vbCrLf
& " !! ERROR !!"
87 Sub get_files(srcdir
, dir
, list
)
91 ' pattern for files to keep
92 Set rekeep
= New RegExp
93 rekeep
.Pattern
= "\.h(pp)?$"
96 ' pattern for files to exclude
97 Set reskip = New RegExp
98 reskip.Pattern = "\
.svn
"
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
110 Sub get_dir_files(srcdir, dir, list)
113 get_files srcdir, dir, list
115 ' Recurse in subfolders
116 For Each folder in dir.SubFolders
117 get_dir_files srcdir, folder, list
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
"
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
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
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
158 ' Display the missing files if any
160 str = "The following headers are missing
in source
.list
and not in /src
/ or vice versa
." _
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
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)
177 If deep = skip Then skip = skip - 1
182 ElseIf deep - 1 = skip Then
186 line = Replace(line, "#
if ", "")
187 If deep = skip And ( _
192 line = "DIRECTMUSIC
" Or _
195 line = "HAVE_THREAD
" _
196 ) Then skip = skip + 1
200 line = Replace(line, "#
", "")
201 if first_filter <> 0 Then
202 res = res & " </Filter
>" & vbCrLf
203 filters = filters & vbCrLf
209 " <Filter
" & vbCrLf & _
210 " Name
=" & Chr(34) & filter & Chr(34) & 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 & _
220 line = Replace(line, "/" ,"\
")
221 if first_file <> 0 Then
222 vcxproj = vcxproj & vbCrLf
223 files = files & vbCrLf
228 " <File
" & vbCrLf & _
229 " RelativePath
=" & Chr(34) & ".\
..\src\
" & line & Chr(34) & vbCrLf & _
232 Select Case Split(Line, ".")(1)
236 cltype = "ResourceCompile
"
240 vcxproj = vcxproj & " <" & cltype & " Include
="& Chr(34) & "..\src\
" & line & Chr(34) & " />"
242 " <" & cltype & " Include
="& Chr(34) & "..\src\
" & line & Chr(34) & ">" & vbCrLf & _
243 " <Filter
>" & filter & "</Filter
>" & vbCrLf & _
249 res = res & " </Filter
>"
254 Function load_lang_data(dir, ByRef vcxproj, ByRef files)
255 Dim res, folder, file, first_time
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
264 vcxproj = vcxproj & vbCrLf
265 files = files & vbCrLf
270 " <File
" & vbCrLf & _
271 " RelativePath
=" & Chr(34) & "..\src\lang\
" & file & ".txt
" & Chr(34) & vbCrLf & _
273 " <FileConfiguration
" & vbCrLf & _
274 " Name
=" & Chr(34) & "Debug|Win32
" & Chr(34) & 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
"
;$(InputPath)"
exit 0
;

;" & 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 & _
283 " </FileConfiguration
>" & vbCrLf & _
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 & _
293 " <CustomBuild Include
=" & Chr(34) & "..\src\lang\
" & file & ".txt
" & Chr(34) & ">" & vbCrLf & _
294 " <Filter
>Translations
</Filter
>" & vbCrLf & _
301 Function load_settings_data(dir, ByRef vcxproj, ByRef command, ByRef files)
302 Dim res, folder, file, first_time
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
311 vcxproj = vcxproj & vbCrLf
312 files = files & vbCrLf
317 " <File
" & vbCrLf & _
318 " RelativePath
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & vbCrLf & _
321 vcxproj = vcxproj & _
322 " <None Include
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & " />"
323 command = command & " ..\src\table\
" & file
325 " <None Include
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & ">" & vbCrLf & _
326 " <Filter
>INI
</Filter
>" & vbCrLf & _
330 load_settings_data = res
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()
347 ' Our generated content
348 destfile.WriteLine(data2)
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()
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)
371 ROOT_DIR = FSO.GetFolder("..").Path
372 If Not FSO.FileExists(ROOT_DIR & "/source
.list
") Then
373 ROOT_DIR = FSO.GetFolder(".").Path
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."
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