Module: PKGConfig

Defined in:
lib/pkg-config/version.rb,
lib/pkg-config.rb

Overview

Copyright 2012-2017 Kouhei Sutou <[email protected]>

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Constant Summary collapse

VERSION =
"1.2.0"
@@paths =
[]
@@override_variables =
{}

Class Method Summary collapse

Class Method Details

.add_path(path) ⇒ Object



373
374
375
# File 'lib/pkg-config.rb', line 373

def add_path(path)
  @@paths << path
end

.cflags(pkg) ⇒ Object



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

def cflags(pkg)
  package_config(pkg).cflags
end

.cflags_only_I(pkg) ⇒ Object



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

def cflags_only_I(pkg)
  package_config(pkg).cflags_only_I
end

.cflags_only_other(pkg) ⇒ Object



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

def cflags_only_other(pkg)
  package_config(pkg).cflags_only_other
end

.check_version?(pkg, major = 0, minor = 0, micro = 0) ⇒ Boolean



432
433
434
435
436
437
438
439
440
441
# File 'lib/pkg-config.rb', line 432

def check_version?(pkg, major=0, minor=0, micro=0)
  return false unless exist?(pkg)
  ver = modversion(pkg).split(".").collect {|item| item.to_i}
  (0..2).each {|i| ver[i] = 0 unless ver[i]}

  (ver[0] > major ||
   (ver[0] == major && ver[1] > minor) ||
   (ver[0] == major && ver[1] == minor &&
    ver[2] >= micro))
end

.description(pkg) ⇒ Object



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

def description(pkg)
  package_config(pkg).description
end

.exist?(pkg) ⇒ Boolean



392
393
394
# File 'lib/pkg-config.rb', line 392

def exist?(pkg)
  package_config(pkg).exist?
end

.have_package(pkg, major = nil, minor = 0, micro = 0) ⇒ Object



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/pkg-config.rb', line 443

def have_package(pkg, major=nil, minor=0, micro=0)
  message = "#{pkg}"
  unless major.nil?
    message << " version (>= #{major}.#{minor}.#{micro})"
  end
  major ||= 0
  enough_version = checking_for(checking_message(message)) do
    check_version?(pkg, major, minor, micro)
  end
  if enough_version
    libraries = libs_only_l(pkg)
    dldflags = libs(pkg)
    dldflags = (Shellwords.shellwords(dldflags) -
                Shellwords.shellwords(libraries))
    dldflags = dldflags.map {|s| /\s/ =~ s ? "\"#{s}\"" : s }.join(' ')
    $libs   += ' ' + libraries
    if /mswin/ =~ RUBY_PLATFORM
      $DLDFLAGS += ' ' + dldflags
    else
      $LDFLAGS += ' ' + dldflags
    end
    $CFLAGS += ' ' + cflags_only_other(pkg)
    $CXXFLAGS += ' ' + cflags_only_other(pkg)
    $INCFLAGS += ' ' + cflags_only_I(pkg)
  end
  enough_version
end

.libs(pkg) ⇒ Object



396
397
398
# File 'lib/pkg-config.rb', line 396

def libs(pkg)
  package_config(pkg).libs
end

.libs_only_l(pkg) ⇒ Object



400
401
402
# File 'lib/pkg-config.rb', line 400

def libs_only_l(pkg)
  package_config(pkg).libs_only_l
end

.libs_only_L(pkg) ⇒ Object



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

def libs_only_L(pkg)
  package_config(pkg).libs_only_L
end

.modversion(pkg) ⇒ Object



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

def modversion(pkg)
  package_config(pkg).version
end

.msvc?Boolean



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

def msvc?
  /mswin/.match(RUBY_PLATFORM) and /^cl\b/.match(RbConfig::CONFIG['CC'])
end

.package_config(package) ⇒ Object



385
386
387
388
389
390
# File 'lib/pkg-config.rb', line 385

def package_config(package)
  PackageConfig.new(package,
                    :msvc_syntax => msvc?,
                    :override_variables => @@override_variables,
                    :paths => @@paths)
end

.set_override_variable(key, value) ⇒ Object



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

def set_override_variable(key, value)
  @@override_variables[key] = value
end

.variable(pkg, name) ⇒ Object



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

def variable(pkg, name)
  package_config(pkg).variable(name)
end