Class: MxxRu::Cpp::Toolsets::GccFamily

Inherits:
MxxRu::Cpp::Toolset
  • Object
show all
Defined in:
lib/mxx_ru/cpp/toolsets/gcc_family.rb

Overview

Toolset implemetation for GCC compiler.

Direct Known Subclasses

GccDarwin, GccMswinFamily, GccUnixFamily

Constant Summary collapse

GCC_PORT_TAG =

Tag name, indicates gcc port beeing used.

"gcc_port"
GCC_PORT_UNIX =

GCC_PORT: GCC on Unix/Linux.

"unix"
GCC_PORT_MINGW =

GCC_PORT: MinGW on Win32.

"mingw"
GCC_PORT_CYGWIN =

GCC_PORT: Cygwin on Win32.

"cygwin"

Instance Method Summary collapse

Constructor Details

#initialize(a_name) ⇒ GccFamily

Returns a new instance of GccFamily.



48
49
50
51
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 48

def initialize( a_name )
  super( a_name )
  @is_cpp0x_std = false
end

Instance Method Details

#c_compiler_nameObject

Returns C compiler name.



54
55
56
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 54

def c_compiler_name
  tag( [ C_COMPILER_NAME_TAG, COMPILER_NAME_TAG ], "gcc" )
end

#cpp_compiler_nameObject

Returns C++ compiler name.



59
60
61
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 59

def cpp_compiler_name
  tag( [ CPP_COMPILER_NAME_TAG, COMPILER_NAME_TAG ], "g++" )
end

#dll_file_name(source_name, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#dll_file_name.



174
175
176
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 174

def dll_file_name( source_name, target )
  return construct_target_name( source_name, 'lib', '.so', target )
end

#enclose_linker_include_lib_options_into_brackes(options) ⇒ Object

Enclose library list into brackets if necessary.

For example, on Linux -Wl,–start-group and -Wl,–end-group should be used around library list.



292
293
294
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 292

def enclose_linker_include_lib_options_into_brackes( options )
  "-Wl,--start-group #{options} -Wl,--end-group "
end

#exe_file_name(source_name, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#exe_file_name.



249
250
251
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 249

def exe_file_name( source_name, target )
  return construct_target_name( source_name, NO_PREFIX, NO_SUFFIX, target )
end

#force_cpp0x_stdObject

Sets a flag includes “-std=c++0x” compiler option.



322
323
324
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 322

def force_cpp0x_std
  @is_cpp0x_std = true
end

See description at MxxRu::Cpp::Toolset#implib_link_name.



179
180
181
182
183
184
185
186
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 179

def implib_link_name(
  dll_real_name,
  target )

  # Target name should be passed to linker on UNIX platform
  return lib_link_name(
    File.basename( target.mxx_target_name ), target )
end

See description at MxxRu::Cpp::Toolset#implib_link_path.



189
190
191
192
193
194
195
196
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 189

def implib_link_path(
  dll_real_name,
  dll_real_path,
  target )

  # DLL name is the import library name on UNIX platform.
  return dll_real_path
end

#lib_file_name(source_name, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#lib_file_name.



151
152
153
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 151

def lib_file_name( source_name, target )
  return construct_target_name( source_name, 'lib', '.a', target )
end

See description at MxxRu::Cpp::Toolset#lib_link_name.



156
157
158
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 156

def lib_link_name( source_name, target )
  return source_name
end

#librarian_nameObject

Returns librarian name.



69
70
71
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 69

def librarian_name
  tag( LIBRARIAN_NAME_TAG, "ar" )
end

#linker_nameObject

Returns linker name.



64
65
66
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 64

def linker_name
  tag( LINKER_NAME_TAG, "g++" )
end

#make_c_obj_command_lines(obj_name, source_name, compiler_options, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_c_obj_command_lines.



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 125

def make_c_obj_command_lines(
  obj_name,
  source_name,
  compiler_options,
  target )

  cmd_line = "-c -o #{obj_name} " +
    "#{compiler_options.join(' ')} #{source_name}"

  return [ "#{c_compiler_name} #{cmd_line}" ]
end

#make_cpp_obj_command_lines(obj_name, source_name, compiler_options, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_c_obj_command_lines.



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 138

def make_cpp_obj_command_lines(
  obj_name,
  source_name,
  compiler_options,
  target )

  cmd_line = "-c -o #{obj_name} " +
    "#{compiler_options.join(' ')} #{source_name}"

  return [ "#{cpp_compiler_name} #{cmd_line}" ]
end

#make_dll_command_lines(a_dll_name, a_dll_info, a_linker_lists, a_target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_dll_command_lines.



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 199

def make_dll_command_lines(
  a_dll_name,
  a_dll_info,
  a_linker_lists,
  a_target )

  result = "-shared " +
    "#{a_linker_lists.linker_options.join(' ')} " +
    "-o #{a_dll_name} "

  a_linker_lists.lib_paths.each { |p| result << "-L#{p} " }

  result << "#{a_linker_lists.objs.join(' ')} "
  result << make_linker_include_lib_options(
      a_target, a_linker_lists.libs )

  result << port_specific_dll_link_options(
    a_dll_name, a_dll_info, a_linker_lists, a_target )

  return [ "#{linker_name} #{result}" ]
