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_vs100.sln is for MSVC 2010
14 ' openttd_vs100.vcxproj is for MSVC 2010
15 ' openttd_vs100.vcxproj.filters is for MSVC 2010
16 ' langs_vs100.vcxproj is for MSVC 2010
17 ' strgen_vs100.vcxproj is for MSVC 2010
18 ' strgen_vs100.vcxproj.filters is for MSVC 2010
19 ' generate_vs100.vcxproj is for MSVC 2010
20 ' version_vs100.vcxproj is for MSVC 2010
22 ' openttd_vs90.sln is for MSVC 2008
23 ' openttd_vs90.vcproj is for MSVC 2008
24 ' langs_vs90.vcproj is for MSVC 2008
25 ' strgen_vs90.vcproj is for MSVC 2008
26 ' generate_vs90.vcproj is for MSVC 2008
27 ' version_vs90.vcproj is for MSVC 2008
29 ' openttd_vs80.sln is for MSVC 2005
30 ' openttd_vs80.vcproj is for MSVC 2005
31 ' langs_vs80.vcproj is for MSVC 2005
32 ' strgen_vs80.vcproj is for MSVC 2005
33 ' generate_vs80.vcproj is for MSVC 2005
34 ' version_vs80.vcproj is for MSVC 2005
36 Sub get_files(srcdir
, dir
, list
)
40 ' pattern for files to keep
41 Set rekeep
= New RegExp
42 rekeep
.Pattern
= "\.h(pp)?$"
45 ' pattern for files to exclude
46 Set reskip = New RegExp
47 reskip.Pattern = "\
.svn
"
50 For Each file in dir.Files
51 filename = Replace(file.path, srcdir, "") ' Remove */src/
52 filename = Replace(filename, "\
", "/") ' Replace separators
53 If rekeep.Test(filename) And Not reskip.Test(filename) Then
54 list.Add filename, filename
59 Sub get_dir_files(srcdir, dir, list)
62 get_files srcdir, dir, list
64 ' Recurse in subfolders
65 For Each folder in dir.SubFolders
66 get_dir_files srcdir, folder, list
70 Sub headers_check(filename, dir)
71 Dim source_list_headers, src_dir_headers, regexp, line, file, str
73 ' Define regexp for source.list parsing
74 Set regexp = New RegExp
75 regexp.Pattern = "\
.h
"
78 ' Parse source.list and store headers in a dictionary
79 Set source_list_headers = CreateObject("Scripting
.Dictionary
")
80 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
81 While Not file.AtEndOfStream
82 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
83 If Len(line) > 0 And regexp.Test(line) And line <> "../objs
/langs
/table
/strings
.h
" And line <> "../objs
/settings
/table
/settings
.h
" Then
84 source_list_headers.Add line, line
89 ' Get header files in /src/
90 Set src_dir_headers = CreateObject("Scripting
.Dictionary
")
91 get_dir_files dir, FSO.GetFolder(dir), src_dir_headers
93 ' Finding files in source.list but not in /src/
94 For Each line In source_list_headers
95 If Not src_dir_headers.Exists(line) Then
96 str = str & "< " & line & vbCrLf
100 ' Finding files in /src/ but not in source.list
101 For Each line In src_dir_headers
102 If Not source_list_headers.Exists(line) Then
103 str = str & "> " & line & vbCrLf
107 ' Display the missing files if any
109 str = "The following headers are missing
in source
.list
and not in /src
/ or vice versa
." _
115 Function load_main_data(filename, ByRef vcxproj, ByRef filters, ByRef files)
116 Dim res, file, line, deep, skip, first_filter, first_file, filter, cltype, index, ext, pathelems, outdir, config
118 configs(0) = "Release|Win32
"
119 configs(1) = "Debug|Win32
"
120 configs(2) = "Release|x64
"
121 configs(3) = "Debug|x64
"
124 ' Read the source.list and process it
125 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
126 While Not file.AtEndOfStream
127 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
128 If Len(line) > 0 Then
129 Select Case Split(line, " ")(0)
131 If deep = skip Then skip = skip - 1
136 ElseIf deep - 1 = skip Then
140 line = Replace(line, "#
if ", "")
141 If deep = skip And ( _
146 line = "DIRECTMUSIC
" Or _
149 line = "HAVE_THREAD
" _
150 ) Then skip = skip + 1
154 line = Replace(line, "#
", "")
155 if first_filter <> 0 Then
156 res = res & " </Filter
>" & vbCrLf
157 filters = filters & vbCrLf
163 " <Filter
" & vbCrLf & _
164 " Name
=" & Chr(34) & filter & Chr(34) & vbCrLf & _
166 filters = filters & _
167 " <Filter Include
="& Chr(34) & filter & Chr(34) & ">" & vbCrLf & _
168 " <UniqueIdentifier
>{c76ff9f1
-1e62
-46d8
-8d55
-" & String(12 - Len(CStr(index)), "0") & index & "}</UniqueIdentifier
>" & vbCrLf & _
174 line = Replace(line, "/" ,"\
")
175 if first_file <> 0 Then
176 vcxproj = vcxproj & vbCrLf
177 files = files & vbCrLf
181 ext = Split(Line, ".")(1)
182 pathelems = Split(Line, "\
")
183 If UBound(pathelems) > 0 Then
184 ReDim Preserve pathelems(UBound(pathelems) - 1)
185 outdir = "$(IntDir)\" & Join(pathelems
, "\") & "\"
190 " <File" & vbCrLf
& _
191 " RelativePath=" & Chr(34) & ".\..\src\" & line
& Chr(34) & vbCrLf
& _
193 If ext
= "cpp" And outdir
<> "" Then
194 For Each config
In configs
196 " <FileConfiguration" & vbCrLf
& _
197 " Name=" & Chr(34) & config
& Chr(34) & vbCrLf
& _
199 " <Tool" & vbCrLf
& _
200 " Name=" & Chr(34) & "VCCLCompilerTool" & Chr(34) & vbCrLf
& _
201 " AssemblerListingLocation=" & Chr(34) & outdir
& Chr(34) & vbCrLf
& _
202 " ObjectFile=" & Chr(34) & outdir
& Chr(34) & vbCrLf
& _
203 " XMLDocumentationFileName=" & Chr(34) & outdir
& Chr(34) & vbCrLf
& _
205 " </FileConfiguration>" & vbCrLf
214 cltype
= "ResourceCompile"
218 If ext
= "cpp" And outdir
<> "" Then
219 vcxproj
= vcxproj
& _
220 " <ClCompile Include=" & Chr(34) & "..\src\" & line
& Chr(34) & ">" & vbCrLf
& _
221 " <AssemblerListingLocation>" & outdir
& "</AssemblerListingLocation>" & vbCrLf
& _
222 " <ObjectFileName>" & outdir
& "</ObjectFileName>" & vbCrLf
& _
223 " <XMLDocumentationFileName>" & outdir
& "</XMLDocumentationFileName>" & vbCrLf
& _
226 vcxproj
= vcxproj
& " <" & cltype
& " Include="& Chr(34) & "..\src\" & line
& Chr(34) & " />"
229 " <" & cltype
& " Include="& Chr(34) & "..\src\" & line
& Chr(34) & ">" & vbCrLf
& _
230 " <Filter>" & filter
& "</Filter>" & vbCrLf
& _
236 res
= res
& " </Filter>"
241 Function load_lang_data(dir
, ByRef vcxproj
, ByRef files
)
242 Dim res
, folder
, file
, first_time
244 Set folder
= FSO
.GetFolder(dir
)
245 For Each file
In folder
.Files
246 file
= FSO
.GetFileName(file
)
247 If file
<> "english.txt" And FSO
.GetExtensionName(file
) = "txt" Then
248 file
= Left(file
, Len(file
) - 4)
249 If first_time
<> 0 Then
251 vcxproj
= vcxproj
& vbCrLf
252 files
= files
& vbCrLf
257 " <File" & vbCrLf
& _
258 " RelativePath=" & Chr(34) & "..\src\lang\" & file
& ".txt" & Chr(34) & vbCrLf
& _
260 " <FileConfiguration" & vbCrLf
& _
261 " Name=" & Chr(34) & "Debug|Win32" & Chr(34) & vbCrLf
& _
263 " <Tool" & vbCrLf
& _
264 " Name=" & Chr(34) & "VCCustomBuildTool" & Chr(34) & vbCrLf
& _
265 " Description=" & Chr(34) & "Generating " & file
& " language file" & Chr(34) & vbCrLf
& _
266 " CommandLine=" & Chr(34) & "..\objs\strgen\strgen.exe -s ..\src\lang -d ..\bin\lang "$(InputPath)"
exit 0
" & Chr(34) & vbCrLf
& _
267 " AdditionalDependencies=" & Chr(34) & "..\src\lang\english.txt;..\objs\strgen\strgen.exe" & Chr(34) & vbCrLf
& _
268 " Outputs=" & Chr(34) & "..\bin\lang\" & file
& ".lng" & Chr(34) & vbCrLf
& _
270 " </FileConfiguration>" & vbCrLf
& _
272 vcxproj
= vcxproj
& _
273 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file
& ".txt" & Chr(34) & ">" & vbCrLf
& _
274 " <Message Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">Generating
" & file & " language file
</Message
>" & vbCrLf & _
275 " <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 & _
276 " <AdditionalInputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\src\lang\english
.txt
;..\objs\strgen\strgen
.exe
;%(AdditionalInputs
)</AdditionalInputs
>" & vbCrLf & _
277 " <Outputs Condition
=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\bin\lang\" & file & ".lng;%(Outputs)</Outputs>" & vbCrLf & _
280 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file
& ".txt" & Chr(34) & ">" & vbCrLf
& _
281 " <Filter>Translations</Filter>" & vbCrLf
& _
288 Function load_settings_data(dir
, ByRef vcxproj
, ByRef command
, ByRef files
)
289 Dim res
, folder
, file
, first_time
291 command
= "..\objs\settings\settings_gen.exe -o ..\objs\settings\table\settings.h -b ..\src\table\settings.h.preamble -a ..\src\table\settings.h.postamble"
292 Set folder
= FSO
.GetFolder(dir
)
293 For Each file
In folder
.Files
294 file
= FSO
.GetFileName(file
)
295 If FSO
.GetExtensionName(file
) = "ini" Then
296 if first_time
<> 0 Then
298 vcxproj
= vcxproj
& vbCrLf
299 files
= files
& vbCrLf
304 " <File" & vbCrLf
& _
305 " RelativePath=" & Chr(34) & "..\src\table\" & file
& Chr(34) & vbCrLf
& _
308 vcxproj
= vcxproj
& _
309 " <None Include=" & Chr(34) & "..\src\table\" & file
& Chr(34) & " />"
310 command
= command
& " ..\src\table\" & file
312 " <None Include=" & Chr(34) & "..\src\table\" & file
& Chr(34) & ">" & vbCrLf
& _
313 " <Filter>INI</Filter>" & vbCrLf
& _
317 load_settings_data
= res
320 Sub generate(data
, dest
, data2
)
321 Dim srcfile
, destfile
, line
322 WScript
.Echo
"Generating " & FSO
.GetFileName(dest
) & "..."
323 Set srcfile
= FSO
.OpenTextFile(dest
& ".in", 1, 0, 0)
324 Set destfile
= FSO
.CreateTextFile(dest
, -1, 0)
326 If Not IsNull(data2
) Then
327 ' Everything above the !!FILTERS!! marker
328 line
= srcfile
.ReadLine()
329 While line
<> "!!FILTERS!!"
330 If len(line
) > 0 Then destfile
.WriteLine(line
)
331 line
= srcfile
.ReadLine()
334 ' Our generated content
335 destfile
.WriteLine(data2
)
338 ' Everything above the !!FILES!! marker
339 line
= srcfile
.ReadLine()
340 While line
<> "!!FILES!!"
341 If len(line
) > 0 Then destfile
.WriteLine(line
)
342 line
= srcfile
.ReadLine()
345 ' Our generated content
346 destfile
.WriteLine(data
)
348 ' Everything below the !!FILES!! marker
349 While Not srcfile
.AtEndOfStream
350 line
= srcfile
.ReadLine()
351 If len(line
) > 0 Then destfile
.WriteLine(line
)
358 ROOT_DIR
= FSO
.GetFolder("..").Path
359 If Not FSO
.FileExists(ROOT_DIR
& "/source.list") Then
360 ROOT_DIR
= FSO
.GetFolder(".").Path
362 If Not FSO
.FileExists(ROOT_DIR
& "/source.list") Then
363 WScript
.Echo
"Can't find source.list, needed in order to make this run." _
364 & vbCrLf
& "Please go to either the project dir, or the root dir of a clean SVN checkout."
368 headers_check ROOT_DIR
& "/source.list", ROOT_DIR
& "\src\" ' Backslashes needed for DoFiles
370 Dim openttd
, openttdvcxproj
, openttdfilters
, openttdfiles
371 openttd
= load_main_data(ROOT_DIR
& "/source.list", openttdvcxproj
, openttdfilters
, openttdfiles
)
372 generate openttd
, ROOT_DIR
& "/projects/openttd_vs80.vcproj", Null
373 generate openttd
, ROOT_DIR
& "/projects/openttd_vs90.vcproj", Null
374 generate openttdvcxproj
, ROOT_DIR
& "/projects/openttd_vs100.vcxproj", Null
375 generate openttdfiles
, ROOT_DIR
& "/projects/openttd_vs100.vcxproj.filters", openttdfilters
377 Dim lang
, langvcxproj
, langfiles
378 lang
= load_lang_data(ROOT_DIR
& "/src/lang", langvcxproj
, langfiles
)
379 generate lang
, ROOT_DIR
& "/projects/langs_vs80.vcproj", Null
380 generate lang
, ROOT_DIR
& "/projects/langs_vs90.vcproj", Null
381 generate langvcxproj
, ROOT_DIR
& "/projects/langs_vs100.vcxproj", Null
382 generate langfiles
, ROOT_DIR
& "/projects/langs_vs100.vcxproj.filters", Null
384 Dim settings
, settingsvcxproj
, settingscommand
, settingsfiles
385 settings
= load_settings_data(ROOT_DIR
& "/src/table", settingsvcxproj
, settingscommand
, settingsfiles
)
386 generate settings
, ROOT_DIR
& "/projects/settings_vs80.vcproj", settingscommand
387 generate settings
, ROOT_DIR
& "/projects/settings_vs90.vcproj", settingscommand
388 generate settingsvcxproj
, ROOT_DIR
& "/projects/settings_vs100.vcxproj", settingscommand
389 generate settingsfiles
, ROOT_DIR
& "/projects/settings_vs100.vcxproj.filters", Null