1 # UCW Library configuration system: pkg-config and friends
2 # (c) 2008 Martin Mares <mj@ucw.cz>
3 # (c) 2017 Pavel Charvat <pchar@ucw.cz>
5 package UCW::Configure::Pkg;
12 our @ISA = qw(Exporter);
13 our @EXPORT = qw(&TryCmd &PkgConfig &TrivConfig);
18 defined $res or return;
20 return $res unless $?;
24 sub maybe_manually($) {
27 if (Get("$n")) { Log "YES (set manually)\n"; }
28 else { Log "NO (set manually)\n"; }
35 Log "Checking for pkg-config ... ";
36 if (!maybe_manually("CONFIG_HAVE_PKGCONFIG")) {
37 my $ver = TryCmd("pkg-config --version 2>/dev/null");
40 Set("CONFIG_HAVE_PKGCONFIG", 0);
42 Log("YES: version $ver\n");
43 Set("CONFIG_HAVE_PKGCONFIG", 1);
44 Set("CONFIG_VER_PKGCONFIG", $ver);
47 return Get("CONFIG_HAVE_PKGCONFIG");
53 my $upper = $pkg; $upper =~ tr/a-z/A-Z/; $upper =~ s/[^0-9A-Z]+/_/g;
54 PkgConfigTool() unless IsSet("CONFIG_HAVE_PKGCONFIG");
55 Log "Checking for package $pkg ... ";
56 maybe_manually("CONFIG_HAVE_$upper") and return Get("CONFIG_HAVE_$upper");
57 if (!Get("CONFIG_HAVE_PKGCONFIG")) {
58 Log("NONE: pkg-config missing\n");
61 my $pc = "pkg-config";
62 if (defined($opts{path})) {
63 $pc = "PKG_CONFIG_PATH=$opts{path} $pc";
65 if (defined($opts{args})) {
66 $pc = "$pc $opts{args}";
68 my $ver = TryCmd("$pc --modversion $pkg 2>/dev/null");
73 if (defined($opts{minversion})) {
74 my $min = $opts{minversion};
75 if (!defined TryCmd("$pc --atleast-version=$min $pkg")) {
76 Log("NO: version $ver is too old (need >= $min)\n");
80 Log("YES: version $ver\n");
81 Set("CONFIG_HAVE_$upper" => 1);
82 Set("CONFIG_VER_$upper" => $ver);
83 my $cf = TryCmd("$pc --cflags $pkg");
84 Set("${upper}_CFLAGS" => $cf) if defined $cf;
85 my $lf = TryCmd("$pc --libs $pkg");
86 Set("${upper}_LIBS" => $lf) if defined $lf;
92 return join(".", map { sprintf("%05s", $_) } split(/\./, $v));
98 my $upper = $pkg; $upper =~ tr/a-z/A-Z/; $upper =~ s/[^0-9A-Z]+/_/g;
99 Log "Checking for package $pkg ... ";
100 maybe_manually("CONFIG_HAVE_$upper") and return Get("CONFIG_HAVE_$upper");
101 my $pc = $opts{script};
102 my $ver = TryCmd("$pc --version 2>/dev/null");
107 if (defined($opts{minversion})) {
108 my $min = $opts{minversion};
109 if (ver_norm($ver) lt ver_norm($min)) {
110 Log("NO: version $ver is too old (need >= $min)\n");
114 Log("YES: version $ver\n");
115 Set("CONFIG_HAVE_$upper" => 1);
116 Set("CONFIG_VER_$upper" => $ver);
118 my $want = $opts{want};
119 defined $want or $want = ["cflags", "libs"];
121 my $uw = $w; $uw =~ tr/a-z-/A-Z_/;
122 my $cf = TryCmd("$pc --$w");
123 Set("${upper}_${uw}" => $cf) if defined $cf;