[Vala] [Patch] mingw32-gcc support



Hello

    This is a simple patch to allow valac to generate win32 executable using mingw32 C compiler properly.
It is just a dirty hack in to gobject/valaccodecompiler.c not gobject/valaccodecompiler.vala.
It seems that g_spawn_command_line_sync and g_shell_quote in GLIB has some problem on Win32 platform.

Pathompol Suebpradist

----------------------------- PATCH ----------------------
--- vala-0.3.3.orig/gobject/valaccodecompiler.c Wed Jun  4 03:22:52 2008
+++ vala-0.3.3/gobject/valaccodecompiler.c Sat Jun  7 11:25:21 2008
@@ -28,6 +28,46 @@
 #include <glib/gstdio.h>
 
 
+#ifdef _WIN32
+#undef g_shell_quote
+//based on glib's g_shell_quote
+gchar*
+g_shell_quote_win32 (const gchar *unquoted_string)
+{
+  /* We always use single quotes, because the algorithm is cheesier.
+   * We could use double if we felt like it, that might be more
+   * human-readable.
+   */
+
+  const gchar *p;
+  GString *dest;
+
+  g_return_val_if_fail (unquoted_string != NULL, NULL);
+  
+  dest = g_string_new ("\"");
+
+  p = unquoted_string;
+
+  /* could speed this up a lot by appending chunks of text at a
+   * time.
+   */
+  while (*p)
+    {
+      /* Replace literal ' with a close ', a \', and a open ' */
+      if (*p == '\"')
+        g_string_append (dest, "\"\\\"\"");
+      else
+        g_string_append_c (dest, *p);
+
+      ++p;
+    }
+
+  /* close the quote */
+  g_string_append_c (dest, '\"');
+  return g_string_free (dest, FALSE);
+}
+#define g_shell_quote g_shell_quote_win32
+#endif
 
 
 enum  {
@@ -184,10 +224,65 @@
  ;
  /* TODO compile the C code files in parallel*/
  if (cc_command == NULL) {
+#ifdef _WIN32
+ cc_command = "gcc";
+#else
  cc_command = "cc";
+#endif
  }
  _tmp9 = NULL;
  cmdline = (_tmp9 = cc_command, (_tmp9 == NULL ? NULL : g_strdup (_tmp9)));
+ /* To compile with mingw32 we have to pass source files argument before -o */ 
+ /* we're only interested in non-pkg source files */
+ source_files = vala_code_context_get_source_files (context);
+ {
+ GeeList* file_collection;
+ int file_it;
+ file_collection = source_files;
+ for (file_it = 0; file_it < gee_collection_get_size (GEE_COLLECTION (file_collection)); file_it = file_it + 1) {
+ ValaSourceFile* file;
+ file = ((ValaSourceFile*) (gee_list_get (GEE_LIST (file_collection), file_it)));
+ {
+ if (!vala_source_file_get_external_package (file)) {
+ char* _tmp28;
+ char* _tmp27;
+ char* _tmp26;
+ char* _tmp25;
+ _tmp28 = NULL;
+ _tmp27 = NULL;
+ _tmp26 = NULL;
+ _tmp25 = NULL;
+ cmdline = (_tmp28 = g_strconcat (cmdline, (_tmp27 = (g_strconcat (" ", (_tmp26 = g_shell_quote ((_tmp25 = vala_source_file_get_csource_filename (file)))), NULL))), NULL), (cmdline = (g_free (cmdline), NULL)), _tmp28);
+ _tmp27 = (g_free (_tmp27), NULL);
+ _tmp26 = (g_free (_tmp26), NULL);
+ _tmp25 = (g_free (_tmp25), NULL);
+ }
+ (file == NULL ? NULL : (file = (g_object_unref (file), NULL)));
+ }
+ }
+ }
+ c_source_files = vala_code_context_get_c_source_files (context);
+ {
+ GeeList* file_collection;
+ int file_it;
+ file_collection = c_source_files;
+ for (file_it = 0; file_it < gee_collection_get_size (GEE_COLLECTION (file_collection)); file_it = file_it + 1) {
+ char* file;
+ file = ((char*) (gee_list_get (GEE_LIST (file_collection), file_it)));
+ {
+ char* _tmp31;
+ char* _tmp30;
+ char* _tmp29;
+ _tmp31 = NULL;
+ _tmp30 = NULL;
+ _tmp29 = NULL;
+ cmdline = (_tmp31 = g_strconcat (cmdline, (_tmp30 = (g_strconcat (" ", (_tmp29 = g_shell_quote (file)), NULL))), NULL), (cmdline = (g_free (cmdline), NULL)), _tmp31);
+ _tmp30 = (g_free (_tmp30), NULL);
+ _tmp29 = (g_free (_tmp29), NULL);
+ file = (g_free (file), NULL);
+ }
+ }
+ }
  if (vala_code_context_get_debug (context)) {
  char* _tmp10;
  _tmp10 = NULL;
@@ -220,6 +315,11 @@
  output = (g_free (output), NULL);
  }
  }
