Introduce CHashTableEntryT
[openttd/fttd.git] / projects / generate.vbs
blobbf47a451a344fe817b767542fd29f6bb6ee38ec5
1 Option Explicit
3 ' $Id$
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/>.
10 Dim FSO
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)
37 Dim file, filename
38 Dim rekeep, reskip
40 ' pattern for files to keep
41 Set rekeep = New RegExp
42 rekeep.Pattern = "\.h(pp)?$"
43 rekeep.Global = True
45 ' pattern for files to exclude
46 Set reskip = New RegExp
47 reskip.Pattern = "\.svn"
48 reskip.Global = True
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
55 End If
56 Next
57 End Sub
59 Sub get_dir_files(srcdir, dir, list)
60 Dim folder
61 ' Get files
62 get_files srcdir, dir, list
64 ' Recurse in subfolders
65 For Each folder in dir.SubFolders
66 get_dir_files srcdir, folder, list
67 Next
68 End Sub
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"
76 regexp.Global = True
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
85 End If
86 Wend
87 file.Close()
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
97 End If
98 Next
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
104 End If
105 Next
107 ' Display the missing files if any
108 If str <> "" Then
109 str = "The following headers are missing in source.list and not in /src/ or vice versa." _
110 & vbCrLf & str
111 WScript.Echo str
112 End If
113 End Sub
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
117 Dim configs(3)
118 configs(0) = "Release|Win32"
119 configs(1) = "Debug|Win32"
120 configs(2) = "Release|x64"
121 configs(3) = "Debug|x64"
122 res = ""
123 index = 0
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)
130 Case "#end"
131 If deep = skip Then skip = skip - 1
132 deep = deep - 1
133 Case "#else"
134 If deep = skip Then
135 skip = skip - 1
136 ElseIf deep - 1 = skip Then
137 skip = skip + 1
138 End If
139 Case "#if"
140 line = Replace(line, "#if ", "")
141 If deep = skip And ( _
142 line = "SDL" Or _
143 line = "PNG" Or _
144 line = "WIN32" Or _
145 line = "MSVC" Or _
146 line = "DIRECTMUSIC" Or _
147 line = "AI" Or _
148 line = "SSE" Or _
149 line = "HAVE_THREAD" _
150 ) Then skip = skip + 1
151 deep = deep + 1
152 Case "#"
153 if deep = skip Then
154 line = Replace(line, "# ", "")
155 if first_filter <> 0 Then
156 res = res & " </Filter>" & vbCrLf
157 filters = filters & vbCrLf
158 Else
159 first_filter = 1
160 End If
161 filter = line
162 res = res & _
163 " <Filter" & vbCrLf & _
164 " Name=" & Chr(34) & filter & Chr(34) & vbCrLf & _
165 " >" & 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 & _
169 " </Filter>"
170 index = index + 1
171 End If
172 Case Else
173 If deep = skip Then
174 line = Replace(line, "/" ,"\")
175 if first_file <> 0 Then
176 vcxproj = vcxproj & vbCrLf
177 files = files & vbCrLf
178 Else
179 first_file = 1
180 End If
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, "\") & "\"
186 Else
187 outdir = ""
188 End If
189 res = res & _
190 " <File" & vbCrLf & _
191 " RelativePath=" & Chr(34) & ".\..\src\" & line & Chr(34) & vbCrLf & _
192 " >" & vbCrLf
193 If ext = "cpp" And outdir <> "" Then
194 For Each config In configs
195 res = res & _
196 " <FileConfiguration" & vbCrLf & _
197 " Name=" & Chr(34) & config & Chr(34) & vbCrLf & _
198 " >" & 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 & _
204 " />" & vbCrLf & _
205 " </FileConfiguration>" & vbCrLf
206 Next
207 End If
208 res = res & _
209 " </File>" & vbCrLf
210 Select Case ext
211 Case "cpp"
212 cltype = "ClCompile"
213 Case "rc"
214 cltype = "ResourceCompile"
215 Case Else
216 cltype = "ClInclude"
217 End Select
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 & _
224 " </ClCompile>"
225 Else
226 vcxproj = vcxproj & " <" & cltype & " Include="& Chr(34) & "..\src\" & line & Chr(34) & " />"
227 End If
228 files = files & _
229 " <" & cltype & " Include="& Chr(34) & "..\src\" & line & Chr(34) & ">" & vbCrLf & _
230 " <Filter>" & filter & "</Filter>" & vbCrLf & _
231 " </" & cltype & ">"
232 End If
233 End Select
234 End If
235 Wend
236 res = res & " </Filter>"
237 file.Close()
238 load_main_data = res
239 End Function
241 Function load_lang_data(dir, ByRef vcxproj, ByRef files)
242 Dim res, folder, file, first_time
243 res = ""
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
250 res = res & vbCrLf
251 vcxproj = vcxproj & vbCrLf
252 files = files & vbCrLf
253 Else
254 first_time = 1
255 End If
256 res = res & _
257 " <File" & vbCrLf & _
258 " RelativePath=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & vbCrLf & _
259 " >" & vbCrLf & _
260 " <FileConfiguration" & vbCrLf & _
261 " Name=" & Chr(34) & "Debug|Win32" & Chr(34) & vbCrLf & _
262 " >" & 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 &quot;$(InputPath)&quot;&#x0D;&#x0A;exit 0&#x0D;&#x0A;" & 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 & _
269 " />" & vbCrLf & _
270 " </FileConfiguration>" & vbCrLf & _
271 " </File>"
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 & _
278 " </CustomBuild>"
279 files = files & _
280 " <CustomBuild Include=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) & ">" & vbCrLf & _
281 " <Filter>Translations</Filter>" & vbCrLf & _
282 " </CustomBuild>"
283 End If
284 Next
285 load_lang_data = res
286 End Function
288 Function load_settings_data(dir, ByRef vcxproj, ByRef command, ByRef files)
289 Dim res, folder, file, first_time
290 res = ""
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
297 res = res & vbCrLf
298 vcxproj = vcxproj & vbCrLf
299 files = files & vbCrLf
300 Else
301 first_time = 1
302 End If
303 res = res & _
304 " <File" & vbCrLf & _
305 " RelativePath=" & Chr(34) & "..\src\table\" & file & Chr(34) & vbCrLf & _
306 " >" & vbCrLf & _
307 " </File>"
308 vcxproj = vcxproj & _
309 " <None Include=" & Chr(34) & "..\src\table\" & file & Chr(34) & " />"
310 command = command & " ..\src\table\" & file
311 files = files & _
312 " <None Include=" & Chr(34) & "..\src\table\" & file & Chr(34) & ">" & vbCrLf & _
313 " <Filter>INI</Filter>" & vbCrLf & _
314 " </None>"
315 End If
316 Next
317 load_settings_data = res
318 End Function
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()
332 Wend
334 ' Our generated content
335 destfile.WriteLine(data2)
336 End If
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()
343 Wend
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)
352 Wend
353 srcfile.Close()
354 destfile.Close()
355 End Sub
357 Dim ROOT_DIR
358 ROOT_DIR = FSO.GetFolder("..").Path
359 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
360 ROOT_DIR = FSO.GetFolder(".").Path
361 End If
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."
365 WScript.Quit(1)
366 End If
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