Build Git with MSVC
v2 cover Build Git with MSVC
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
=== V2 2009.09.14 ===
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 (8):
Avoid declaration after statement
Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++ Change regerror() declaration from K&R style to ANSI C (C89) mingw.c: Use the O_BINARY flag to open files
Fix __stdcall/WINAPI 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 (9):
boolean is a typedef under MSVC, so rename variable to 'i_boolean' Add define guards to compat/win32.h
Add empty header files for MSVC port
Make usage of windows.h lean and mean
Define strncasecmp as _strnicmp for MSVC
Add ftruncate implementation 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 | 22 +- compat/mingw.h | 2 + compat/msvc.c | 43 ++ compat/msvc.h | 51 +++ 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 +- test-parse-options.c | 12 +- thread-utils.c | 5 +- 46 files changed, 2094 insertions(+), 39 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 v2 1/17 Avoid declaration after statement
From: Frank Li <[email protected]>
Microsoft Visual C++ 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 v2 2/17 boolean is a typedef under MSVC, so rename variable to 'i_boolean'
With MSVC 'boolean' is already a typedef to unsigned char in the rpcndr.h in the SDK. So, just rename to 'i_boolean' to avoid conflicts in this one file, instead of any include magic.
--- test-parse-options.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
test-parse-options.c +6 -6
@@ -1,7 +1,7 @@#include "cache.h" #include "parse-options.h" -static int boolean =0 ; +static int i_boolean =0 ;static int integer =0 ;static unsigned long timestamp;static int abbrev =7 ;
@@ -34,10 +34,10 @@ int main(int argc, const char **argv)NULL };struct option options[] = { -OPT_BOOLEAN ('b' ,"boolean" , &boolean,"get a boolean" ), -OPT_BIT ('4' ,"or4" , &boolean, +OPT_BOOLEAN ('b' ,"boolean" , &i_boolean,"get a boolean" ), +OPT_BIT ('4' ,"or4" , &i_boolean,"bitwise-or boolean with ...0100" ,4 ), -OPT_NEGBIT (0 ,"neg-or4" , &boolean,"same as --no-or4" ,4 ), +OPT_NEGBIT (0 ,"neg-or4" , &i_boolean,"same as --no-or4" ,4 ),OPT_GROUP ("" ),OPT_INTEGER ('i' ,"integer" , &integer,"get a integer" ),OPT_INTEGER ('j' ,NULL , &integer,"get a integer, too" ),
@@ -57,7 +57,7 @@ int main(int argc, const char **argv)OPT_ARGUMENT ("quux" ,"means --quux" ),OPT_NUMBER_CALLBACK (&integer,"set integer to NUM" , number_callback), - { OPTION_BOOLEAN, '+', NULL, &boolean, NULL, "same as -b", + { OPTION_BOOLEAN, '+', NULL, &i_boolean, NULL, "same as -b", PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH },OPT_GROUP ("Standard options" ), OPT__ABBREV(&abbrev),
@@ -70,7 +70,7 @@ int main(int argc, const char **argv) argc =parse_options (argc, argv, prefix, options, usage,0 ); -printf ("boolean: %d\n" , boolean); +printf ("boolean: %d\n" , i_boolean);printf ("integer: %u\n" , integer);printf ("timestamp: %lu\n" , timestamp);printf ("string: %s\n" , string ? string :"(not set)" );
Signature · 1 line
1.6.2.1.418.g33d56.dirty
Re: [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean'
Marius Storm-Olsen said the following on 14.09.2009 15:11:
Quoted 2 lines
With MSVC 'boolean' is already a typedef to unsigned char in the
rpcndr.hin the SDK. So, just rename to 'i_boolean' to avoid conflicts in this one file, instead of any include magic.
This patch can actually be dropped, since patch 12 makes the windows.h include "Lean and Mean", and rpcndr.h is not indirectly include anymore. Sorry for not spotting this before sending the series..
--
.marius
PATCH v2 3/17 Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++
In reply to Marius Storm-OlsenFrom: Frank Li <[email protected]>
Microsoft's vsnprintf function does not add NUL at the end of the buffer, if the result fits the buffer size exactly.
--- compat/snprintf.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 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
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v2 4/17 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 v2 5/17 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 v2 6/17 mingw.c: Use the O_BINARY flag to open files
From: Frank Li <[email protected]>
On Windows, binary files must be opened using the O_BINARY flag for untranslated mode. MinGW does this for us automatically, but Microsoft Visual C++ does not.
--- compat/mingw.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
compat/mingw.c +2 -2
@@ -132,7 +132,7 @@ int mingw_open (const char *filename, int oflags, ...)if (!strcmp (filename,"/dev/null" )) filename ="nul" ; - fd =open (filename, oflags, mode); + fd =open (filename, oflags |O_BINARY , mode);if (fd <0 && (oflags &O_CREAT ) && errno ==EACCES ) {DWORD attrs =GetFileAttributes (filename);
@@ -278,7 +278,7 @@ int mkstemp(char *template)char *filename =mktemp (template);if (filename ==NULL )return -1 ; -return open (filename,O_RDWR |O_CREAT ,0600 ); +return open (filename,O_RDWR |O_CREAT |O_BINARY ,0600 ); }int gettimeofday (struct timeval *tv,void *tz)
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v2 7/17 Fix __stdcall/WINAPI placement and function prototype
From: Frank Li <[email protected]>
WINAPI is a macro which translates into the proper calling convention, so replace __stdcall with that.
MSVC requires WINAPI 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
@@ -1029,7 +1029,7 @@ static sig_handler_t timer_fn = SIG_DFL;* length to call the signal handler. */ -static __stdcall unsigned ticktack (void *dummy) +static unsigned WINAPI ticktack (void *dummy) {while (WaitForSingleObject (timer_event, timer_interval) ==WAIT_TIMEOUT ) {if (timer_fn ==SIG_DFL )
@@ -1156,7 +1156,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 WINAPI run_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
Re: [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype
Quoted 2 lines · Marius Storm-Olsen
WINAPI is a macro which translates into the proper calling convention, so replace
__stdcallwith that.
I've already pointed out elsewhere that the documentation of _beginthreadex explicitly says that the calling convention of the function pointer must be __stdcall. It does not mention WINAPI. Therefore, I think that these two changes are not correct:
run-command.c int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const · line 319
Quoted 5 lines
run-command.c +2
-2-static __stdcall unsigned ticktack(void *dummy) +static unsigned WINAPI ticktack(void *dummy) -static __stdcall unsigned run_thread(void *data) +static unsigned WINAPI run_thread(void *data)
You should s/WINAPI/__stdcall/.
-- Hannes
Re: [msysGit] [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype
Hi,
Quoted 9 lines · Johannes Sixt
Quoted 2 lines · Marius Storm-Olsen
WINAPI is a macro which translates into the proper calling convention, so replace
__stdcallwith that.I've already pointed out elsewhere that the documentation of
_beginthreadexexplicitly says that the calling convention of the function pointer must be__stdcall. It does not mention WINAPI. Therefore, I think that these two changes are not correct:
Quoted 7 lines
run-command.c int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const · line 319
Quoted 5 lines
run-command.c +2
-2-static __stdcall unsigned ticktack(void *dummy) +static unsigned WINAPI ticktack(void *dummy) -static __stdcall unsigned run_thread(void *data) +static unsigned WINAPI run_thread(void *data)You should s/WINAPI/__stdcall/.
I don't think that comments by our most proficient MSys guy should be disregarded as thee comments were.
Ciao,
Dscho
Re: [msysGit] [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype
Johannes Schindelin said the following on 15.09.2009 02:24:
Quoted 9 lines
Hi,
Quoted 5 lines · Johannes Sixt
Quoted 2 lines · Marius Storm-Olsen
WINAPI is a macro which translates into the proper calling convention, so replace
__stdcallwith that.I've already pointed out elsewhere that the documentation of
_beginthreadexexplicitly says that the calling convention of the function pointer must be__stdcall. It does not mention WINAPI. Therefore, I think that these two changes are not correct:
Quoted 7 lines
Quoted 5 lines
compat/mingw.c static sig_handler_t timer_fn = SIG_DFL;
Quoted 4 lines
compat/mingw.c +2
-2-static __stdcall unsigned ticktack(void *dummy) +static unsigned WINAPI ticktack(void *dummy) -static __stdcall unsigned run_thread(void *data) +static unsigned WINAPI run_thread(void *data)You should s/WINAPI/__stdcall/.
I don't think that comments by our most proficient MSys guy should be disregarded as thee comments were.
I also pointed out that WINAPI is just a define for __stdcall (since _MSC_VER >= 800; VC 6.0 being _MSC_VER == 1200 and VC 2008 being _MSC_VER == 1500), and that's probably never going to change now. So, the change is not as bad as Hannes portrays it to be, and makes things less convoluted by using the same convention all over.
However, I'll cave for the pressure, and reroll the commit :)
--
.marius
PATCH v2 8/17 Test for WIN32 instead of __MINGW32_
In reply to Marius Storm-OlsenFrom: 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.
--- help.c | 2 +- pager.c | 4 ++-- run-command.c | 8 ++++---- run-command.h | 2 +- setup.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)
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 WINAPI run_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
Re: [PATCH 08/17] Test for WIN32 instead of __MINGW32_
Quoted 8 lines · Marius Storm-Olsen
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.
Signed-off-by Frank Li <[email protected]>Signed-off-by Marius Storm-Olsen <[email protected]>
The description sounds very sensible; I wish I read this one first, before wasting time scratching my head while reading 03/17. Shouldn't that patch be squashed into this one?
Quoted 111 lines
--- help.c | 2 +- pager.c | 4 ++-- run-command.c | 8 ++++---- run-command.h | 2 +- setup.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)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 WINAPI run_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
Re: [PATCH 08/17] Test for WIN32 instead of __MINGW32_
Junio C Hamano said the following on 14.09.2009 21:31:
Quoted 8 lines
Quoted 6 lines · Marius Storm-Olsen
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.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Frank Li <[email protected]>Signed-off-by Marius Storm-Olsen <[email protected]>The description sounds very sensible; I wish I read this one first, before wasting time scratching my head while reading 03/17. Shouldn't that patch be squashed into this one?
Heh, yeah, I agree. After patch got updated with suggestions from last roll, it clearly makes more sense hear now. I'll update tomorrow. Thanks.
--
.marius
PATCH v2 9/17 Add empty header files for MSVC port
In reply to Marius Storm-OlsenMSVC 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 v2 10/17 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 v2 11/17 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 v2 12/17 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> +unsigned int _CRT_fmode = _O_BINARY;static int err_win_to_posix (DWORD winerr)
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 v2 13/17 Define strncasecmp as _strnicmp for MSVC
--- compat/msvc.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
compat/msvc.h +1 -0
@@ -10,6 +10,7 @@#define __inline__ __inline#define __attribute__ (x)#define va_copy (dst, src) ((dst) = (src)) +#define strncasecmp (s1, s2, n) _strnicmp(s1, s2, n)static __inlineint strcasecmp (const char *s1,const char *s2) {
Signature · 1 line
1.6.2.1.418.g33d56.dirty
PATCH v2 14/17 Add ftruncate implementation for MSVC
The MSVC Posix implementation doesn't contain ftruncate, so add our own which can handle large files (64bit offsets).
--- compat/msvc.c | 8 ++++++++ compat/msvc.h | 2 ++ 2 files changed, 10 insertions(+), 0 deletions(-)
compat/msvc.c +8 -0
@@ -32,4 +32,12 @@ int closedir(DIR *dir)return 0 ; } +int ftruncate (int fd,__int64 length) +{ +HANDLE fh = (HANDLE )_get_osfhandle (fd); +if (!fh ||_lseeki64 (fd, length,SEEK_SET )) +return -1 ; +return SetEndOfFile (fh) ?0 :-1 ; +} +#include "mingw.c"
compat/msvc.h +2 -0
@@ -46,4 +46,6 @@ struct _stati64 {time_t st_mtime; time_t st_ctime; }; + +int ftruncate (int fd,__int64 length);#endif
Signature · 1 line
1.6.2.1.418.g33d56.dirty
Re: [PATCH 14/17] Add ftruncate implementation for MSVC
Quoted 15 lines · Marius Storm-Olsen
The MSVC Posix implementation doesn't contain ftruncate, so add our own which can handle large files (64bit offsets).
Signed-off-by Marius Storm-Olsen <[email protected]>--- compat/msvc.c | 8 ++++++++ compat/msvc.h | 2 ++ 2 files changed, 10 insertions(+), 0 deletions(-)compat/msvc.c +0
-0@@ -32,4 +32,12 @@ int closedir(DIR *dir)return 0 ;
compat/msvc.c int closedir(DIR *dir) · line 42
Quoted 10 lines
compat/msvc.c +8
-0} +int ftruncate (int fd,__int64 length) +{ +HANDLE fh = (HANDLE )_get_osfhandle (fd); +if (!fh ||_lseeki64 (fd, length,SEEK_SET )) +return -1 ; +return SetEndOfFile (fh) ?0 :-1 ; +} +
Wouldn't it break this toy program? ftruncate() should preserve the file offset and use of the seek in the above feels iffy.
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
int main(int ac, char **av)
{
int fd = open("testfile", O_CREAT|O_WRONLY, 0666);
if (fd < 0)
exit(1);
write(fd, "abcdefghijklmnopqrstuvwxyz\n", 27);
lseek(fd, 7, SEEK_SET);
write(fd, "H", 1);
ftruncate(fd, 24);
write(fd, "IJ", 2);
close(fd);
exit(0);
}The only two in-tree users of ftruncate() do not care about this, though. They both seek to the beginning and then truncate to zero length.
Re: [PATCH 14/17] Add ftruncate implementation for MSVC
In reply to Marius Storm-Olsencompat/msvc.c int closedir(DIR *dir) · line 38
Quoted 4 lines · Marius Storm-Olsen
compat/msvc.c +4
-0+int ftruncate (int fd,__int64 length) +{ + HANDLE fh = (HANDLE)_get_osfhandle(fd); + if (!fh || _lseeki64(fd, length, SEEK_SET))
According to MSDN, error is manifested by returning INVALID_HANDLE_VALUE (–1):
Re: [PATCH 14/17] Add ftruncate implementation for MSVC
Alex Riesen said the following on 14.09.2009 16:18:
Quoted 7 lines · Marius Storm-Olsen
compat/msvc.c int closedir(DIR *dir) · line 38
Quoted 4 lines
compat/msvc.c +4
-0+int ftruncate (int fd,__int64 length) +{ +HANDLE fh = (HANDLE )_get_osfhandle (fd); +if (!fh ||_lseeki64 (fd, length,SEEK_SET ))According to MSDN, error is manifested by returning
INVALID_HANDLE_VALUE(–1):
You're absolutely right. I was too deep in Posix-land when writing this. Updated patch will follow tomorrow.
--
.marius
PATCH v2 15/17 Add MSVC to Makefile
In reply to Marius Storm-OlsenEnable 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 git.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 v2 16/17 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 v2 17/17 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.
---
NOTE: Be aware that these scripts are written only with Windows in mind, but could be rewritten to support any platform; and that I'm no Perl Guru. Anyone with an itch, feel free to send improvements, more generators, and what not, so it's more useful, stable and cross-platform. I guess some might want CMake, Scons, Eclipse or KDevelop generators too.. maybe.
.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 15/17] Add MSVC to Makefile
In reply to Marius Storm-OlsenQuoted 6 lines · Marius Storm-Olsen
(quoted diff) +0
-0@@ -1327,7 +1379,7 @@ strip: $(PROGRAMS) git$Xgit.o:
git.ccommon-cmds.hGIT-CFLAGS $(QUIET_CC)$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
'-DGIT_HTML_PATH="$(htmldir_SQ)"' \
- $(ALL_CFLAGS) -c $(filter %.c,$^)
+ $(ALL_CFLAGS) -o git.o -c $(filter %.c,$^)
Why do you use "-o git.o" instead of "-o $@"?
Re: [PATCH 15/17] Add MSVC to Makefile
Alex Riesen said the following on 14.09.2009 16:06:
Quoted 9 lines · Marius Storm-Olsen
Makefile strip: $(PROGRAMS) git$X · line 1382
Quoted 6 lines
Makefile +1
-1@@ -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 git.o -c $(filter %.c,$^)Why do you use "-o git.o" instead of "-o $@"?
No reason really. I'll resend tomorrow.
--
.marius
Re: [msysGit] [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files
In reply to Marius Storm-OlsenQuoted 3 lines · Marius Storm-Olsen
On Windows, binary files must be opened using the
O_BINARYflag for untranslated mode. MinGW does this for us automatically, but Microsoft Visual C++ does not.
Wouldn't it be better to set explicitly set _fmode = _O_BINARY when _MSC_VER is defined? _CRT_fmode is mingw specific, that in addition to setting _fmode also sets mode on stdin/stdout/stderr (see
http://www.koders.com/c/fid2B507DE94598397757D615EDF52267578AD838A2.aspx).
Current patch will not set binary mode for files opened with fopen, as well as stdin/stdout/stderr. One catch might be that declaring it like "unsigned int _fmode = _O_BINARY" might not work, it seems that you are supposed to set it somewhere in the code (see
http://msdn.microsoft.com/en-us/library/ee2849wt(VS.80).aspx). Perhaps implementing a function like _mingw32_init_fmode in crc1.c in mingw-runtime and calling it early in main() would be better?
Thanks,
Alexey.
Re: [PATCH 01/17] Avoid declaration after statement
In reply to Marius Storm-OlsenQuoted 4 lines · Marius Storm-Olsen
From: Frank Li <[email protected]>
Microsoft Visual C++ does not understand this C99 style
But you don't use the C++ compiler (which does understand that syntax).
Re: [PATCH 01/17] Avoid declaration after statement
Quoted 6 lines
Quoted 3 lines
Microsoft Visual C++ does not understand this C99 style
But you don't use the C++ compiler (which does understand that syntax).
Microsoft Visual C++ is product name. If you think it is confuse, it can change to "MSVC"
Re: [PATCH 01/17] Avoid declaration after statement
Quoted 10 lines · Frank Li
Quoted 6 lines
Quoted 3 lines
Microsoft Visual C++ does not understand this C99 style
But you don't use the C++ compiler (which does understand that syntax).
Microsoft Visual C++ is product name. If you think it is confuse, it can change to "MSVC"
I do. OTOH, some people actually use a "product" to compile "software", so maybe it is okay.
Re: [PATCH 01/17] Avoid declaration after statement
Alex Riesen said the following on 14.09.2009 16:10:
Quoted 11 lines · Frank Li
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Microsoft Visual C++ does not understand this C99 style
But you don't use the C++ compiler (which does understand that syntax).
Microsoft Visual C++ is product name. If you think it is confuse, it can change to "MSVC"
I do. OTOH, some people actually use a "product" to compile "software", so maybe it is okay.
Ok, I'll s/Microsoft Visual C++/MSVC/ and resend tomorrow, just to be consistent with the other patches.
--
.marius
Re: [PATCH 01/17] Avoid declaration after statement
In reply to Alex RiesenAlex Riesen said the following on 14.09.2009 15:59:
Quoted 6 lines · Marius Storm-Olsen
Quoted 3 lines
From: Frank Li <[email protected]>
Microsoft Visual C++ does not understand this C99 style
But you don't use the C++ compiler (which does understand that syntax).
It doesn't change the name of the compiler which is called "Microsoft Visual C++". We're just using the C part of it :)
--
.marius