Module: PKGConfig

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

Overview

Copyright 2012-2023 Sutou Kouhei <[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.5.6"
@@paths =
[]
@@override_variables =
{}

Class Method Summary collapse

Class Method Details

.add_path(path) ⇒ Object



567
568
569
# File 'lib/pkg-config.rb', line 567

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

.cflags(pkg) ⇒ Object



602
603
604
# File 'lib/pkg-config.rb', line 602

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

.cflags_only_I(pkg) ⇒ Object



606
607
608
# File 'lib/pkg-config.rb', line 606

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

.cflags_only_other(pkg) ⇒ Object



610
611
612
# File 'lib/pkg-config.rb', line 610

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

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

Returns:

  • (Boolean)


626
627
628
629
630
631
632
633
634
635
# File 'lib/pkg-config.rb', line 626

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



618
619
620
# File 'lib/pkg-config.rb', line 618

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

.exist?(pkg) ⇒ Boolean

Returns:

  • (Boolean)


586
587
588
# File 'lib/pkg-config.rb', line 586

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

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



637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
# File 'lib/pkg-config.rb', line 637

def have_package(pkg, major=nil, minor=0, micro=0)
  message = "#{pkg}"
  unless major.nil?
    message << " version (>= #{major}.#{minor}.#{micro})"
  end
  major ||= 0
  result = checking_for(checking_message(message), "%s") do
    if check_version?(pkg, major, minor, micro)
      "yes (#{modversion(pkg)})"
    else
      if exist?(pkg)
        "no (#{modversion(pkg)}"
      else
        "no (nonexistent)"
      end
    end
  end
  enough_version = result.start_with?("yes")
  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)
    if defined?($CXXFLAGS)
      $CXXFLAGS += " " + cflags_only_other(pkg)
    end
    $INCFLAGS += " " + cflags_only_I(pkg)
  end
  enough_version
end

.libs(pkg) ⇒ Object



590
591
592
# File 'lib/pkg-config.rb', line 590

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

.libs_only_l(pkg) ⇒ Object



594
595
596
# File 'lib/pkg-config.rb', line 594

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

.libs_only_L(pkg) ⇒ Object



598
599
600
# File 'lib/pkg-config.rb', line 598

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

.modversion(pkg) ⇒ Object



614
615
616
# File 'lib/pkg-config.rb', line 614

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

.msvc?Boolean

Returns:

  • (Boolean)


575
576
577
# File 'lib/pkg-config.rb', line 575

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

.package_config(package) ⇒ Object



579
580
581
582
583
584
# File 'lib/pkg-config.rb', line 579

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

.set_override_variable(key, value) ⇒ Object



571
572
573
# File 'lib/pkg-config.rb', line 571

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

.variable(pkg, name) ⇒ Object



622
623
624
# File 'lib/pkg-config.rb', line 622

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