blob: 52313186ed19361e5f8bdfb7c7d12120e0422543 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#!/usr/bin/env ruby
require 'amqpgen'
#
# Run a set of code generation templates.
#
if ARGV.size < 3
puts <<EOS
Usage: #{ARGV[0]} OUTDIR SPEC.xml [ ... ] TEMPLATE.rb [ ... ]
or: #{ARGV[0]} OUTDIR SPEC.xml [ ... ] all [ makefragment.mk ]
Parse all SPEC.xml files to create an AMQP model, run each TEMPLATE
putting the resulting files under OUTDIR. Prints a list of files
generated to standard output.
If OUTDIR is '-' then just prints file list without generating files.
EOS
exit 1
end
Outdir=ARGV[0]
Specs=ARGV.grep(/\.xml$/)
Amqp=AmqpRoot.new(*Specs)
# Run selected templates
if ARGV.grep("^all$")
templates=Dir["#{File.dirname __FILE__}/templates/*.rb"]
else
templates=ARGV.grep(/\.rb$/)
end
templates.each { |t| require t }
# Generate makefile
makefile=ARGV.grep(/.mk$/)[0]
if makefile
dir=Dir.getwd
Dir.chdir File.dirname(__FILE__)
generator_files=Dir["**/*.rb"] << File.basename(__FILE__)
Dir.chdir dir
rgen_generator=generator_files.map{ |f| "$(rgen_dir)/#{f}" }
rgen_srcs=GenFiles.get.map{ |f| "#{Outdir}/#{f}" }
rgen_client_cpp = rgen_srcs.select { |f| f =~ /qpid\/client\/.+\.cpp$/ }
rgen_common_cpp = rgen_srcs.select { |f| f =~ /qpid\/framing\/.+\.cpp$/ }
rgen_h = rgen_srcs.select { |f| f =~ /.+\.h$/ }
File.open(makefile, 'w') { |out|
out << <<EOS
# Generated makefile fragment.
# Including makefile defines $(rgen_dir) $(rgen_cmd) and $(specs).
rgen_generator=#{rgen_generator.join(" \\\n ")}
rgen_client_cpp=#{rgen_client_cpp.join(" \\\n ")}
rgen_common_cpp=#{rgen_common_cpp.join(" \\\n ")}
rgen_h=#{rgen_h.join(" \\\n ")}
rgen_srcs=rgen_h rgen_client_cpp rgen_common_cpp
if GENERATE
$(rgen_srcs) $(srcdir)/#{File.basename makefile}: $(rgen_generator) $(specs)
$(rgen_cmd)
# Empty rule in case a generator file is renamed/removed.
$(rgen_generator):
endif
EOS
}
end
|