Module: PKGConfig

Defined in:
lib/pkg-config.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.add_path(path) ⇒ Object



28
29
30
# File 'lib/pkg-config.rb', line 28

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

.cflags(pkg) ⇒ Object



63
64
65
# File 'lib/pkg-config.rb', line 63

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

.cflags_only_I(pkg) ⇒ Object



67
68
69
# File 'lib/pkg-config.rb', line 67

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

.cflags_only_other(pkg) ⇒ Object



71
72
73
# File 'lib/pkg-config.rb', line 71

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

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

Returns:

  • (Boolean)


87
88
89
90
91
92
93
94
95
96
# File 'lib/pkg-config.rb', line 87

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



79
80
81
# File 'lib/pkg-config.rb', line 79

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

.exist?(pkg) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/pkg-config.rb', line 47

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

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



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/pkg-config.rb', line 98

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



51
52
53
# File 'lib/pkg-config.rb', line 51

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

.libs_only_l(pkg) ⇒ Object



55
56
57
# File 'lib/pkg-config.rb', line 55

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

.libs_only_L(pkg) ⇒ Object



59
60
61
# File 'lib/pkg-config.rb', line 59

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

.modversion(pkg) ⇒ Object



75
76
77
# File 'lib/pkg-config.rb', line 75

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

.msvc?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/pkg-config.rb', line 36

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

.package_config(package) ⇒ Object



40
41
42
43
44
45
# File 'lib/pkg-config.rb', line 40

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

.set_override_variable(key, value) ⇒ Object



32
33
34
# File 'lib/pkg-config.rb', line 32

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

.variable(pkg, name) ⇒ Object



83
84
85
# File 'lib/pkg-config.rb', line 83

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