1 package make::utilities;
3 @EXPORT = qw(make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs translate_functions);
5 # Parse the output of a *_config program,
6 # such as pcre_config, take out the -L
7 # directive and return an rpath for it.
9 # \033[1;32msrc/Makefile\033[0m
11 my %already_added = ();
15 my ($executable) = @_;
16 chomp($data = `$executable`);
19 if (!exists $already_added{$libpath})
21 print "Adding extra library path \033[1;32m$libpath\033[0m ...\n";
22 $already_added{$libpath} = 1;
24 return "-Wl,--rpath -Wl,$libpath -L$libpath";
29 if (!exists $ENV{PKG_CONFIG_PATH})
31 $ENV{PKG_CONFIG_PATH} = "/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/libdata/pkgconfig:/usr/X11R6/libdata/pkgconfig";
35 $ENV{PKG_CONFIG_PATH} .= ":/usr/local/lib/pkgconfig:/usr/local/libdata/pkgconfig:/usr/X11R6/libdata/pkgconfig";
39 sub pkgconfig_get_include_dirs($$$)
41 my ($packagename, $headername, $defaults) = @_;
44 print "Locating include directory for package \033[1;32m$packagename\033[0m ... ";
46 $ret = `pkg-config --cflags $packagename 2>/dev/null`;
47 if ((!defined $ret) || ($ret eq ""))
49 $foo = `locate "$headername" | head -n 1`;
50 $foo =~ /(.+)\Q$headername\E/;
61 if (($defaults ne "") && (($ret eq "") || (!defined $ret)))
63 $ret = "$foo " . $defaults;
66 if (($ret eq " ") || (!defined $ret))
68 print "\033[1;32mUsing defaults\033[0m\n";
72 print "\033[1;32m$ret\033[0m\n";
77 sub pkgconfig_get_lib_dirs($$$)
79 my ($packagename, $libname, $defaults) = @_;
82 print "Locating library directory for package \033[1;32m$packagename\033[0m ... ";
84 $ret = `pkg-config --libs $packagename 2>/dev/null`;
85 if ((!defined $ret) || ($ret eq ""))
87 $foo = `locate "$libname" | head -n 1`;
88 $foo =~ /(.+)\Q$libname\E/;
100 if (($defaults ne "") && (($ret eq "") || (!defined $ret)))
102 $ret = "$foo " . $defaults;
105 if (($ret eq " ") || (!defined $ret))
107 print "\033[1;32mUsing defaults\033[0m\n";
111 print "\033[1;32m$ret\033[0m\n";
116 # Translate a $CompileFlags etc line and parse out function calls
117 # to functions within these modules at configure time.
118 sub translate_functions($)
121 while ($line =~ /pkgconflibs\("(.+?)","(.+?)","(.+?)"\)/)
123 my $replace = pkgconfig_get_lib_dirs($1, $2, $3);
124 $line =~ s/pkgconflibs\("(.+?)","(.+?)","(.+?)"\)/$replace/;
126 while ($line =~ /pkgconflibs\("(.+?)","(.+?)",""\)/)
128 my $replace = pkgconfig_get_lib_dirs($1, $2, "");
129 $line =~ s/pkgconflibs\("(.+?)","(.+?)",""\)/$replace/;
131 while ($line =~ /pkgconfincludes\("(.+?)","(.+?)",""\)/)
133 my $replace = pkgconfig_get_include_dirs($1, $2, "");
134 $line =~ s/pkgconfincludes\("(.+?)","(.+?)",""\)/$replace/;
136 while ($line =~ /pkgconfincludes\("(.+?)","(.+?)","(.+?)"\)/)
138 my $replace = pkgconfig_get_include_dirs($1, $2, $3);
139 $line =~ s/pkgconfincludes\("(.+?)","(.+?)","(.+?)"\)/$replace/;
141 while ($line =~ /rpath\("(.+?)"\)/)
143 my $replace = make_rpath($1);
144 $line =~ s/rpath\("(.+?)"\)/$replace/;