|
14 | 14 | # License along with this library; if not, write to the Free Software |
15 | 15 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
16 | 16 |
|
17 | | -begin |
18 | | - require_relative "pkg-config/version" |
19 | | -rescue LoadError |
20 | | -end |
21 | | - |
22 | 17 | require "English" |
23 | 18 | require "pathname" |
24 | 19 | require "rbconfig" |
25 | 20 | require "shellwords" |
26 | 21 |
|
| 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 | + |
27 | 139 | class PackageConfig |
28 | 140 | class Error < StandardError |
29 | 141 | end |
@@ -569,118 +681,3 @@ def normalize_paths(paths) |
569 | 681 | end |
570 | 682 | end |
571 | 683 | 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 |
0 commit comments