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 safety_check(filename
)
37 Dim file
, line
, regexp
, list
40 Set regexp
= New RegExp
41 regexp
.Pattern
= "#|ottdres.rc|win32.cpp|win32_v.cpp"
44 ' We use a dictionary to check duplicates
45 Set list
= CreateObject("Scripting.Dictionary")
47 Set file
= FSO
.OpenTextFile(filename
, 1, 0, 0)
48 While Not file
.AtEndOfStream
49 line
= Replace(file
.ReadLine
, Chr(9), "") ' Remove tabs
50 If Len(line
) > 0 And Not regexp
.Test(line
) Then
51 line
= FSO
.GetFileName(line
)
52 if list
.Exists(line
) Then
53 WScript
.Echo
" !! ERROR !!" _
55 & vbCrLf
& "The filename '" & line
& "' is already used in this project." _
56 & vbCrLf
& "Because MSVC uses one single directory for all object files, it" _
57 & vbCrLf
& "cannot handle filenames with the same name inside the same project." _
58 & vbCrLf
& "Please rename either one of the file and try generating again." _
60 & vbCrLf
& " !! ERROR !!"
69 Sub get_files(srcdir
, dir
, list
)
73 ' pattern for files to keep
74 Set rekeep
= New RegExp
75 rekeep
.Pattern
= "\.h(pp)?$"
78 ' pattern for files to exclude
79 Set reskip = New RegExp
80 reskip.Pattern = "\
.svn
"
83 For Each file in dir.Files
84 filename = Replace(file.path, srcdir, "") ' Remove */src/
85 filename = Replace(filename, "\
", "/") ' Replace separators
86 If rekeep.Test(filename) And Not reskip.Test(filename) Then
87 list.Add filename, filename
92 Sub get_dir_files(srcdir, dir, list)
95 get_files srcdir, dir, list
97 ' Recurse in subfolders
98 For Each folder in dir.SubFolders
99 get_dir_files srcdir, folder, list
103 Sub headers_check(filename, dir)
104 Dim source_list_headers, src_dir_headers, regexp, line, file, str
106 ' Define regexp for source.list parsing
107 Set regexp = New RegExp
108 regexp.Pattern = "\
.h
"
111 ' Parse source.list and store headers in a dictionary
112 Set source_list_headers = CreateObject("Scripting
.Dictionary
")
113 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
114 While Not file.AtEndOfStream
115 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
116 If Len(line) > 0 And regexp.Test(line) And line <> "../objs
/langs
/table
/strings
.h
" And line <> "../objs
/settings
/table
/settings
.h
" Then
117 source_list_headers.Add line, line
122 ' Get header files in /src/
123 Set src_dir_headers = CreateObject("Scripting
.Dictionary
")
124 get_dir_files dir, FSO.GetFolder(dir), src_dir_headers
126 ' Finding files in source.list but not in /src/
127 For Each line In source_list_headers
128 If Not src_dir_headers.Exists(line) Then
129 str = str & "< " & line & vbCrLf
133 ' Finding files in /src/ but not in source.list
134 For Each line In src_dir_headers
135 If Not source_list_headers.Exists(line) Then
136 str = str & "> " & line & vbCrLf
140 ' Display the missing files if any
142 str = "The following headers are missing
in source
.list
and not in /src
/ or vice versa
." _
148 Function load_main_data(filename, ByRef vcxproj, ByRef filters, ByRef files)
149 Dim res, file, line, deep, skip, first_filter, first_file, filter, cltype, index
152 ' Read the source.list and process it
153 Set file = FSO.OpenTextFile(filename, 1, 0, 0)
154 While Not file.AtEndOfStream
155 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
156 If Len(line) > 0 Then
157 Select Case Split(line, " ")(0)
159 If deep = skip Then skip = skip - 1
164 ElseIf deep - 1 = skip Then
168 line = Replace(line, "#
if ", "")
169 If deep = skip And ( _
174 line = "DIRECTMUSIC
" Or _
176 line = "HAVE_THREAD
" _
177 ) Then skip = skip + 1
181 line = Replace(line, "#
", "")
182 if first_filter <> 0 Then
183 res = res & " </Filter
>" & vbCrLf
184 filters = filters & vbCrLf
190 " <Filter
" & vbCrLf & _
191 " Name
=" & Chr(34) & filter & Chr(34) & vbCrLf & _
193 filters = filters & _
194 " <Filter Include
="& Chr(34) & filter & Chr(34) & ">" & vbCrLf & _
195 " <UniqueIdentifier
>{c76ff9f1
-1e62
-46d8
-8d55
-" & String(12 - Len(CStr(index)), "0") & index & "}</UniqueIdentifier
>" & vbCrLf & _
201 line = Replace(line, "/" ,"\
")
202 if first_file <> 0 Then
203 vcxproj = vcxproj & vbCrLf
204 files = files & vbCrLf
209 " <File
" & vbCrLf & _
210 " RelativePath
=" & Chr(34) & ".\
..\src\
" & line & Chr(34) & vbCrLf & _
213 Select Case Split(Line, ".")(1)
217 cltype = "ResourceCompile
"
221 vcxproj = vcxproj & " <" & cltype & " Include
="& Chr(34) & "..\src\
" & line & Chr(34) & " />"
223 " <" & cltype & " Include
="& Chr(34) & "..\src\
" & line & Chr(34) & ">" & vbCrLf & _
224 " <Filter
>" & filter & "</Filter
>" & vbCrLf & _
230 res = res & " </Filter
>"
235 Function load_lang_data(dir, ByRef vcxproj, ByRef files)
236 Dim res, folder, file, first_time
238 Set folder = FSO.GetFolder(dir)
239 For Each file In folder.Files
240 file = FSO.GetFileName(file)
241 If file <> "english
.txt
" And FSO.GetExtensionName(file) = "txt
" Then
242 file = Left(file, Len(file) - 4)
243 If first_time <> 0 Then
245 vcxproj = vcxproj & vbCrLf
246 files = files & vbCrLf
251 " <File
" & vbCrLf & _
252 " RelativePath
=" & Chr(34) & "..\src\lang\
" & file & ".txt
" & Chr(34) & vbCrLf & _
254 " <FileConfiguration
" & vbCrLf & _
255 " Name
=" & Chr(34) & "Debug|Win32
" & Chr(34) & vbCrLf & _
257 " <Tool
" & vbCrLf & _
258 " Name
=" & Chr(34) & "VCCustomBuildTool
" & Chr(34) & vbCrLf & _
259 " Description
=" & Chr(34) & "Generating
" & file & " language file
" & Chr(34) & vbCrLf & _
260 " CommandLine
=" & Chr(34) & "..\objs\strgen\strgen
.exe
-s
..\src\lang
-d
..\bin\lang
"
;$(InputPath)"
exit 0
;

;" & Chr(34) & vbCrLf & _
261 " AdditionalDependencies
=" & Chr(34) & "..\src\lang\english
.txt
;..\objs\strgen\strgen
.exe
" & Chr(34) & vbCrLf & _
262 " Outputs
=" & Chr(34) & "..\bin\lang\
" & file & ".lng
" & Chr(34) & vbCrLf & _
264 " </FileConfiguration
>" & vbCrLf & _
266 vcxproj = vcxproj & _
267 " <CustomBuild Include
=" & Chr(34) & "..\src\lang\
" & file & ".txt
" & Chr(34) & ">" & vbCrLf & _
268 " <Message Condition
=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">Generating " & file & " language file</Message>" & vbCrLf & _
269 " <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 & _
270 " <AdditionalInputs Condition
=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\src\lang\english.txt;..\objs\strgen\strgen.exe;%(AdditionalInputs)</AdditionalInputs>" & vbCrLf & _
271 " <Outputs Condition=" & Chr(34) & "'$(Configuration)|$(Platform)'=='Debug|Win32'" & Chr(34) & ">..\bin\lang\
" & file & ".lng
;%(Outputs
)</Outputs
>" & vbCrLf & _
274 " <CustomBuild Include
=" & Chr(34) & "..\src\lang\
" & file & ".txt
" & Chr(34) & ">" & vbCrLf & _
275 " <Filter
>Translations
</Filter
>" & vbCrLf & _
282 Function load_settings_data(dir, ByRef vcxproj, ByRef command, ByRef files)
283 Dim res, folder, file, first_time
285 command = "..\objs\settings\settings_gen
.exe
-o
..\objs\settings\table\settings
.h
-b
..\src\table\settings
.h
.preamble
-a
..\src\table\settings
.h
.postamble
"
286 Set folder = FSO.GetFolder(dir)
287 For Each file In folder.Files
288 file = FSO.GetFileName(file)
289 If FSO.GetExtensionName(file) = "ini
" Then
290 if first_time <> 0 Then
292 vcxproj = vcxproj & vbCrLf
293 files = files & vbCrLf
298 " <File
" & vbCrLf & _
299 " RelativePath
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & vbCrLf & _
302 vcxproj = vcxproj & _
303 " <None Include
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & " />"
304 command = command & " ..\src\table\
" & file
306 " <None Include
=" & Chr(34) & "..\src\table\
" & file & Chr(34) & ">" & vbCrLf & _
307 " <Filter
>INI
</Filter
>" & vbCrLf & _
311 load_settings_data = res
314 Sub generate(data, dest, data2)
315 Dim srcfile, destfile, line
316 WScript.Echo "Generating
" & FSO.GetFileName(dest) & "..."
317 Set srcfile = FSO.OpenTextFile(dest & ".in", 1, 0, 0)
318 Set destfile = FSO.CreateTextFile(dest, -1, 0)
320 If Not IsNull(data2) Then
321 ' Everything above the !!FILTERS!! marker
322 line = srcfile.ReadLine()
323 While line <> "!!FILTERS
!!"
324 If len(line) > 0 Then destfile.WriteLine(line)
325 line = srcfile.ReadLine()
328 ' Our generated content
329 destfile.WriteLine(data2)
332 ' Everything above the !!FILES!! marker
333 line = srcfile.ReadLine()
334 While line <> "!!FILES
!!"
335 If len(line) > 0 Then destfile.WriteLine(line)
336 line = srcfile.ReadLine()
339 ' Our generated content
340 destfile.WriteLine(data)
342 ' Everything below the !!FILES!! marker
343 While Not srcfile.AtEndOfStream
344 line = srcfile.ReadLine()
345 If len(line) > 0 Then destfile.WriteLine(line)
352 ROOT_DIR = FSO.GetFolder("..").Path
353 If Not FSO.FileExists(ROOT_DIR & "/source
.list
") Then
354 ROOT_DIR = FSO.GetFolder(".").Path
356 If Not FSO.FileExists(ROOT_DIR & "/source
.list
") Then
357 WScript.Echo "Can
't find source.list, needed in order to make this run." _
358 & vbCrLf
& "Please go to either the project dir, or the root dir of a clean SVN checkout."
362 safety_check ROOT_DIR
& "/source.list"
363 headers_check ROOT_DIR
& "/source.list", ROOT_DIR
& "\src\" ' Backslashes needed for DoFiles
365 Dim openttd
, openttdvcxproj
, openttdfilters
, openttdfiles
366 openttd
= load_main_data(ROOT_DIR
& "/source.list", openttdvcxproj
, openttdfilters
, openttdfiles
)
367 generate openttd
, ROOT_DIR
& "/projects/openttd_vs80.vcproj", Null
368 generate openttd
, ROOT_DIR
& "/projects/openttd_vs90.vcproj", Null
369 generate openttdvcxproj
, ROOT_DIR
& "/projects/openttd_vs100.vcxproj", Null
370 generate openttdfiles
, ROOT_DIR
& "/projects/openttd_vs100.vcxproj.filters", openttdfilters
372 Dim lang
, langvcxproj
, langfiles
373 lang
= load_lang_data(ROOT_DIR
& "/src/lang", langvcxproj
, langfiles
)
374 generate lang
, ROOT_DIR
& "/projects/langs_vs80.vcproj", Null
375 generate lang
, ROOT_DIR
& "/projects/langs_vs90.vcproj", Null
376 generate langvcxproj
, ROOT_DIR
& "/projects/langs_vs100.vcxproj", Null
377 generate langfiles
, ROOT_DIR
& "/projects/langs_vs100.vcxproj.filters", Null
379 Dim settings
, settingsvcxproj
, settingscommand
, settingsfiles
380 settings
= load_settings_data(ROOT_DIR
& "/src/table", settingsvcxproj
, settingscommand
, settingsfiles
)
381 generate settings
, ROOT_DIR
& "/projects/settings_vs80.vcproj", settingscommand
382 generate settings
, ROOT_DIR
& "/projects/settings_vs90.vcproj", settingscommand
383 generate settingsvcxproj
, ROOT_DIR
& "/projects/settings_vs100.vcxproj", settingscommand
384 generate settingsfiles
, ROOT_DIR
& "/projects/settings_vs100.vcxproj.filters", Null