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_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
49 Set regexp
= New RegExp
50 regexp
.Pattern
= "#|ottdres.rc|win32.cpp|win32_v.cpp"
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 !!" _
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." _
69 & vbCrLf
& " !! ERROR !!"
78 Sub get_files(srcdir
, dir
, list
)
82 ' pattern for files to keep
83 Set rekeep
= New RegExp
84 rekeep
.Pattern
= "\.h(pp)?$"
87 ' pattern for files to exclude
88 Set reskip = New RegExp
89 reskip.Pattern = "\
.svn
"
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
101 Sub get_dir_files(srcdir, dir, list)
104 get_files srcdir, dir, list
106 ' Recurse in subfolders
107 For Each folder in dir.SubFolders
108 get_dir_files srcdir, folder, list
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
"
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
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
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
149 ' Display the missing files if any
151 str = "The following headers are missing
in source
.list
and not in /src
/ or vice versa
." _
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
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)
168 If deep = skip Then skip = skip - 1
173 ElseIf deep - 1 = skip Then
177 line = Replace(line, "#
if ", "")
178 If deep = skip And ( _
183 line = "DIRECTMUSIC
" Or _
186 line = "HAVE_THREAD
" _
187 ) Then skip = skip + 1
191 line = Replace(line, "#
", "")
192 if first_filter <> 0 Then
193 res = res & " </Filter
>" & vbCrLf
194 filters = filters & vbCrLf
200 " <Filter
" & vbCrLf & _
201 " Name
=" & Chr(34) & filter & Chr(34) & 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 & _
211 line = Replace(line, "/" ,"\
")
212 if first_file <> 0 Then
213 vcxproj = vcxproj & vbCrLf
214 files = files & vbCrLf
219 " <File
" & vbCrLf & _
220 " RelativePath
=" & Chr(34) & ".\
..\src\
" & line & Chr(34) & vbCrLf & _
223 Select Case Split(Line, ".")(1)
227 cltype = "ResourceCompile
"
231 vcxproj = vcxproj & " <" & cltype & " Include
="& Chr(34) & "..\src\
" & line & Chr(34) & " />"
233 " <" & cltype & " Include
="& Chr(34) & "..\src\
" & line & Chr(34) & ">" & vbCrLf & _
234 " <Filter
>" & filter & "</Filter
>" & vbCrLf & _
240 res = res & " </Filter
>"
245 Function load_lang_data(dir, ByRef vcxproj, ByRef files)
246 Dim res, folder, file, first_time
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
255 vcxproj = vcxproj & vbCrLf
256 files = files & vbCrLf
261 " <File
" & vbCrLf & _
262 " RelativePath
=" & Chr(34) & "..\src\lang\
" & file & ".txt
" & Chr(34) & vbCrLf & _
264 " <FileConfiguration
" & vbCrLf & _
265 " Name
=" & Chr(34) & "Debug|Win32
" & Chr(34) & 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
"
;$(InputPath)"
exit 0
;

;" & 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 & _
274 " </FileConfiguration
>" & vbCrLf & _
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 & _
284 " <CustomBuild Include
=" & Chr(34) & "..\src\lang\
" & file & ".txt
" & Chr(34) & ">" & vbCrLf & _
285 " <Filter
>Translations
</Filter
>" & vbCrLf & _
292 Function load_settings_data(dir, ByRef vcxproj, ByRef command, ByRef files)
293 Dim res, folder, file, first_time
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
302 vcxproj = vcxproj & vbCrLf
303 files = files & vbCrLf
308 " <File
" & vbCrLf & _
309 " RelativePath
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & vbCrLf & _
312 vcxproj = vcxproj & _
313 " <None Include
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & " />"
314 command = command & " ..\src\table\
" & file
316 " <None Include
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & ">" & vbCrLf & _
317 " <Filter
>INI
</Filter
>" & vbCrLf & _
321 load_settings_data = res
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()
338 ' Our generated content
339 destfile.WriteLine(data2)
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()
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)
362 ROOT_DIR = FSO.GetFolder("..").Path
363 If Not FSO.FileExists(ROOT_DIR & "/source
.list
") Then
364 ROOT_DIR = FSO.GetFolder(".").Path
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."
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