Skip to content

Commit abacfff

Browse files
committed
Use only one file for easy to bundle
1 parent 1e8cced commit abacfff

File tree

3 files changed

+120
-141
lines changed

3 files changed

+120
-141
lines changed

lib/pkg-config.rb

Lines changed: 117 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,128 @@
1414
# License along with this library; if not, write to the Free Software
1515
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1616

17-
begin
18-
require_relative "pkg-config/version"
19-
rescue LoadError
20-
end
21-
2217
require "English"
2318
require "pathname"
2419
require "rbconfig"
2520
require "shellwords"
2621

22+
module PKGConfig
23+
VERSION = "1.6.0"
24+
25+
@@paths = []
26+
@@override_variables = {}
27+
28+
module_function
29+
def add_path(path)
30+
@@paths << path
31+
end
32+
33+
def set_override_variable(key, value)
34+
@@override_variables[key] = value
35+
end
36+
37+
def msvc?
38+
/mswin/.match(RUBY_PLATFORM) and /^cl\b/.match(RbConfig::CONFIG["CC"])
39+
end
40+
41+
def package_config(package)
42+
PackageConfig.new(package,
43+
:msvc_syntax => msvc?,
44+
:override_variables => @@override_variables,
45+
:paths => @@paths)
46+
end
47+
48+
def exist?(pkg)
49+
package_config(pkg).exist?
50+
end
51+
52+
def libs(pkg)
53+
package_config(pkg).libs
54+
end
55+
56+
def libs_only_l(pkg)
57+
package_config(pkg).libs_only_l
58+
end
59+
60+
def libs_only_L(pkg)
61+
package_config(pkg).libs_only_L
62+
end
63+
64+
def cflags(pkg)
65+
package_config(pkg).cflags
66+
end
67+
68+
def cflags_only_I(pkg)
69+
package_config(pkg).cflags_only_I
70+
end
71+
72+
def cflags_only_other(pkg)
73+
package_config(pkg).cflags_only_other
74+
end
75+
76+
def modversion(pkg)
77+
package_config(pkg).version
78+
end
79+
80+
def description(pkg)
81+
package_config(pkg).description
82+
end
83+
84+
def variable(pkg, name)
85+
package_config(pkg).variable(name)
86+
end
87+
88+
def check_version?(pkg, major=0, minor=0, micro=0)
89+
return false unless exist?(pkg)
90+
ver = modversion(pkg).split(".").collect {|item| item.to_i}
91+
(0..2).each {|i| ver[i] = 0 unless ver[i]}
92+
93+
(ver[0] > major ||
94+
(ver[0] == major && ver[1] > minor) ||
95+
(ver[0] == major && ver[1] == minor &&
96+
ver[2] >= micro))
97+
end
98+
99+
def have_package(pkg, major=nil, minor=0, micro=0)
100+
message = "#{pkg}"
101+
unless major.nil?
102+
message << " version (>= #{major}.#{minor}.#{micro})"
103+
end
104+
major ||= 0
105+
result = checking_for(checking_message(message), "%s") do
106+
if check_version?(pkg, major, minor, micro)
107+
"yes (#{modversion(pkg)})"
108+
else
109+
if exist?(pkg)
110+
"no (#{modversion(pkg)})"
111+
else
112+
"no (nonexistent)"
113+
end
114+
end
115+
end
116+
enough_version = result.start_with?("yes")
117+
if enough_version
118+
libraries = libs_only_l(pkg)
119+
dldflags = libs(pkg)
120+
dldflags = (Shellwords.shellwords(dldflags) -
121+
Shellwords.shellwords(libraries))
122+
dldflags = dldflags.map {|s| /\s/ =~ s ? "\"#{s}\"" : s }.join(" ")
123+
$libs += " " + libraries
124+
if /mswin/ =~ RUBY_PLATFORM
125+
$DLDFLAGS += " " + dldflags
126+
else
127+
$LDFLAGS += " " + dldflags
128+
end
129+
$CFLAGS += " " + cflags_only_other(pkg)
130+
if defined?($CXXFLAGS)
131+
$CXXFLAGS += " " + cflags_only_other(pkg)
132+
end
133+
$INCFLAGS += " " + cflags_only_I(pkg)
134+
end
135+
enough_version
136+
end
137+
end
138+
27139
class PackageConfig
28140
class Error < StandardError
29141
end
@@ -569,118 +681,3 @@ def normalize_paths(paths)
569681
end
570682
end
571683
end
572-
573-
module PKGConfig
574-
@@paths = []
575-
@@override_variables = {}
576-
577-
module_function
578-
def add_path(path)
579-
@@paths << path
580-
end
581-
582-
def set_override_variable(key, value)
583-
@@override_variables[key] = value
584-
end
585-
586-
def msvc?
587-
/mswin/.match(RUBY_PLATFORM) and /^cl\b/.match(RbConfig::CONFIG["CC"])
588-
end
589-
590-
def package_config(package)
591-
PackageConfig.new(package,
592-
:msvc_syntax => msvc?,
593-
:override_variables => @@override_variables,
594-
:paths => @@paths)
595-
end
596-
597-
def exist?(pkg)
598-
package_config(pkg).exist?
599-
end
600-
601-
def libs(pkg)
602-
package_config(pkg).libs
603-
end
604-
605-
def libs_only_l(pkg)
606-
package_config(pkg).libs_only_l
607-
end
608-
609-
def libs_only_L(pkg)
610-
package_config(pkg).libs_only_L
611-
end
612-
613-
def cflags(pkg)
614-
package_config(pkg).cflags
615-
end
616-
617-
def cflags_only_I(pkg)
618-
package_config(pkg).cflags_only_I
619-
end
620-
621-
def cflags_only_other(pkg)
622-
package_config(pkg).cflags_only_other
623-
end
624-
625-
def modversion(pkg)
626-
package_config(pkg).version
627-
end
628-
629-
def description(pkg)
630-
package_config(pkg).description
631-
end
632-
633-
def variable(pkg, name)
634-
package_config(pkg).variable(name)
635-
end
636-
637-
def check_version?(pkg, major=0, minor=0, micro=0)
638-
return false unless exist?(pkg)
639-
ver = modversion(pkg).split(".").collect {|item| item.to_i}
640-
(0..2).each {|i| ver[i] = 0 unless ver[i]}
641-
642-
(ver[0] > major ||
643-
(ver[0] == major && ver[1] > minor) ||
644-
(ver[0] == major && ver[1] == minor &&
645-
ver[2] >= micro))
646-
end
647-
648-
def have_package(pkg, major=nil, minor=0, micro=0)
649-
message = "#{pkg}"
650-
unless major.nil?
651-
message << " version (>= #{major}.#{minor}.#{micro})"
652-
end
653-
major ||= 0
654-
result = checking_for(checking_message(message), "%s") do
655-
if check_version?(pkg, major, minor, micro)
656-
"yes (#{modversion(pkg)})"
657-
else
658-
if exist?(pkg)
659-
"no (#{modversion(pkg)})"
660-
else
661-
"no (nonexistent)"
662-
end
663-
end
664-
end
665-
enough_version = result.start_with?("yes")
666-
if enough_version
667-
libraries = libs_only_l(pkg)
668-
dldflags = libs(pkg)
669-
dldflags = (Shellwords.shellwords(dldflags) -
670-
Shellwords.shellwords(libraries))
671-
dldflags = dldflags.map {|s| /\s/ =~ s ? "\"#{s}\"" : s }.join(" ")
672-
$libs += " " + libraries
673-
if /mswin/ =~ RUBY_PLATFORM
674-
$DLDFLAGS += " " + dldflags
675-
else
676-
$LDFLAGS += " " + dldflags
677-
end
678-
$CFLAGS += " " + cflags_only_other(pkg)
679-
if defined?($CXXFLAGS)
680-
$CXXFLAGS += " " + cflags_only_other(pkg)
681-
end
682-
$INCFLAGS += " " + cflags_only_I(pkg)
683-
end
684-
enough_version
685-
end
686-
end

lib/pkg-config/version.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.

pkg-config.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
# License along with this library; if not, write to the Free Software
1717
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818

19-
require_relative "lib/pkg-config/version"
19+
pkg_config_content = File.read(File.join(__dir__, "lib/pkg-config.rb"))
20+
version = pkg_config_content[/^ VERSION = "(.+?)"/, 1]
2021

2122
Gem::Specification.new do |spec|
2223
spec.name = "pkg-config"
23-
spec.version = PKGConfig::VERSION
24+
spec.version = version
2425
spec.homepage = "https://github.com/ruby-gnome/pkg-config"
2526
spec.authors = ["Sutou Kouhei"]
2627
spec.email = ["[email protected]"]

0 commit comments

Comments
 (0)