Class: PackageConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/pkg-config.rb

Defined Under Namespace

Classes: Error, NotFoundError

Constant Summary collapse

SEPARATOR =
File::PATH_SEPARATOR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ PackageConfig

Returns a new instance of PackageConfig.



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/pkg-config.rb', line 383

def initialize(name, options={})
  if Pathname(name).absolute?
    @pc_path = name
    @path_position = 0
    @name = File.basename(@pc_path, ".*")
  else
    @pc_path = nil
    @path_position = nil
    @name = name
  end
  @options = options
  @paths = [
    @options[:path],
    self.class.default_path,
  ].compact.join(SEPARATOR).split(SEPARATOR)
  @paths.unshift(*(@options[:paths] || []))
  @paths = normalize_paths(@paths)
  @msvc_syntax = @options[:msvc_syntax]
  @variables = @declarations = nil
  override_variables = self.class.custom_override_variables
  @override_variables = parse_override_variables(override_variables)
  default_override_variables = @options[:override_variables] || {}
  @override_variables = default_override_variables.merge(@override_variables)
end

Instance Attribute Details

#msvc_syntaxObject

Returns the value of attribute msvc_syntax.



382
383
384
# File 'lib/pkg-config.rb', line 382

def msvc_syntax
  @msvc_syntax
end

#nameObject (readonly)

Returns the value of attribute name.



380
381
382
# File 'lib/pkg-config.rb', line 380

def name
  @name
end

#pathsObject (readonly)

Returns the value of attribute paths.



381
382
383
# File 'lib/pkg-config.rb', line 381

def paths
  @paths
end

Class Method Details

.clear_configure_args_cacheObject



168
169
170
171
172
173
# File 'lib/pkg-config.rb', line 168

def clear_configure_args_cache
  @native_pkg_config = nil
  @native_pkg_config_prefix = nil
  @default_path = nil
  @custom_override_variables = nil
end

.custom_override_variablesObject



164
165
166
# File 'lib/pkg-config.rb', line 164

def custom_override_variables
  @custom_override_variables ||= with_config("override-variables", "")
end

.default_pathObject



159
160
161
# File 'lib/pkg-config.rb', line 159

def default_path
  @default_path ||= compute_default_path
end

.native_pkg_configObject



149
150
151
# File 'lib/pkg-config.rb', line 149

def native_pkg_config
  @native_pkg_config ||= guess_native_pkg_config
end

.native_pkg_config_prefixObject



154
155
156
# File 'lib/pkg-config.rb', line 154

def native_pkg_config_prefix
  @native_pkg_config_prefix ||= compute_native_pkg_config_prefix
end

Instance Method Details

#cflagsObject



428
429
430
431
# File 'lib/pkg-config.rb', line 428

def cflags
  path_flags, other_flags = collect_cflags
  (path_flags + other_flags).join(" ")
end

#cflags_only_IObject



433
434
435
# File 'lib/pkg-config.rb', line 433

def cflags_only_I
  collect_cflags[0].join(" ")
end

#cflags_only_otherObject



437
438
439
# File 'lib/pkg-config.rb', line 437

def cflags_only_other
  collect_cflags[1].join(" ")
end

#declaration(name) ⇒ Object



478
479
480
481
# File 'lib/pkg-config.rb', line 478

def declaration(name)
  parse_pc if @declarations.nil?
  expand_value(@declarations[name])
end

#descriptionObject



469
470
471
# File 'lib/pkg-config.rb', line 469

def description
  declaration("Description")
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


408
409
410
# File 'lib/pkg-config.rb', line 408

def eql?(other)
  other.is_a?(self.class) and @name == other.name
end

#exist?Boolean

Returns:

  • (Boolean)


416
417
418
# File 'lib/pkg-config.rb', line 416

def exist?
  not pc_path.nil?
end

#hashObject



412
413
414
# File 'lib/pkg-config.rb', line 412

def hash
  @name.hash
end

#libsObject



441
442
443
# File 'lib/pkg-config.rb', line 441

def libs
  collect_libs.join(" ")
end

#libs_only_lObject



445
446
447
448
449
450
451
452
453
# File 'lib/pkg-config.rb', line 445

def libs_only_l
  collect_libs.find_all do |arg|
    if @msvc_syntax
      arg.end_with?(".lib")
    else
      arg.start_with?("-l")
    end
  end.join(" ")
end

#libs_only_LObject



455
456
457
458
459
460
461
462
463
# File 'lib/pkg-config.rb', line 455

def libs_only_L
  collect_libs.find_all do |arg|
    if @msvc_syntax
      arg.start_with?("/libpath:")
    else
      arg.start_with?("-L")
    end
  end.join(" ")
end

#pc_pathObject



483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/pkg-config.rb', line 483

def pc_path
  if @pc_path
    return @pc_path if File.exist?(@pc_path)
  else
    @paths.each_with_index do |path, i|
      _pc_path = File.join(path, "#{@name}.pc")
      if File.exist?(_pc_path)
        @path_position = i + 1
        return _pc_path
      end
    end
  end
  nil
end

#requiresObject



420
421
422
# File 'lib/pkg-config.rb', line 420

def requires
  parse_requires(declaration("Requires"))
end

#requires_privateObject



424
425
426
# File 'lib/pkg-config.rb', line 424

def requires_private
  parse_requires(declaration("Requires.private"))
end

#variable(name) ⇒ Object



473
474
475
476
# File 'lib/pkg-config.rb', line 473

def variable(name)
  parse_pc if @variables.nil?
  expand_value(@override_variables[name] || @variables[name])
end

#versionObject



465
466
467
# File 'lib/pkg-config.rb', line 465

def version
  declaration("Version")
end