compat/mingw: support MSys2-based MinGW build
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jan 14, 2016 at 17:51 UTC
3ecd153a3bdbefb25a4bf451d7b91cf8f1ece2a9
1 file changed
+23
-1
compat/mingw.h
+23
-1
@@ -1,14 +1,26 @@
1
+#ifdef __MINGW64_VERSION_MAJOR
2
+#include <stdint.h>
3
+#include <wchar.h>
4
+typedef _sigset_t sigset_t;
5
+#endif
6
#include <winsock2.h>
7
#include <ws2tcpip.h>
8
9
+/* MinGW-w64 reports to have flockfile, but it does not actually have it. */
10
+#ifdef __MINGW64_VERSION_MAJOR
11
+#undef _POSIX_THREAD_SAFE_FUNCTIONS
12
+#endif
13
+
14
/*
15
* things that are not available in header files
16
*/
17
8
-typedef int pid_t;
18
typedef int uid_t;
19
typedef int socklen_t;
20
+#ifndef __MINGW64_VERSION_MAJOR
21
+typedef int pid_t;
22
#define hstrerror strerror
23
+#endif
24
25
#define S_IFLNK 0120000 /* Symbolic link */
26
#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
@@ -100,8 +112,10 @@ static inline int symlink(const char *oldpath, const char *newpath)
112
{ errno = ENOSYS; return -1; }
113
static inline int fchmod(int fildes, mode_t mode)
114
{ errno = ENOSYS; return -1; }
115
+#ifndef __MINGW64_VERSION_MAJOR
116
static inline pid_t fork(void)
117
{ errno = ENOSYS; return -1; }
118
+#endif
119
static inline unsigned int alarm(unsigned int seconds)
120
{ return 0; }
121
static inline int fsync(int fd)
@@ -176,8 +190,10 @@ int pipe(int filedes[2]);
190
unsigned int sleep (unsigned int seconds);
191
int mkstemp(char *template);
192
int gettimeofday(struct timeval *tv, void *tz);
193
+#ifndef __MINGW64_VERSION_MAJOR
194
struct tm *gmtime_r(const time_t *timep, struct tm *result);
195
struct tm *localtime_r(const time_t *timep, struct tm *result);
196
+#endif
197
int getpagesize(void); /* defined in MinGW's libgcc.a */
198
struct passwd *getpwuid(uid_t uid);
199
int setitimer(int type, struct itimerval *in, struct itimerval *out);
@@ -301,8 +317,10 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
317
/*
318
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
319
*/
320
+#ifndef __MINGW64_VERSION_MAJOR
321
#define off_t off64_t
322
#define lseek _lseeki64
323
+#endif
324
325
/* use struct stat with 64 bit st_size */
326
#ifdef stat
@@ -375,8 +393,12 @@ static inline char *mingw_find_last_dir_sep(const char *path)
393
int mingw_offset_1st_component(const char *path);
394
#define offset_1st_component mingw_offset_1st_component
395
#define PATH_SEP ';'
396
+#ifndef __MINGW64_VERSION_MAJOR
397
#define PRIuMAX "I64u"
398
#define PRId64 "I64d"
399
+#else
400
+#include <inttypes.h>
401
+#endif
402
403
void mingw_open_html(const char *path);
404
#define open_html mingw_open_html