]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/utilities.pm
Output for 'using defaults' when nothing of interest found
[user/henk/code/inspircd.git] / make / utilities.pm
1 package make::utilities;
2 use Exporter 'import';
3 @EXPORT = qw(make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs translate_functions);
4
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.
8
9 # \033[1;32msrc/Makefile\033[0m
10
11 my %already_added = ();
12
13 sub make_rpath($)
14 {
15         my ($executable) = @_;
16         chomp($data = `$executable`);
17         $data =~ /-L(\S+)\s/;
18         $libpath = $1;
19         if (!exists $already_added{$libpath})
20         {
21                 print "Adding extra library path \033[1;32m$libpath\033[0m ...\n";
22                 $already_added{$libpath} = 1;
23         }
24         return "-Wl,--rpath -Wl,$libpath -L$libpath";
25 }
26
27 sub extend_pkg_path()
28 {
29         if (!exists $ENV{PKG_CONFIG_PATH})
30         {
31                 $ENV{PKG_CONFIG_PATH} = "/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/libdata/pkgconfig:/usr/X11R6/libdata/pkgconfig";
32         }
33         else
34         {
35                 $ENV{PKG_CONFIG_PATH} .= ":/usr/local/lib/pkgconfig:/usr/local/libdata/pkgconfig:/usr/X11R6/libdata/pkgconfig";
36         }
37 }
38
39 sub pkgconfig_get_include_dirs($$$)
40 {
41         my ($packagename, $headername, $defaults) = @_;
42         extend_pkg_path();
43
44         print "Locating include directory for package \033[1;32m$packagename\033[0m ... ";
45
46         $ret = `pkg-config --cflags $packagename 2>/dev/null`;
47         if ((!defined $ret) || ($ret eq ""))
48         {
49                 $foo = `locate "$headername" | head -n 1`;
50                 $foo =~ /(.+)\Q$headername\E/;
51                 if (defined $1)
52                 {
53                         $foo = "-I$1";
54                 }
55                 else
56                 {
57                         $foo = "";
58                 }
59                 $ret = "$foo";
60         }
61         if (($defaults ne "") && (($ret eq "") || (!defined $ret)))
62         {
63                 $ret = "$foo " . $defaults;
64         }
65         chomp($ret);
66         if (($ret eq " ") || (!defined $ret))
67         {
68                 print "\033[1;32mUsing defaults\033[0m\n";
69         }
70         else
71         {
72                 print "\033[1;32m$ret\033[0m\n";
73         }
74         return $ret;
75 }
76
77 sub pkgconfig_get_lib_dirs($$$)
78 {
79         my ($packagename, $libname, $defaults) = @_;
80         extend_pkg_path();
81
82         print "Locating library directory for package \033[1;32m$packagename\033[0m ... ";
83
84         $ret = `pkg-config --libs $packagename 2>/dev/null`;
85         if ((!defined $ret) || ($ret eq ""))
86         {
87                 $foo = `locate "$libname" | head -n 1`;
88                 $foo =~ /(.+)\Q$libname\E/;
89                 if (defined $1)
90                 {
91                         $foo = "-L$1";
92                 }
93                 else
94                 {
95                         $foo = "";
96                 }
97                 $ret = "$foo";
98         }
99
100         if (($defaults ne "") && (($ret eq "") || (!defined $ret)))
101         {
102                 $ret = "$foo " . $defaults;
103         }
104         chomp($ret);
105         if (($ret eq " ") || (!defined $ret))
106         {
107                 print "\033[1;32mUsing defaults\033[0m\n";
108         }
109         else
110         {
111                 print "\033[1;32m$ret\033[0m\n";
112         }
113         return $ret;
114 }
115
116 # Translate a $CompileFlags etc line and parse out function calls
117 # to functions within these modules at configure time.
118 sub translate_functions($)
119 {
120         my ($line) = @_;
121         while ($line =~ /pkgconflibs\("(.+?)","(.+?)","(.+?)"\)/)
122         {
123                 my $replace = pkgconfig_get_lib_dirs($1, $2, $3);
124                 $line =~ s/pkgconflibs\("(.+?)","(.+?)","(.+?)"\)/$replace/;
125         }
126         while ($line =~ /pkgconflibs\("(.+?)","(.+?)",""\)/)
127         {
128                 my $replace = pkgconfig_get_lib_dirs($1, $2, "");
129                 $line =~ s/pkgconflibs\("(.+?)","(.+?)",""\)/$replace/;
130         }
131         while ($line =~ /pkgconfincludes\("(.+?)","(.+?)",""\)/)
132         {
133                 my $replace = pkgconfig_get_include_dirs($1, $2, "");
134                 $line =~ s/pkgconfincludes\("(.+?)","(.+?)",""\)/$replace/;
135         }
136         while ($line =~ /pkgconfincludes\("(.+?)","(.+?)","(.+?)"\)/)
137         {
138                 my $replace = pkgconfig_get_include_dirs($1, $2, $3);
139                 $line =~ s/pkgconfincludes\("(.+?)","(.+?)","(.+?)"\)/$replace/;
140         }
141         while ($line =~ /rpath\("(.+?)"\)/)
142         {
143                 my $replace = make_rpath($1);
144                 $line =~ s/rpath\("(.+?)"\)/$replace/;
145         }
146         return $line;
147 }
148
149 1;
150