Fixed Clear signature
[mcs.git] / tools / prj2make / pkgconfiginvoker.cs
blob409fd4c801367225f6c51b67c62856b5bd328432
1 // created on 6/8/2004 at 5:44 AM
2 using System;
3 using System.Diagnostics;
5 namespace Mfconsulting.General
7 public sealed class PkgConfigInvoker
10 public static string GetPkgConfigVersion()
12 string pkgout = null;
14 pkgout = RunPkgConfig("--version");
16 if(pkgout != null)
18 return pkgout;
21 return null;
24 public static string GetPkgVariableValue(string strPkg, string strVarName)
26 string pkgout = null;
28 pkgout = RunPkgConfig(String.Format("--variable={0} {1}",
29 strVarName, strPkg));
31 if(pkgout != null)
33 return pkgout;
36 return null;
39 public static string GetPkgConfigModuleVersion(string strPkg)
41 string pkgout = null;
43 pkgout = RunPkgConfig(String.Format("--modversion {0}", strPkg));
45 if(pkgout != null)
47 return pkgout;
50 return null;
53 public static string RunPkgConfig(string strArgLine)
55 string pkgout;
57 ProcessStartInfo pi = new ProcessStartInfo ();
58 pi.FileName = "pkg-config";
59 pi.RedirectStandardOutput = true;
60 pi.UseShellExecute = false;
61 pi.Arguments = strArgLine;
62 Process p = null;
63 try
65 p = Process.Start (pi);
67 catch (Exception e)
69 Console.WriteLine("Couldn't run pkg-config: " + e.Message);
70 return null;
73 if (p.StandardOutput == null)
75 Console.WriteLine("Specified package did not return any information");
78 pkgout = p.StandardOutput.ReadToEnd ();
79 p.WaitForExit ();
80 if (p.ExitCode != 0)
82 Console.WriteLine("Error running pkg-config. Check the above output.");
83 return null;
86 if (pkgout != null)
88 p.Close ();
89 return pkgout;
92 p.Close ();
94 return null;