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_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
)
49 ' pattern for files to keep
50 Set rekeep
= New RegExp
51 rekeep
.Pattern
= "\.h(pp)?$"
54 ' pattern for files to exclude
55 Set reskip = New RegExp
56 reskip.Pattern = "\
.svn
"
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
68 Sub get_dir_files(srcdir, dir, list)
71 get_files srcdir, dir, list
73 ' Recurse in subfolders
74 For Each folder in dir.SubFolders
75 get_dir_files srcdir, folder, list
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
"
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
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
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
116 ' Display the missing files if any
118 str = "The following headers are missing
in source
.list
and not in /src
/ or vice versa
." _
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
127 configs(0) = "Release|Win32
"
128 configs(1) = "Debug|Win32
"
129 configs(2) = "Release|x64
"
130 configs(3) = "Debug|x64
"
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)
140 If deep = skip Then skip = skip - 1
145 ElseIf deep - 1 = skip Then
149 line = Replace(line, "#
if ", "")
150 If deep = skip And ( _
155 line = "DIRECTMUSIC
" Or _
158 line = "HAVE_THREAD
" _
159 ) Then skip = skip + 1
163 line = Replace(line, "#
", "")
164 if first_filter <> 0 Then
165 res = res & " </Filter
>" & vbCrLf
166 filters = filters & vbCrLf
172 " <Filter
" & vbCrLf & _
173 " Name
=" & Chr(34) & filter & Chr(34) & 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 & _
183 line = Replace(line, "/" ,"\
")
184 if first_file <> 0 Then
185 vcxproj = vcxproj & vbCrLf
186 files = files & vbCrLf
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
, "\") & "\"
199 " <File" & vbCrLf
& _
200 " RelativePath=" & Chr(34) & ".\..\src\" & line
& Chr(34) & vbCrLf
& _
202 If ext
= "cpp" And outdir
<> "" Then
203 For Each config
In configs
205 " <FileConfiguration" & vbCrLf
& _
206 " Name=" & Chr(34) & config
& Chr(34) & 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
& _
214 " </FileConfiguration>" & vbCrLf
223 cltype
= "ResourceCompile"
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
& _
235 vcxproj
= vcxproj
& " <" & cltype
& " Include="& Chr(34) & "..\src\" & line
& Chr(34) & " />"
238 " <" & cltype
& " Include="& Chr(34) & "..\src\" & line
& Chr(34) & ">" & vbCrLf
& _
239 " <Filter>" & filter
& "</Filter>" & vbCrLf
& _
245 res
= res
& " </Filter>"
250 Function load_lang_data(dir
, ByRef vcxproj
, ByRef files
)
251 Dim res
, folder
, file
, first_time
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
260 vcxproj
= vcxproj
& vbCrLf
261 files
= files
& vbCrLf
266 " <File" & vbCrLf
& _
267 " RelativePath=" & Chr(34) & "..\src\lang\" & file
& ".txt" & Chr(34) & vbCrLf
& _
269 " <FileConfiguration" & vbCrLf
& _
270 " Name=" & Chr(34) & "Debug|Win32" & Chr(34) & 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 "$(InputPath)"
exit 0
" & 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
& _
279 " </FileConfiguration>" & vbCrLf
& _
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 & _
289 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file
& ".txt" & Chr(34) & ">" & vbCrLf
& _
290 " <Filter>Translations</Filter>" & vbCrLf
& _
297 Function load_settings_data(dir
, ByRef vcxproj
, ByRef command
, ByRef files
)
298 Dim res
, folder
, file
, first_time
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
307 vcxproj
= vcxproj
& vbCrLf
308 files
= files
& vbCrLf
313 " <File" & vbCrLf
& _
314 " RelativePath=" & Chr(34) & "..\src\table\" & file
& Chr(34) & vbCrLf
& _
317 vcxproj
= vcxproj
& _
318 " <None Include=" & Chr(34) & "..\src\table\" & file
& Chr(34) & " />"
319 command
= command
& " ..\src\table\" & file
321 " <None Include=" & Chr(34) & "..\src\table\" & file
& Chr(34) & ">" & vbCrLf
& _
322 " <Filter>INI</Filter>" & vbCrLf
& _
326 load_settings_data
= res
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()
343 ' Our generated content
344 destfile
.WriteLine(data2
)
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()
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
)
367 ROOT_DIR
= FSO
.GetFolder("..").Path
368 If Not FSO
.FileExists(ROOT_DIR
& "/source.list") Then
369 ROOT_DIR
= FSO
.GetFolder(".").Path
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."
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