git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 4/5] compat/mingw: support MSys2-based MinGW build

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 14, 2016, 16:51 UTC
Message-ID
<ed8e411fc0447058bba75a4bdce1b8519813e10b.1452790142.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1452790142.git.johannes.schindelin@gmx.de>

The excellent MSys2 project brings a substantially updated MinGW environment including newer GCC versions and new headers. To support compiling Git, let's special-case the new MinGW (tell-tale: the _MINGW64_VERSION_MAJOR constant is defined).

Note: this commit only addresses compile failures, not compile warnings
(that task is left for a future patch).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 compat/mingw.h | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/compat/mingw.h b/compat/mingw.h
index b3e5044..a2da783 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -1,14 +1,26 @@
+#ifdef __MINGW64_VERSION_MAJOR
+#include <stdint.h>
+#include <wchar.h>
+typedef _sigset_t sigset_t;
+#endif
 #include <winsock2.h>
 #include <ws2tcpip.h>
 
+/* MinGW-w64 reports to have flockfile, but it does not actually have it. */
+#ifdef __MINGW64_VERSION_MAJOR
+#undef _POSIX_THREAD_SAFE_FUNCTIONS
+#endif
+
 /*
  * things that are not available in header files
  */
 
-typedef int pid_t;
 typedef int uid_t;
 typedef int socklen_t;
+#ifndef __MINGW64_VERSION_MAJOR
+typedef int pid_t;
 #define hstrerror strerror
+#endif
 
 #define S_IFLNK    0120000 /* Symbolic link */
 #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
@@ -100,8 +112,10 @@ static inline int symlink(const char *oldpath, const char *newpath)
 { errno = ENOSYS; return -1; }
 static inline int fchmod(int fildes, mode_t mode)
 { errno = ENOSYS; return -1; }
+#ifndef __MINGW64_VERSION_MAJOR
 static inline pid_t fork(void)
 { errno = ENOSYS; return -1; }
+#endif
 static inline unsigned int alarm(unsigned int seconds)
 { return 0; }
 static inline int fsync(int fd)
@@ -176,8 +190,10 @@ int pipe(int filedes[2]);
 unsigned int sleep (unsigned int seconds);
 int mkstemp(char *template);
 int gettimeofday(struct timeval *tv, void *tz);
+#ifndef __MINGW64_VERSION_MAJOR
 struct tm *gmtime_r(const time_t *timep, struct tm *result);
 struct tm *localtime_r(const time_t *timep, struct tm *result);
+#endif
 int getpagesize(void);	/* defined in MinGW's libgcc.a */
 struct passwd *getpwuid(uid_t uid);
 int setitimer(int type, struct itimerval *in, struct itimerval *out);
@@ -301,8 +317,10 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
 /*
  * Use mingw specific stat()/lstat()/fstat() implementations on Windows.
  */
+#ifndef __MINGW64_VERSION_MAJOR
 #define off_t off64_t
 #define lseek _lseeki64
+#endif
 
 /* use struct stat with 64 bit st_size */
 #ifdef stat
@@ -383,8 +401,12 @@ static inline char *mingw_find_last_dir_sep(const char *path)
 int mingw_offset_1st_component(const char *path);
 #define offset_1st_component mingw_offset_1st_component
 #define PATH_SEP ';'
+#ifndef __MINGW64_VERSION_MAJOR
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
+#else
+#include <inttypes.h>
+#endif
 
 void mingw_open_html(const char *path);
 #define open_html mingw_open_html
-- 
2.7.0.windows.1.7.g55a05c8
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 20 of 23 in “Fix compile errors with MSys2”
  1. 0/5 Fix compile errors with MSys2Johannes Schindelin, Jan 13, 2016
  2. 1/5 config.mak.uname: support MSys2Johannes Schindelin, Jan 13, 2016
  3. Jeff KingJan 13, 2016
  4. Johannes SchindelinJan 13, 2016
  5. Dennis KaarsemakerJan 13, 2016
  6. 2/5 config.mak.uname: supporting 64-bit MSys2Johannes Schindelin, Jan 13, 2016
  7. SZEDER GáborJan 21, 2016
  8. Johannes SchindelinJan 21, 2016
  9. 3/5 nedmalloc: allow compiling with MSys2's compilerJohannes Schindelin, Jan 13, 2016
  10. Junio C HamanoJan 13, 2016
  11. 4/5 compat/mingw: support MSys2-based MinGW buildJohannes Schindelin, Jan 13, 2016
  12. 5/5 compat/winansi: support compiling with MSys2Johannes Schindelin, Jan 13, 2016
  13. Junio C HamanoJan 13, 2016
  14. Johannes SchindelinJan 14, 2016
  15. 0/5 Fix compile errors with MSys2Johannes Schindelin, Jan 14, 2016
  16. 1/5 config.mak.uname: support MSys2Johannes Schindelin, Jan 14, 2016
  17. Johannes SixtJan 14, 2016
  18. 2/5 config.mak.uname: supporting 64-bit MSys2Johannes Schindelin, Jan 14, 2016
  19. 3/5 nedmalloc: allow compiling with MSys2's compilerJohannes Schindelin, Jan 14, 2016
  20. 4/5 compat/mingw: support MSys2-based MinGW buildJohannes Schindelin, Jan 14, 2016
  21. 5/5 compat/winansi: support compiling with MSys2Johannes Schindelin, Jan 14, 2016
  22. Junio C HamanoJan 14, 2016
  23. Johannes SixtJan 14, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.