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

[E-devel] patch for the compilation of embryo with MinGW




Hey,

here is a patch that make embryo compile with MinGW.

regards

Vincent Torri
? embryo_mingw.diff
? src/bin/toto.log
Index: configure.in
===================================================================
RCS file: /var/cvs/e/e17/libs/embryo/configure.in,v
retrieving revision 1.52
diff -u -r1.52 configure.in
--- configure.in	4 Dec 2006 12:14:18 -0000	1.52
+++ configure.in	5 Jan 2007 11:26:40 -0000
@@ -19,15 +19,28 @@
 
 AC_CHECK_FUNCS(gettimeofday)
 
+create_shared_lib=""
+case "$host_os" in
+	mingw|mingw32)
+		create_shared_lib="-no-undefined "
+		;;
+esac
+
+AC_SUBST(create_shared_lib)
+
 AC_CHECK_HEADERS(fnmatch.h,, AC_MSG_ERROR([Cannot find fnmatch.h. Make sure your CFLAGS environment variable contains include lines for the location of this file]))
 
+fnmatch_libs=""
 AC_CHECK_FUNCS(fnmatch, res=yes, res=no)
 if test "x$res" = "xno"; then
-	AC_CHECK_LIB(fnmatch, fnmatch, res=yes, res=no)
+	AC_CHECK_LIB(fnmatch, fnmatch, res=yes fnmatch_libs="-lfnmatch", res=no)
+dnl Test for compilation with MinGW.
+dnl fnmatch function is in the libiberty library
+	if test "x$res" = "xno"; then
+		AC_CHECK_LIB(iberty, fnmatch, res=yes fnmatch_libs="-liberty", res=no)
+	fi
 	if test "x$res" = "xno"; then
-		AC_MSG_ERROR([Cannot find fnmatch() in neither libc nor libfnmatch])
-	else
-		fnmatch_libs="-lfnmatch"
+		AC_MSG_ERROR([Cannot find fnmatch() in neither libc nor libfnmatch, nor libiberty])
 	fi
 fi
 
Index: src/bin/embryo_cc_prefix.c
===================================================================
RCS file: /var/cvs/e/e17/libs/embryo/src/bin/embryo_cc_prefix.c,v
retrieving revision 1.4
diff -u -r1.4 embryo_cc_prefix.c
--- src/bin/embryo_cc_prefix.c	6 Sep 2006 07:11:31 -0000	1.4
+++ src/bin/embryo_cc_prefix.c	5 Jan 2007 11:26:40 -0000
@@ -11,18 +11,218 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/param.h>
-#include <dlfcn.h>
 #include <math.h>
 #include <fnmatch.h>
 #include <limits.h>
 #include <ctype.h>
 #include <time.h>
 #include <dirent.h>
+#ifdef WIN32
+#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#else
+#include <dlfcn.h> 	/* dlopen,dlclose,etc */
 #include <pwd.h>
 #include <grp.h>
 #include <glob.h>
+#endif /* WIN32 */
+
 #include "embryo_cc_prefix.h"
 
