Develop and Download Open Source Software

Browse Subversion Repository

Contents of /script/vcprogen.rb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 374 - (show annotations) (download)
Thu Feb 12 23:47:22 2009 UTC (15 years, 1 month ago) by satofumi
File size: 13434 byte(s)
TTF リソースの解放まわりでエラーになるのを無視
1 #!/usr/bin/env ruby
2 #
3 # Visual Studio .NET 2003 の vcproj 生成ツール
4 # Satofumi KAMIMURA
5 # $Id$
6
7 # 置換処理
8 def replace(template, key, value, add = false)
9
10 # 検索パターンの生成
11 path = key.split('/') - [""]
12 name = path.pop
13 parent = path.pop
14
15 reg_str = '(<'
16 path.each { |tag|
17 reg_str += tag + '.+?<'
18 }
19 reg_str += parent + '.+?' + name + '=")(.+?)(")'
20
21 left = template
22 template = ''
23 pattern = Regexp.compile(reg_str, Regexp::MULTILINE)
24 while left =~ pattern
25 template += $` + $1 + ((add) ? $2 : '') + value + $3
26 left = $'
27 end
28
29 return template + left
30 end
31
32
33 # ファイルの行毎に置換処理
34 def replaceFromFile(template, config_file)
35 open(config_file) { |io|
36 while line = io.gets
37 tags = line.chomp.split(/\s/, 2)
38 if tags.size() >= 2
39 if tags[0].downcase == "true"
40 add_tags = tags[1].split(/\s/, 2)
41 template = replace(template, add_tags[0], add_tags[1], true)
42 else
43 template = replace(template, tags[0], tags[1])
44 end
45 end
46 end
47 return template
48 } rescue STDERR.puts "replaceFromFile: Warning: #$!"
49 end
50
51 # Makefile の指定タグに指定されているファイルを展開
52
53
54 # include パスを追加
55 def addIncludes(includes, file)
56 includes.push(File.dirname(file))
57 end
58
59
60 # 1行分の行の取り出し
61 def parseLine(line, io, dir_path)
62 while line[-1,1] == '\\'
63 line = line.chop + io.gets
64 end
65 files = line.split
66 files.map! { |file| dir_path + '/' + file }
67 return files.join(' ')
68 end
69
70
71 # Makefile.am を展開する
72 def extendMakefile(file, keyword = 'SOURCES')
73 pattern = Regexp.compile('^\w+?_' + keyword + '\s+=')
74 open(file) { |io|
75 while line = io.gets
76 line.strip!
77 if pattern =~ line
78 return parseLine($', io, File.dirname(file))
79 end
80 end
81 } rescue STDERR.puts "extendMakefile: Warning: #$!"
82 return ""
83 end
84
85
86 # コードに含めるファイル一覧を生成
87 def createFileList(sources, headers, includes, files, mask)
88 files.split(/\s/).each { |file|
89 if File.basename(file) == "Makefile.am"
90 createFileList(sources, headers, includes, extendMakefile(file), mask)
91 next
92 end
93 ext = File.extname(file)[1..-1]
94 if !mask.split(/[,\s]/).index(ext)
95 next
96 end
97
98 addIncludes(includes, file)
99 if ext == "h" || ext == "hh"
100 headers.push(file)
101 else
102 sources.push(file)
103 end
104 }
105 end
106
107
108 # ファイルタグの生成
109 def createFilesXML(list, offset)
110 tags = ''
111 list.each { |file|
112 tags +=
113 offset + '<File RelativePath="' + file.gsub('/', '\\') + "\"></File>\n"
114 }
115 return tags
116 end
117
118
119 # ソースファイルを挿入
120 def insertSources(template, sources)
121
122 tags = createFilesXML(sources, "\t\t\t")
123 if tags.empty?
124 return
125 end
126 pattern = /(<Filter\s+Name="Source files".+?\}">)(.+?<\/Filter>)/m
127 if template =~ pattern
128 template.sub!(pattern, $1 + "\n" + tags + $2)
129 end
130 end
131
132
133 # ヘッダファイルを挿入
134 def insertHeaders(template, headers)
135
136 tags = createFilesXML(headers, "\t\t\t")
137 if tags.empty?
138 return
139 end
140 pattern = /<Filter\s+Name="Header files".+?\}">^.+?<\/Filter>/m
141 if template =~ pattern
142 template.sub!(pattern, $1 + "\n" + tags + $2)
143 end
144 end
145
146
147 # include/ の生成
148 def createIncludes(template, includes, files)
149 targets = []
150 files.split(/\s/).each { |file|
151 if File.basename(file) == "Makefile.am"
152 targets += extendMakefile(file, "HEADERS").split(' ')
153 else
154 includes << file
155 end
156 }
157
158 offset = "\t\t\t\t"
159 cmd = 'del /q include;' + "\n" + offset + 'mkdir include;' + "\n"
160 targets.each { |file|
161 cmd += offset + 'copy ' + file.gsub('/', '\\') + ' include\;' + "\n"
162 }
163 return replace(template, '/Configuration/Tool/CommandLine', cmd.chomp)
164 end
165
166
167 # 追加のインクルードパスを挿入
168 def insertIncludes(template, includes)
169
170 replace = '.\; .\include;' + includes.uniq.join('; ').gsub('/', '\\') + ';'
171 path = "/Configuration/Tool/AdditionalIncludeDirectories"
172 return replace(template, path, replace)
173 end
174
175
176 # lib 生成用テンプレート
177 lib_template = <<-EOB
178 <?xml version="1.0" encoding="shift_jis"?>
179 <VisualStudioProject
180 ProjectType="Visual C++"
181 Version="7.10"
182 Name="lib_template"
183 ProjectGUID="{E35DE899-8736-4A8E-A604-821469165AF1}"
184 RootNamespace="lib_template"
185 Keyword="ManagedCProj">
186 <Platforms>
187 <Platform
188 Name="Win32"/>
189 </Platforms>
190 <Configurations>
191 <Configuration
192 Name="Debug|Win32"
193 OutputDirectory="$(SolutionDir)$(ConfigurationName)"
194 IntermediateDirectory="$(ConfigurationName)"
195 ConfigurationType="4"
196 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
197 CharacterSet="2"
198 ManagedExtensions="0">
199 <Tool
200 Name="VCCLCompilerTool"
201 Optimization="0"
202 AdditionalIncludeDirectories=";"
203 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
204 MinimalRebuild="TRUE"
205 RuntimeLibrary="3"
206 RuntimeTypeInfo="TRUE"
207 WarningLevel="3"
208 DebugInformationFormat="4"/>
209 <Tool
210 Name="VCCustomBuildTool"/>
211 <Tool
212 Name="VCLibrarianTool"
213 AdditionalDependencies=";"
214 AdditionalLibraryDirectories=";"/>
215 <Tool
216 Name="VCMIDLTool"/>
217 <Tool
218 Name="VCPostBuildEventTool"/>
219 <Tool
220 Name="VCPreBuildEventTool"
221 CommandLine=";"/>
222 <Tool
223 Name="VCPreLinkEventTool"/>
224 <Tool
225 Name="VCResourceCompilerTool"/>
226 <Tool
227 Name="VCWebServiceProxyGeneratorTool"/>
228 <Tool
229 Name="VCXMLDataGeneratorTool"/>
230 <Tool
231 Name="VCManagedWrapperGeneratorTool"/>
232 <Tool
233 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
234 </Configuration>
235 <Configuration
236 Name="Release|Win32"
237 OutputDirectory="$(SolutionDir)$(ConfigurationName)"
238 IntermediateDirectory="$(ConfigurationName)"
239 ConfigurationType="4"
240 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
241 CharacterSet="2"
242 ManagedExtensions="0">
243 <Tool
244 Name="VCCLCompilerTool"
245 AdditionalIncludeDirectories=";"
246 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
247 MinimalRebuild="TRUE"
248 RuntimeLibrary="2"
249 RuntimeTypeInfo="TRUE"
250 WarningLevel="3"
251 DebugInformationFormat="4"/>
252 <Tool
253 Name="VCCustomBuildTool"/>
254 <Tool
255 Name="VCLibrarianTool"
256 AdditionalDependencies=";"
257 AdditionalLibraryDirectories=";"/>
258 <Tool
259 Name="VCMIDLTool"/>
260 <Tool
261 Name="VCPostBuildEventTool"/>
262 <Tool
263 Name="VCPreBuildEventTool"
264 CommandLine=";"/>
265 <Tool
266 Name="VCPreLinkEventTool"/>
267 <Tool
268 Name="VCResourceCompilerTool"/>
269 <Tool
270 Name="VCWebServiceProxyGeneratorTool"/>
271 <Tool
272 Name="VCXMLDataGeneratorTool"/>
273 <Tool
274 Name="VCWebDeploymentTool"/>
275 <Tool
276 Name="VCManagedWrapperGeneratorTool"/>
277 <Tool
278 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
279 </Configuration>
280 </Configurations>
281 <References>
282 </References>
283 <Files>
284 <Filter
285 Name="Source files"
286 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
287 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
288 </Filter>
289 <Filter
290 Name="Header files"
291 Filter="h;hpp;hxx;hm;inl;inc;xsd"
292 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
293 </Filter>
294 <Filter
295 Name="Resource files"
296 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
297 UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
298 </Filter>
299 </Files>
300 <Globals>
301 </Globals>
302 </VisualStudioProject>
303 EOB
304
305
306 # exe 生成用テンプレート
307 exe_template = <<-EOB
308 <?xml version="1.0" encoding="shift_jis"?>
309 <VisualStudioProject
310 ProjectType="Visual C++"
311 Version="7.10"
312 Name="exe_template"
313 ProjectGUID="{BA46C739-97CD-4F68-9F3D-ECF9759134CE}"
314 RootNamespace="exe_template"
315 Keyword="ManagedCProj">
316 <Platforms>
317 <Platform
318 Name="Win32"/>
319 </Platforms>
320 <Configurations>
321 <Configuration
322 Name="Debug|Win32"
323 OutputDirectory="$(SolutionDir)$(ConfigurationName)"
324 IntermediateDirectory="$(ConfigurationName)"
325 ConfigurationType="1"
326 CharacterSet="1"
327 >
328 Tool
329 Name="VCCLCompilerTool"
330 Optimization="0"
331 AdditionalIncludeDirectories=";"
332 PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS"
333 MinimalRebuild="TRUE"
334 RuntimeLibrary="3"
335 UsePrecompiledHeader="0"
336 WarningLevel="3"
337 Detect64BitPortabilityProblems="true"
338 DebugInformationFormat="4"/>
339 <Tool
340 Name="VCCustomBuildTool"/>
341 <Tool
342 Name="VCLinkerTool"
343 OutputFile="$(OutDir)\\$(ProjectName).exe"
344 LinkIncremental="2"
345 SuppressStartupBanner="TRUE"
346 GenerateDebugInformation="TRUE"
347 SubSystem="1"
348 TargetMachine="1"
349 />
350 <Tool
351 Name="VCMIDLTool"/>
352 <Tool
353 Name="VCPostBuildEventTool"/>
354 <Tool
355 Name="VCPreBuildEventTool"
356 CommandLine=";"/>
357 <Tool
358 Name="VCPreLinkEventTool"/>
359 <Tool
360 Name="VCResourceCompilerTool"/>
361 <Tool
362 Name="VCWebServiceProxyGeneratorTool"/>
363 <Tool
364 Name="VCXMLDataGeneratorTool"/>
365 <Tool
366 Name="VCWebDeploymentTool"/>
367 <Tool
368 Name="VCManagedWrapperGeneratorTool"/>
369 <Tool
370 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
371 </Configuration>
372 <Configuration
373 Name="Release|Win32"
374 OutputDirectory="$(SolutionDir)$(ConfigurationName)"
375 IntermediateDirectory="$(ConfigurationName)"
376 ConfigurationType="1"
377 CharacterSet="1
378 WholeProgramOptimization="1""
379 >
380 <Tool
381 Name="VCCLCompilerTool"
382 AdditionalIncludeDirectories=";"
383 PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS"
384 MinimalRebuild="TRUE"
385 RuntimeLibrary="2"
386 UsePrecompiledHeader="0"
387 WarningLevel="3"
388 Detect64BitPortabilityProblems="true"
389 DebugInformationFormat="3"/>
390 <Tool
391 Name="VCCustomBuildTool"/>
392 <Tool
393 Name="VCLinkerTool"
394 OutputFile="$(OutDir)\\$(ProjectName).exe"
395 LinkIncremental="1"
396 GenerateDebugInformation="TRUE"/>
397 <Tool
398 Name="VCMIDLTool"/>
399 <Tool
400 Name="VCPostBuildEventTool"/>
401 <Tool
402 Name="VCPreBuildEventTool"
403 CommandLine=";"/>
404 <Tool
405 Name="VCPreLinkEventTool"/>
406 <Tool
407 Name="VCResourceCompilerTool"/>
408 <Tool
409 Name="VCWebServiceProxyGeneratorTool"/>
410 <Tool
411 Name="VCXMLDataGeneratorTool"/>
412 <Tool
413 Name="VCWebDeploymentTool"/>
414 <Tool
415 Name="VCManagedWrapperGeneratorTool"/>
416 <Tool
417 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
418 </Configuration>
419 </Configurations>
420 <References>
421 </References>
422 <Files>
423 <Filter
424 Name="Source files"
425 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
426 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
427 </Filter>
428 <Filter
429 Name="Header files"
430 Filter="h;hpp;hxx;hm;inl;inc;xsd"
431 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
432 </Filter>
433 <Filter
434 Name="Resource files"
435 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
436 UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
437 </Filter>
438 </Files>
439 <Globals>
440 </Globals>
441 </VisualStudioProject>
442 EOB
443
444
445 def stripNoneDependencies(template)
446
447 template = template.gsub(/AdditionalDependencies=\";\"/, "AdditionalDependencies=\"\"")
448 template = template.gsub(/AdditionalLibraryDirectories=\";\"/, "AdditionalLibraryDirectories=\"\"")
449
450 return template
451 end
452
453
454 # 使い方を表示して終了
455 def printUsage()
456 print \
457 "usage:\n" \
458 "\t% ruby " + __FILE__ + " [options] <config.txt>\n" \
459 "\n" \
460 "options: \n" \
461 "--name <project name> specify project name\n" \
462 "--type <exe, lib> specify project output type\n" \
463 "--mask \"cpp,c,h\" specify handled file type\n" \
464 "--sources \"<Makefile.am list>\" to create sources list\n" \
465 "--headers \"<Makefile.am list>\" to create include folder\n" \
466 "--codes \"<Makefile.am list>\" means sourcesb and headers option\n" \
467 "\n"
468 exit
469 end
470
471
472 # メイン処理
473 if ARGV.empty?
474 printUsage()
475 end
476
477 # オプションの判定
478 pre_arg = nil
479 proj_name = nil
480 proj_type = nil
481 proj_mask = "c,cpp,h"
482 proj_sources = nil
483 proj_headers = nil
484 files = []
485 ARGV.reverse.each { |arg|
486 case arg
487 when /--name/
488 proj_name = pre_arg.split('.')[0]
489 files.shift
490
491 when /--type/
492 if pre_arg == "exe" || pre_arg == "lib"
493 proj_type = pre_arg
494 end
495 files.shift
496
497 when /--mask/
498 proj_mask = pre_arg
499 files.shift
500
501 when /--sources/
502 proj_sources = pre_arg
503 files.shift
504
505 when /--headers/
506 proj_headers = pre_arg
507 files.shift
508
509 when /--codes/
510 proj_sources = pre_arg
511 proj_headers = pre_arg
512 files.shift
513
514 else
515 files.unshift(arg)
516 end
517 pre_arg = arg
518 }
519 config_file = files.shift
520 if proj_name == nil
521 print "name is not specified!\n"
522 printUsage()
523 end
524 if proj_type == nil
525 print "type is not specified!\n"
526 printUsage()
527 end
528 template = (proj_type == "exe") ? exe_template : lib_template
529
530
531 # プロジェクト名の置換
532 template = replace(template, "/VisualStudioProject/Name", proj_name)
533 template = replace(template, "/VisualStudioProject/RootNamespace", proj_name)
534
535
536 # コンフィグファイル指定の要素を置換
537 if config_file
538 template = replaceFromFile(template, config_file)
539 end
540
541 sources = []
542 headers = []
543 includes = []
544
545
546 # source files, include path の調整
547 if proj_sources
548 createFileList(sources, headers, includes, proj_sources, proj_mask)
549 end
550
551
552 # include folder の生成
553 if proj_headers
554 template = createIncludes(template, includes, proj_headers)
555 end
556
557
558 # sources, headers, includes の反映
559 insertSources(template, sources)
560 insertHeaders(template, headers)
561 template = insertIncludes(template, includes)
562
563
564 # Additional*=";" だとエラーになるのを修正
565 template = stripNoneDependencies(template);
566
567
568 # プロジェクトファイルの生成
569 open(proj_name + '.vcproj', 'w') { |io|
570 io.print template
571 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26