end

#make_dll_requirements(a_dll_name, a_dll_info, a_linker_lists, a_target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_dll_requirements.



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 222

def make_dll_requirements(
  a_dll_name,
  a_dll_info,
  a_linker_lists,
  a_target )

  result = DllRequirements.new

  # On UNIX all requirements are dependencies.

  # This library, as a first one.
  result.add_libs( [
    BinaryLibrary.new( a_dll_info.link_name, BinaryLibrary::SHARED ) ] )
  result.add_lib_paths( [ a_dll_info.link_path ] )

  # And all required libraries.
  a_target.mxx_required_prjs.each { |d|
    if Toolset::has_linkable_dependecies?( d )
      result.add_libs( d.mxx_required_libs )
      result.add_lib_paths( d.mxx_required_lib_paths )
    end
  }

  return result
end

#make_exe_command_lines(a_exe_name, a_exe_info, a_linker_lists, a_target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_exe_command_lines.



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 254

def make_exe_command_lines(
  a_exe_name,
  a_exe_info,
  a_linker_lists,
  a_target )

  result = "#{a_linker_lists.linker_options.join(' ')} " +
    "-o #{a_exe_name} "

  a_linker_lists.lib_paths.each { |p| result << "-L#{p} " }

  result << "#{a_linker_lists.objs.join(' ')} "
  result << make_linker_include_lib_options(
      a_target, a_linker_lists.libs )

  result << port_specific_exe_link_options(
    a_exe_name, a_exe_info, a_linker_lists, a_target )

  return [ "#{linker_name} #{result}" ]
end

#make_lib_command_lines(lib_name, obj_files, librarian_options, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_lib_command_lines.



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 161

def make_lib_command_lines(
  lib_name,
  obj_files,
  librarian_options,
  target )

  result = "-r #{librarian_options.join(' ')} " +
    "#{lib_name} #{obj_files.join(' ')}"

  return [ "#{librarian_name} #{result}" ]
end

#make_linker_include_lib_options(target, libs) ⇒ Object

Make fragment of linker command line which contains names of included libraries.

target

target for that this fragment will be prepared.

libs

list of BinaryLibrary with required libraries.



280
281
282
283
284
285
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 280

def make_linker_include_lib_options( target, libs )
  all_libs = libs.inject( '' ) { |r, l|
      r << '-l' << port_specific_lib_name_checker( l.name ) << ' '
  }
  enclose_linker_include_lib_options_into_brackes( all_libs )
end

#obj_file_extObject

See description at MxxRu::Cpp::Toolset#obj_file_ext.



120
121
122
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 120

def obj_file_ext
  return ".o"
end

Return string containing port-specific linker option for DLL linking.

All parameters are similar to make_dll_command_lines parameters.

Return empty string in a base class.



301
302
303
304
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 301

def port_specific_dll_link_options(
  a_dll_name, a_dll_info, a_linker_lists, a_target )
  return ""
end

Return string containing port-specific linker option for EXE linking.

All parameters are similar to make_exe_command_lines parameters.

Return empty string in a base class.



311
312
313
314
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 311

def port_specific_exe_link_options(
  a_exe_name, a_exe_info, a_linker_lists, a_target )
  return ""
end

#port_specific_lib_name_checker(library_name) ⇒ Object

Return correct name of library to be given for linker.



317
318
319
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 317

def port_specific_lib_name_checker(library_name)
  library_name
end

#setup_mandatory_options(target) ⇒ Object

See description at MxxRu::Cpp::Toolset#setup_mandatory_options.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/mxx_ru/cpp/toolsets/gcc_family.rb', line 74

def setup_mandatory_options( target )

  if RUNTIME_DEBUG == target.mxx_runtime_mode
    target.compiler_option( "-g" )
    target.linker_option( "-g" )
  elsif RUNTIME_RELEASE == target.mxx_runtime_mode
    target.define( "NDEBUG" )
    target.linker_option( "-s" )
    if OPTIM_SIZE == target.mxx_optimization
      target.compiler_option( "-Os" )
    else
      target.compiler_option( "-O2" )
    end
  end

  if RTTI_DISABLED == target.mxx_rtti_mode
    target.cpp_compiler_option( "-fno-rtti" )
  end

  if RTL_STATIC == target.mxx_rtl_mode
    target.linker_option( "-static-libgcc" )
  else
    target.linker_option( "-shared-libgcc" )
  end

  target.compiler_option( "-fPIC" )

  # If C++ files are exist, linker should use stdc++ library.
  if target.mxx_cpp_files.size
#           target.lib( "stdc++" )
  end

  target.mxx_all_defines.each { |d|
    target.compiler_option( "-D" + d )
  }

  target.mxx_all_include_paths.each { |p|
    target.compiler_option( "-I" + p )
  }

  if true == @is_cpp0x_std
    target.cpp_compiler_option( "-std=c++0x" )
  end
end