+/* FIXME: that hack is a temporary one. That code will be in MinGW soon */
+#ifdef WIN32
+
+#define RTLD_LAZY 1 /* lazy function call binding */
+#define RTLD_NOW 2 /* immediate function call binding */
+#define RTLD_GLOBAL 4 /* symbols in this dlopen'ed obj are visible
+			 to other dlopen'ed objs */
+
+static char *dlerr_ptr;
+static char dlerr_data[80];
+
+void *dlopen (const char *file, int mode)
+{
+  HMODULE hmodule;
+
+  hmodule = LoadLibrary(file);
+  if (hmodule == NULL) {
+    int error;
+
+    error = GetLastError();
+    sprintf(dlerr_data, "LoadLibraryEx returned %d.", error);
+    dlerr_ptr = dlerr_data;
+  }
+  return hmodule;
+}
+
+int dlclose (void *handle)
+{
+  if (FreeLibrary(handle)) {
+    return 0;
+  }
+  else {
+    int error;
+
+    error = GetLastError();
+    sprintf(dlerr_data, "FreeLibrary returned %d.", error);
+    dlerr_ptr = dlerr_data;
+    return -1;
+  }
+}
+
+void *dlsym (void *handle, const char *name)
+{
+  FARPROC fp;
+
+  fp = GetProcAddress(handle, name);
+  if (fp == NULL) {
+    int error;
+
+    error = GetLastError();
+    sprintf(dlerr_data, "GetProcAddress returned %d.", error);
+    dlerr_ptr = dlerr_data;
+  }
+  return fp;
+}
+
+char *dlerror (void)
+{
+  if (dlerr_ptr != NULL) {
+    dlerr_ptr = NULL;
+    return dlerr_data;
+  }
+  else {
+    return NULL;
+  }
+}
+
+char *realpath(const char *path, char resolved_path[PATH_MAX])
+{
+  char *return_path = 0;
+
+  if (path) //Else EINVAL
+  {
+    if (resolved_path)
+    {
+      return_path = resolved_path;
+    }
+    else
+    {
+      //Non standard extension that glibc uses
+      return_path = malloc(PATH_MAX);
+    }
+
+    if (return_path) //Else EINVAL
+    {
+      //This is a Win32 API function similar to what realpath() is supposed to do
+      size_t size = GetFullPathNameA(path, PATH_MAX, return_path, 0);
+
+      //GetFullPathNameA() returns a size larger than buffer if buffer is too small
+      if (size > PATH_MAX)
+      {
+        if (return_path != resolved_path) //Malloc'd buffer - Unstandard extension retry
+        {
+          size_t new_size;
+
+          free(return_path);
+          return_path = malloc(size);
+
+          if (return_path)
+          {
+            new_size = GetFullPathNameA(path, size, return_path, 0); //Try again
+
+            if (new_size > size) //If it's still too large, we have a problem, don't try again
+            {
+              free(return_path);
+              return_path = 0;
+              errno = ENAMETOOLONG;
+            }
+            else
+            {
+              size = new_size;
+            }
+          }
+          else
+          {
+            //I wasn't sure what to return here, but the standard does say to return EINVAL
+            //if resolved_path is null, and in this case we couldn't malloc large enough buffer
+            errno = EINVAL;
+          }  
+        }
+        else //resolved_path buffer isn't big enough
+        {
+          return_path = 0;
+          errno = ENAMETOOLONG;
+        }
+      }
+
+      //GetFullPathNameA() returns 0 if some path resolve problem occured
+      if (!size) 
+      {
+        if (return_path != resolved_path) //Malloc'd buffer
+        {
+          free(return_path);
+        }
+
+        return_path = 0;
+
+        //Convert MS errors into standard errors
+        switch (GetLastError())
+        {
+          case ERROR_FILE_NOT_FOUND:
+            errno = ENOENT;
+            break;
+
+          case ERROR_PATH_NOT_FOUND: case ERROR_INVALID_DRIVE:
+            errno = ENOTDIR;
+            break;
+
+          case ERROR_ACCESS_DENIED:
+            errno = EACCES;
+            break;
+
+          default: //Unknown Error
+            errno = EIO;
+            break;
+        }
+      }
+
+      //If we get to here with a valid return_path, we're still doing good
+      if (return_path)
+      {
+        struct stat stat_buffer;
+
+        //Make sure path exists, stat() returns 0 on success
+        if (stat(return_path, &stat_buffer)) 
+        {
+          if (return_path != resolved_path)
+          {
+            free(return_path);
+          }
+
+          return_path = 0;
+          //stat() will set the correct errno for us
+        }
+        //else we succeeded!
+      }
+    }
+    else
+    {
+      errno = EINVAL;
+    }
+  }
+  else
+  {
+    errno = EINVAL;
+  }
+
+  return return_path;
+}
+
+#endif /* WIN32 */
+
 /* local subsystem functions */
 static int _e_prefix_share_hunt(void);
 static int _e_prefix_fallbacks(void);
Index: src/bin/embryo_cc_sc1.c
===================================================================
RCS file: /var/cvs/e/e17/libs/embryo/src/bin/embryo_cc_sc1.c,v
retrieving revision 1.32
diff -u -r1.32 embryo_cc_sc1.c
--- src/bin/embryo_cc_sc1.c	10 Jul 2006 18:31:18 -0000	1.32
+++ src/bin/embryo_cc_sc1.c	5 Jan 2007 11:26:43 -0000
@@ -36,6 +36,12 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#ifdef WIN32
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#endif /* WIN32 */
+
 #include "embryo_cc_osdefs.h"
 #include "embryo_cc_sc.h"
 #include "embryo_cc_prefix.h"
@@ -314,7 +320,16 @@
    if (!tmpdir) tmpdir = "/tmp";
 
    snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir);
+#ifndef WIN32
    fd_out = mkstemp(outfname);
+#else
+   if (mktemp (outfname))
+     do
+       fd_out = open (outfname, O_CREAT | O_EXCL, S_IREAD | S_IWRITE);
+     while (!(fd_out == -1 && errno == EEXIST) && mktemp (outfname));
+   else
+     fd_out = -1;
+#endif /* WIN32 */
    if (fd_out < 0)
      error(101, outfname);
 
Index: src/lib/Embryo.h
===================================================================
RCS file: /var/cvs/e/e17/libs/embryo/src/lib/Embryo.h,v
retrieving revision 1.13
diff -u -r1.13 Embryo.h
--- src/lib/Embryo.h	27 Dec 2005 17:17:31 -0000	1.13
+++ src/lib/Embryo.h	5 Jan 2007 11:26:44 -0000
@@ -4,7 +4,7 @@
 #ifdef EAPI
 #undef EAPI
 #endif
-#ifdef WIN32
+#ifdef _MSC_VER
 # ifdef BUILDING_DLL
 #  define EAPI __declspec(dllexport)
 # else
Index: src/lib/Makefile.am
===================================================================
RCS file: /var/cvs/e/e17/libs/embryo/src/lib/Makefile.am,v
retrieving revision 1.13
diff -u -r1.13 Makefile.am
--- src/lib/Makefile.am	22 Mar 2005 13:10:09 -0000	1.13
+++ src/lib/Makefile.am	5 Jan 2007 11:26:44 -0000
@@ -7,7 +7,6 @@
 		       -I$(top_builddir) \
                        -I$(top_srcdir)/src/lib \
 		       -I$(top_srcdir)/src/lib/include 
-					      
 
 lib_LTLIBRARIES      = libembryo.la
 include_HEADERS      = Embryo.h
@@ -23,4 +22,4 @@
 
 libembryo_la_LIBADD       = -lm @fnmatch_libs@
 libembryo_la_DEPENDENCIES = $(top_builddir)/config.h
-libembryo_la_LDFLAGS      = -version-info 9:1:9
+libembryo_la_LDFLAGS      = @create_shared_lib@ -version-info 9:1:9