1 package make::utilities;
4 @EXPORT = qw(make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs translate_functions);
6 # Parse the output of a *_config program,
7 # such as pcre_config, take out the -L
8 # directive and return an rpath for it.
10 # \033[1;32msrc/Makefile\033[0m
12 my %already_added = ();
16 my ($executable, $module) = @_;
17 chomp($data = `$executable`);
19 while ($data =~ /-L(\S+)/)
22 if (!exists $already_added{$libpath})
24 print "Adding extra library path to \033[1;32m$module\033[0m ... \033[1;32m$libpath\033[0m\n";
25 $already_added{$libpath} = 1;
27 $output .= "-Wl,--rpath -Wl,$libpath -L$libpath ";
35 if (!exists $ENV{PKG_CONFIG_PATH})
37 $ENV{PKG_CONFIG_PATH} = "/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/libdata/pkgconfig:/usr/X11R6/libdata/pkgconfig";
41 $ENV{PKG_CONFIG_PATH} .= ":/usr/local/lib/pkgconfig:/usr/local/libdata/pkgconfig:/usr/X11R6/libdata/pkgconfig";
45 sub pkgconfig_get_include_dirs($$$;$)
47 my ($packagename, $headername, $defaults, $module) = @_;
50 print "Locating include directory for package \033[1;32m$packagename\033[0m for module \033[1;32m$module\033[0m... ";
52 $ret = `pkg-config --cflags $packagename 2>/dev/null`;
53 if ((!defined $ret) || ($ret eq ""))
55 $foo = `locate "$headername" | head -n 1`;
56 $foo =~ /(.+)\Q$headername\E/;
67 if (($defaults ne "") && (($ret eq "") || (!defined $ret)))
69 $ret = "$foo " . $defaults;
72 if (($ret eq " ") || (!defined $ret))
74 print "\033[1;32mUsing defaults\033[0m\n";
78 print "\033[1;32m$ret\033[0m\n";
83 sub pkgconfig_get_lib_dirs($$$;$)
85 my ($packagename, $libname, $defaults, $module) = @_;
88 print "Locating library directory for package \033[1;32m$packagename\033[0m for module \033[1;32m$module\033[0m... ";
90 $ret = `pkg-config --libs $packagename 2>/dev/null`;
91 if ((!defined $ret) || ($ret eq ""))
93 $foo = `locate "$libname" | head -n 1`;
94 $foo =~ /(.+)\Q$libname\E/;
106 if (($defaults ne "") && (($ret eq "") || (!defined $ret)))
108 $ret = "$foo " . $defaults;
111 if (($ret eq " ") || (!defined $ret))
113 print "\033[1;32mUsing defaults\033[0m\n";
117 print "\033[1;32m$ret\033[0m\n";
122 # Translate a $CompileFlags etc line and parse out function calls
123 # to functions within these modules at configure time.
124 sub translate_functions($$)
126 my ($line,$module) = @_;
130 $module =~ /modules*\/(.+?)$/;
133 # This is only a cursory check, just designed to catch casual accidental use of backticks.
134 # There are pleanty of ways around it, but its not supposed to be for security, just checking
135 # that people are using the new configuration api as theyre supposed to and not just using
136 # backticks instead of eval(), being as eval has accountability. People wanting to get around
137 # the accountability will do so anyway.
138 if (($line =~ /`/) && ($line !~ /eval\(.+?`.+?\)/))
140 die "Developers should no longer use backticks in configuration macros. Please use exec() and eval() macros instead. Offending line: $line (In module: $module)";
142 while ($line =~ /exec\("(.+?)"\)/)
144 print "Executing program for module \033[1;32m$module\033[0m ... \033[1;32m$1\033[0m\n";
147 $line =~ s/exec\("(.+?)"\)/$replace/;
149 while ($line =~ /eval\("(.+?)"\)/)
151 print "Evaluating perl code for module \033[1;32m$module\033[0m ... ";
156 } until sysopen(TF, $tmpfile, O_RDWR|O_CREAT|O_EXCL, 0700);
157 print "(Created and executed \033[1;32m$tmpfile\033[0m)\n";
160 my $replace = `perl $tmpfile`;
162 $line =~ s/eval\("(.+?)"\)/$replace/;
164 while ($line =~ /pkgconflibs\("(.+?)","(.+?)","(.+?)"\)/)
166 my $replace = pkgconfig_get_lib_dirs($1, $2, $3, $module);
167 $line =~ s/pkgconflibs\("(.+?)","(.+?)","(.+?)"\)/$replace/;
169 while ($line =~ /pkgconflibs\("(.+?)","(.+?)",""\)/)
171 my $replace = pkgconfig_get_lib_dirs($1, $2, "", $module);
172 $line =~ s/pkgconflibs\("(.+?)","(.+?)",""\)/$replace/;
174 while ($line =~ /pkgconfincludes\("(.+?)","(.+?)",""\)/)
176 my $replace = pkgconfig_get_include_dirs($1, $2, "", $module);
177 $line =~ s/pkgconfincludes\("(.+?)","(.+?)",""\)/$replace/;
179 while ($line =~ /pkgconfincludes\("(.+?)","(.+?)","(.+?)"\)/)
181 my $replace = pkgconfig_get_include_dirs($1, $2, $3, $module);
182 $line =~ s/pkgconfincludes\("(.+?)","(.+?)","(.+?)"\)/$replace/;
184 while ($line =~ /rpath\("(.+?)"\)/)
186 my $replace = make_rpath($1,$module);
187 $line =~ s/rpath\("(.+?)"\)/$replace/;
192 print "\n\nConfiguration failed. The following error occured:\n\n$@\n";