+# Translate a $CompileFlags etc line and parse out function calls
+# to functions within these modules at configure time.
+sub translate_functions($$)
+{
+ my ($line,$module) = @_;
+
+ eval
+ {
+ $module =~ /modules*\/(.+?)$/;
+ $module = $1;
+
+ # This is only a cursory check, just designed to catch casual accidental use of backticks.
+ # There are pleanty of ways around it, but its not supposed to be for security, just checking
+ # that people are using the new configuration api as theyre supposed to and not just using
+ # backticks instead of eval(), being as eval has accountability. People wanting to get around
+ # the accountability will do so anyway.
+ if (($line =~ /`/) && ($line !~ /eval\(.+?`.+?\)/))
+ {
+ die "Developers should no longer use backticks in configuration macros. Please use exec() and eval() macros instead. Offending line: $line (In module: $module)";
+ }
+ while ($line =~ /exec\("(.+?)"\)/)
+ {
+ print "Executing program for module \e[1;32m$module\e[0m ... \e[1;32m$1\e[0m\n";
+ my $replace = `$1`;
+ die $replace if ($replace =~ /Configuration failed/);
+ chomp($replace);
+ $line =~ s/exec\("(.+?)"\)/$replace/;
+ }
+ while ($line =~ /execruntime\("(.+?)"\)/)
+ {
+ $line =~ s/execruntime\("(.+?)"\)/`$1`/;
+ }
+ while ($line =~ /eval\("(.+?)"\)/)
+ {
+ print "Evaluating perl code for module \e[1;32m$module\e[0m ... ";
+ my $tmpfile;
+ do
+ {
+ $tmpfile = tmpnam();
+ } until sysopen(TF, $tmpfile, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW, 0700);
+ print "(Created and executed \e[1;32m$tmpfile\e[0m)\n";
+ print TF $1;
+ close TF;
+ my $replace = `perl $tmpfile`;
+ chomp($replace);
+ $line =~ s/eval\("(.+?)"\)/$replace/;
+ }
+ while ($line =~ /pkgconflibs\("(.+?)","(.+?)","(.+?)"\)/)
+ {
+ my $replace = pkgconfig_get_lib_dirs($1, $2, $3, $module);
+ $line =~ s/pkgconflibs\("(.+?)","(.+?)","(.+?)"\)/$replace/;
+ }
+ while ($line =~ /pkgconfversion\("(.+?)","(.+?)"\)/)
+ {
+ if (pkgconfig_check_version($1, $2, $module) != 1)
+ {
+ die "Version of package $1 is too old. Please upgrade it to version \e[1;32m$2\e[0m or greater and try again.";
+ }
+ # This doesnt actually get replaced with anything
+ $line =~ s/pkgconfversion\("(.+?)","(.+?)"\)//;
+ }
+ while ($line =~ /pkgconflibs\("(.+?)","(.+?)",""\)/)
+ {
+ my $replace = pkgconfig_get_lib_dirs($1, $2, "", $module);
+ $line =~ s/pkgconflibs\("(.+?)","(.+?)",""\)/$replace/;
+ }
+ while ($line =~ /pkgconfincludes\("(.+?)","(.+?)",""\)/)
+ {
+ my $replace = pkgconfig_get_include_dirs($1, $2, "", $module);
+ $line =~ s/pkgconfincludes\("(.+?)","(.+?)",""\)/$replace/;
+ }
+ while ($line =~ /pkgconfincludes\("(.+?)","(.+?)","(.+?)"\)/)
+ {
+ my $replace = pkgconfig_get_include_dirs($1, $2, $3, $module);
+ $line =~ s/pkgconfincludes\("(.+?)","(.+?)","(.+?)"\)/$replace/;
+ }
+ while ($line =~ /rpath\("(.+?)"\)/)
+ {
+ my $replace = make_rpath($1,$module);
+ $replace = "" if ($^O =~ /darwin/i);
+ $line =~ s/rpath\("(.+?)"\)/$replace/;
+ }
+ };
+ if ($@)
+ {
+ my $err = $@;
+ $err =~ s/at .+? line \d+.*//g;
+ print "\n\nConfiguration failed. The following error occured:\n\n$err\n";
+ exit;
+ }
+ else
+ {
+ return $line;
+ }
+}
+