+#ifdef _WIN32 //generate win32 application
+ char* _tmpW32;
+ _tmpW32 = NULL;
+ cmdline = (_tmpW32 = g_strconcat (cmdline, (" -mwindows"), NULL), (cmdline = (g_free (cmdline), NULL)), _tmpW32);
+#endif
  _tmp18 = NULL;
  _tmp17 = NULL;
  cmdline = (_tmp18 = g_strconcat (cmdline, (_tmp17 = (g_strconcat (" ", pkgflags, NULL))), NULL), (cmdline = (g_free (cmdline), NULL)), _tmp18);
@@ -258,58 +358,12 @@
  _tmp23 = (g_free (_tmp23), NULL);
  _tmp22 = (g_free (_tmp22), NULL);
  }
- /* we're only interested in non-pkg source files */
- source_files = vala_code_context_get_source_files (context);
- {
- GeeList* file_collection;
- int file_it;
- file_collection = source_files;
- for (file_it = 0; file_it < gee_collection_get_size (GEE_COLLECTION (file_collection)); file_it = file_it + 1) {
- ValaSourceFile* file;
- file = ((ValaSourceFile*) (gee_list_get (GEE_LIST (file_collection), file_it)));
- {
- if (!vala_source_file_get_external_package (file)) {
- char* _tmp28;
- char* _tmp27;
- char* _tmp26;
- char* _tmp25;
- _tmp28 = NULL;
- _tmp27 = NULL;
- _tmp26 = NULL;
- _tmp25 = NULL;
- cmdline = (_tmp28 = g_strconcat (cmdline, (_tmp27 = (g_strconcat (" ", (_tmp26 = g_shell_quote ((_tmp25 = vala_source_file_get_csource_filename (file)))), NULL))), NULL), (cmdline = (g_free (cmdline), NULL)), _tmp28);
- _tmp27 = (g_free (_tmp27), NULL);
- _tmp26 = (g_free (_tmp26), NULL);
- _tmp25 = (g_free (_tmp25), NULL);
- }
- (file == NULL ? NULL : (file = (g_object_unref (file), NULL)));
- }
- }
- }
- c_source_files = vala_code_context_get_c_source_files (context);
- {
- GeeList* file_collection;
- int file_it;
- file_collection = c_source_files;
- for (file_it = 0; file_it < gee_collection_get_size (GEE_COLLECTION (file_collection)); file_it = file_it + 1) {
- char* file;
- file = ((char*) (gee_list_get (GEE_LIST (file_collection), file_it)));
- {
- char* _tmp31;
- char* _tmp30;
- char* _tmp29;
- _tmp31 = NULL;
- _tmp30 = NULL;
- _tmp29 = NULL;
- cmdline = (_tmp31 = g_strconcat (cmdline, (_tmp30 = (g_strconcat (" ", (_tmp29 = g_shell_quote (file)), NULL))), NULL), (cmdline = (g_free (cmdline), NULL)), _tmp31);
- _tmp30 = (g_free (_tmp30), NULL);
- _tmp29 = (g_free (_tmp29), NULL);
- file = (g_free (file), NULL);
- }
- }
- }
  {
+#ifdef _WIN32
+ system(cmdline);
+#else
  g_spawn_command_line_sync (cmdline, NULL, NULL, &exit_status, &inner_error);
+#endif
  if (inner_error != NULL) {
  if (inner_error->domain == G_SPAWN_ERROR) {
  goto __catch2_g_spawn_error;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]