class MxxRu::Cpp::Toolsets::GccFamily

Toolset implemetation for GCC compiler.

Constants

GCC_PORT_CYGWIN

GCC_PORT: Cygwin on Win32.

GCC_PORT_MINGW

GCC_PORT: MinGW on Win32.

GCC_PORT_TAG

Tag name, indicates gcc port beeing used.

GCC_PORT_UNIX

GCC_PORT: GCC on Unix/Linux.

Public Class Methods

new( a_name ) click to toggle source
Calls superclass method MxxRu::Cpp::Toolset::new
# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 48
def initialize( a_name )
  super( a_name )
end

Public Instance Methods

c_compiler_name() click to toggle source

Returns C compiler name.

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 53
def c_compiler_name
  tag( [ C_COMPILER_NAME_TAG, COMPILER_NAME_TAG ], "gcc" )
end
cpp_compiler_name() click to toggle source

Returns C++ compiler name.

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 58
def cpp_compiler_name
  tag( [ CPP_COMPILER_NAME_TAG, COMPILER_NAME_TAG ], "g++" )
end
dll_file_name( source_name, target ) click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 175
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 ) click to toggle source

Enclose library list into brackets if necessary.

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 293
def enclose_linker_include_lib_options_into_brackes( options )
  "-Wl,--start-group #{options} -Wl,--end-group "
end
exe_file_name( source_name, target ) click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 250
def exe_file_name( source_name, target )
  return construct_target_name( source_name, NO_PREFIX, NO_SUFFIX, target )
end
lib_file_name( source_name, target ) click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 152
def lib_file_name( source_name, target )
  return construct_target_name( source_name, 'lib', '.a', target )
end
librarian_name() click to toggle source

Returns librarian name.

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 68
def librarian_name
  tag( LIBRARIAN_NAME_TAG, "ar" )
end
linker_name() click to toggle source

Returns linker name.

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 63
def linker_name
  tag( LINKER_NAME_TAG, "g++" )
end
make_c_obj_command_lines( obj_name, source_name, compiler_options, target ) click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 126
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 ) click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 139
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 ) click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 200
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 ) click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 223
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 ) click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 255
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 ) click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 162
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 ) click to toggle source

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.

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 281
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
make_toolset_id_string() click to toggle source

Create toolset identification string.

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 323
def make_toolset_id_string
  result = IO.popen( "#{c_compiler_name} -v 2>&1", :err => [:child, :out] ) do |io|
    target = 'generic'
    version = 'unknown'
    io.each_line do |line|
      if /^Target:\s*(?<trgt>\S+)/ =~ line
        target = trgt
      elsif /^gcc version (?<v>\S+)/ =~ line
        version = v
      end
    end
    version + '--' + target
  end
  "gcc_#{result}"
end
obj_file_ext() click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 121
def obj_file_ext
  return ".o"
end
port_specific_lib_name_checker(library_name) click to toggle source

Return correct name of library to be given for linker.

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 318
def port_specific_lib_name_checker(library_name)
  library_name
end
setup_mandatory_options( target ) click to toggle source

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

# File lib/mxx_ru/cpp/toolsets/gcc_family.rb, line 73
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.mxx_all_defines.each { |d|
    target.compiler_option( "-D" + d )
  }

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

  if CPP_STD17 == cpp_std
    target.cpp_compiler_option( '-std=c++17' )
  elsif CPP_STD14 == cpp_std
    target.cpp_compiler_option( '-std=c++14' )
  elsif CPP_STD11 == cpp_std
    target.cpp_compiler_option( '-std=c++11' )
  end

  if CPP_STD11 <= cpp_std and
      THREADING_MULTI == target.mxx_threading_mode
    target.linker_option( '-pthread' )
  end
end