Build Git with MSVC
v3 cover Build Git with MSVC
=== V3 2009.09.15 ===
1) Reworded patch 01: s/Microsoft Visual C++/MSVC/
2) Nuked patch 02
3) Merged patch 03 into path 08
4) Rewrote patch 06 to set _fmode instead for both MinGW and MSVC
5) Fix patch 07 to use __stdcall for thread functions instead of WINAPI
6) Rewrote patch 14 to rather use a define to _chsize
7) Fix patch 15 to use "-o $@" instead of "-o git.o"
Think that's it..
=== V2 2009.09.14 ===
Here's a second roll of the series for supporting compilation of Git using Visual C++ (MSVC). (Sorry for the long delay on a followup, time is in short supply these days)
There's no guarantee that the compiled result will work as well as the current MinGW compile, or at all. However, I think it's important to get the Git repo to a compilable state with MSVC as quickly as possible, to further enable contributions from the Windows developers which we are sorely lacking at the moment.
I hope that a repo which compiles successfully with the tools they are accustomed to (also a very good debugger) will entice them to send more patches.
In addition to this series, I have also setup a repo with binaries of the required libs to compile Git with MSVC. Only 32bit versions for now. So, the developer can choose to either use that, or Frank's source code repo to build Git with MSVC. You'll find the binary repo here:
http://repo.or.cz/w/msvcgit.git
Note that the binaries will still require the msysgit environment for execution, due to the non-binary components of Git. (Scripts, gitk, git-gui, etc). You'll find that repo here:
http://repo.or.cz/w/msysgit.git
1) Rebased ontop on current git.git 'next'.
2) Fixed code and commit msgs based on the previous feedback. Let me know if I forgot anything!
3) Added a proper Makefile patch for MSVC support.
You now compile with 'make MSVC=1'.
4) Added perl scripts (contrib) which uses GNU Make output to generate MSVC IDE (.sln & .vcproj) projects and QMake projects, and picking up the project settings from the Makefile, so it's all in one place.
5) Added necessary patches to make things compile ontop of current 'next'.
=== V1 2009.08.21 ===
So, Frank Li started this series, and I took it upon my self to help out a bit; cleaning, reorganizing, rebasing the series. Hopefully we're now a bit closer to including the series into mainline..
Here's a summary of what has happend:
1) This series is rebased ontop of git.git 'next', which needed an extra patch to avoid a non-constant array creation, which mscv doesn't like.
2) I've polished (tied to anyways) the commit messages a bit.
3) I've applied much of the feedback provided to the first round of the patches.
4) I've split, merged and reordered some of the patches, so things that belong together are in the same commits, and in a order of 'importance'
5) I've removed the
#define func _func
stuff, as it's not needed and Microsoft cannot really kill the compatibility functions anyways. So, adding the define
_CRT_NONSTDC_NO_DEPRECATE
will kill the warnings seen without the defines above.
6) ..probably much more as well, but I forget..
Note: I did not sign off on the last two commits, which involve the adding of the vcproj files, since I don't agree on adding them as is. We need a Makefile way of compiling primarily, and second, a script to generate the vcproj, as already discussed. But the commits are included for completeness, at to let others compile and play with it.
I've kept the original author as is, and just signed the patches.. Thanks for watching, now bring on the comments!
Frank Li (6):
Avoid declaration after statement
Change regerror() declaration from K&R style to ANSI C (C89) Fix __stdcall placement and function prototype Test for WIN32 instead of __MINGW32_
Add MinGW header files to build git with MSVC
Add platform files for MSVC porting
Marius Storm-Olsen (8):
Add define guards to compat/win32.h
Set _O_BINARY as default fmode for both MinGW and MSVC
Add empty header files for MSVC port
Make usage of windows.h lean and mean
Define strncasecmp and ftruncate for MSVC
Add MSVC to Makefile
Add README for MSVC build
Add scripts to generate projects for other buildsystems (MSVC vcproj,
QMake)
.gitignore | 11 + Makefile | 54 +++- compat/mingw.c | 20 +- compat/mingw.h | 9 + compat/msvc.c | 35 ++ compat/msvc.h | 50 +++ compat/regex/regex.c | 7 +- compat/snprintf.c | 10 +- compat/vcbuild/README | 50 +++ compat/vcbuild/include/alloca.h | 1 + compat/vcbuild/include/arpa/inet.h | 1 + compat/vcbuild/include/dirent.h | 128 ++++++ compat/vcbuild/include/grp.h | 1 + compat/vcbuild/include/inttypes.h | 1 + compat/vcbuild/include/netdb.h | 1 + compat/vcbuild/include/netinet/in.h | 1 + compat/vcbuild/include/netinet/tcp.h | 1 + compat/vcbuild/include/pwd.h | 1 + compat/vcbuild/include/sys/ioctl.h | 1 + compat/vcbuild/include/sys/param.h | 1 + compat/vcbuild/include/sys/poll.h | 1 + compat/vcbuild/include/sys/select.h | 1 + compat/vcbuild/include/sys/socket.h | 1 + compat/vcbuild/include/sys/time.h | 1 + compat/vcbuild/include/sys/utime.h | 34 ++ compat/vcbuild/include/sys/wait.h | 1 + compat/vcbuild/include/unistd.h | 92 ++++ compat/vcbuild/include/utime.h | 1 + compat/vcbuild/scripts/clink.pl | 48 +++ compat/vcbuild/scripts/lib.pl | 26 ++ compat/win32.h | 7 + compat/winansi.c | 1 - contrib/buildsystems/Generators.pm | 42 ++ contrib/buildsystems/Generators/QMake.pm | 189 +++++++++ contrib/buildsystems/Generators/Vcproj.pm | 639 +++++++++++++++++++++++++++++ contrib/buildsystems/engine.pl | 353 ++++++++++++++++ contrib/buildsystems/generate | 29 ++ contrib/buildsystems/parse.pl | 228 ++++++++++ git-compat-util.h | 9 + help.c | 5 +- pager.c | 4 +- run-command.c | 12 +- run-command.h | 2 +- setup.c | 2 +- thread-utils.c | 5 +- 45 files changed, 2084 insertions(+), 33 deletions(-) create mode 100644 compat/msvc.c create mode 100644 compat/msvc.h create mode 100644 compat/vcbuild/README create mode 100644 compat/vcbuild/include/alloca.h create mode 100644 compat/vcbuild/include/arpa/inet.h create mode 100644 compat/vcbuild/include/dirent.h create mode 100644 compat/vcbuild/include/grp.h create mode 100644 compat/vcbuild/include/inttypes.h create mode 100644 compat/vcbuild/include/netdb.h create mode 100644 compat/vcbuild/include/netinet/in.h create mode 100644 compat/vcbuild/include/netinet/tcp.h create mode 100644 compat/vcbuild/include/pwd.h create mode 100644 compat/vcbuild/include/sys/ioctl.h create mode 100644 compat/vcbuild/include/sys/param.h create mode 100644 compat/vcbuild/include/sys/poll.h create mode 100644 compat/vcbuild/include/sys/select.h create mode 100644 compat/vcbuild/include/sys/socket.h create mode 100644 compat/vcbuild/include/sys/time.h create mode 100644 compat/vcbuild/include/sys/utime.h create mode 100644 compat/vcbuild/include/sys/wait.h create mode 100644 compat/vcbuild/include/unistd.h create mode 100644 compat/vcbuild/include/utime.h create mode 100644 compat/vcbuild/scripts/clink.pl create mode 100644 compat/vcbuild/scripts/lib.pl create mode 100644 contrib/buildsystems/Generators.pm create mode 100644 contrib/buildsystems/Generators/QMake.pm create mode 100644 contrib/buildsystems/Generators/Vcproj.pm create mode 100644 contrib/buildsystems/engine.pl create mode 100644 contrib/buildsystems/generate create mode 100644 contrib/buildsystems/parse.pl
PATCH v3 1/14 Avoid declaration after statement
From: Frank Li <[email protected]>
MSVC does not understand this C99 style
--- compat/mingw.c | 14 ++++++++++---- help.c | 3 ++- run-command.c | 2 ++ 3 files changed, 14 insertions(+), 5 deletions(-)
compat/mingw.c +10 -4
@@ -123,13 +123,17 @@ int mingw_open (const char *filename, int oflags, ...) {va_list args;unsigned mode; +int fd; +va_start (args, oflags); mode =va_arg (args, int);va_end (args);if (!strcmp (filename,"/dev/null" )) filename ="nul" ; -int fd =open (filename, oflags, mode); + + fd =open (filename, oflags, mode); +if (fd <0 && (oflags &O_CREAT ) && errno ==EACCES ) {DWORD attrs =GetFileAttributes (filename);if (attrs !=INVALID_FILE_ATTRIBUTES && (attrs &FILE_ATTRIBUTE_DIRECTORY ))
@@ -580,10 +584,11 @@ static char **get_path_split(void)static void free_path_split (char **path) { +char **p = path; +if (!path)return ; -char **p = path;while (*p)free (*p++);free (path);
@@ -1120,9 +1125,9 @@ int sigaction(int sig, struct sigaction *in, struct sigaction *out)#undef signalsig_handler_t mingw_signal (int sig,sig_handler_t handler) { +sig_handler_t old = timer_fn;if (sig !=SIGALRM )return signal (sig, handler); -sig_handler_t old = timer_fn; timer_fn = handler;return old; }
@@ -1209,8 +1214,9 @@ struct dirent *mingw_readdir(DIR *dir)if (dir->dd_handle == (long )INVALID_HANDLE_VALUE && dir->dd_stat ==0 ) { +DWORD lasterr; handle =FindFirstFileA (dir->dd_name, &buf); -DWORD lasterr =GetLastError (); + lasterr =GetLastError (); dir->dd_handle = (long )handle;if (handle ==INVALID_HANDLE_VALUE && (lasterr !=ERROR_NO_MORE_FILES )) { errno =err_win_to_posix (lasterr);
help.c +2 -1
@@ -127,7 +127,7 @@ static int is_executable(const char *name)return 0 ;#ifdef __MINGW32__ -/* cannot trust the executable bit, peek into the file instead */ +{/* cannot trust the executable bit, peek into the file instead */ char buf[3 ] = {0 };int n;int fd =open (name,O_RDONLY );
@@ -140,6 +140,7 @@ static int is_executable(const char *name) st.st_mode |=S_IXUSR ; close(fd); } +}#endif return st.st_mode &S_IXUSR ; }
run-command.c +2 -0
@@ -134,6 +134,7 @@ fail_pipe:error ("cannot fork() for %s: %s" , cmd->argv[0 ],strerror (failed_errno = errno));#else +{int s0 =-1 , s1 =-1 , s2 =-1 ;/* backups of stdin, stdout, stderr */ const char **sargv = cmd->argv;char **env = environ;
@@ -197,6 +198,7 @@ fail_pipe:dup2 (s1,1 ),close (s1);if (s2 >=0 ) dup2(s2, 2), close(s2); +}#endif if (cmd->pid <0 ) {
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 2/14 Add define guards to compat/win32.h
--- compat/win32.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
compat/win32.h +5 -0
@@ -1,3 +1,6 @@ +#ifndef WIN32_H +#define WIN32_H +/* common Win32 functions for MinGW and Cygwin */ #include <windows.h>
@@ -32,3 +35,5 @@ static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fd return ENOENT; } } + +#endif
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 3/14 Change regerror() declaration from K&R style to ANSI C (C89)
From: Frank Li <[email protected]>
The MSVC headers typedef errcode as int, and thus confused the compiler in the K&R style definition. ANSI style deconfuses it.
--- compat/regex/regex.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
compat/regex/regex.c +2 -5
@@ -4852,11 +4852,8 @@ regexec (preg, string, nmatch, pmatch, eflags)from either regcomp or regexec. We don't use PREG here. */ size_t -regerror (errcode, preg, errbuf, errbuf_size) -int errcode; -const regex_t *preg; -char *errbuf; -size_t errbuf_size; +regerror (int errcode,const regex_t *preg, +char *errbuf,size_t errbuf_size) {const char *msg;size_t msg_size;
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 4/14 Set _O_BINARY as default fmode for both MinGW and MSVC
MinGW set the _CRT_fmode to set both the default fmode and _O_BINARY on stdin/stdout/stderr. Rather use the main() define in mingw.h to set this for both MinGW and MSVC.
This will ensure that a MinGW and MSVC build will handle input and output identically.
--- compat/mingw.c | 2 -- compat/mingw.h | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-)
compat/mingw.c +0 -2
@@ -3,8 +3,6 @@#include <conio.h> #include "../strbuf.h" -unsigned int _CRT_fmode = _O_BINARY; -static int err_win_to_posix (DWORD winerr) {int error =ENOSYS ;
compat/mingw.h +8 -0
@@ -229,10 +229,18 @@ void free_environ(char **env);* A replacement of main() that ensures that argv[0] has a path */ +extern int _fmode;#define main (c,v) dummy_decl_mingw_main(); \ static int mingw_main(); \ int main(int argc, const char **argv) \ { \ + _fmode = _O_BINARY; \ + if (stdin) \ + _setmode(_fileno(stdin), _O_BINARY); \ + if (stdout) \ + _setmode(_fileno(stdout), _O_BINARY); \ + if (stderr) \ + _setmode(_fileno(stderr), _O_BINARY); \ argv[0] = xstrdup(_pgmptr); \ return mingw_main(argc, argv); \ } \
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 5/14 Fix __stdcall placement and function prototype
From: Frank Li <[email protected]>
MSVC requires __stdcall to be between the functions return value and the function name, and that the function pointer type is in the form of
return_type (WINAPI *function_name)(arguments...)
--- compat/mingw.c | 4 ++-- run-command.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
compat/mingw.c +2 -2
@@ -1027,7 +1027,7 @@ static sig_handler_t timer_fn = SIG_DFL;* length to call the signal handler. */ -static __stdcall unsigned ticktack (void *dummy) +static unsigned __stdcallticktack (void *dummy) {while (WaitForSingleObject (timer_event, timer_interval) ==WAIT_TIMEOUT ) {if (timer_fn ==SIG_DFL )
@@ -1154,7 +1154,7 @@ void mingw_open_html(const char *unixpath)int link (const char *oldpath,const char *newpath) { - typedef BOOL WINAPI (*T)(const char*, const char*, LPSECURITY_ATTRIBUTES); + typedef BOOL (WINAPI *T)(const char*, const char*, LPSECURITY_ATTRIBUTES);static T create_hard_link =NULL ;if (!create_hard_link) { create_hard_link = (T) GetProcAddress(
run-command.c +1 -1
@@ -316,7 +316,7 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const }#ifdef __MINGW32__ -static __stdcall unsigned run_thread (void *data) +static unsigned __stdcallrun_thread (void *data) {struct async *async = data;return async->proc (async->fd_for_proc, async->data);
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 6/14 Test for WIN32 instead of __MINGW32_
From: Frank Li <[email protected]>
The code which is conditional on MinGW32 is actually conditional on Windows. Use the WIN32 symbol, which is defined by the MINGW32 and MSVC environments, but not by Cygwin.
Define SNPRINTF_SIZE_CORR=1 for MSVC too, as its vsnprintf function does not add NUL at the end of the buffer if the result fits the buffer size exactly.
--- compat/snprintf.c | 10 ++++++---- help.c | 2 +- pager.c | 4 ++-- run-command.c | 8 ++++---- run-command.h | 2 +- setup.c | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-)
compat/snprintf.c +6 -4
@@ -2,12 +2,14 @@/* * The size parameter specifies the available space, i.e. includes -* the trailing NUL byte; but Windows's vsnprintf expects the -* number of characters to write, and does not necessarily write the -* trailing NUL. +* the trailing NUL byte; but Windows's vsnprintf uses the entire +* buffer and avoids the trailing NUL, should the buffer be exactly +* big enough for the result. Defining SNPRINTF_SIZE_CORR to 1 will +* therefore remove 1 byte from the reported buffer size, so we +* always have room for a trailing NUL byte. */ #ifndef SNPRINTF_SIZE_CORR -#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ <4 +#if defined(WIN32 ) && (!defined(__GNUC__) || __GNUC__ <4 )#define SNPRINTF_SIZE_CORR 1#else #define SNPRINTF_SIZE_CORR 0
help.c +1 -1
@@ -126,7 +126,7 @@ static int is_executable(const char *name) !S_ISREG(st.st_mode))return 0 ; -#ifdef __MINGW32__ +#ifdef WIN32 {/* cannot trust the executable bit, peek into the file instead */ char buf[3 ] = {0 };int n;
pager.c +2 -2
@@ -9,7 +9,7 @@static int spawned_pager; -#ifndef __MINGW32__ +#ifndef WIN32 static void pager_preexec (void ) {/*
@@ -72,7 +72,7 @@ void setup_pager(void)static const char *env[] = {"LESS=FRSX" ,NULL }; pager_process.env = env; } -#ifndef __MINGW32__ +#ifndef WIN32 pager_process.preexec_cb = pager_preexec;#endif if (start_command (&pager_process))
run-command.c +4 -4
@@ -75,7 +75,7 @@ fail_pipe:trace_argv_printf (cmd->argv,"trace: run_command:" ); -#ifndef __MINGW32__ +#ifndef WIN32 fflush (NULL ); cmd->pid =fork ();if (!cmd->pid) {
@@ -315,7 +315,7 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, constreturn run_command (&cmd); } -#ifdef __MINGW32__ +#ifdef WIN32 static unsigned __stdcallrun_thread (void *data) {struct async *async = data;
@@ -331,7 +331,7 @@ int start_async(struct async *async)return error ("cannot create pipe: %s" ,strerror (errno)); async->out = pipe_out[0 ]; -#ifndef __MINGW32__ +#ifndef WIN32 /* Flush stdio before fork() to avoid cloning buffers */ fflush (NULL );
@@ -360,7 +360,7 @@ int start_async(struct async *async)int finish_async (struct async *async) { -#ifndef __MINGW32__ +#ifndef WIN32 int ret =wait_or_whine (async->pid,"child process" ,0 );#else DWORD ret =0 ;
run-command.h +1 -1
@@ -70,7 +70,7 @@ struct async {int (*proc)(int fd,void *data);void *data;int out;/* caller reads from here and closes it */ -#ifndef __MINGW32__ +#ifndef WIN32 pid_t pid;#else HANDLE tid;
setup.c +1 -1
@@ -41,7 +41,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)const char *prefix_filename (const char *pfx,int pfx_len,const char *arg) {static char path[PATH_MAX ]; -#ifndef __MINGW32__ +#ifndef WIN32 if (!pfx || !*pfx ||is_absolute_path (arg))return arg;memcpy (path, pfx, pfx_len);
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 7/14 Add empty header files for MSVC port
MSVC lacks many of the header files included by git-compat-util.h, so add blank header files for these instead of going ifdef crazy.
--- compat/vcbuild/include/arpa/inet.h | 1 + compat/vcbuild/include/grp.h | 1 + compat/vcbuild/include/inttypes.h | 1 + compat/vcbuild/include/netdb.h | 1 + compat/vcbuild/include/netinet/in.h | 1 + compat/vcbuild/include/netinet/tcp.h | 1 + compat/vcbuild/include/pwd.h | 1 + compat/vcbuild/include/sys/ioctl.h | 1 + compat/vcbuild/include/sys/param.h | 1 + compat/vcbuild/include/sys/poll.h | 1 + compat/vcbuild/include/sys/select.h | 1 + compat/vcbuild/include/sys/socket.h | 1 + compat/vcbuild/include/sys/time.h | 1 + compat/vcbuild/include/sys/wait.h | 1 + 14 files changed, 14 insertions(+), 0 deletions(-) create mode 100644 compat/vcbuild/include/arpa/inet.h create mode 100644 compat/vcbuild/include/grp.h create mode 100644 compat/vcbuild/include/inttypes.h create mode 100644 compat/vcbuild/include/netdb.h create mode 100644 compat/vcbuild/include/netinet/in.h create mode 100644 compat/vcbuild/include/netinet/tcp.h create mode 100644 compat/vcbuild/include/pwd.h create mode 100644 compat/vcbuild/include/sys/ioctl.h create mode 100644 compat/vcbuild/include/sys/param.h create mode 100644 compat/vcbuild/include/sys/poll.h create mode 100644 compat/vcbuild/include/sys/select.h create mode 100644 compat/vcbuild/include/sys/socket.h create mode 100644 compat/vcbuild/include/sys/time.h create mode 100644 compat/vcbuild/include/sys/wait.h
compat/vcbuild/include/arpa/inet.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/grp.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/inttypes.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/netdb.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/netinet/in.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/netinet/tcp.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/pwd.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/sys/ioctl.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/sys/param.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/sys/poll.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/sys/select.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/sys/socket.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/sys/time.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
compat/vcbuild/include/sys/wait.h new file +1 -0
@@ -0,0 +1 @@ +/* Intentionally empty file to support building git with MSVC */
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 8/14 Add MinGW header files to build git with MSVC
From: Frank Li <[email protected]>
Added the header files dirent.h, unistd.h and utime.h Add alloca.h, which simply includes malloc.h, which defines alloca
--- compat/vcbuild/include/alloca.h | 1 + compat/vcbuild/include/dirent.h | 128 ++++++++++++++++++++++++++++++++++++ compat/vcbuild/include/sys/utime.h | 34 ++++++++++ compat/vcbuild/include/unistd.h | 92 ++++++++++++++++++++++++++ compat/vcbuild/include/utime.h | 1 + 5 files changed, 256 insertions(+), 0 deletions(-) create mode 100644 compat/vcbuild/include/alloca.h create mode 100644 compat/vcbuild/include/dirent.h create mode 100644 compat/vcbuild/include/sys/utime.h create mode 100644 compat/vcbuild/include/unistd.h create mode 100644 compat/vcbuild/include/utime.h
compat/vcbuild/include/alloca.h new file +1 -0
@@ -0,0 +1 @@ +#include <malloc.h>
compat/vcbuild/include/dirent.h new file +128 -0
128 lines not on this page · raw message
compat/vcbuild/include/sys/utime.h new file +34 -0
@@ -0,0 +1,34 @@ +#ifndef _UTIME_H_ +#define _UTIME_H_ +/* +* UTIME.H +* This file has no copyright assigned and is placed in the Public Domain. +* This file is a part of the mingw-runtime package. +* +* The mingw-runtime package and its code is distributed in the hope that it +* will be useful but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESSED OR +* IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to +* warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* You are free to use this package and its code without limitation. +*/ + +/* +* Structure used by _utime function. +*/ +struct _utimbuf +{ +time_t actime;/* Access time */ +time_t modtime;/* Modification time */ +}; + +#ifndef _NO_OLDNAMES +/* NOTE: Must be the same as _utimbuf above. */ +struct utimbuf +{ +time_t actime; +time_t modtime; +}; +#endif /* Not _NO_OLDNAMES */ + +#endif
compat/vcbuild/include/unistd.h new file +92 -0
92 lines not on this page · raw message
compat/vcbuild/include/utime.h new file +1 -0
@@ -0,0 +1 @@ +#include <sys/utime.h>
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 9/14 Add platform files for MSVC porting
From: Frank Li <[email protected]>
Add msvc.c and msvc.h to build git under MSVC
--- compat/msvc.c | 35 +++++++++++++++++++++++++++++++++ compat/msvc.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ git-compat-util.h | 3 ++ 3 files changed, 93 insertions(+), 0 deletions(-) create mode 100644 compat/msvc.c create mode 100644 compat/msvc.h
compat/msvc.c new file +35 -0
@@ -0,0 +1,35 @@ +#include "../git-compat-util.h" +#include "win32.h" +#include <conio.h> +#include "../strbuf.h" + +DIR *opendir (const char *name) +{ +int len; +DIR *p; + p = (DIR *)malloc (sizeof (DIR )); +memset (p,0 ,sizeof (DIR )); +strncpy (p->dd_name, name,PATH_MAX ); + len =strlen (p->dd_name); + p->dd_name[len] ='/' ; + p->dd_name[len+1 ] ='*' ; + +if (p ==NULL ) +return NULL ; + + p->dd_handle =_findfirst (p->dd_name, &p->dd_dta); + +if (p->dd_handle ==-1 ) { +free (p); +return NULL ; + } +return p; +} +int closedir (DIR *dir) +{ +_findclose (dir->dd_handle); +free (dir); +return 0 ; +} + +#include "mingw.c"
compat/msvc.h new file +55 -0
55 lines not on this page · raw message
git-compat-util.h +3 -0
@@ -113,6 +113,9 @@/* pull in Windows compatibility stuff */ #include "compat/mingw.h" #endif /* __MINGW32__ */ +#ifdef _MSC_VER +#include "compat/msvc.h" +#endif #ifndef NO_LIBGEN_H #include <libgen.h>
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 10/14 Make usage of windows.h lean and mean
Centralize the include of windows.h in git-compat-util.h, turn on WIN32_LEAN_AND_MEAN to avoid including plenty of other header files which is not needed in Git. Also ensure we load winsock2.h first, so we don't load the older winsock definitions at a later stage, since they contain duplicate definitions.
When moving windows.h into git-compat-util.h, we need to protect the definition of struct pollfd in mingw.h, since this file is used by both MinGW and MSVC, and the latter defines this struct in winsock2.h.
We need to keep the windows.h include in compat/win32.h, since its shared by both MinGW and Cygwin, and we're not touching Cygwin in this commit. The include in git-compat-util.h is protected with an ifdef WIN32, which is not the case when compiling for Cygwin.
--- compat/mingw.c | 2 ++ compat/mingw.h | 2 ++ compat/msvc.h | 7 ------- compat/win32.h | 2 ++ compat/winansi.c | 1 - git-compat-util.h | 6 ++++++ thread-utils.c | 5 +---- 7 files changed, 13 insertions(+), 12 deletions(-)
compat/mingw.c +2 -0
@@ -3,6 +3,8 @@#include <conio.h> #include "../strbuf.h" +#include <shellapi.h> +static int err_win_to_posix (DWORD winerr) {int error =ENOSYS ;
compat/mingw.h +2 -0
@@ -41,6 +41,7 @@ struct passwd {extern char *getpass (const char *prompt); +#ifndef POLLIN struct pollfd { int fd; /* file descriptor */ short events; /* requested events */
@@ -48,6 +49,7 @@ struct pollfd { };#define POLLIN 1#define POLLHUP 2 +#endif typedef void (__cdecl *sig_handler_t )(int );struct sigaction {
compat/msvc.h +0 -7
@@ -1,13 +1,6 @@#ifndef __MSVC__HEAD#define __MSVC__HEAD -/* Define minimize windows version */ -#define WINVER 0x0500 -#define _WIN32_WINNT 0x0500 -#define _WIN32_WINDOWS 0x0410 -#define _WIN32_IE 0x0700 -#define NTDDI_VERSION NTDDI_WIN2KSP1 -#include <winsock2.h> #include <direct.h> #include <process.h> #include <malloc.h>
compat/win32.h +2 -0
@@ -2,7 +2,9 @@#define WIN32_H /* common Win32 functions for MinGW and Cygwin */ +#ifndef WIN32 /* Not defined by Cygwin */ #include <windows.h> +#endif static inline int file_attr_to_st_mode (DWORD attr) {
compat/winansi.c +0 -1
@@ -2,7 +2,6 @@* Copyright 2008 Peter Harris <[email protected]> */ -#include <windows.h> #include "../git-compat-util.h" /*
git-compat-util.h +6 -0
@@ -65,6 +65,12 @@#define _NETBSD_SOURCE 1#define _SGI_SOURCE 1 +#ifdef WIN32 /* Both MinGW and MSVC */ +#define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */ +#include <winsock2.h> +#include <windows.h> +#endif +#include <unistd.h> #include <stdio.h> #include <sys/stat.h>
thread-utils.c +1 -4
@@ -1,9 +1,6 @@#include "cache.h" -#ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# include <windows.h> -#elif defined(hpux) || defined(__hpux) || defined(_hpux) +#if defined(hpux) || defined(__hpux) || defined(_hpux)# include <sys/pstat.h> #endif
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 11/14 Define strncasecmp and ftruncate for MSVC
--- compat/msvc.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
compat/msvc.h +2 -0
@@ -10,6 +10,8 @@#define __inline__ __inline#define __attribute__ (x)#define va_copy (dst, src) ((dst) = (src)) +#define strncasecmp _strnicmp +#define ftruncate _chsizestatic __inlineint strcasecmp (const char *s1,const char *s2) {
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 12/14 Add MSVC to Makefile
Enable MSVC builds with GNU Make by simply calling
make MSVC=1
(Debug build possible by adding DEBUG=1 as well)
Two scripts, clink.pl and lib.pl, are used to convert certain GCC specific command line options into something MSVC understands. By building for MSVC with GNU Make, we can ensure that the MSVC port always follows the latest code, and does not lag behind due to unmaintained NMake Makefile or IDE projects.
--- Makefile | 54 ++++++++++++++++++++++++++++++++++++++- compat/vcbuild/scripts/clink.pl | 48 ++++++++++++++++++++++++++++++++++ compat/vcbuild/scripts/lib.pl | 26 ++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletions(-) create mode 100644 compat/vcbuild/scripts/clink.pl create mode 100644 compat/vcbuild/scripts/lib.pl
Makefile +53 -1
@@ -877,6 +877,57 @@ ifneq (,$(findstring CYGWIN,$(uname_S))) COMPAT_OBJS += compat/cygwin.o UNRELIABLE_FSTAT = UnfortunatelyYes endif +ifdef MSVC + pathsep = ; + NO_PREAD = YesPlease + NO_OPENSSL = YesPlease + NO_LIBGEN_H = YesPlease + NO_SYMLINK_HEAD = YesPlease + NO_IPV6 = YesPlease + NO_SETENV = YesPlease + NO_UNSETENV = YesPlease + NO_STRCASESTR = YesPlease + NO_STRLCPY = YesPlease + NO_MEMMEM = YesPlease + # NEEDS_LIBICONV = YesPlease + NO_ICONV = YesPlease + NO_C99_FORMAT = YesPlease + NO_STRTOUMAX = YesPlease + NO_STRTOULL = YesPlease + NO_MKDTEMP = YesPlease + NO_MKSTEMPS = YesPlease + SNPRINTF_RETURNS_BOGUS = YesPlease + NO_SVN_TESTS = YesPlease + NO_PERL_MAKEMAKER = YesPlease + RUNTIME_PREFIX = YesPlease + NO_POSIX_ONLY_PROGRAMS = YesPlease + NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease + NO_NSEC = YesPlease + USE_WIN32_MMAP = YesPlease + # USE_NED_ALLOCATOR = YesPlease + UNRELIABLE_FSTAT = UnfortunatelyYes + OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo + NO_REGEX = YesPlease + NO_CURL = YesPlease + NO_PTHREADS = YesPlease + + CC = compat/vcbuild/scripts/clink.pl + AR = compat/vcbuild/scripts/lib.pl + CFLAGS = + BASIC_CFLAGS = -nologo -I. -I../zlib -Icompat/vcbuild -Icompat/vcbuild/include -DWIN32-D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE + COMPAT_OBJS = compat/msvc.o compat/fnmatch/fnmatch.o compat/winansi.o + COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/fnmatch -Icompat/regex -Icompat/fnmatch -DSTRIP_EXTENSION=\".exe\" + BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib + EXTLIBS = advapi32.lib shell32.lib wininet.lib ws2_32.lib + lib = +ifndef DEBUG + BASIC_CFLAGS += -GL -Os -MT + BASIC_LDFLAGS += -LTCG +else + BASIC_CFLAGS += -Zi -MTd +endif + X = .exe +else ifneq (,$(findstring MINGW,$(uname_S))) pathsep = ; NO_PREAD = YesPlease
@@ -925,6 +976,7 @@ else NO_PTHREADS = YesPlease endif endif +endif -include config.mak.autogen -include config.mak
@@ -1327,7 +1379,7 @@ strip: $(PROGRAMS) git$X git.o: git.c common-cmds.h GIT-CFLAGS $(QUIET_CC)$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \ '-DGIT_HTML_PATH="$(htmldir_SQ)"' \ - $(ALL_CFLAGS) -c $(filter %.c,$^) + $(ALL_CFLAGS) -o $@ -c $(filter %.c,$^) git$X: git.o $(BUILTIN_OBJS) $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
compat/vcbuild/scripts/clink.pl new file +48 -0
48 lines not on this page · raw message
compat/vcbuild/scripts/lib.pl new file +26 -0
@@ -0,0 +1,26 @@ +#!/usr/bin/perl -w +###################################################################### +# Libifies files on Windows +# +# This is a wrapper to facilitate the compilation of Git with MSVC +# using GNU Make as the build system. So, instead of manipulating the +# Makefile into something nasty, just to support non-space arguments +# etc, we use this wrapper to fix the command line options +# +# Copyright (C) 2009 Marius Storm-Olsen <[email protected]> +###################################################################### +use strict; +my @args = (); +while (@ARGV) { + my $arg = shift @ARGV; + if ("$arg" eq "rcs") { + # Consume the rcs option + } elsif ("$arg" =~ /\.a$/) { + push(@args, "-OUT:$arg"); + } else { + push(@args, $arg); + } +} +unshift(@args, "lib.exe"); +# printf("**** @args\n"); +exit system(@args);
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 13/14 Add README for MSVC build
Based on original README patch from Frank Li
--- compat/vcbuild/README | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) create mode 100644 compat/vcbuild/README
compat/vcbuild/README new file +39 -0
@@ -0,0 +1,39 @@ +The Steps of Build Git with VS2008 + +1. You need the build environment, which contains the Git dependencies + to be able to compile, link and run Git with MSVC. + + You can either use the binary repository: + + WWW: http://repo.or.cz/w/msvcgit.git + Git: git clone git://repo.or.cz/msvcgit.git + Zip: http://repo.or.cz/w/msvcgit.git?a=snapshot;h=master;sf=zip + + and call the setup_32bit_env.cmd batch script before compiling Git, + (see repo/package README for details), or the source repository: + + WWW: http://repo.or.cz/w/gitbuild.git + Git: git clone git://repo.or.cz/gitbuild.git + Zip: (None, as it's a project with submodules) + + and build the support libs as instructed in that repo/package. + +2. Ensure you have the msysgit environment in your path, so you have + GNU Make, bash and perl available. + + WWW: http://repo.or.cz/w/msysgit.git + Git: git clone git://repo.or.cz/msysgit.git + Zip: http://repo.or.cz/w/msysgit.git?a=snapshot;h=master;sf=zip + + This environment is also needed when you use the resulting + executables, since Git might need to run scripts which are part of + the git operations. + +4. Inside Git's directory run the command: + make common-cmds.h + to generate the common-cmds.h file needed to compile git. + +5. Then build Git with the GNU Make Makefile in the Git projects root + make MSVC=1 + +Done!
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v3 14/14 Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake)
These scripts generate projects for the MSVC IDE (.vcproj files) or QMake (.pro files), based on the output of a 'make -n MSVC=1 V=1' run.
This enables us to simply do the necesarry changes in the Makefile, and you can update the other buildsystems by regenerating the files. Keeping the other buildsystems up-to-date with main development.
The generator system is designed to easily drop in pm's for other buildsystems as well, if someone has an itch. However, the focus has been Windows development, so the 'engine' might need patches to support any platform.
Also add some .gitignore entries for MSVC files.
--- .gitignore | 11 + compat/vcbuild/README | 13 +- contrib/buildsystems/Generators.pm | 42 ++ contrib/buildsystems/Generators/QMake.pm | 189 +++++++++ contrib/buildsystems/Generators/Vcproj.pm | 639 +++++++++++++++++++++++++++++ contrib/buildsystems/engine.pl | 353 ++++++++++++++++ contrib/buildsystems/generate | 29 ++ contrib/buildsystems/parse.pl | 228 ++++++++++ 8 files changed, 1503 insertions(+), 1 deletions(-) create mode 100644 contrib/buildsystems/Generators.pm create mode 100644 contrib/buildsystems/Generators/QMake.pm create mode 100644 contrib/buildsystems/Generators/Vcproj.pm create mode 100644 contrib/buildsystems/engine.pl create mode 100644 contrib/buildsystems/generate create mode 100644 contrib/buildsystems/parse.pl
.gitignore +11 -0
@@ -179,3 +179,14 @@ configure tags TAGS cscope* +*.obj +*.lib +*.sln +*.suo +*.ncb +*.vcproj +*.user +*.idb +*.pdb +Debug/ +Release/
compat/vcbuild/README +12 -1
@@ -33,7 +33,18 @@ The Steps of Build Git with VS2008 make common-cmds.h to generate the common-cmds.h file needed to compile git. -5. Then build Git with the GNU Make Makefile in the Git projects root +5. Then either build Git with the GNU Make Makefile in the Git projects + root make MSVC=1 + or generate Visual Studio solution/projects (.sln/.vcproj) with the + command + perl contrib/buildsystems/generate -g Vcproj + and open and build the solution with the IDE + devenv git.sln /useenv + or build with the IDE build engine directly from the command line + devenv git.sln /useenv /build "Release|Win32" + The /useenv option is required, so Visual Studio picks up the + environment variables for the support libraries required to build + Git, which you set up in step 1. Done!
contrib/buildsystems/Generators.pm new file +42 -0
42 lines not on this page · raw message
contrib/buildsystems/Generators/QMake.pm new file +189 -0
189 lines not on this page · raw message
contrib/buildsystems/Generators/Vcproj.pm new file +639 -0
639 lines not on this page · raw message
contrib/buildsystems/engine.pl new file +353 -0
353 lines not on this page · raw message
contrib/buildsystems/generate new file +29 -0
@@ -0,0 +1,29 @@ +#!/usr/bin/perl -w +###################################################################### +# Generate buildsystem files +# +# This script generate buildsystem files based on the output of a +# GNU Make --dry-run, enabling Windows users to develop Git with their +# trusted IDE with native projects. +# +# Note: +# It is not meant as *the* way of building Git with MSVC, but merely a +# convenience. The correct way of building Git with MSVC is to use the +# GNU Make tool to build with the maintained Makefile in the root of +# the project. If you have the msysgit environment installed and +# available in your current console, together with the Visual Studio +# environment you wish to build for, all you have to do is run the +# command: +# make MSVC=1 +# +# Copyright (C) 2009 Marius Storm-Olsen <[email protected]> +###################################################################### +use strict; +use File::Basename; +use Cwd; + +my $git_dir = getcwd(); +$git_dir =~ s=\\=/=g; +$git_dir = dirname($git_dir) while (!-e "$git_dir/git.c" && "$git_dir" ne ""); +die "Couldn't find Git repo" if ("$git_dir" eq ""); +exec join(" ", ("PERL5LIB=${git_dir}/contrib/buildsystems ${git_dir}/contrib/buildsystems/engine.pl", @ARGV));
contrib/buildsystems/parse.pl new file +228 -0
228 lines not on this page · raw message
Signature · 1 line
1.6.2.1.418.g33d56.dirty
Re: [PATCH 13/14] Add README for MSVC build
In reply to Marius Storm-OlsenQuoted 36 lines · Marius Storm-Olsen
Based on original README patch from Frank Li
Signed-off-by Marius Storm-Olsen <[email protected]>---
compat/vcbuild/README | 39 +++++++++++++++++++++++++++++++++++++++1 files changed, 39 insertions(+), 0 deletions(-)create mode 100644 compat/vcbuild/README
compat/vcbuild/README new file +22
-0@@ -0,0 +1,39 @@ +The Steps of Build Git with VS2008 + +1. You need the build environment, which contains the Git dependencies + to be able to compile, link and run Git with MSVC. + + You can either use the binary repository: + + WWW: http://repo.or.cz/w/msvcgit.git + Git: git clone git://repo.or.cz/msvcgit.git + Zip: http://repo.or.cz/w/msvcgit.git?a=snapshot;h=master;sf=zip + + and call the setup_32bit_env.cmd batch script before compiling Git, + (see repo/package README for details), or the source repository: + + WWW: http://repo.or.cz/w/gitbuild.git + Git: git clone git://repo.or.cz/gitbuild.git + Zip: (None, as it's a project with submodules) + + and build the support libs as instructed in that repo/package. + +2. Ensure you have the msysgit environment in your path, so you have + GNU Make, bash and perl available.
compat/vcbuild/README line 32
Quoted 10 lines
compat/vcbuild/README new file +10
-0+ + WWW: http://repo.or.cz/w/msysgit.git + Git: git clone git://repo.or.cz/msysgit.git + Zip: http://repo.or.cz/w/msysgit.git?a=snapshot;h=master;sf=zip + + This environment is also needed when you use the resulting + executables, since Git might need to run scripts which are part of + the git operations. + +4. Inside Git's directory run the command:
Shouldn't be 3.?
compat/vcbuild/README line 36
Quoted 4 lines
compat/vcbuild/README new file +4
-0+ make common-cmds.h + to generate the common-cmds.h file needed to compile git. + +5. Then build Git with the GNU Make Makefile in the Git projects root
4.?
Quoted 11 lines
compat/vcbuild/README new file +3
-1+ make MSVC=1 + +Done! --1.6.2.1.418.g33d56.dirty
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 13/14] Add README for MSVC build
Thiago Farina said the following on 16.09.2009 03:22:
Quoted 48 lines · Marius Storm-Olsen
Quoted 36 lines
Based on original README patch from Frank Li
Signed-off-by Marius Storm-Olsen <[email protected]>--- compat/vcbuild/README | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) create mode 100644 compat/vcbuild/READMEcompat/vcbuild/README new file +22
-0@@ -0,0 +1,39 @@ +The Steps of Build Git with VS2008 + +1. You need the build environment, which contains the Git dependencies + to be able to compile, link and run Git with MSVC. + + You can either use the binary repository: + + WWW: http://repo.or.cz/w/msvcgit.git + Git: git clone git://repo.or.cz/msvcgit.git + Zip: http://repo.or.cz/w/msvcgit.git?a=snapshot;h=master;sf=zip + + and call the setup_32bit_env.cmd batch script before compiling Git, + (see repo/package README for details), or the source repository: + + WWW: http://repo.or.cz/w/gitbuild.git + Git: git clone git://repo.or.cz/gitbuild.git + Zip: (None, as it's a project with submodules) + + and build the support libs as instructed in that repo/package. + +2. Ensure you have the msysgit environment in your path, so you have + GNU Make, bash and perl available.compat/vcbuild/README line 32
Quoted 10 lines
compat/vcbuild/README new file +10
-0+ + WWW: http://repo.or.cz/w/msysgit.git + Git: git clone git://repo.or.cz/msysgit.git + Zip: http://repo.or.cz/w/msysgit.git?a=snapshot;h=master;sf=zip + + This environment is also needed when you use the resulting + executables, since Git might need to run scripts which are part of + the git operations. + +4. Inside Git's directory run the command:Shouldn't be 3.?
Quoted 5 lines
compat/vcbuild/README line 36
Quoted 4 lines
compat/vcbuild/README new file +4
-0+ make common-cmds.h + to generate the common-cmds.h file needed to compile git. + +5. Then build Git with the GNU Make Makefile in the Git projects root4.?
Heh, you're right.. I've been modifying this file too much lately :-)
--
.marius
Re: [PATCH 04/14] Set _O_BINARY as default fmode for both MinGW and MSVC
In reply to Marius Storm-OlsenQuoted 1 line · Marius Storm-Olsen
+extern int
_fmode;
Is it really needed? I might be wrong, but I thought _fmode needed a more complex declaration, at least on mingw, for which you are supposed to include stdlib.h. For example, for mingw, in stdlib.h, it is declared this way:
#if !defined (__DECLSPEC_SUPPORTED) || defined (__IN_MINGW_RUNTIME)
#ifdef __MSVCRT__
extern int* _imp___fmode;
#define _fmode (*_imp___fmode)
#else
/* CRTDLL */
extern int* _imp___fmode_dll;
#define _fmode (*_imp___fmode_dll)
#endif
#else /* __DECLSPEC_SUPPORTED */
#ifdef __MSVCRT____MINGW_IMPORT int _fmode;
#else /* ! __MSVCRT__ */__MINGW_IMPORT int _fmode_dll;
#define _fmode _fmode_dll
#endif /* ! __MSVCRT__ */
#endif /* __DECLSPEC_SUPPORTED */
As you can see it is a little more complex than a simple extern (e.g. it uses __declspec(dllimport) when it is supported, and a bit of manual dereferencing otherwise). So maybe you would just include stdlib.h and use definition from there?
Re: [PATCH 04/14] Set _O_BINARY as default fmode for both MinGW and MSVC
In reply to Marius Storm-OlsenQuoted 1 line · Marius Storm-Olsen
+extern int
_fmode;
And indeed. I just ported this patch to my custom msysgit branch (based on v1.6.4.3) and it didn't compile:
CC git.o
cc1.exe: warnings being treated as errors
In file included from git-compat-util.h:116,
from builtin.h:4,
from git.c:1:compat/mingw.h:243: error: '_fmode' redeclared without dllimport
attribute: previous dllimport ignoredgit.c: In function 'main':
git.c:456: error: the address of '_iob' will always evaluate as 'true'
make: *** [git.o] Error 1
Re: [PATCH 04/14] Set _O_BINARY as default fmode for both MinGW and MSVC
In reply to Marius Storm-OlsenGMail ate the bottom half of my message... again. :( Seems like there's a strange bug in copy/pasting, I better compose long emails in TextMate from now on. Here's a "reconstruction":
Quoted 1 line · Marius Storm-Olsen
+extern int
_fmode;
And indeed. I just ported this patch to my custom msysgit branch (based on v1.6.4.3) and it didn't compile:
CC git.o
cc1.exe: warnings being treated as errors
In file included from git-compat-util.h:116,
from builtin.h:4,
from git.c:1:compat/mingw.h:243: error: '_fmode' redeclared without dllimport
attribute: previous dllimport ignoredgit.c: In function 'main':
git.c:456: error: the address of '_iob' will always evaluate as 'true'
make: *** [git.o] Error 1
Review
Quoted 6 lines
(quoted diff) +6
-0+ if (stdin) \ + _setmode(_fileno(stdin), _O_BINARY); \ + if (stdout) \ + _setmode(_fileno(stdout), _O_BINARY); \ + if (stderr) \ + _setmode(_fileno(stderr), _O_BINARY); \
Also, at least mingw/gcc that is coming with msysgit thinks that stdin/stdout/stderr always evaluate to true, and this check causes problems as well. In the end, your patch should become something like this:
compat/mingw.c +0 -1
@@ -5,7 +5,6 @@#include "../strbuf.h" extern int hide_dotfiles; -unsigned int _CRT_fmode = _O_BINARY;static int err_win_to_posix (DWORD winerr) {
compat/mingw.h +4 -0
@@ -244,6 +244,10 @@ char **env_setenv(char **env, const char *name);static int mingw_main (); \int main (int argc,const char **argv) \ { \ + _fmode = _O_BINARY; \ +_setmode (_fileno (stdin), _O_BINARY); \ +_setmode (_fileno (stdout), _O_BINARY); \ +_setmode (_fileno (stderr), _O_BINARY); \ argv[0 ] =xstrdup (_pgmptr); \return mingw_main (argc, argv); \ } \
I can't check if it compiles with MSVC, but with msysgit it compiles fine. Tests pass at least up to 3400 (haven't finished the rest).
Re: [PATCH 04/14] Set _O_BINARY as default fmode for both MinGW and MSVC
Alexey Borzenkov said the following on 15.09.2009 21:07:
Quoted 8 lines
GMail ate the bottom half of my message... again. :( Seems like there's a strange bug in copy/pasting, I better compose long emails in TextMate from now on. Here's a "reconstruction":
Quoted 1 line · Marius Storm-Olsen
+extern int
_fmode;And indeed. I just ported this patch to my custom msysgit branch (based on v1.6.4.3) and it didn't compile:
Hmmm, I compile this fine with both MinGW from the msysgit 'devel' branch, and MSVC; but I see your point.
I'll give your updated patch a roll tomorrow. Thanks
--
.marius