+# 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;
+
+ if ($line =~ /ifuname\(\!"(\w+)"\)/)
+ {
+ my $uname = $1;
+ if ($uname eq $^O)
+ {
+ $line = "";
+ return "";
+ }
+
+ $line =~ s/ifuname\(\!"(.+?)"\)//;
+ }
+
+ if ($line =~ /ifuname\("(\w+)"\)/)
+ {
+ my $uname = $1;
+ if ($uname ne $^O)
+ {
+ $line = "";
+ return "";
+ }
+
+ $line =~ s/ifuname\("(.+?)"\)//;
+ }
+
+ if ($line =~ /if\("(\w+)"\)/)
+ {
+ if (defined $main::config{$1})
+ {
+ if (($main::config{$1} !~ /y/i) and ($main::config{$1} ne "1"))
+ {
+ $line = "";
+ return "";
+ }
+ }
+
+ $line =~ s/if\("(.+?)"\)//;
+ }
+ if ($line =~ /if\(\!"(\w+)"\)/)
+ {
+ if (!exists $main::config{$1})
+ {
+ $line = "";
+ return "";
+ }
+ else
+ {
+ if (defined $1)
+ {
+ if (exists ($main::config{$1}) and (($main::config{$1} =~ /y/i) or ($main::config{$1} eq "1")))
+ {
+ $line = "";
+ return "";
+ }
+ }
+ }
+
+ $line =~ s/if\(\!"(.+?)"\)//;
+ }
+ 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);
+ unlink($tmpfile);
+ $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);
+ $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";
+ print "\nMake sure you have pkg-config installed\n";
+ print "\nIn the case of gnutls configuration errors on debian,\n";
+ print "Ubuntu, etc, you should ensure that you have installed\n";
+ print "gnutls-bin as well as libgnutls-dev and libgnutls.\n";
+ exit;
+ }
+ else
+ {
+ return $line;
+ }
+}
+