|
1 Option Explicit |
|
2 |
|
3 Dim FSO |
|
4 Set FSO = CreateObject("Scripting.FileSystemObject") |
|
5 |
|
6 ' openttd_vs90.sln is for MSVC 2008 |
|
7 ' openttd_vs90.vcproj is for MSVC 2008 |
|
8 ' langs_vs90.vcproj is for MSVC 2008 |
|
9 ' strgen_vs90.vcproj is for MSVC 2008 |
|
10 |
|
11 ' openttd_vs80.sln is for MSVC 2005 |
|
12 ' openttd_vs80.vcproj is for MSVC 2005 |
|
13 ' langs_vs80.vcproj is for MSVC 2005 |
|
14 ' strgen_vs80.vcproj is for MSVC 2005 |
|
15 |
|
16 Sub safety_check(filename) |
|
17 Dim file, line, regexp, list |
|
18 |
|
19 ' Define regexp |
|
20 Set regexp = New RegExp |
|
21 regexp.Pattern = "#|ottdres.rc|win32.cpp|win32_v.cpp" |
|
22 regexp.Global = True |
|
23 |
|
24 ' We use a dictionary to check duplicates |
|
25 Set list = CreateObject("Scripting.Dictionary") |
|
26 |
|
27 Set file = FSO.OpenTextFile(filename, 1, 0, 0) |
|
28 While Not file.AtEndOfStream |
|
29 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs |
|
30 If Len(line) > 0 And Not regexp.Test(line) Then |
|
31 line = FSO.GetFileName(line) |
|
32 if list.Exists(line) Then |
|
33 WScript.Echo " !! ERROR !!" _ |
|
34 & vbCrLf & "" _ |
|
35 & vbCrLf & "The filename '" & line & "' is already used in this project." _ |
|
36 & vbCrLf & "Because MSVC uses one single directory for all object files, it" _ |
|
37 & vbCrLf & "cannot handle filenames with the same name inside the same project." _ |
|
38 & vbCrLf & "Please rename either one of the file and try generating again." _ |
|
39 & vbCrLf & "" _ |
|
40 & vbCrLf & " !! ERROR !!" |
|
41 WScript.Quit(1) |
|
42 End If |
|
43 list.Add line, line |
|
44 End If |
|
45 Wend |
|
46 file.Close |
|
47 End Sub |
|
48 |
|
49 Function load_main_data(filename) |
|
50 Dim res, file, line, deep, skip, first_time |
|
51 res = "" |
|
52 ' Read the source.list and process it |
|
53 Set file = FSO.OpenTextFile(filename, 1, 0, 0) |
|
54 While Not file.AtEndOfStream |
|
55 line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs |
|
56 If Len(line) > 0 Then |
|
57 Select Case Split(line, " ")(0) |
|
58 Case "#end" |
|
59 If deep = skip Then skip = skip - 1 |
|
60 deep = deep - 1 |
|
61 Case "#else" |
|
62 If deep = skip Then |
|
63 skip = skip - 1 |
|
64 ElseIf deep - 1 = skip Then |
|
65 skip = skip + 1 |
|
66 End If |
|
67 Case "#if" |
|
68 line = Replace(line, "#if ", "") |
|
69 If deep = skip And ( _ |
|
70 line = "SDL" Or _ |
|
71 line = "PNG" Or _ |
|
72 line = "WIN32" Or _ |
|
73 line = "MSVC" Or _ |
|
74 line = "DIRECTMUSIC" Or _ |
|
75 line = "NO_THREADS" _ |
|
76 ) Then skip = skip + 1 |
|
77 deep = deep + 1 |
|
78 Case "#" |
|
79 if deep = skip Then |
|
80 line = Replace(line, "# ", "") |
|
81 if first_time <> 0 Then |
|
82 res = res & " </Filter>" & vbCrLf |
|
83 Else |
|
84 first_time = 1 |
|
85 End If |
|
86 res = res & _ |
|
87 " <Filter" & vbCrLf & _ |
|
88 " Name=" & Chr(34) & line & Chr(34) & vbCrLf & _ |
|
89 " >" & vbCrLf |
|
90 End If |
|
91 Case Else |
|
92 If deep = skip Then |
|
93 line = Replace(line, "/" ,"\") |
|
94 res = res & _ |
|
95 " <File" & vbCrLf & _ |
|
96 " RelativePath=" & Chr(34) & ".\..\src\" & line & Chr(34) & vbCrLf & _ |
|
97 " >" & vbCrLf & _ |
|
98 " </File>" & vbCrLf |
|
99 End If |
|
100 End Select |
|
101 End If |
|
102 Wend |
|
103 res = res & " </Filter>" |
|
104 file.Close() |
|
105 load_main_data = res |
|
106 End Function |
|
107 |
|
108 Function load_lang_data(dir) |
|
109 Dim res, folder, file |
|
110 res = "" |
|
111 Set folder = FSO.GetFolder(dir) |
|
112 For Each file In folder.Files |
|
113 file = FSO.GetFileName(file) |
|
114 If FSO.GetExtensionName(file) = "txt" Then |
|
115 file = Left(file, Len(file) - 4) |
|
116 res = res _ |
|
117 & vbCrLf & " <File" _ |
|
118 & vbCrLf & " RelativePath=" & Chr(34) & "..\src\lang\" & file & ".txt" & Chr(34) _ |
|
119 & vbCrLf & " >" _ |
|
120 & vbCrLf & " <FileConfiguration" _ |
|
121 & vbCrLf & " Name=" & Chr(34) & "Debug|Win32" & Chr(34) _ |
|
122 & vbCrLf & " >" _ |
|
123 & vbCrLf & " <Tool" _ |
|
124 & vbCrLf & " Name=" & Chr(34) & "VCCustomBuildTool" & Chr(34) _ |
|
125 & vbCrLf & " Description=" & Chr(34) & "Generating " & file & " language file" & Chr(34) _ |
|
126 & vbCrLf & " CommandLine=" & Chr(34) & "..\objs\strgen\strgen.exe -s ..\src\lang -d ..\bin\lang "$(InputPath)"
" & Chr(34) _ |
|
127 & vbCrLf & " AdditionalDependencies=" & Chr(34) & Chr(34) _ |
|
128 & vbCrLf & " Outputs=" & Chr(34) & "..\bin\lang\" & file & ".lng" & Chr(34) _ |
|
129 & vbCrLf & " />" _ |
|
130 & vbCrLf & " </FileConfiguration>" _ |
|
131 & vbCrLf & " </File>" |
|
132 End If |
|
133 Next |
|
134 load_lang_data = res |
|
135 End Function |
|
136 |
|
137 Sub generate(data, dest) |
|
138 Dim srcfile, destfile, line |
|
139 WScript.Echo "Generating " & FSO.GetFileName(dest) & "..." |
|
140 Set srcfile = FSO.OpenTextFile(dest & ".in", 1, 0, 0) |
|
141 Set destfile = FSO.CreateTextFile(dest, -1, 0) |
|
142 |
|
143 ' Everything above the !!FILES!! marker |
|
144 line = srcfile.ReadLine() |
|
145 While line <> "!!FILES!!" |
|
146 If len(line) > 0 Then destfile.WriteLine(line) |
|
147 line = srcfile.ReadLine() |
|
148 Wend |
|
149 |
|
150 ' Our generated content |
|
151 destfile.WriteLine(data) |
|
152 |
|
153 ' Everything below the !!FILES!! marker |
|
154 While Not srcfile.AtEndOfStream |
|
155 line = srcfile.ReadLine() |
|
156 If len(line) > 0 Then destfile.WriteLine(line) |
|
157 Wend |
|
158 srcfile.Close() |
|
159 destfile.Close() |
|
160 End Sub |
|
161 |
|
162 Dim ROOT_DIR |
|
163 ROOT_DIR = FSO.GetFolder("..").Path |
|
164 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then |
|
165 ROOT_DIR = FSO.GetFolder(".").Path |
|
166 End If |
|
167 If Not FSO.FileExists(ROOT_DIR & "/source.list") Then |
|
168 WScript.Echo "Can't find source.list, needed in order to make this run." _ |
|
169 & vbCrLf & "Please go to either the project dir, or the root dir of a clean SVN checkout." |
|
170 WScript.Quit(1) |
|
171 End If |
|
172 |
|
173 safety_check ROOT_DIR & "/source.list" |
|
174 |
|
175 Dim openttd |
|
176 openttd = load_main_data(ROOT_DIR &"/source.list") |
|
177 generate openttd, ROOT_DIR & "/projects/openttd_vs80.vcproj" |
|
178 generate openttd, ROOT_DIR & "/projects/openttd_vs90.vcproj" |
|
179 |
|
180 Dim lang |
|
181 lang = load_lang_data(ROOT_DIR & "/src/lang") |
|
182 generate lang, ROOT_DIR & "/projects/langs_vs80.vcproj" |
|
183 generate lang, ROOT_DIR & "/projects/langs_vs90.vcproj" |