On Sat, May 16, 2009 at 20:55, Benjamin Johnson <obeythepenguin@gmail.com> wrote:
In case anyone finds this useful, I've written a patch to compile
libgpod-0.7.2 on Windows.  I was able to build the library (using
./configure --prefix= --disable-libxml --disable-pygobject) and run
the included test applications on my first-gen iPod nano.  Everything
should be correctly #ifdef'd to not break other platforms, but I have
not tested this yet since my Linux system already syncs the iPod just
fine. :-)

I think you should avoid having all these conditionals in the code. My comments below; I hope they're useful.
 


My specific build environment was Windows XP Professional SP3,
MinGW-5.1.4, MSYS-1.0.10, gtk+-bundle_2.16.1-20090419_win32,
libintl-0.14.4-lib.

Anyway, the patch:

diff -ur libgpod-0.7.2.orig/src/db-artwork-writer.c
libgpod-0.7.2/src/db-artwork-writer.c
--- libgpod-0.7.2.orig/src/db-artwork-writer.c  Sat May 16 14:22:23 2009
+++ libgpod-0.7.2/src/db-artwork-writer.c       Sat May 16 14:26:12 2009
@@ -44,7 +44,9 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#ifndef WIN32
 #include <sys/mman.h>
+#endif

You should probably add a HAVE_SYS_MMAN_H check to autoconf.
 

 #include <sys/stat.h>
 #include <stdio.h>
 #include <sys/types.h>
diff -ur libgpod-0.7.2.orig/src/itdb_itunesdb.c
libgpod-0.7.2/src/itdb_itunesdb.c
--- libgpod-0.7.2.orig/src/itdb_itunesdb.c      Sat May 16 14:22:23 2009
+++ libgpod-0.7.2/src/itdb_itunesdb.c   Sat May 16 14:27:23 2009
@@ -5335,9 +5335,11 @@
       itdb->filename = fn;
    }

+#ifndef WIN32
    /* make sure all buffers are flushed as some people tend to
       disconnect as soon as gtkpod returns */
    sync ();
+#endif

What about creating a dummy definition for sync in Win32? It would be more readable than having the 4-5 ifdefs in the patch. Autoconf helps you here with AC_REPLACE_FUNCS.

+#ifdef WIN32
+    file_out =  g_open (to_file, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,
+                       0);
+#else
    file_out =  g_open (to_file, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,
                        S_IRWXU|S_IRWXG|S_IRWXO);
+#endif

What is the reason for this condition? If the S_I* constants don't exist on Windows, maybe you should define them to zero in a header. An alternative is to pass 0777 instead of the constants, which should work on Windows as well.
 

    if (file_out < 0)
    {
       g_set_error (error,
diff -ur libgpod-0.7.2.orig/src/ithumb-writer.c
libgpod-0.7.2/src/ithumb-writer.c
--- libgpod-0.7.2.orig/src/ithumb-writer.c      Sat May 16 14:22:23 2009
+++ libgpod-0.7.2/src/ithumb-writer.c   Sat May 16 14:25:18 2009
@@ -673,7 +673,11 @@
                               return NULL;
                       }
                       dir = g_build_filename (photos_dir, "Thumbs", NULL);
-                       mkdir (dir, 0777);
+#ifdef WIN32
+                       mkdir (dir);
+#else
+                       mkdir (dir, 0777);
+#endif

You could use g_mkdir instead of ifdef here with no other changes.
 

                       g_free (dir);
                       g_free (photos_dir);

@@ -697,7 +701,11 @@
                       return NULL;
               }
               dir = g_build_filename (control_dir, "Artwork", NULL);
+#ifdef WIN32
+               mkdir (dir);
+#else
               mkdir (dir, 0777);
+#endif

Same here.