Mxx_ru 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +4 -3
- data/bin/mxxrugen +197 -0
- data/lib/mxx_ru/cmd_line_option_processor.rb +126 -0
- data/lib/mxx_ru/cpp.rb +1 -0
- data/lib/mxx_ru/cpp/composite.rb +2 -12
- data/lib/mxx_ru/cpp/lib_collection.rb +96 -0
- data/lib/mxx_ru/cpp/mode.rb +72 -10
- data/lib/mxx_ru/cpp/target.rb +85 -136
- data/lib/mxx_ru/cpp/toolset.rb +96 -9
- data/lib/mxx_ru/cpp/toolsets/bcc_win32_family.rb +5 -5
- data/lib/mxx_ru/cpp/toolsets/c89_nsk_family.rb +5 -5
- data/lib/mxx_ru/cpp/toolsets/gcc_family.rb +5 -5
- data/lib/mxx_ru/cpp/toolsets/gcc_mingw.rb +2 -2
- data/lib/mxx_ru/cpp/toolsets/vc8.rb +6 -1
- data/lib/mxx_ru/cpp/toolsets/vc_family.rb +4 -4
- data/lib/mxx_ru/generators/bin-unittest/g.rb +200 -0
- data/lib/mxx_ru/generators/bin-unittest/template.erb +16 -0
- data/lib/mxx_ru/generators/cpp-composite/g.rb +37 -0
- data/lib/mxx_ru/generators/cpp-dll/g.rb +37 -0
- data/lib/mxx_ru/generators/cpp-exe/g.rb +37 -0
- data/lib/mxx_ru/generators/cpp-lib-collection/g.rb +37 -0
- data/lib/mxx_ru/generators/cpp-lib/g.rb +37 -0
- data/lib/mxx_ru/generators/impl/cpp/generation.rb +291 -0
- data/lib/mxx_ru/generators/impl/cpp/template.erb +27 -0
- data/lib/mxx_ru/generators/impl/std_receiver.rb +80 -0
- data/lib/mxx_ru/util.rb +110 -22
- data/lib/mxx_ru/version.rb +38 -0
- data/tests/mxx_ru/generators/cpp/tc_generator.rb +34 -0
- data/tests/mxx_ru/generators/cpp/tc_options.rb +79 -0
- data/tests/mxx_ru/generators/cpp/tc_template_params.rb +45 -0
- data/tests/mxx_ru/lib_collection/a.cpp +8 -0
- data/tests/mxx_ru/lib_collection/a.hpp +8 -0
- data/tests/mxx_ru/lib_collection/a.rb +8 -0
- data/tests/mxx_ru/lib_collection/b.cpp +8 -0
- data/tests/mxx_ru/lib_collection/b.hpp +8 -0
- data/tests/mxx_ru/lib_collection/b.rb +8 -0
- data/tests/mxx_ru/lib_collection/c.cpp +8 -0
- data/tests/mxx_ru/lib_collection/c.hpp +8 -0
- data/tests/mxx_ru/lib_collection/c.rb +8 -0
- data/tests/mxx_ru/lib_collection/collection_a_b.rb +7 -0
- data/tests/mxx_ru/lib_collection/collection_c_d.rb +7 -0
- data/tests/mxx_ru/lib_collection/collection_c_d_e.rb +7 -0
- data/tests/mxx_ru/lib_collection/collection_f.rb +6 -0
- data/tests/mxx_ru/lib_collection/collection_i.rb +6 -0
- data/tests/mxx_ru/lib_collection/d.cpp +8 -0
- data/tests/mxx_ru/lib_collection/d.hpp +8 -0
- data/tests/mxx_ru/lib_collection/d.rb +8 -0
- data/tests/mxx_ru/lib_collection/e.cpp +8 -0
- data/tests/mxx_ru/lib_collection/e.hpp +8 -0
- data/tests/mxx_ru/lib_collection/e.rb +8 -0
- data/tests/mxx_ru/lib_collection/f.cpp +8 -0
- data/tests/mxx_ru/lib_collection/f.hpp +8 -0
- data/tests/mxx_ru/lib_collection/f.rb +7 -0
- data/tests/mxx_ru/lib_collection/g.cpp +8 -0
- data/tests/mxx_ru/lib_collection/g.hpp +8 -0
- data/tests/mxx_ru/lib_collection/g.rb +7 -0
- data/tests/mxx_ru/lib_collection/i.cpp +10 -0
- data/tests/mxx_ru/lib_collection/i.hpp +16 -0
- data/tests/mxx_ru/lib_collection/i.rb +17 -0
- data/tests/mxx_ru/lib_collection/main.cpp +18 -0
- data/tests/mxx_ru/lib_collection/main.rb +12 -0
- data/tests/mxx_ru/lib_collection/tc_lib_collection.rb +17 -0
- data/tests/mxx_ru/toolset/tc_tag_search.rb +68 -0
- data/tests/test_with_compilation.rb +1 -1
- metadata +67 -14
- data/tests/cpp/mswin_res_dll/o/dll.o +0 -0
- data/tests/cpp/mswin_res_exe/o/main.o +0 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 1996-2004, Yauheni Akhotnikau
|
3
|
+
# Copyright (c) 2004-2006, JSC Intervale
|
4
|
+
# Copyright (c) 2006, The Mxx_ru Project
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
# are permitted provided that the following conditions are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer.
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
# this list of conditions and the following disclaimer in the documentation
|
14
|
+
# and/or other materials provided with the distribution.
|
15
|
+
# 3. The name of the author may not be used to endorse or promote products derived
|
16
|
+
# from this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
19
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
+
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
21
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
26
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#++
|
28
|
+
|
29
|
+
# Since v.1.4.0
|
30
|
+
#
|
31
|
+
# Generator for MxxRu::Cpp::exe_target stub.
|
32
|
+
|
33
|
+
require 'mxx_ru/generators/impl/cpp/generation'
|
34
|
+
|
35
|
+
MODULE = MxxRu::Generators::Impl::Cpp
|
36
|
+
MODULE::generate_for( MODULE::EXE, ARGV )
|
37
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 1996-2004, Yauheni Akhotnikau
|
3
|
+
# Copyright (c) 2004-2006, JSC Intervale
|
4
|
+
# Copyright (c) 2006, The Mxx_ru Project
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
# are permitted provided that the following conditions are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer.
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
# this list of conditions and the following disclaimer in the documentation
|
14
|
+
# and/or other materials provided with the distribution.
|
15
|
+
# 3. The name of the author may not be used to endorse or promote products derived
|
16
|
+
# from this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
19
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
+
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
21
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
26
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#++
|
28
|
+
|
29
|
+
# Since v.1.4.0
|
30
|
+
#
|
31
|
+
# Generator for MxxRu::Cpp::lib_collection_target stub.
|
32
|
+
|
33
|
+
require 'mxx_ru/generators/impl/cpp/generation'
|
34
|
+
|
35
|
+
MODULE = MxxRu::Generators::Impl::Cpp
|
36
|
+
MODULE::generate_for( MODULE::LIB_COLLECTION, ARGV )
|
37
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 1996-2004, Yauheni Akhotnikau
|
3
|
+
# Copyright (c) 2004-2006, JSC Intervale
|
4
|
+
# Copyright (c) 2006, The Mxx_ru Project
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
# are permitted provided that the following conditions are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer.
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
# this list of conditions and the following disclaimer in the documentation
|
14
|
+
# and/or other materials provided with the distribution.
|
15
|
+
# 3. The name of the author may not be used to endorse or promote products derived
|
16
|
+
# from this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
19
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
+
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
21
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
26
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#++
|
28
|
+
|
29
|
+
# Since v.1.4.0
|
30
|
+
#
|
31
|
+
# Generator for MxxRu::Cpp::lib_target stub.
|
32
|
+
|
33
|
+
require 'mxx_ru/generators/impl/cpp/generation'
|
34
|
+
|
35
|
+
MODULE = MxxRu::Generators::Impl::Cpp
|
36
|
+
MODULE::generate_for( MODULE::LIB, ARGV )
|
37
|
+
|
@@ -0,0 +1,291 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 1996-2004, Yauheni Akhotnikau
|
3
|
+
# Copyright (c) 2004-2006, JSC Intervale
|
4
|
+
# Copyright (c) 2006, The Mxx_ru Project
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
# are permitted provided that the following conditions are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer.
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
# this list of conditions and the following disclaimer in the documentation
|
14
|
+
# and/or other materials provided with the distribution.
|
15
|
+
# 3. The name of the author may not be used to endorse or promote products derived
|
16
|
+
# from this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
19
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
+
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
21
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
26
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#++
|
28
|
+
|
29
|
+
# Since v.1.4.0
|
30
|
+
#
|
31
|
+
# Implementation of project's stabs generation for C++ projects.
|
32
|
+
|
33
|
+
require 'erb'
|
34
|
+
require 'optparse'
|
35
|
+
|
36
|
+
require 'mxx_ru/generators/impl/std_receiver'
|
37
|
+
|
38
|
+
module MxxRu
|
39
|
+
|
40
|
+
module Generators
|
41
|
+
|
42
|
+
module Impl
|
43
|
+
|
44
|
+
module Cpp
|
45
|
+
|
46
|
+
# Types of C/C++ projects.
|
47
|
+
|
48
|
+
# Project type is static library.
|
49
|
+
LIB = :lib
|
50
|
+
# Project type is library collection.
|
51
|
+
LIB_COLLECTION = :lib_collection
|
52
|
+
# Project type is dinamic library.
|
53
|
+
DLL = :dll
|
54
|
+
# Project type is executable.
|
55
|
+
EXE = :exe
|
56
|
+
# Project type is composite.
|
57
|
+
COMPOSITE = :composite
|
58
|
+
|
59
|
+
# Class for storing command-line arguments as options.
|
60
|
+
#
|
61
|
+
# Usage:
|
62
|
+
# options = Options.parse( args, banner, { :implib_path => false } )
|
63
|
+
#
|
64
|
+
class Options
|
65
|
+
# Name of target (-t, --target).
|
66
|
+
attr_accessor :target_name
|
67
|
+
# Project path (name of project directory in cmd-line).
|
68
|
+
attr_accessor :project_path
|
69
|
+
# Name of import library path (--implib-path).
|
70
|
+
attr_accessor :implib_path
|
71
|
+
# Name of output file (-o, --output-file). nil if missing.
|
72
|
+
attr_accessor :output_file
|
73
|
+
|
74
|
+
# Parsing command-line arguments and returning Options instance.
|
75
|
+
#
|
76
|
+
# These keys are supported in _params_:
|
77
|
+
# [_implib_path_] true or false. Enables/disables argument --implib-path.
|
78
|
+
#
|
79
|
+
# Calls exit(1) if --help present in _args_.
|
80
|
+
#
|
81
|
+
def Options.parse( args, banner, params )
|
82
|
+
parser = OptionParser.new
|
83
|
+
|
84
|
+
result = Options.new
|
85
|
+
|
86
|
+
parser.banner = banner
|
87
|
+
|
88
|
+
parser.on( '-t', '--target NAME', 'Target name' ) do |p|
|
89
|
+
result.target_name = p
|
90
|
+
end
|
91
|
+
|
92
|
+
parser.on( '-o', '--output-file FILE', 'Output file name' ) do |p|
|
93
|
+
result.output_file = p
|
94
|
+
end
|
95
|
+
|
96
|
+
if true == params.fetch( :implib_path, false )
|
97
|
+
parser.on( '--implib-path PATH', 'Import library path name' ) do |p|
|
98
|
+
result.implib_path = p
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
parser.on_tail( '-h', '--help', 'Show this message' ) do
|
103
|
+
puts parser
|
104
|
+
exit(1)
|
105
|
+
end
|
106
|
+
|
107
|
+
parser.order!( args ) do |noarg|
|
108
|
+
# Any non-options is considered as project path name.
|
109
|
+
result.project_path = noarg
|
110
|
+
end
|
111
|
+
|
112
|
+
result
|
113
|
+
end
|
114
|
+
end # class Options
|
115
|
+
|
116
|
+
# Class to be used in ERb template generation.
|
117
|
+
#
|
118
|
+
# Usage:
|
119
|
+
# template_params = TemplateParams.new( target_type, options )
|
120
|
+
# template = ERb.new( IO.read( some_template_file ) )
|
121
|
+
# result = template.generate( template.get_binding )
|
122
|
+
#
|
123
|
+
class TemplateParams
|
124
|
+
# Dependencies between target_type and setup_target function name.
|
125
|
+
@@setup_target_functions = {
|
126
|
+
LIB => 'lib_target',
|
127
|
+
LIB_COLLECTION => 'lib_collection_target',
|
128
|
+
DLL => 'dll_target',
|
129
|
+
EXE => 'exe_target',
|
130
|
+
COMPOSITE => 'composite_target'
|
131
|
+
}
|
132
|
+
|
133
|
+
# target_type checker.
|
134
|
+
#
|
135
|
+
# Raises exception if target_type has unsupported value.
|
136
|
+
def TemplateParams.check_target_type( target_type )
|
137
|
+
if nil == @@setup_target_functions.fetch( target_type, nil )
|
138
|
+
raise InvalidValueEx.new( "unsupported target_type: #{target_type}" )
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# For a case when target_name is undetectable.
|
143
|
+
YOUR_TARGET_NAME = 'your target name'
|
144
|
+
# For a case when implib_path is undetectable.
|
145
|
+
YOUR_IMPLIB_PATH = 'your import library path'
|
146
|
+
|
147
|
+
# Type of target.
|
148
|
+
attr_reader :target_type
|
149
|
+
# Name of target.
|
150
|
+
attr_reader :target_name
|
151
|
+
# Name of import library path.
|
152
|
+
attr_reader :implib_path
|
153
|
+
|
154
|
+
# Param target_type must be present in @@setup_target_functions.
|
155
|
+
def initialize( target_type, options )
|
156
|
+
TemplateParams.check_target_type( target_type )
|
157
|
+
|
158
|
+
@target_type = target_type
|
159
|
+
@options = options
|
160
|
+
|
161
|
+
try_setup_target_name
|
162
|
+
try_setup_implib_name
|
163
|
+
end
|
164
|
+
|
165
|
+
# Name of setup target functions (like lib_target, dll_target, etc).
|
166
|
+
def setup_target_function
|
167
|
+
@@setup_target_functions.fetch( @target_type )
|
168
|
+
end
|
169
|
+
|
170
|
+
# Returns true if implib_path need to be defined for this type of target.
|
171
|
+
# Or, in case of EXE target, if implib_path defined in options.
|
172
|
+
# (Under Windows even EXEs may have import libraries).
|
173
|
+
def has_or_require_implib
|
174
|
+
DLL == @target_type || nil != @options.implib_path
|
175
|
+
end
|
176
|
+
|
177
|
+
# Returns binding to use in ERb generation.
|
178
|
+
def get_binding
|
179
|
+
binding
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
# Try to setup name of target from options.
|
184
|
+
#
|
185
|
+
# If --target specified target name is gotten from it.
|
186
|
+
# Otherwise if project path specified then name is constructed from it.
|
187
|
+
# Otherwise value 'your target name' is used.
|
188
|
+
#
|
189
|
+
def try_setup_target_name
|
190
|
+
@target_name = if @options.target_name
|
191
|
+
@options.target_name
|
192
|
+
elsif @options.project_path
|
193
|
+
@options.project_path.gsub( /[\\\/]/, '.' )
|
194
|
+
else
|
195
|
+
YOUR_TARGET_NAME
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# Try to setup name of implib path from options.
|
200
|
+
#
|
201
|
+
# If --implib-path specified then its value used.
|
202
|
+
# Otherwise value 'your import library path' is used.
|
203
|
+
#
|
204
|
+
def try_setup_implib_name
|
205
|
+
@implib_path = @options.implib_path ?
|
206
|
+
@options.implib_path :
|
207
|
+
YOUR_IMPLIB_PATH
|
208
|
+
end
|
209
|
+
|
210
|
+
end # class TemplateParams
|
211
|
+
|
212
|
+
# Main class for code generation of C/C++ projects.
|
213
|
+
#
|
214
|
+
# Usage:
|
215
|
+
# receiver = StdReceiver.new
|
216
|
+
# generator = Generator.new( target_type, args, receiver )
|
217
|
+
# generator.run
|
218
|
+
#
|
219
|
+
class Generator
|
220
|
+
def initialize( target_type, args, receiver )
|
221
|
+
@target_type = target_type
|
222
|
+
@args = args
|
223
|
+
@receiver = receiver
|
224
|
+
end
|
225
|
+
|
226
|
+
def run
|
227
|
+
options = Options.parse( @args,
|
228
|
+
"Stubs for C/C++ projects generator\n" +
|
229
|
+
target_specific_banner_line + "\n",
|
230
|
+
:implib_path => ( EXE == @target_type || DLL == @target_type ) )
|
231
|
+
result = do_generation( options )
|
232
|
+
@receiver.receive( result, options.output_file )
|
233
|
+
end
|
234
|
+
|
235
|
+
private
|
236
|
+
# Target specific parts of banner.
|
237
|
+
TARGET_SPECIFIC_BANNERS = {
|
238
|
+
LIB => [ 'Lib target generator', 'cpp-lib' ],
|
239
|
+
LIB_COLLECTION =>
|
240
|
+
[ 'LibCollection target generator', 'cpp-lib-collection' ],
|
241
|
+
DLL => [ 'DLL target generator', 'cpp-dll' ],
|
242
|
+
EXE => [ 'EXE target generator', 'cpp-exe' ],
|
243
|
+
COMPOSITE => [ 'Composite target generator', 'cpp-composite' ]
|
244
|
+
}
|
245
|
+
|
246
|
+
# Returns part of banner which depends from target type.
|
247
|
+
def target_specific_banner_line
|
248
|
+
parts = TARGET_SPECIFIC_BANNERS.fetch( @target_type, nil )
|
249
|
+
if parts
|
250
|
+
"#{parts[0]}\n\nUsage:\nmxxrugen [<mxxrugen-options>] " +
|
251
|
+
"#{parts[1]} [<options>]\n"
|
252
|
+
else
|
253
|
+
''
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
# Performs main generation actions.
|
258
|
+
#
|
259
|
+
# Returns generation result as String.
|
260
|
+
def do_generation( options )
|
261
|
+
template = IO.read( File.join( File.dirname( __FILE__ ), 'template.erb' ) )
|
262
|
+
generator = ERB.new( template )
|
263
|
+
|
264
|
+
params = TemplateParams.new( @target_type, options )
|
265
|
+
generator.result( params.get_binding ).gsub( /\n\n\n+/, "\n\n" )
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
# Helper method for generation.
|
270
|
+
#
|
271
|
+
# Usage:
|
272
|
+
# # For using StdReceiver.
|
273
|
+
# generate_for( EXE, ARGV )
|
274
|
+
#
|
275
|
+
# # For using custom Receiver.
|
276
|
+
# generate_for( EXE, ARGV, CustomReceiver.new )
|
277
|
+
#
|
278
|
+
def Cpp.generate_for( target_type, args, receiver = nil )
|
279
|
+
generator = Generator.new( target_type, args,
|
280
|
+
receiver ? receiver : StdReceiver.new )
|
281
|
+
generator.run
|
282
|
+
end
|
283
|
+
|
284
|
+
end # module Cpp
|
285
|
+
|
286
|
+
end # module Impl
|
287
|
+
|
288
|
+
end # module Generators
|
289
|
+
|
290
|
+
end # module MxxRu
|
291
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gem 'Mxx_ru', '>= 1.3.0'
|
4
|
+
|
5
|
+
require 'mxx_ru/cpp'
|
6
|
+
|
7
|
+
MxxRu::Cpp::<%= setup_target_function %> {
|
8
|
+
<% if COMPOSITE != target_type %>
|
9
|
+
# Define your target name here.
|
10
|
+
target '<%= target_name %>'
|
11
|
+
<% end %>
|
12
|
+
|
13
|
+
<% if has_or_require_implib %>
|
14
|
+
# Define your import library path here.
|
15
|
+
implib_path '<%= implib_path %>'
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
# Enumerate one or more required projects.
|
19
|
+
#required_prj 'some project'
|
20
|
+
|
21
|
+
<% if COMPOSITE != target_type %>
|
22
|
+
# Enumerate your C/C++ files here.
|
23
|
+
#c_source 'C source file'
|
24
|
+
#cpp_source 'C++ source file'
|
25
|
+
<% end %>
|
26
|
+
}
|
27
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 1996-2004, Yauheni Akhotnikau
|
3
|
+
# Copyright (c) 2004-2006, JSC Intervale
|
4
|
+
# Copyright (c) 2006, The Mxx_ru Project
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
# are permitted provided that the following conditions are met:
|
9
|
+
#
|
10
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer.
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
# this list of conditions and the following disclaimer in the documentation
|
14
|
+
# and/or other materials provided with the distribution.
|
15
|
+
# 3. The name of the author may not be used to endorse or promote products derived
|
16
|
+
# from this software without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
19
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
+
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
21
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
26
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#++
|
28
|
+
|
29
|
+
# Since v.1.4.0
|
30
|
+
#
|
31
|
+
# Implementation of standard object that send result of code generation
|
32
|
+
# to standard output stream or into specified output file.
|
33
|
+
|
34
|
+
require 'fileutils'
|
35
|
+
|
36
|
+
require 'mxx_ru/util'
|
37
|
+
|
38
|
+
module MxxRu
|
39
|
+
|
40
|
+
module Generators
|
41
|
+
|
42
|
+
module Impl
|
43
|
+
|
44
|
+
# Objects of this class will send result of code generation to standard
|
45
|
+
# output stream or into specified output file.
|
46
|
+
#
|
47
|
+
# Usage:
|
48
|
+
# receiver = StdReceiver.new
|
49
|
+
# # Send result to $stdout.
|
50
|
+
# receiver.receive( result, nil )
|
51
|
+
# # Send result to file.
|
52
|
+
# receiver.receive( result, 'some_file' )
|
53
|
+
#
|
54
|
+
class StdReceiver
|
55
|
+
|
56
|
+
# Sends _result_ to output file if _output_file_name_ isn't nil.
|
57
|
+
#
|
58
|
+
# If _result_ is going to output file then:
|
59
|
+
# 1. Temporary file will be created.
|
60
|
+
# 2. Result will be written to temporary file.
|
61
|
+
# 3. Output file will be deleted if exists.
|
62
|
+
# 4. Temporary file will be moved to output file.
|
63
|
+
def receive( result, output_file_name )
|
64
|
+
if output_file_name
|
65
|
+
tmp_file_name = MxxRu::Util::TmpFiles.instance.create( result )
|
66
|
+
FileUtils.rm( output_file_name, :force => true )
|
67
|
+
FileUtils.cp( tmp_file_name, output_file_name )
|
68
|
+
else
|
69
|
+
$stdout.write( result )
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end # class StdReceiver
|
74
|
+
|
75
|
+
end # module Impl
|
76
|
+
|
77
|
+
end # module Generators
|
78
|
+
|
79
|
+
end # module MxxRu
|
80
|
+
|