]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
compiler: Support configurable pkg-config command so can cross compile
authorRobert Ancell <robert.ancell@canonical.com>
Tue, 18 Dec 2012 22:04:49 +0000 (11:04 +1300)
committerLuca Bruno <luca.bruno@immobiliare.it>
Mon, 14 Jul 2014 16:28:45 +0000 (18:28 +0200)
Fixes bug 690456

codegen/valaccodecompiler.vala
compiler/valacompiler.vala

index b192760fea75b0ad3c83b9637682c73f93d513c6..1ad3f0803e6f81828f47ecee5c4a950957e00e99 100644 (file)
@@ -29,8 +29,8 @@ public class Vala.CCodeCompiler {
        public CCodeCompiler () {
        }
 
-       static bool package_exists(string package_name) {
-               string pc = "pkg-config --exists " + package_name;
+       static bool package_exists(string package_name, string? pkg_config_command = "pkg-config") {
+               string pc = pkg_config_command + " --exists " + package_name;
                int exit_status;
 
                try {
@@ -48,10 +48,14 @@ public class Vala.CCodeCompiler {
         *
         * @param context a code context
         */
-       public void compile (CodeContext context, string? cc_command, string[] cc_options) {
+       public void compile (CodeContext context, string? cc_command, string[] cc_options, string? pkg_config_command = null) {
                bool use_pkgconfig = false;
 
-               string pc = "pkg-config --cflags";
+               if (pkg_config_command == null) {
+                       pkg_config_command = "pkg-config";
+               }
+
+               string pc = pkg_config_command + " --cflags";
                if (!context.compile_only) {
                        pc += " --libs";
                }
@@ -61,7 +65,7 @@ public class Vala.CCodeCompiler {
                        pc += " gthread-2.0";
                }
                foreach (string pkg in context.get_packages ()) {
-                       if (package_exists (pkg)) {
+                       if (package_exists (pkg, pkg_config_command)) {
                                use_pkgconfig = true;
                                pc += " " + pkg;
                        }
index 0962baca583b1041bdb7418a1fc744f987089abf..6ac1e1c8d44b090930ef195a380210d8bfb128dd 100644 (file)
@@ -71,6 +71,7 @@ class Vala.Compiler {
        static string cc_command;
        [CCode (array_length = false, array_null_terminated = true)]
        static string[] cc_options;
+       static string pkg_config_command;
        static string dump_tree;
        static bool save_temps;
        [CCode (array_length = false, array_null_terminated = true)]
@@ -131,6 +132,7 @@ class Vala.Compiler {
                { "enable-gobject-tracing", 0, 0, OptionArg.NONE, ref gobject_tracing, "Enable GObject creation tracing", null },
                { "cc", 0, 0, OptionArg.STRING, ref cc_command, "Use COMMAND as C compiler command", "COMMAND" },
                { "Xcc", 'X', 0, OptionArg.STRING_ARRAY, ref cc_options, "Pass OPTION to the C compiler", "OPTION..." },
+               { "pkg-config", 0, 0, OptionArg.STRING, ref pkg_config_command, "Use COMMAND as pkg-config command", "COMMAND" },
                { "dump-tree", 0, 0, OptionArg.FILENAME, ref dump_tree, "Write code tree to FILE", "FILE" },
                { "save-temps", 0, 0, OptionArg.NONE, ref save_temps, "Keep temporary files", null },
                { "profile", 0, 0, OptionArg.STRING, ref profile, "Use the given profile instead of the default", "PROFILE" },
@@ -442,10 +444,13 @@ class Vala.Compiler {
                        if (cc_command == null && Environment.get_variable ("CC") != null) {
                                cc_command = Environment.get_variable ("CC");
                        }
+                       if (pkg_config_command == null && Environment.get_variable ("PKG_CONFIG") != null) {
+                               pkg_config_command = Environment.get_variable ("PKG_CONFIG");
+                       }
                        if (cc_options == null) {
-                               ccompiler.compile (context, cc_command, new string[] { });
+                               ccompiler.compile (context, cc_command, new string[] { }, pkg_config_command);
                        } else {
-                               ccompiler.compile (context, cc_command, cc_options);
+                               ccompiler.compile (context, cc_command, cc_options, pkg_config_command);
                        }
                }