7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'ext/gdal-ruby/ruby-2.2-patch.rb', line 7
def pkg_config(pkg, option=nil)
if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
elsif ($PKGCONFIG ||=
(pkgconfig = with_config("pkg-config", ("pkg-config" unless CROSS_COMPILING))) &&
find_executable0(pkgconfig) && pkgconfig) and
system("#{$PKGCONFIG} --exists #{pkg}")
pkgconfig = $PKGCONFIG
get = proc {|opt|
opt = IO.popen("#{$PKGCONFIG} --#{opt} #{pkg}", err:[:child, :out], &:read)
opt.strip if $?.success?
}
elsif find_executable0(pkgconfig = "#{pkg}-config")
else
pkgconfig = nil
end
if pkgconfig
get ||= proc {|opt|
opt = IO.popen("#{pkgconfig} --#{opt}", err:[:child, :out], &:read)
opt.strip if $?.success?
}
end
orig_ldflags = $LDFLAGS
if get and option
get[option]
elsif get and try_ldflags(ldflags = get['libs'])
if incflags = get['cflags-only-I']
$INCFLAGS << " " << incflags
cflags = get['cflags-only-other']
else
cflags = get['cflags']
end
libs = get['libs-only-l'] || ''
ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ")
$CFLAGS += " " << cflags
$CXXFLAGS += " " << cflags
$LDFLAGS = [orig_ldflags, ldflags].join(' ')
$libs += " " << libs
Logging::message "package configuration for %s\n", pkg
Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n",
cflags, ldflags, libs
[cflags, ldflags, libs]
else
Logging::message "package configuration for %s is not found\n", pkg
nil
end
end
|