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.



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/pkg-config.rb', line 380

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
  path = @options[:path] || ENV["PKG_CONFIG_PATH"]
  @paths = [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.



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

def msvc_syntax
  @msvc_syntax
end

#nameObject (readonly)

Returns the value of attribute name.



377
378
379
# File 'lib/pkg-config.rb', line 377

def name
  @name
end

#pathsObject (readonly)

Returns the value of attribute paths.



378
379
380
# File 'lib/pkg-config.rb', line 378

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



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

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

#cflags_only_IObject



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

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

#cflags_only_otherObject



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

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

#declaration(name) ⇒ Object



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

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

#descriptionObject



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

def description
  declaration("Description")
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


403
404
405
# File 'lib/pkg-config.rb', line 403

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

#exist?Boolean

Returns:

  • (Boolean)


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

def exist?
  not pc_path.nil?
end

#hashObject



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

def hash
  @name.hash
end

#libsObject



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

def libs
  collect_libs.join(" ")
end

#libs_only_lObject



440
441
442
443
444
445
446
447
448
# File 'lib/pkg-config.rb', line 440

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



450
451
452
453
454
455
456
457
458
# File 'lib/pkg-config.rb', line 450

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



478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/pkg-config.rb', line 478

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



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

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

#requires_privateObject



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

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

#variable(name) ⇒ Object



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

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

#versionObject



460
461
462
# File 'lib/pkg-config.rb', line 460

def version
  declaration("Version")
end