All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC/PATCH v2 00/17] Build Git with MSVC
@ 2009-09-14 13:11 Marius Storm-Olsen
  2009-09-14 13:11 ` [PATCH 01/17] Avoid declaration after statement Marius Storm-Olsen
  0 siblings, 1 reply; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 01/17] Avoid declaration after statement
  2009-09-14 13:11 [RFC/PATCH v2 00/17] Build Git with MSVC Marius Storm-Olsen
@ 2009-09-14 13:11 ` Marius Storm-Olsen
  2009-09-14 13:11   ` [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean' Marius Storm-Olsen
  2009-09-14 13:59   ` [PATCH 01/17] Avoid declaration after statement Alex Riesen
  0 siblings, 2 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen

From: Frank Li <lznuaa@gmail.com>

Microsoft Visual C++ does not understand this C99 style

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/mingw.c |   14 ++++++++++----
 help.c         |    3 ++-
 run-command.c  |    2 ++
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 36ef8d3..5478b74 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -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 signal
 sig_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);
diff --git a/help.c b/help.c
index 294337e..fd51b8e 100644
--- a/help.c
+++ b/help.c
@@ -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;
 }
diff --git a/run-command.c b/run-command.c
index ac314a5..02aaedf 100644
--- a/run-command.c
+++ b/run-command.c
@@ -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) {
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean'
  2009-09-14 13:11 ` [PATCH 01/17] Avoid declaration after statement Marius Storm-Olsen
@ 2009-09-14 13:11   ` Marius Storm-Olsen
  2009-09-14 13:11     ` [PATCH 03/17] Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++ Marius Storm-Olsen
  2009-09-14 13:41     ` [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean' Marius Storm-Olsen
  2009-09-14 13:59   ` [PATCH 01/17] Avoid declaration after statement Alex Riesen
  1 sibling, 2 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen

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.

Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 test-parse-options.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/test-parse-options.c b/test-parse-options.c
index efa734b..0c2d327 100644
--- a/test-parse-options.c
+++ b/test-parse-options.c
@@ -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)");
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 03/17] Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++
  2009-09-14 13:11   ` [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean' Marius Storm-Olsen
@ 2009-09-14 13:11     ` Marius Storm-Olsen
  2009-09-14 13:11       ` [PATCH 04/17] Add define guards to compat/win32.h Marius Storm-Olsen
  2009-09-14 13:41     ` [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean' Marius Storm-Olsen
  1 sibling, 1 reply; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen

From: Frank Li <lznuaa@gmail.com>

Microsoft's vsnprintf function does not add NUL at the end
of the buffer, if the result fits the buffer size exactly.

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/snprintf.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/compat/snprintf.c b/compat/snprintf.c
index 4d07087..e1e0e75 100644
--- a/compat/snprintf.c
+++ b/compat/snprintf.c
@@ -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
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 04/17] Add define guards to compat/win32.h
  2009-09-14 13:11     ` [PATCH 03/17] Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++ Marius Storm-Olsen
@ 2009-09-14 13:11       ` Marius Storm-Olsen
  2009-09-14 13:11         ` [PATCH 05/17] Change regerror() declaration from K&R style to ANSI C (C89) Marius Storm-Olsen
  0 siblings, 1 reply; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen

Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/win32.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/compat/win32.h b/compat/win32.h
index c26384e..e8c178d 100644
--- a/compat/win32.h
+++ b/compat/win32.h
@@ -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
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 05/17] Change regerror() declaration from K&R style to ANSI C (C89)
  2009-09-14 13:11       ` [PATCH 04/17] Add define guards to compat/win32.h Marius Storm-Olsen
@ 2009-09-14 13:11         ` Marius Storm-Olsen
  2009-09-14 13:11           ` [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files Marius Storm-Olsen
  0 siblings, 1 reply; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen

From: Frank Li <lznuaa@gmail.com>

The MSVC headers typedef errcode as int, and thus confused the
compiler in the K&R style definition. ANSI style deconfuses it.

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/regex/regex.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/compat/regex/regex.c b/compat/regex/regex.c
index 5ea0075..67d5c37 100644
--- a/compat/regex/regex.c
+++ b/compat/regex/regex.c
@@ -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;
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files
  2009-09-14 13:11         ` [PATCH 05/17] Change regerror() declaration from K&R style to ANSI C (C89) Marius Storm-Olsen
@ 2009-09-14 13:11           ` Marius Storm-Olsen
  2009-09-14 13:11             ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Marius Storm-Olsen
  2009-09-14 19:06             ` [msysGit] [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files Alexey Borzenkov
  0 siblings, 2 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


From: Frank Li <lznuaa@gmail.com>

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.

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/mingw.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 5478b74..12db9a6 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -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)
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype
  2009-09-14 13:11           ` [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files Marius Storm-Olsen
@ 2009-09-14 13:11             ` Marius Storm-Olsen
  2009-09-14 13:11               ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Marius Storm-Olsen
  2009-09-14 20:00               ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Johannes Sixt
  2009-09-14 19:06             ` [msysGit] [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files Alexey Borzenkov
  1 sibling, 2 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


From: Frank Li <lznuaa@gmail.com>

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...)

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/mingw.c |    4 ++--
 run-command.c  |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 12db9a6..90764eb 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -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(
diff --git a/run-command.c b/run-command.c
index 02aaedf..91f6d2e 100644
--- a/run-command.c
+++ b/run-command.c
@@ -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);
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 08/17] Test for WIN32 instead of __MINGW32_
  2009-09-14 13:11             ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Marius Storm-Olsen
@ 2009-09-14 13:11               ` Marius Storm-Olsen
  2009-09-14 13:11                 ` [PATCH 09/17] Add empty header files for MSVC port Marius Storm-Olsen
  2009-09-14 19:31                 ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Junio C Hamano
  2009-09-14 20:00               ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Johannes Sixt
  1 sibling, 2 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


From: Frank Li <lznuaa@gmail.com>

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 <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 help.c        |    2 +-
 pager.c       |    4 ++--
 run-command.c |    8 ++++----
 run-command.h |    2 +-
 setup.c       |    2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/help.c b/help.c
index fd51b8e..e8db31f 100644
--- a/help.c
+++ b/help.c
@@ -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;
diff --git a/pager.c b/pager.c
index f416d38..86facec 100644
--- a/pager.c
+++ b/pager.c
@@ -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))
diff --git a/run-command.c b/run-command.c
index 91f6d2e..cb006e7 100644
--- a/run-command.c
+++ b/run-command.c
@@ -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, const
 	return 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;
diff --git a/run-command.h b/run-command.h
index 0c00b25..fb34209 100644
--- a/run-command.h
+++ b/run-command.h
@@ -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;
diff --git a/setup.c b/setup.c
index e3781b6..029371e 100644
--- a/setup.c
+++ b/setup.c
@@ -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);
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 09/17] Add empty header files for MSVC port
  2009-09-14 13:11               ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Marius Storm-Olsen
@ 2009-09-14 13:11                 ` Marius Storm-Olsen
  2009-09-14 13:11                   ` [PATCH 10/17] Add MinGW header files to build git with MSVC Marius Storm-Olsen
  2009-09-14 19:31                 ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Junio C Hamano
  1 sibling, 1 reply; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


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.

Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 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

diff --git a/compat/vcbuild/include/arpa/inet.h b/compat/vcbuild/include/arpa/inet.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/arpa/inet.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/grp.h b/compat/vcbuild/include/grp.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/grp.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/inttypes.h b/compat/vcbuild/include/inttypes.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/inttypes.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/netdb.h b/compat/vcbuild/include/netdb.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/netdb.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/netinet/in.h b/compat/vcbuild/include/netinet/in.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/netinet/in.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/netinet/tcp.h b/compat/vcbuild/include/netinet/tcp.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/netinet/tcp.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/pwd.h b/compat/vcbuild/include/pwd.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/pwd.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/sys/ioctl.h b/compat/vcbuild/include/sys/ioctl.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/sys/ioctl.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/sys/param.h b/compat/vcbuild/include/sys/param.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/sys/param.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/sys/poll.h b/compat/vcbuild/include/sys/poll.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/sys/poll.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/sys/select.h b/compat/vcbuild/include/sys/select.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/sys/select.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/sys/socket.h b/compat/vcbuild/include/sys/socket.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/sys/socket.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/sys/time.h b/compat/vcbuild/include/sys/time.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/sys/time.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
diff --git a/compat/vcbuild/include/sys/wait.h b/compat/vcbuild/include/sys/wait.h
new file mode 100644
index 0000000..0d8552a
--- /dev/null
+++ b/compat/vcbuild/include/sys/wait.h
@@ -0,0 +1 @@
+/* Intentionally empty file to support building git with MSVC */
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 10/17] Add MinGW header files to build git with MSVC
  2009-09-14 13:11                 ` [PATCH 09/17] Add empty header files for MSVC port Marius Storm-Olsen
@ 2009-09-14 13:11                   ` Marius Storm-Olsen
  2009-09-14 13:11                     ` [PATCH 11/17] Add platform files for MSVC porting Marius Storm-Olsen
  0 siblings, 1 reply; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


From: Frank Li <lznuaa@gmail.com>

Added the header files dirent.h, unistd.h and utime.h
Add alloca.h, which simply includes malloc.h, which defines alloca

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 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

diff --git a/compat/vcbuild/include/alloca.h b/compat/vcbuild/include/alloca.h
new file mode 100644
index 0000000..c0d7985
--- /dev/null
+++ b/compat/vcbuild/include/alloca.h
@@ -0,0 +1 @@
+#include <malloc.h>
diff --git a/compat/vcbuild/include/dirent.h b/compat/vcbuild/include/dirent.h
new file mode 100644
index 0000000..440618d
--- /dev/null
+++ b/compat/vcbuild/include/dirent.h
@@ -0,0 +1,128 @@
+/*
+ * DIRENT.H (formerly DIRLIB.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.
+ */
+#ifndef _DIRENT_H_
+#define _DIRENT_H_
+#include <io.h>
+
+#define PATH_MAX 512
+
+#define __MINGW_NOTHROW
+
+#ifndef RC_INVOKED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct dirent
+{
+	long		d_ino;		/* Always zero. */
+	unsigned short	d_reclen;	/* Always zero. */
+	unsigned short	d_namlen;	/* Length of name in d_name. */
+	char		d_name[FILENAME_MAX]; /* File name. */
+};
+
+/*
+ * This is an internal data structure. Good programmers will not use it
+ * except as an argument to one of the functions below.
+ * dd_stat field is now int (was short in older versions).
+ */
+typedef struct
+{
+	/* disk transfer area for this dir */
+	struct _finddata_t	dd_dta;
+
+	/* dirent struct to return from dir (NOTE: this makes this thread
+	 * safe as long as only one thread uses a particular DIR struct at
+	 * a time) */
+	struct dirent		dd_dir;
+
+	/* _findnext handle */
+	long			dd_handle;
+
+	/*
+	 * Status of search:
+	 *   0 = not started yet (next entry to read is first entry)
+	 *  -1 = off the end
+	 *   positive = 0 based index of next entry
+	 */
+	int			dd_stat;
+
+	/* given path for dir with search pattern (struct is extended) */
+	char			dd_name[PATH_MAX+3];
+} DIR;
+
+DIR* __cdecl __MINGW_NOTHROW opendir (const char*);
+struct dirent* __cdecl __MINGW_NOTHROW readdir (DIR*);
+int __cdecl __MINGW_NOTHROW closedir (DIR*);
+void __cdecl __MINGW_NOTHROW rewinddir (DIR*);
+long __cdecl __MINGW_NOTHROW telldir (DIR*);
+void __cdecl __MINGW_NOTHROW seekdir (DIR*, long);
+
+
+/* wide char versions */
+
+struct _wdirent
+{
+	long		d_ino;		/* Always zero. */
+	unsigned short	d_reclen;	/* Always zero. */
+	unsigned short	d_namlen;	/* Length of name in d_name. */
+	wchar_t		d_name[FILENAME_MAX]; /* File name. */
+};
+
+/*
+ * This is an internal data structure. Good programmers will not use it
+ * except as an argument to one of the functions below.
+ */
+typedef struct
+{
+	/* disk transfer area for this dir */
+	//struct _wfinddata_t	dd_dta;
+
+	/* dirent struct to return from dir (NOTE: this makes this thread
+	 * safe as long as only one thread uses a particular DIR struct at
+	 * a time) */
+	struct _wdirent		dd_dir;
+
+	/* _findnext handle */
+	long			dd_handle;
+
+	/*
+	 * Status of search:
+	 *   0 = not started yet (next entry to read is first entry)
+	 *  -1 = off the end
+	 *   positive = 0 based index of next entry
+	 */
+	int			dd_stat;
+
+	/* given path for dir with search pattern (struct is extended) */
+	wchar_t			dd_name[1];
+} _WDIR;
+
+
+
+_WDIR* __cdecl __MINGW_NOTHROW _wopendir (const wchar_t*);
+struct _wdirent*  __cdecl __MINGW_NOTHROW _wreaddir (_WDIR*);
+int __cdecl __MINGW_NOTHROW _wclosedir (_WDIR*);
+void __cdecl __MINGW_NOTHROW _wrewinddir (_WDIR*);
+long __cdecl __MINGW_NOTHROW _wtelldir (_WDIR*);
+void __cdecl __MINGW_NOTHROW _wseekdir (_WDIR*, long);
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* Not RC_INVOKED */
+
+#endif	/* Not _DIRENT_H_ */
diff --git a/compat/vcbuild/include/sys/utime.h b/compat/vcbuild/include/sys/utime.h
new file mode 100644
index 0000000..582589c
--- /dev/null
+++ b/compat/vcbuild/include/sys/utime.h
@@ -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
diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
new file mode 100644
index 0000000..2a4f276
--- /dev/null
+++ b/compat/vcbuild/include/unistd.h
@@ -0,0 +1,92 @@
+#ifndef _UNISTD_
+#define _UNISTD_
+
+/* Win32 define for porting git*/
+
+#ifndef _MODE_T_
+#define	_MODE_T_
+typedef unsigned short _mode_t;
+
+#ifndef	_NO_OLDNAMES
+typedef _mode_t	mode_t;
+#endif
+#endif	/* Not _MODE_T_ */
+
+#ifndef _SSIZE_T_
+#define _SSIZE_T_
+typedef long _ssize_t;
+
+#ifndef	_OFF_T_
+#define	_OFF_T_
+typedef long _off_t;
+
+#ifndef	_NO_OLDNAMES
+typedef _off_t	off_t;
+#endif
+#endif	/* Not _OFF_T_ */
+
+
+#ifndef	_NO_OLDNAMES
+typedef _ssize_t ssize_t;
+#endif
+#endif /* Not _SSIZE_T_ */
+
+typedef signed char int8_t;
+typedef unsigned char   uint8_t;
+typedef short  int16_t;
+typedef unsigned short  uint16_t;
+typedef int  int32_t;
+typedef unsigned   uint32_t;
+typedef long long  int64_t;
+typedef unsigned long long   uint64_t;
+
+typedef long long  intmax_t;
+typedef unsigned long long uintmax_t;
+
+typedef int64_t off64_t;
+
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
+/* Some defines for _access nAccessMode (MS doesn't define them, but
+ * it doesn't seem to hurt to add them). */
+#define	F_OK	0	/* Check for file existence */
+/* Well maybe it does hurt.  On newer versions of MSVCRT, an access mode
+   of 1 causes invalid parameter error. */
+#define	X_OK	0	/* MS access() doesn't check for execute permission. */
+#define	W_OK	2	/* Check for write permission */
+#define	R_OK	4	/* Check for read permission */
+
+#define	_S_IFIFO	0x1000	/* FIFO */
+#define	_S_IFCHR	0x2000	/* Character */
+#define	_S_IFBLK	0x3000	/* Block: Is this ever set under w32? */
+#define	_S_IFDIR	0x4000	/* Directory */
+#define	_S_IFREG	0x8000	/* Regular */
+
+#define	_S_IFMT		0xF000	/* File type mask */
+
+#define	_S_IXUSR	_S_IEXEC
+#define	_S_IWUSR	_S_IWRITE
+#define	_S_IRUSR	_S_IREAD
+#define	_S_ISDIR(m)	(((m) & _S_IFMT) == _S_IFDIR)
+
+#define	S_IFIFO		_S_IFIFO
+#define	S_IFCHR		_S_IFCHR
+#define	S_IFBLK		_S_IFBLK
+#define	S_IFDIR		_S_IFDIR
+#define	S_IFREG		_S_IFREG
+#define	S_IFMT		_S_IFMT
+#define	S_IEXEC		_S_IEXEC
+#define	S_IWRITE	_S_IWRITE
+#define	S_IREAD		_S_IREAD
+#define	S_IRWXU		_S_IRWXU
+#define	S_IXUSR		_S_IXUSR
+#define	S_IWUSR		_S_IWUSR
+#define	S_IRUSR		_S_IRUSR
+
+
+#define	S_ISDIR(m)	(((m) & S_IFMT) == S_IFDIR)
+#define	S_ISREG(m)	(((m) & S_IFMT) == S_IFREG)
+#define	S_ISFIFO(m)	(((m) & S_IFMT) == S_IFIFO)
+
+#endif
diff --git a/compat/vcbuild/include/utime.h b/compat/vcbuild/include/utime.h
new file mode 100644
index 0000000..8285f38
--- /dev/null
+++ b/compat/vcbuild/include/utime.h
@@ -0,0 +1 @@
+#include <sys/utime.h>
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 11/17] Add platform files for MSVC porting
  2009-09-14 13:11                   ` [PATCH 10/17] Add MinGW header files to build git with MSVC Marius Storm-Olsen
@ 2009-09-14 13:11                     ` Marius Storm-Olsen
  2009-09-14 13:11                       ` [PATCH 12/17] Make usage of windows.h lean and mean Marius Storm-Olsen
  0 siblings, 1 reply; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


From: Frank Li <lznuaa@gmail.com>

Add msvc.c and msvc.h to build git under MSVC

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 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

diff --git a/compat/msvc.c b/compat/msvc.c
new file mode 100644
index 0000000..ac04a4c
--- /dev/null
+++ b/compat/msvc.c
@@ -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"
diff --git a/compat/msvc.h b/compat/msvc.h
new file mode 100644
index 0000000..6daf313
--- /dev/null
+++ b/compat/msvc.h
@@ -0,0 +1,55 @@
+#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>
+
+/* porting function */
+#define inline __inline
+#define __inline__ __inline
+#define __attribute__(x)
+#define va_copy(dst, src)     ((dst) = (src))
+
+static __inline int strcasecmp (const char *s1, const char *s2)
+{
+	int size1 = strlen(s1);
+	int sisz2 = strlen(s2);
+	return _strnicmp(s1, s2, sisz2 > size1 ? sisz2 : size1);
+}
+
+#undef ERROR
+#undef stat
+#undef _stati64
+#include "compat/mingw.h"
+#undef stat
+#define stat _stati64
+#define _stat64(x,y) mingw_lstat(x,y)
+
+/*
+   Even though _stati64 is normally just defined at _stat64
+   on Windows, we specify it here as a proper struct to avoid
+   compiler warnings about macro redefinition due to magic in
+   mingw.h. Struct taken from ReactOS (GNU GPL license).
+*/
+struct _stati64 {
+	_dev_t  st_dev;
+	_ino_t  st_ino;
+	unsigned short st_mode;
+	short   st_nlink;
+	short   st_uid;
+	short   st_gid;
+	_dev_t  st_rdev;
+	__int64 st_size;
+	time_t  st_atime;
+	time_t  st_mtime;
+	time_t  st_ctime;
+};
+#endif
diff --git a/git-compat-util.h b/git-compat-util.h
index e5e9f39..8ea444f 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -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>
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 12/17] Make usage of windows.h lean and mean
  2009-09-14 13:11                     ` [PATCH 11/17] Add platform files for MSVC porting Marius Storm-Olsen
@ 2009-09-14 13:11                       ` Marius Storm-Olsen
  2009-09-14 13:11                         ` [PATCH 13/17] Define strncasecmp as _strnicmp for MSVC Marius Storm-Olsen
  0 siblings, 1 reply; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


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.

Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 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(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 90764eb..fe21c29 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -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)
diff --git a/compat/mingw.h b/compat/mingw.h
index c43917c..4784adc 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -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 {
diff --git a/compat/msvc.h b/compat/msvc.h
index 6daf313..53a6d30 100644
--- a/compat/msvc.h
+++ b/compat/msvc.h
@@ -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>
diff --git a/compat/win32.h b/compat/win32.h
index e8c178d..8ce9104 100644
--- a/compat/win32.h
+++ b/compat/win32.h
@@ -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)
 {
diff --git a/compat/winansi.c b/compat/winansi.c
index 9217c24..dedce21 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -2,7 +2,6 @@
  * Copyright 2008 Peter Harris <git@peter.is-a-geek.org>
  */
 
-#include <windows.h>
 #include "../git-compat-util.h"
 
 /*
diff --git a/git-compat-util.h b/git-compat-util.h
index 8ea444f..8d6e29c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -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>
diff --git a/thread-utils.c b/thread-utils.c
index 55e7e29..4f9c829 100644
--- a/thread-utils.c
+++ b/thread-utils.c
@@ -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
 
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 13/17] Define strncasecmp as _strnicmp for MSVC
  2009-09-14 13:11                       ` [PATCH 12/17] Make usage of windows.h lean and mean Marius Storm-Olsen
@ 2009-09-14 13:11                         ` Marius Storm-Olsen
  2009-09-14 13:11                           ` [PATCH 14/17] Add ftruncate implementation " Marius Storm-Olsen
  0 siblings, 1 reply; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/msvc.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/compat/msvc.h b/compat/msvc.h
index 53a6d30..a62507f 100644
--- a/compat/msvc.h
+++ b/compat/msvc.h
@@ -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 __inline int strcasecmp (const char *s1, const char *s2)
 {
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 14/17] Add ftruncate implementation for MSVC
  2009-09-14 13:11                         ` [PATCH 13/17] Define strncasecmp as _strnicmp for MSVC Marius Storm-Olsen
@ 2009-09-14 13:11                           ` Marius Storm-Olsen
  2009-09-14 13:11                             ` [PATCH 15/17] Add MSVC to Makefile Marius Storm-Olsen
                                               ` (2 more replies)
  0 siblings, 3 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, 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 <mstormo@gmail.com>
---
 compat/msvc.c |    8 ++++++++
 compat/msvc.h |    2 ++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/compat/msvc.c b/compat/msvc.c
index ac04a4c..b96b045 100644
--- a/compat/msvc.c
+++ b/compat/msvc.c
@@ -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"
diff --git a/compat/msvc.h b/compat/msvc.h
index a62507f..d9fc04b 100644
--- a/compat/msvc.h
+++ b/compat/msvc.h
@@ -46,4 +46,6 @@ struct _stati64 {
 	time_t  st_mtime;
 	time_t  st_ctime;
 };
+
+int ftruncate(int fd, __int64 length);
 #endif
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 15/17] Add MSVC to Makefile
  2009-09-14 13:11                           ` [PATCH 14/17] Add ftruncate implementation " Marius Storm-Olsen
@ 2009-09-14 13:11                             ` Marius Storm-Olsen
  2009-09-14 13:11                               ` [PATCH 16/17] Add README for MSVC build Marius Storm-Olsen
  2009-09-14 14:06                               ` [PATCH 15/17] Add MSVC to Makefile Alex Riesen
  2009-09-14 14:18                             ` [PATCH 14/17] Add ftruncate implementation for MSVC Alex Riesen
  2009-09-14 19:48                             ` Junio C Hamano
  2 siblings, 2 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


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.

Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 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

diff --git a/Makefile b/Makefile
index bde2acd..3bdd749 100644
--- a/Makefile
+++ b/Makefile
@@ -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 \
diff --git a/compat/vcbuild/scripts/clink.pl b/compat/vcbuild/scripts/clink.pl
new file mode 100644
index 0000000..0ffd59f
--- /dev/null
+++ b/compat/vcbuild/scripts/clink.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/perl -w
+######################################################################
+# Compiles or links files
+#
+# 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 <mstormo@gmail.com>
+######################################################################
+use strict;
+my @args = ();
+my @cflags = ();
+my $is_linking = 0;
+while (@ARGV) {
+	my $arg = shift @ARGV;
+	if ("$arg" =~ /^-[DIMGO]/) {
+		push(@cflags, $arg);
+	} elsif ("$arg" eq "-o") {
+		my $file_out = shift @ARGV;
+		if ("$file_out" =~ /exe$/) {
+			$is_linking = 1;
+			push(@args, "-OUT:$file_out");
+		} else {
+			push(@args, "-Fo$file_out");
+		}
+	} elsif ("$arg" eq "-lz") {
+		push(@args, "zlib.lib");
+	} elsif ("$arg" eq "-liconv") {
+		push(@args, "iconv.lib");
+	} elsif ("$arg" =~ /^-L/ && "$arg" ne "-LTCG") {
+		$arg =~ s/^-L/-LIBPATH:/;
+		push(@args, $arg);
+	} elsif ("$arg" =~ /^-R/) {
+		# eat
+	} else {
+		push(@args, $arg);
+	}
+}
+if ($is_linking) {
+	unshift(@args, "link.exe");
+} else {
+	unshift(@args, "cl.exe");
+	push(@args, @cflags);
+}
+#printf("**** @args\n");
+exit system(@args);
diff --git a/compat/vcbuild/scripts/lib.pl b/compat/vcbuild/scripts/lib.pl
new file mode 100644
index 0000000..68f6644
--- /dev/null
+++ b/compat/vcbuild/scripts/lib.pl
@@ -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 <mstormo@gmail.com>
+######################################################################
+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);
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 16/17] Add README for MSVC build
  2009-09-14 13:11                             ` [PATCH 15/17] Add MSVC to Makefile Marius Storm-Olsen
@ 2009-09-14 13:11                               ` Marius Storm-Olsen
  2009-09-14 13:11                                 ` [PATCH 17/17] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Marius Storm-Olsen
  2009-09-14 14:06                               ` [PATCH 15/17] Add MSVC to Makefile Alex Riesen
  1 sibling, 1 reply; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


Based on original README patch from Frank Li

Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 compat/vcbuild/README |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)
 create mode 100644 compat/vcbuild/README

diff --git a/compat/vcbuild/README b/compat/vcbuild/README
new file mode 100644
index 0000000..5d7a07a
--- /dev/null
+++ b/compat/vcbuild/README
@@ -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!
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 17/17] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake)
  2009-09-14 13:11                               ` [PATCH 16/17] Add README for MSVC build Marius Storm-Olsen
@ 2009-09-14 13:11                                 ` Marius Storm-Olsen
  0 siblings, 0 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:11 UTC (permalink / raw)
  To: Johannes.Schindelin; +Cc: msysgit, git, lznuaa, Marius Storm-Olsen


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.

Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
 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

diff --git a/.gitignore b/.gitignore
index 47672b0..51a37b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -179,3 +179,14 @@ configure
 tags
 TAGS
 cscope*
+*.obj
+*.lib
+*.sln
+*.suo
+*.ncb
+*.vcproj
+*.user
+*.idb
+*.pdb
+Debug/
+Release/
diff --git a/compat/vcbuild/README b/compat/vcbuild/README
index 5d7a07a..e64f7e5 100644
--- a/compat/vcbuild/README
+++ b/compat/vcbuild/README
@@ -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!
diff --git a/contrib/buildsystems/Generators.pm b/contrib/buildsystems/Generators.pm
new file mode 100644
index 0000000..408ef71
--- /dev/null
+++ b/contrib/buildsystems/Generators.pm
@@ -0,0 +1,42 @@
+package Generators;
+require Exporter;
+
+use strict;
+use File::Basename;
+no strict 'refs';
+use vars qw($VERSION @AVAILABLE);
+
+our $VERSION = '1.00';
+our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
+@ISA = qw(Exporter);
+
+BEGIN {
+    local(*D);
+    my $me = $INC{"Generators.pm"};
+    die "Couldn't find myself in \@INC, which is required to load the generators!" if ("$me" eq "");
+    $me = dirname($me);
+    if (opendir(D,"$me/Generators")) {
+        foreach my $gen (readdir(D)) {
+            next if ($gen  =~ /^\.\.?$/);
+            require "${me}/Generators/$gen";
+            $gen =~ s,\.pm,,;
+            push(@AVAILABLE, $gen);
+        }
+        closedir(D);
+        my $gens = join(', ', @AVAILABLE);
+    }
+
+    push @EXPORT_OK, qw(available);
+}
+
+sub available {
+    return @AVAILABLE;
+}
+
+sub generate {
+    my ($gen, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
+    return eval("Generators::${gen}::generate(\$git_dir, \$out_dir, \$rel_dir, \%build_structure)") if grep(/^$gen$/, @AVAILABLE);
+    die "Generator \"${gen}\" is not available!\nAvailable generators are: @AVAILABLE\n";
+}
+
+1;
diff --git a/contrib/buildsystems/Generators/QMake.pm b/contrib/buildsystems/Generators/QMake.pm
new file mode 100644
index 0000000..ff3b657
--- /dev/null
+++ b/contrib/buildsystems/Generators/QMake.pm
@@ -0,0 +1,189 @@
+package Generators::QMake;
+require Exporter;
+
+use strict;
+use vars qw($VERSION);
+
+our $VERSION = '1.00';
+our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
+@ISA = qw(Exporter);
+
+BEGIN {
+    push @EXPORT_OK, qw(generate);
+}
+
+sub generate {
+    my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
+
+    my @libs = @{$build_structure{"LIBS"}};
+    foreach (@libs) {
+        createLibProject($_, $git_dir, $out_dir, $rel_dir, %build_structure);
+    }
+
+    my @apps = @{$build_structure{"APPS"}};
+    foreach (@apps) {
+        createAppProject($_, $git_dir, $out_dir, $rel_dir, %build_structure);
+    }
+
+    createGlueProject($git_dir, $out_dir, $rel_dir, %build_structure);
+    return 0;
+}
+
+sub createLibProject {
+    my ($libname, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
+    print "Generate $libname lib project\n";
+    $rel_dir = "../$rel_dir";
+
+    my $sources = join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"LIBS_${libname}_SOURCES"}})));
+    my $defines = join(" \\\n\t", sort(@{$build_structure{"LIBS_${libname}_DEFINES"}}));
+    my $includes= join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"LIBS_${libname}_INCLUDES"}})));
+    my $cflags  = join(" ", sort(@{$build_structure{"LIBS_${libname}_CFLAGS"}}));
+
+    my $cflags_debug = $cflags;
+    $cflags_debug =~ s/-MT/-MTd/;
+    $cflags_debug =~ s/-O.//;
+
+    my $cflags_release = $cflags;
+    $cflags_release =~ s/-MTd/-MT/;
+
+    my @tmp  = @{$build_structure{"LIBS_${libname}_LFLAGS"}};
+    my @tmp2 = ();
+    foreach (@tmp) {
+        if (/^-LTCG/) {
+        } elsif (/^-L/) {
+            $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
+        }
+        push(@tmp2, $_);
+    }
+    my $lflags = join(" ", sort(@tmp));
+
+    my $target = $libname;
+    $target =~ s/\//_/g;
+    $defines =~ s/-D//g;
+    $defines =~ s/"/\\\\"/g;
+    $includes =~ s/-I//g;
+    mkdir "$target" || die "Could not create the directory $target for lib project!\n";
+    open F, ">$target/$target.pro" || die "Could not open $target/$target.pro for writing!\n";
+    print F << "EOM";
+TEMPLATE = lib
+TARGET = $target
+DESTDIR = $rel_dir
+
+CONFIG -= qt
+CONFIG += static
+
+QMAKE_CFLAGS =
+QMAKE_CFLAGS_RELEASE = $cflags_release
+QMAKE_CFLAGS_DEBUG = $cflags_debug
+QMAKE_LIBFLAGS = $lflags
+
+DEFINES += \\
+        $defines
+
+INCLUDEPATH += \\
+        $includes
+
+SOURCES += \\
+        $sources
+EOM
+    close F;
+}
+
+sub createAppProject {
+    my ($appname, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
+    print "Generate $appname app project\n";
+    $rel_dir = "../$rel_dir";
+
+    my $sources = join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"APPS_${appname}_SOURCES"}})));
+    my $defines = join(" \\\n\t", sort(@{$build_structure{"APPS_${appname}_DEFINES"}}));
+    my $includes= join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"APPS_${appname}_INCLUDES"}})));
+    my $cflags  = join(" ", sort(@{$build_structure{"APPS_${appname}_CFLAGS"}}));
+
+    my $cflags_debug = $cflags;
+    $cflags_debug =~ s/-MT/-MTd/;
+    $cflags_debug =~ s/-O.//;
+
+    my $cflags_release = $cflags;
+    $cflags_release =~ s/-MTd/-MT/;
+
+    my $libs;
+    foreach (sort(@{$build_structure{"APPS_${appname}_LIBS"}})) {
+        $_ =~ s/\//_/g;
+        $libs .= " $_";
+    }
+    my @tmp  = @{$build_structure{"APPS_${appname}_LFLAGS"}};
+    my @tmp2 = ();
+    foreach (@tmp) {
+        # next if ($_ eq "-NODEFAULTLIB:MSVCRT.lib");
+        if (/^-LTCG/) {
+        } elsif (/^-L/) {
+            $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
+        }
+        push(@tmp2, $_);
+    }
+    my $lflags = join(" ", sort(@tmp));
+
+    my $target = $appname;
+    $target =~ s/\.exe//;
+    $target =~ s/\//_/g;
+    $defines =~ s/-D//g;
+    $defines =~ s/"/\\\\"/g;
+    $includes =~ s/-I//g;
+    mkdir "$target" || die "Could not create the directory $target for app project!\n";
+    open F, ">$target/$target.pro" || die "Could not open $target/$target.pro for writing!\n";
+    print F << "EOM";
+TEMPLATE = app
+TARGET = $target
+DESTDIR = $rel_dir
+
+CONFIG -= qt embed_manifest_exe
+CONFIG += console
+
+QMAKE_CFLAGS =
+QMAKE_CFLAGS_RELEASE = $cflags_release
+QMAKE_CFLAGS_DEBUG = $cflags_debug
+QMAKE_LFLAGS = $lflags
+LIBS   = $libs
+
+DEFINES += \\
+        $defines
+
+INCLUDEPATH += \\
+        $includes
+
+win32:QMAKE_LFLAGS += -LIBPATH:$rel_dir
+else: QMAKE_LFLAGS += -L$rel_dir
+
+SOURCES += \\
+        $sources
+EOM
+    close F;
+}
+
+sub createGlueProject {
+    my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
+    my $libs = join(" \\ \n", map("\t$_|$_.pro", @{$build_structure{"LIBS"}}));
+    my $apps = join(" \\ \n", map("\t$_|$_.pro", @{$build_structure{"APPS"}}));
+    $libs =~ s/\.a//g;
+    $libs =~ s/\//_/g;
+    $libs =~ s/\|/\//g;
+    $apps =~ s/\.exe//g;
+    $apps =~ s/\//_/g;
+    $apps =~ s/\|/\//g;
+
+    my $filename = $out_dir;
+    $filename =~ s/.*\/([^\/]+)$/$1/;
+    $filename =~ s/\/$//;
+    print "Generate glue project $filename.pro\n";
+    open F, ">$filename.pro" || die "Could not open $filename.pro for writing!\n";
+    print F << "EOM";
+TEMPLATE = subdirs
+CONFIG += ordered
+SUBDIRS += \\
+$libs \\
+$apps
+EOM
+    close F;
+}
+
+1;
diff --git a/contrib/buildsystems/Generators/Vcproj.pm b/contrib/buildsystems/Generators/Vcproj.pm
new file mode 100644
index 0000000..00ec0c1
--- /dev/null
+++ b/contrib/buildsystems/Generators/Vcproj.pm
@@ -0,0 +1,639 @@
+package Generators::Vcproj;
+require Exporter;
+
+use strict;
+use vars qw($VERSION);
+
+our $VERSION = '1.00';
+our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
+@ISA = qw(Exporter);
+
+BEGIN {
+    push @EXPORT_OK, qw(generate);
+}
+
+my $guid_index = 0;
+my @GUIDS = (
+    "{E07B9989-2BF7-4F21-8918-BE22BA467AC3}",
+    "{278FFB51-0296-4A44-A81A-22B87B7C3592}",
+    "{7346A2C4-F0FD-444F-9EBE-1AF23B2B5650}",
+    "{67F421AC-EB34-4D49-820B-3196807B423F}",
+    "{385DCFE1-CC8C-4211-A451-80FCFC31CA51}",
+    "{97CC46C5-D2CC-4D26-B634-E75792B79916}",
+    "{C7CE21FE-6EF8-4012-A5C7-A22BCEDFBA11}",
+    "{51575134-3FDF-42D1-BABD-3FB12669C6C9}",
+    "{0AE195E4-9823-4B87-8E6F-20C5614AF2FF}",
+    "{4B918255-67CA-43BB-A46C-26704B666E6B}",
+    "{18CCFEEF-C8EE-4CC1-A265-26F95C9F4649}",
+    "{5D5D90FA-01B7-4973-AFE5-CA88C53AC197}",
+    "{1F054320-036D-49E1-B384-FB5DF0BC8AC0}",
+    "{7CED65EE-F2D9-4171-825B-C7D561FE5786}",
+    "{8D341679-0F07-4664-9A56-3BA0DE88B9BC}",
+    "{C189FEDC-2957-4BD7-9FA4-7622241EA145}",
+    "{66844203-1B9F-4C53-9274-164FFF95B847}",
+    "{E4FEA145-DECC-440D-AEEA-598CF381FD43}",
+    "{73300A8E-C8AC-41B0-B555-4F596B681BA7}",
+    "{873FDEB1-D01D-40BF-A1BF-8BBC58EC0F51}",
+    "{7922C8BE-76C5-4AC6-8BF7-885C0F93B782}",
+    "{E245D370-308B-4A49-BFC1-1E527827975F}",
+    "{F6FA957B-66FC-4ED7-B260-E59BBE4FE813}",
+    "{E6055070-0198-431A-BC49-8DB6CEE770AE}",
+    "{54159234-C3EB-43DA-906B-CE5DA5C74654}",
+    "{594CFC35-0B60-46F6-B8EF-9983ACC1187D}",
+    "{D93FCAB7-1F01-48D2-B832-F761B83231A5}",
+    "{DBA5E6AC-E7BE-42D3-8703-4E787141526E}",
+    "{6171953F-DD26-44C7-A3BE-CC45F86FC11F}",
+    "{9E19DDBE-F5E4-4A26-A2FE-0616E04879B8}",
+    "{AE81A615-99E3-4885-9CE0-D9CAA193E867}",
+    "{FBF4067E-1855-4F6C-8BCD-4D62E801A04D}",
+    "{17007948-6593-4AEB-8106-F7884B4F2C19}",
+    "{199D4C8D-8639-4DA6-82EF-08668C35DEE0}",
+    "{E085E50E-C140-4CF3-BE4B-094B14F0DDD6}",
+    "{00785268-A9CC-4E40-AC29-BAC0019159CE}",
+    "{4C06F56A-DCDB-46A6-B67C-02339935CF12}",
+    "{3A62D3FD-519E-4EC9-8171-D2C1BFEA022F}",
+    "{3A62D3FD-519E-4EC9-8171-D2C1BFEA022F}",
+    "{9392EB58-D7BA-410B-B1F0-B2FAA6BC89A7}",
+    "{2ACAB2D5-E0CE-4027-BCA0-D78B2D7A6C66}",
+    "{86E216C3-43CE-481A-BCB2-BE5E62850635}",
+    "{FB631291-7923-4B91-9A57-7B18FDBB7A42}",
+    "{0A176EC9-E934-45B8-B87F-16C7F4C80039}",
+    "{DF55CA80-46E8-4C53-B65B-4990A23DD444}",
+    "{3A0F9895-55D2-4710-BE5E-AD7498B5BF44}",
+    "{294BDC5A-F448-48B6-8110-DD0A81820F8C}",
+    "{4B9F66E9-FAC9-47AB-B1EF-C16756FBFD06}",
+    "{72EA49C6-2806-48BD-B81B-D4905102E19C}",
+    "{5728EB7E-8929-486C-8CD5-3238D060E768}"
+);
+
+sub generate {
+    my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
+    my @libs = @{$build_structure{"LIBS"}};
+    foreach (@libs) {
+        createLibProject($_, $git_dir, $out_dir, $rel_dir, \%build_structure);
+    }
+
+    my @apps = @{$build_structure{"APPS"}};
+    foreach (@apps) {
+        createAppProject($_, $git_dir, $out_dir, $rel_dir, \%build_structure);
+    }
+
+    createGlueProject($git_dir, $out_dir, $rel_dir, %build_structure);
+    return 0;
+}
+
+sub createLibProject {
+    my ($libname, $git_dir, $out_dir, $rel_dir, $build_structure) = @_;
+    print "Generate $libname vcproj lib project\n";
+    $rel_dir = "..\\$rel_dir";
+    $rel_dir =~ s/\//\\/g;
+
+    my $target = $libname;
+    $target =~ s/\//_/g;
+    $target =~ s/\.a//;
+
+    my $uuid = $GUIDS[$guid_index];
+    $$build_structure{"LIBS_${target}_GUID"} = $uuid;
+    $guid_index += 1;
+
+    my @srcs = sort(map("$rel_dir\\$_", @{$$build_structure{"LIBS_${libname}_SOURCES"}}));
+    my @sources;
+    foreach (@srcs) {
+        $_ =~ s/\//\\/g;
+        push(@sources, $_);
+    }
+    my $defines = join(",", sort(@{$$build_structure{"LIBS_${libname}_DEFINES"}}));
+    my $includes= join(";", sort(map("&quot;$rel_dir\\$_&quot;", @{$$build_structure{"LIBS_${libname}_INCLUDES"}})));
+    my $cflags  = join(" ", sort(@{$$build_structure{"LIBS_${libname}_CFLAGS"}}));
+    $cflags =~ s/\"/&quot;/g;
+
+    my $cflags_debug = $cflags;
+    $cflags_debug =~ s/-MT/-MTd/;
+    $cflags_debug =~ s/-O.//;
+
+    my $cflags_release = $cflags;
+    $cflags_release =~ s/-MTd/-MT/;
+
+    my @tmp  = @{$$build_structure{"LIBS_${libname}_LFLAGS"}};
+    my @tmp2 = ();
+    foreach (@tmp) {
+        if (/^-LTCG/) {
+        } elsif (/^-L/) {
+            $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
+        }
+        push(@tmp2, $_);
+    }
+    my $lflags = join(" ", sort(@tmp));
+
+    $defines =~ s/-D//g;
+    $defines =~ s/\"/\\&quot;/g;
+    $defines =~ s/\'//g;
+    $includes =~ s/-I//g;
+    mkdir "$target" || die "Could not create the directory $target for lib project!\n";
+    open F, ">$target/$target.vcproj" || die "Could not open $target/$target.pro for writing!\n";
+    print F << "EOM";
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9,00"
+	Name="$target"
+	ProjectGUID="$uuid">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$rel_dir"
+			ConfigurationType="4"
+			CharacterSet="0"
+			IntermediateDirectory="\$(ProjectDir)\$(ConfigurationName)"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalOptions="$cflags_debug"
+				Optimization="0"
+				InlineFunctionExpansion="1"
+				AdditionalIncludeDirectories="$includes"
+				PreprocessorDefinitions="UNICODE,WIN32,_DEBUG,$defines"
+				MinimalRebuild="true"
+				RuntimeLibrary="1"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLibrarianTool"
+				SuppressStartupBanner="true"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$rel_dir"
+			ConfigurationType="4"
+			CharacterSet="0"
+			WholeProgramOptimization="1"
+			IntermediateDirectory="\$(ProjectDir)\$(ConfigurationName)"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalOptions="$cflags_release"
+				Optimization="2"
+				InlineFunctionExpansion="1"
+				EnableIntrinsicFunctions="true"
+				AdditionalIncludeDirectories="$includes"
+				PreprocessorDefinitions="UNICODE,WIN32,NDEBUG,$defines"
+				RuntimeLibrary="0"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLibrarianTool"
+				SuppressStartupBanner="true"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+EOM
+    foreach(@sources) {
+        print F << "EOM";
+			<File
+				RelativePath="$_"/>
+EOM
+    }
+    print F << "EOM";
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
+EOM
+    close F;
+}
+
+sub createAppProject {
+    my ($appname, $git_dir, $out_dir, $rel_dir, $build_structure) = @_;
+    print "Generate $appname vcproj app project\n";
+    $rel_dir = "..\\$rel_dir";
+    $rel_dir =~ s/\//\\/g;
+
+    my $target = $appname;
+    $target =~ s/\//_/g;
+    $target =~ s/\.exe//;
+
+    my $uuid = $GUIDS[$guid_index];
+    $$build_structure{"APPS_${target}_GUID"} = $uuid;
+    $guid_index += 1;
+
+    my @srcs = sort(map("$rel_dir\\$_", @{$$build_structure{"APPS_${appname}_SOURCES"}}));
+    my @sources;
+    foreach (@srcs) {
+        $_ =~ s/\//\\/g;
+        push(@sources, $_);
+    }
+    my $defines = join(",", sort(@{$$build_structure{"APPS_${appname}_DEFINES"}}));
+    my $includes= join(";", sort(map("&quot;$rel_dir\\$_&quot;", @{$$build_structure{"APPS_${appname}_INCLUDES"}})));
+    my $cflags  = join(" ", sort(@{$$build_structure{"APPS_${appname}_CFLAGS"}}));
+    $cflags =~ s/\"/&quot;/g;
+
+    my $cflags_debug = $cflags;
+    $cflags_debug =~ s/-MT/-MTd/;
+    $cflags_debug =~ s/-O.//;
+
+    my $cflags_release = $cflags;
+    $cflags_release =~ s/-MTd/-MT/;
+
+    my $libs;
+    foreach (sort(@{$$build_structure{"APPS_${appname}_LIBS"}})) {
+        $_ =~ s/\//_/g;
+        $libs .= " $_";
+    }
+    my @tmp  = @{$$build_structure{"APPS_${appname}_LFLAGS"}};
+    my @tmp2 = ();
+    foreach (@tmp) {
+        if (/^-LTCG/) {
+        } elsif (/^-L/) {
+            $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
+        }
+        push(@tmp2, $_);
+    }
+    my $lflags = join(" ", sort(@tmp)) . " -LIBPATH:$rel_dir";
+
+    $defines =~ s/-D//g;
+    $defines =~ s/\"/\\&quot;/g;
+    $defines =~ s/\'//g;
+    $defines =~ s/\\\\/\\/g;
+    $includes =~ s/-I//g;
+    mkdir "$target" || die "Could not create the directory $target for lib project!\n";
+    open F, ">$target/$target.vcproj" || die "Could not open $target/$target.pro for writing!\n";
+    print F << "EOM";
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9,00"
+	Name="$target"
+	ProjectGUID="$uuid">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$rel_dir"
+			ConfigurationType="1"
+			CharacterSet="0"
+			IntermediateDirectory="\$(ProjectDir)\$(ConfigurationName)"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalOptions="$cflags_debug"
+				Optimization="0"
+				InlineFunctionExpansion="1"
+				AdditionalIncludeDirectories="$includes"
+				PreprocessorDefinitions="UNICODE,WIN32,_DEBUG,$defines"
+				MinimalRebuild="true"
+				RuntimeLibrary="1"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="$libs"
+				AdditionalOptions="$lflags"
+				LinkIncremental="2"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$rel_dir"
+			ConfigurationType="1"
+			CharacterSet="0"
+			WholeProgramOptimization="1"
+			IntermediateDirectory="\$(ProjectDir)\$(ConfigurationName)"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalOptions="$cflags_release"
+				Optimization="2"
+				InlineFunctionExpansion="1"
+				EnableIntrinsicFunctions="true"
+				AdditionalIncludeDirectories="$includes"
+				PreprocessorDefinitions="UNICODE,WIN32,NDEBUG,$defines"
+				RuntimeLibrary="0"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="$libs"
+				AdditionalOptions="$lflags"
+				LinkIncremental="1"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+EOM
+    foreach(@sources) {
+        print F << "EOM";
+			<File
+				RelativePath="$_"/>
+EOM
+    }
+    print F << "EOM";
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
+EOM
+    close F;
+}
+
+sub createGlueProject {
+    my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
+    print "Generate solutions file\n";
+    $rel_dir = "..\\$rel_dir";
+    $rel_dir =~ s/\//\\/g;
+    my $SLN_HEAD = "Microsoft Visual Studio Solution File, Format Version 10.00\n";
+    my $SLN_PRE  = "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = ";
+    my $SLN_POST = "\nEndProject\n";
+
+    my @libs = @{$build_structure{"LIBS"}};
+    my @tmp;
+    foreach (@libs) {
+        $_ =~ s/\//_/g;
+        $_ =~ s/\.a//;
+        push(@tmp, $_);
+    }
+    @libs = @tmp;
+
+    my @apps = @{$build_structure{"APPS"}};
+    @tmp = ();
+    foreach (@apps) {
+        $_ =~ s/\//_/g;
+        $_ =~ s/\.exe//;
+        push(@tmp, $_);
+    }
+    @apps = @tmp;
+
+    open F, ">git.sln" || die "Could not open git.sln for writing!\n";
+    print F "$SLN_HEAD";
+    foreach (@libs) {
+        my $libname = $_;
+        my $uuid = $build_structure{"LIBS_${libname}_GUID"};
+        print F "$SLN_PRE";
+        print F "\"${libname}\", \"${libname}\\${libname}.vcproj\", \"${uuid}\"";
+        print F "$SLN_POST";
+    }
+    foreach (@apps) {
+        my $appname = $_;
+        my $uuid = $build_structure{"APPS_${appname}_GUID"};
+        print F "$SLN_PRE";
+        print F "\"${appname}\", \"${appname}\\${appname}.vcproj\", \"${uuid}\"";
+        print F "$SLN_POST";
+    }
+
+    print F << "EOM";
+Global
+	GlobalSection(SolutionConfiguration) = preSolution
+		ConfigName.0 = Debug|Win32
+		ConfigName.1 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectDependencies) = postSolution
+EOM
+    foreach (@{$build_structure{"APPS"}}) {
+        my $appname = $_;
+        my $appname_clean = $_;
+        $appname_clean =~ s/\//_/g;
+        $appname_clean =~ s/\.exe//;
+
+        my $uuid = $build_structure{"APPS_${appname_clean}_GUID"};
+        my $dep_index = 0;
+        foreach(@{$build_structure{"APPS_${appname}_LIBS"}}) {
+            my $libname = $_;
+            $libname =~ s/\//_/g;
+            $libname =~ s/\.(a|lib)//;
+            my $libuuid = $build_structure{"LIBS_${libname}_GUID"};
+            if (defined $libuuid) {
+                print F "\t\t${uuid}.${dep_index} = ${libuuid}\n";
+                $dep_index += 1;
+            }
+        }
+    }
+
+    print F << "EOM";
+	EndGlobalSection
+	GlobalSection(ProjectConfiguration) = postSolution
+EOM
+    foreach (@libs) {
+        my $libname = $_;
+        my $uuid = $build_structure{"LIBS_${libname}_GUID"};
+        print F "\t\t${uuid}.Debug|Win32.ActiveCfg = Debug|Win32\n";
+        print F "\t\t${uuid}.Debug|Win32.Build.0 = Debug|Win32\n";
+        print F "\t\t${uuid}.Release|Win32.ActiveCfg = Release|Win32\n";
+        print F "\t\t${uuid}.Release|Win32.Build.0 = Release|Win32\n";
+    }
+    foreach (@apps) {
+        my $appname = $_;
+        my $uuid = $build_structure{"APPS_${appname}_GUID"};
+        print F "\t\t${uuid}.Debug|Win32.ActiveCfg = Debug|Win32\n";
+        print F "\t\t${uuid}.Debug|Win32.Build.0 = Debug|Win32\n";
+        print F "\t\t${uuid}.Release|Win32.ActiveCfg = Release|Win32\n";
+        print F "\t\t${uuid}.Release|Win32.Build.0 = Release|Win32\n";
+    }
+
+    print F << "EOM";
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+	EndGlobalSection
+	GlobalSection(ExtensibilityAddIns) = postSolution
+	EndGlobalSection
+EndGlobal
+EOM
+    close F;
+}
+
+1;
diff --git a/contrib/buildsystems/engine.pl b/contrib/buildsystems/engine.pl
new file mode 100644
index 0000000..20bd061
--- /dev/null
+++ b/contrib/buildsystems/engine.pl
@@ -0,0 +1,353 @@
+#!/usr/bin/perl -w
+######################################################################
+# Do not call this script directly!
+#
+# The generate script ensures that @INC is correct before the engine
+# is executed.
+#
+# Copyright (C) 2009 Marius Storm-Olsen <mstormo@gmail.com>
+######################################################################
+use strict;
+use File::Basename;
+use File::Spec;
+use Cwd;
+use Generators;
+
+my (%build_structure, %compile_options, @makedry);
+my $out_dir = getcwd();
+my $git_dir = $out_dir;
+$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 "");
+
+my @gens = Generators::available();
+my $gen = "Vcproj";
+
+sub showUsage
+{
+    my $genlist = join(', ', @gens);
+    print << "EOM";
+generate usage:
+  -g <GENERATOR>  --gen <GENERATOR> Specify the buildsystem generator    (default: $gen)
+                                    Available: $genlist
+  -o <PATH>       --out <PATH>      Specify output directory generation  (default: .)
+  -i <FILE>       --in <FILE>       Specify input file, instead of running GNU Make
+  -h,-?           --help            This help
+EOM
+    exit 0;
+}
+
+# Parse command-line options
+while (@ARGV) {
+    my $arg = shift @ARGV;
+    if ("$arg" eq "-h" || "$arg" eq "--help" || "$arg" eq "-?") {
+	showUsage();
+	exit(0);
+    } elsif("$arg" eq "--out" || "$arg" eq "-o") {
+	$out_dir = shift @ARGV;
+    } elsif("$arg" eq "--gen" || "$arg" eq "-g") {
+	$gen = shift @ARGV;
+    } elsif("$arg" eq "--in" || "$arg" eq "-i") {
+	my $infile = shift @ARGV;
+        open(F, "<$infile") || die "Couldn't open file $infile";
+        @makedry = <F>;
+        close(F);
+    }
+}
+
+# NOT using File::Spec->rel2abs($path, $base) here, as
+# it fails badly for me in the msysgit environment
+$git_dir = File::Spec->rel2abs($git_dir);
+$out_dir = File::Spec->rel2abs($out_dir);
+my $rel_dir = makeOutRel2Git($git_dir, $out_dir);
+
+# Print some information so the user feels informed
+print << "EOM";
+-----
+Generator: $gen
+Git dir:   $git_dir
+Out dir:   $out_dir
+-----
+Running GNU Make to figure out build structure...
+EOM
+
+# Pipe a make --dry-run into a variable, if not already loaded from file
+@makedry = `cd $git_dir && make -n MSVC=1 V=1 2>/dev/null` if !@makedry;
+
+# Parse the make output into usable info
+parseMakeOutput();
+
+# Finally, ask the generator to start generating..
+Generators::generate($gen, $git_dir, $out_dir, $rel_dir, %build_structure);
+
+# main flow ends here
+# -------------------------------------------------------------------------------------------------
+
+
+# 1) path: /foo/bar/baz        2) path: /foo/bar/baz   3) path: /foo/bar/baz
+#    base: /foo/bar/baz/temp      base: /foo/bar          base: /tmp
+#    rel:  ..                     rel:  baz               rel:  ../foo/bar/baz
+sub makeOutRel2Git
+{
+    my ($path, $base) = @_;
+    my $rel;
+    if ("$path" eq "$base") {
+        return ".";
+    } elsif ($base =~ /^$path/) {
+        # case 1
+        my $tmp = $base;
+        $tmp =~ s/^$path//;
+        foreach (split('/', $tmp)) {
+            $rel .= "../" if ("$_" ne "");
+        }
+    } elsif ($path =~ /^$base/) {
+        # case 2
+        $rel = $path;
+        $rel =~ s/^$base//;
+        $rel = "./$rel";
+    } else {
+        my $tmp = $base;
+        foreach (split('/', $tmp)) {
+            $rel .= "../" if ("$_" ne "");
+        }
+        $rel .= $path;
+    }
+    $rel =~ s/\/\//\//g; # simplify
+    $rel =~ s/\/$//;     # don't end with /
+    return $rel;
+}
+
+sub parseMakeOutput
+{
+    print "Parsing GNU Make output to figure out build structure...\n";
+    my $line = 0;
+    while (my $text = shift @makedry) {
+        my $ate_next;
+        do {
+            $ate_next = 0;
+            $line++;
+            chomp $text;
+            chop $text if ($text =~ /\r$/);
+            if ($text =~ /\\$/) {
+                $text =~ s/\\$//;
+                $text .= shift @makedry;
+                $ate_next = 1;
+            }
+        } while($ate_next);
+
+        if($text =~ / -c /) {
+            # compilation
+            handleCompileLine($text, $line);
+
+        } elsif ($text =~ / -o /) {
+            # linking executable
+            handleLinkLine($text, $line);
+
+        } elsif ($text =~ /\.o / && $text =~ /\.a /) {
+            # libifying
+            handleLibLine($text, $line);
+#
+#        } elsif ($text =~ /^cp /) {
+#            # copy file around
+#
+#        } elsif ($text =~ /^rm -f /) {
+#            # shell command
+#
+#        } elsif ($text =~ /^make[ \[]/) {
+#            # make output
+#
+#        } elsif ($text =~ /^echo /) {
+#            # echo to file
+#
+#        } elsif ($text =~ /^if /) {
+#            # shell conditional
+#
+#        } elsif ($text =~ /^tclsh /) {
+#            # translation stuff
+#
+#        } elsif ($text =~ /^umask /) {
+#            # handling boilerplates
+#
+#        } elsif ($text =~ /\$\(\:\)/) {
+#            # ignore
+#
+#        } elsif ($text =~ /^FLAGS=/) {
+#            # flags check for dependencies
+#
+#        } elsif ($text =~ /^'\/usr\/bin\/perl' -MError -e/) {
+#            # perl commands for copying files
+#
+#        } elsif ($text =~ /generate-cmdlist\.sh/) {
+#            # command for generating list of commands
+#
+#        } elsif ($text =~ /^test / && $text =~ /|| rm -f /) {
+#            # commands removing executables, if they exist
+#
+#        } elsif ($text =~ /new locations or Tcl/) {
+#            # command for detecting Tcl/Tk changes
+#
+#        } elsif ($text =~ /mkdir -p/) {
+#            # command creating path
+#
+#        } elsif ($text =~ /: no custom templates yet/) {
+#            # whatever
+#
+#        } else {
+#            print "Unhandled (line: $line): $text\n";
+        }
+    }
+
+#    use Data::Dumper;
+#    print "Parsed build structure:\n";
+#    print Dumper(%build_structure);
+}
+
+# variables for the compilation part of each step
+my (@defines, @incpaths, @cflags, @sources);
+
+sub clearCompileStep
+{
+    @defines = ();
+    @incpaths = ();
+    @cflags = ();
+    @sources = ();
+}
+
+sub removeDuplicates
+{
+    my (%dupHash, $entry);
+    %dupHash = map { $_, 1 } @defines;
+    @defines = keys %dupHash;
+
+    %dupHash = map { $_, 1 } @incpaths;
+    @incpaths = keys %dupHash;
+
+    %dupHash = map { $_, 1 } @cflags;
+    @cflags = keys %dupHash;
+}
+
+sub handleCompileLine
+{
+    my ($line, $lineno) = @_;
+    my @parts = split(' ', $line);
+    my $sourcefile;
+    shift(@parts); # ignore cmd
+    while (my $part = shift @parts) {
+        if ("$part" eq "-o") {
+            # ignore object file
+            shift @parts;
+        } elsif ("$part" eq "-c") {
+            # ignore compile flag
+        } elsif ("$part" eq "-c") {
+        } elsif ($part =~ /^.?-I/) {
+            push(@incpaths, $part);
+        } elsif ($part =~ /^.?-D/) {
+            push(@defines, $part);
+        } elsif ($part =~ /^-/) {
+            push(@cflags, $part);
+        } elsif ($part =~ /\.(c|cc|cpp)$/) {
+            $sourcefile = $part;
+        } else {
+            die "Unhandled compiler option @ line $lineno: $part";
+        }
+    }
+    @{$compile_options{"${sourcefile}_CFLAGS"}} = @cflags;
+    @{$compile_options{"${sourcefile}_DEFINES"}} = @defines;
+    @{$compile_options{"${sourcefile}_INCPATHS"}} = @incpaths;
+    clearCompileStep();
+}
+
+sub handleLibLine
+{
+    my ($line, $lineno) = @_;
+    my (@objfiles, @lflags, $libout, $part);
+    # kill cmd and rm 'prefix'
+    $line =~ s/^rm -f .* && .* rcs //;
+    my @parts = split(' ', $line);
+    while ($part = shift @parts) {
+        if ($part =~ /^-/) {
+            push(@lflags, $part);
+        } elsif ($part =~ /\.(o|obj)$/) {
+            push(@objfiles, $part);
+        } elsif ($part =~ /\.(a|lib)$/) {
+            $libout = $part;
+            $libout =~ s/\.a$//;
+        } else {
+            die "Unhandled lib option @ line $lineno: $part";
+        }
+    }
+#    print "LibOut: '$libout'\nLFlags: @lflags\nOfiles: @objfiles\n";
+#    exit(1);
+    foreach (@objfiles) {
+        my $sourcefile = $_;
+        $sourcefile =~ s/\.o/.c/;
+        push(@sources, $sourcefile);
+        push(@cflags, @{$compile_options{"${sourcefile}_CFLAGS"}});
+        push(@defines, @{$compile_options{"${sourcefile}_DEFINES"}});
+        push(@incpaths, @{$compile_options{"${sourcefile}_INCPATHS"}});
+    }
+    removeDuplicates();
+
+    push(@{$build_structure{"LIBS"}}, $libout);
+    @{$build_structure{"LIBS_${libout}"}} = ("_DEFINES", "_INCLUDES", "_CFLAGS", "_SOURCES",
+                                             "_OBJECTS");
+    @{$build_structure{"LIBS_${libout}_DEFINES"}} = @defines;
+    @{$build_structure{"LIBS_${libout}_INCLUDES"}} = @incpaths;
+    @{$build_structure{"LIBS_${libout}_CFLAGS"}} = @cflags;
+    @{$build_structure{"LIBS_${libout}_LFLAGS"}} = @lflags;
+    @{$build_structure{"LIBS_${libout}_SOURCES"}} = @sources;
+    @{$build_structure{"LIBS_${libout}_OBJECTS"}} = @objfiles;
+    clearCompileStep();
+}
+
+sub handleLinkLine
+{
+    my ($line, $lineno) = @_;
+    my (@objfiles, @lflags, @libs, $appout, $part);
+    my @parts = split(' ', $line);
+    shift(@parts); # ignore cmd
+    while ($part = shift @parts) {
+        if ($part =~ /^-IGNORE/) {
+            push(@lflags, $part);
+        } elsif ($part =~ /^-[GRIMDO]/) {
+            # eat compiler flags
+        } elsif ("$part" eq "-o") {
+            $appout = shift @parts;
+        } elsif ("$part" eq "-lz") {
+            push(@libs, "zlib.lib");
+        } elsif ($part =~ /^-/) {
+            push(@lflags, $part);
+        } elsif ($part =~ /\.(a|lib)$/) {
+            $part =~ s/\.a$/.lib/;
+            push(@libs, $part);
+        } elsif ($part =~ /\.(o|obj)$/) {
+            push(@objfiles, $part);
+        } else {
+            die "Unhandled lib option @ line $lineno: $part";
+        }
+    }
+#    print "AppOut: '$appout'\nLFlags: @lflags\nLibs  : @libs\nOfiles: @objfiles\n";
+#    exit(1);
+    foreach (@objfiles) {
+        my $sourcefile = $_;
+        $sourcefile =~ s/\.o/.c/;
+        push(@sources, $sourcefile);
+        push(@cflags, @{$compile_options{"${sourcefile}_CFLAGS"}});
+        push(@defines, @{$compile_options{"${sourcefile}_DEFINES"}});
+        push(@incpaths, @{$compile_options{"${sourcefile}_INCPATHS"}});
+    }
+    removeDuplicates();
+
+    removeDuplicates();
+    push(@{$build_structure{"APPS"}}, $appout);
+    @{$build_structure{"APPS_${appout}"}} = ("_DEFINES", "_INCLUDES", "_CFLAGS", "_LFLAGS",
+                                             "_SOURCES", "_OBJECTS", "_LIBS");
+    @{$build_structure{"APPS_${appout}_DEFINES"}} = @defines;
+    @{$build_structure{"APPS_${appout}_INCLUDES"}} = @incpaths;
+    @{$build_structure{"APPS_${appout}_CFLAGS"}} = @cflags;
+    @{$build_structure{"APPS_${appout}_LFLAGS"}} = @lflags;
+    @{$build_structure{"APPS_${appout}_SOURCES"}} = @sources;
+    @{$build_structure{"APPS_${appout}_OBJECTS"}} = @objfiles;
+    @{$build_structure{"APPS_${appout}_LIBS"}} = @libs;
+    clearCompileStep();
+}
diff --git a/contrib/buildsystems/generate b/contrib/buildsystems/generate
new file mode 100644
index 0000000..bc10f25
--- /dev/null
+++ b/contrib/buildsystems/generate
@@ -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 <mstormo@gmail.com>
+######################################################################
+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));
diff --git a/contrib/buildsystems/parse.pl b/contrib/buildsystems/parse.pl
new file mode 100644
index 0000000..c9656ec
--- /dev/null
+++ b/contrib/buildsystems/parse.pl
@@ -0,0 +1,228 @@
+#!/usr/bin/perl -w
+######################################################################
+# Do not call this script directly!
+#
+# The generate script ensures that @INC is correct before the engine
+# is executed.
+#
+# Copyright (C) 2009 Marius Storm-Olsen <mstormo@gmail.com>
+######################################################################
+use strict;
+use File::Basename;
+use Cwd;
+
+my $file = $ARGV[0];
+die "No file provided!" if !defined $file;
+
+my ($cflags, $target, $type, $line);
+
+open(F, "<$file") || die "Couldn't open file $file";
+my @data = <F>;
+close(F);
+
+while (my $text = shift @data) {
+    my $ate_next;
+    do {
+        $ate_next = 0;
+        $line++;
+        chomp $text;
+        chop $text if ($text =~ /\r$/);
+        if ($text =~ /\\$/) {
+            $text =~ s/\\$//;
+            $text .= shift @data;
+            $ate_next = 1;
+        }
+    } while($ate_next);
+
+    if($text =~ / -c /) {
+        # compilation
+        handleCompileLine($text, $line);
+
+    } elsif ($text =~ / -o /) {
+        # linking executable
+        handleLinkLine($text, $line);
+
+    } elsif ($text =~ /\.o / && $text =~ /\.a /) {
+        # libifying
+        handleLibLine($text, $line);
+
+#    } elsif ($text =~ /^cp /) {
+#        # copy file around
+#
+#    } elsif ($text =~ /^rm -f /) {
+#        # shell command
+#
+#    } elsif ($text =~ /^make[ \[]/) {
+#        # make output
+#
+#    } elsif ($text =~ /^echo /) {
+#        # echo to file
+#
+#    } elsif ($text =~ /^if /) {
+#        # shell conditional
+#
+#    } elsif ($text =~ /^tclsh /) {
+#        # translation stuff
+#
+#    } elsif ($text =~ /^umask /) {
+#        # handling boilerplates
+#
+#    } elsif ($text =~ /\$\(\:\)/) {
+#        # ignore
+#
+#    } elsif ($text =~ /^FLAGS=/) {
+#        # flags check for dependencies
+#
+#    } elsif ($text =~ /^'\/usr\/bin\/perl' -MError -e/) {
+#        # perl commands for copying files
+#
+#    } elsif ($text =~ /generate-cmdlist\.sh/) {
+#        # command for generating list of commands
+#
+#    } elsif ($text =~ /^test / && $text =~ /|| rm -f /) {
+#        # commands removing executables, if they exist
+#
+#    } elsif ($text =~ /new locations or Tcl/) {
+#        # command for detecting Tcl/Tk changes
+#
+#    } elsif ($text =~ /mkdir -p/) {
+#        # command creating path
+#
+#    } elsif ($text =~ /: no custom templates yet/) {
+#        # whatever
+
+    } else {
+#        print "Unhandled (line: $line): $text\n";
+    }
+}
+close(F);
+
+# use Data::Dumper;
+# print "Parsed build structure:\n";
+# print Dumper(%build_structure);
+
+# -------------------------------------------------------------------
+# Functions under here
+# -------------------------------------------------------------------
+my (%build_structure, @defines, @incpaths, @cflags, @sources);
+
+sub clearCompileStep
+{
+    @defines = ();
+    @incpaths = ();
+    @cflags = ();
+    @sources = ();
+}
+
+sub removeDuplicates
+{
+    my (%dupHash, $entry);
+    %dupHash = map { $_, 1 } @defines;
+    @defines = keys %dupHash;
+
+    %dupHash = map { $_, 1 } @incpaths;
+    @incpaths = keys %dupHash;
+
+    %dupHash = map { $_, 1 } @cflags;
+    @cflags = keys %dupHash;
+
+    %dupHash = map { $_, 1 } @sources;
+    @sources = keys %dupHash;
+}
+
+sub handleCompileLine
+{
+    my ($line, $lineno) = @_;
+    my @parts = split(' ', $line);
+    shift(@parts); # ignore cmd
+    while (my $part = shift @parts) {
+        if ("$part" eq "-o") {
+            # ignore object file
+            shift @parts;
+        } elsif ("$part" eq "-c") {
+            # ignore compile flag
+        } elsif ("$part" eq "-c") {
+        } elsif ($part =~ /^.?-I/) {
+            push(@incpaths, $part);
+        } elsif ($part =~ /^.?-D/) {
+            push(@defines, $part);
+        } elsif ($part =~ /^-/) {
+            push(@cflags, $part);
+        } elsif ($part =~ /\.(c|cc|cpp)$/) {
+            push(@sources, $part);
+        } else {
+            die "Unhandled compiler option @ line $lineno: $part";
+        }
+    }
+    #print "Sources: @sources\nCFlags: @cflags\nDefine: @defines\nIncpat: @incpaths\n";
+    #exit(1);
+}
+
+sub handleLibLine
+{
+    my ($line, $lineno) = @_;
+    my (@objfiles, @lflags, $libout, $part);
+    # kill cmd and rm 'prefix'
+    $line =~ s/^rm -f .* && .* rcs //;
+    my @parts = split(' ', $line);
+    while ($part = shift @parts) {
+        if ($part =~ /^-/) {
+            push(@lflags, $part);
+        } elsif ($part =~ /\.(o|obj)$/) {
+            push(@objfiles, $part);
+        } elsif ($part =~ /\.(a|lib)$/) {
+            $libout = $part;
+        } else {
+            die "Unhandled lib option @ line $lineno: $part";
+        }
+    }
+    #print "LibOut: '$libout'\nLFlags: @lflags\nOfiles: @objfiles\n";
+    #exit(1);
+    removeDuplicates();
+    push(@{$build_structure{"LIBS"}}, $libout);
+    @{$build_structure{"LIBS_${libout}"}} = ("_DEFINES", "_INCLUDES", "_CFLAGS", "_SOURCES",
+                                             "_OBJECTS");
+    @{$build_structure{"LIBS_${libout}_DEFINES"}} = @defines;
+    @{$build_structure{"LIBS_${libout}_INCLUDES"}} = @incpaths;
+    @{$build_structure{"LIBS_${libout}_CFLAGS"}} = @cflags;
+    @{$build_structure{"LIBS_${libout}_SOURCES"}} = @sources;
+    @{$build_structure{"LIBS_${libout}_OBJECTS"}} = @objfiles;
+    clearCompileStep();
+}
+
+sub handleLinkLine
+{
+    my ($line, $lineno) = @_;
+    my (@objfiles, @lflags, @libs, $appout, $part);
+    my @parts = split(' ', $line);
+    shift(@parts); # ignore cmd
+    while ($part = shift @parts) {
+        if ($part =~ /^-[GRIDO]/) {
+            # eat compiler flags
+        } elsif ("$part" eq "-o") {
+            $appout = shift @parts;
+        } elsif ($part =~ /^-/) {
+            push(@lflags, $part);
+        } elsif ($part =~ /\.(a|lib)$/) {
+            push(@libs, $part);
+        } elsif ($part =~ /\.(o|obj)$/) {
+            push(@objfiles, $part);
+        } else {
+            die "Unhandled lib option @ line $lineno: $part";
+        }
+    }
+    #print "AppOut: '$appout'\nLFlags: @lflags\nLibs  : @libs\nOfiles: @objfiles\n";
+    #exit(1);
+    removeDuplicates();
+    push(@{$build_structure{"APPS"}}, $appout);
+    @{$build_structure{"APPS_${appout}"}} = ("_DEFINES", "_INCLUDES", "_CFLAGS", "_LFLAGS",
+                                             "_SOURCES", "_OBJECTS", "_LIBS");
+    @{$build_structure{"APPS_${appout}_DEFINES"}} = @defines;
+    @{$build_structure{"APPS_${appout}_INCLUDES"}} = @incpaths;
+    @{$build_structure{"APPS_${appout}_CFLAGS"}} = @cflags;
+    @{$build_structure{"APPS_${appout}_LFLAGS"}} = @lflags;
+    @{$build_structure{"APPS_${appout}_SOURCES"}} = @sources;
+    @{$build_structure{"APPS_${appout}_OBJECTS"}} = @objfiles;
+    @{$build_structure{"APPS_${appout}_LIBS"}} = @libs;
+    clearCompileStep();
+}
-- 
1.6.2.1.418.g33d56.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean'
  2009-09-14 13:11   ` [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean' Marius Storm-Olsen
  2009-09-14 13:11     ` [PATCH 03/17] Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++ Marius Storm-Olsen
@ 2009-09-14 13:41     ` Marius Storm-Olsen
  1 sibling, 0 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 13:41 UTC (permalink / raw)
  To: git; +Cc: Johannes.Schindelin, msysgit, lznuaa

Marius Storm-Olsen said the following on 14.09.2009 15:11:
> 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.

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 01/17] Avoid declaration after statement
  2009-09-14 13:11 ` [PATCH 01/17] Avoid declaration after statement Marius Storm-Olsen
  2009-09-14 13:11   ` [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean' Marius Storm-Olsen
@ 2009-09-14 13:59   ` Alex Riesen
  2009-09-14 14:01     ` Marius Storm-Olsen
  2009-09-14 14:04     ` Frank Li
  1 sibling, 2 replies; 35+ messages in thread
From: Alex Riesen @ 2009-09-14 13:59 UTC (permalink / raw)
  To: Marius Storm-Olsen; +Cc: Johannes.Schindelin, msysgit, git, lznuaa

On Mon, Sep 14, 2009 at 15:11, Marius Storm-Olsen <mstormo@gmail.com> wrote:
> From: Frank Li <lznuaa@gmail.com>
>
> Microsoft Visual C++ does not understand this C99 style
>

But you don't use the C++ compiler (which does understand that syntax).

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 01/17] Avoid declaration after statement
  2009-09-14 13:59   ` [PATCH 01/17] Avoid declaration after statement Alex Riesen
@ 2009-09-14 14:01     ` Marius Storm-Olsen
  2009-09-14 14:04     ` Frank Li
  1 sibling, 0 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 14:01 UTC (permalink / raw)
  To: Alex Riesen; +Cc: Johannes.Schindelin, msysgit, git, lznuaa


Alex Riesen said the following on 14.09.2009 15:59:
> On Mon, Sep 14, 2009 at 15:11, Marius Storm-Olsen <mstormo@gmail.com> wrote:
>> From: Frank Li <lznuaa@gmail.com>
>>
>> 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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 01/17] Avoid declaration after statement
  2009-09-14 13:59   ` [PATCH 01/17] Avoid declaration after statement Alex Riesen
  2009-09-14 14:01     ` Marius Storm-Olsen
@ 2009-09-14 14:04     ` Frank Li
  2009-09-14 14:10       ` Alex Riesen
  1 sibling, 1 reply; 35+ messages in thread
From: Frank Li @ 2009-09-14 14:04 UTC (permalink / raw)
  To: Alex Riesen; +Cc: Marius Storm-Olsen, Johannes.Schindelin, msysgit, git

>>
>> 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"

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 15/17] Add MSVC to Makefile
  2009-09-14 13:11                             ` [PATCH 15/17] Add MSVC to Makefile Marius Storm-Olsen
  2009-09-14 13:11                               ` [PATCH 16/17] Add README for MSVC build Marius Storm-Olsen
@ 2009-09-14 14:06                               ` Alex Riesen
  2009-09-14 19:09                                 ` Marius Storm-Olsen
  1 sibling, 1 reply; 35+ messages in thread
From: Alex Riesen @ 2009-09-14 14:06 UTC (permalink / raw)
  To: Marius Storm-Olsen; +Cc: Johannes.Schindelin, msysgit, git, lznuaa

On Mon, Sep 14, 2009 at 15:11, Marius Storm-Olsen <mstormo@gmail.com> wrote:
> @@ -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 $@"?

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 01/17] Avoid declaration after statement
  2009-09-14 14:04     ` Frank Li
@ 2009-09-14 14:10       ` Alex Riesen
  2009-09-14 19:00         ` Marius Storm-Olsen
  0 siblings, 1 reply; 35+ messages in thread
From: Alex Riesen @ 2009-09-14 14:10 UTC (permalink / raw)
  To: Frank Li; +Cc: Marius Storm-Olsen, Johannes.Schindelin, msysgit, git

On Mon, Sep 14, 2009 at 16:04, Frank Li <lznuaa@gmail.com> wrote:
>>>
>>> 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.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 14/17] Add ftruncate implementation for MSVC
  2009-09-14 13:11                           ` [PATCH 14/17] Add ftruncate implementation " Marius Storm-Olsen
  2009-09-14 13:11                             ` [PATCH 15/17] Add MSVC to Makefile Marius Storm-Olsen
@ 2009-09-14 14:18                             ` Alex Riesen
  2009-09-14 19:03                               ` Marius Storm-Olsen
  2009-09-14 19:48                             ` Junio C Hamano
  2 siblings, 1 reply; 35+ messages in thread
From: Alex Riesen @ 2009-09-14 14:18 UTC (permalink / raw)
  To: Marius Storm-Olsen; +Cc: Johannes.Schindelin, msysgit, git, lznuaa

On Mon, Sep 14, 2009 at 15:11, Marius Storm-Olsen <mstormo@gmail.com> wrote:
> +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):

http://msdn.microsoft.com/en-us/library/ks2530z6.aspx

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 01/17] Avoid declaration after statement
  2009-09-14 14:10       ` Alex Riesen
@ 2009-09-14 19:00         ` Marius Storm-Olsen
  0 siblings, 0 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 19:00 UTC (permalink / raw)
  To: Alex Riesen; +Cc: Frank Li, Johannes.Schindelin, msysgit, git

Alex Riesen said the following on 14.09.2009 16:10:
> On Mon, Sep 14, 2009 at 16:04, Frank Li <lznuaa@gmail.com> wrote:
>>>> 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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 14/17] Add ftruncate implementation for MSVC
  2009-09-14 14:18                             ` [PATCH 14/17] Add ftruncate implementation for MSVC Alex Riesen
@ 2009-09-14 19:03                               ` Marius Storm-Olsen
  0 siblings, 0 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 19:03 UTC (permalink / raw)
  To: Alex Riesen; +Cc: Johannes.Schindelin, msysgit, git, lznuaa

Alex Riesen said the following on 14.09.2009 16:18:
> On Mon, Sep 14, 2009 at 15:11, Marius Storm-Olsen <mstormo@gmail.com> wrote:
>> +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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [msysGit] [PATCH 06/17] mingw.c: Use the O_BINARY flag to open  files
  2009-09-14 13:11           ` [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files Marius Storm-Olsen
  2009-09-14 13:11             ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Marius Storm-Olsen
@ 2009-09-14 19:06             ` Alexey Borzenkov
  1 sibling, 0 replies; 35+ messages in thread
From: Alexey Borzenkov @ 2009-09-14 19:06 UTC (permalink / raw)
  To: Marius Storm-Olsen; +Cc: Johannes.Schindelin, msysgit, git, lznuaa

On Mon, Sep 14, 2009 at 5:11 PM, Marius Storm-Olsen <mstormo@gmail.com> wrote:
> 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.

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.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 15/17] Add MSVC to Makefile
  2009-09-14 14:06                               ` [PATCH 15/17] Add MSVC to Makefile Alex Riesen
@ 2009-09-14 19:09                                 ` Marius Storm-Olsen
  0 siblings, 0 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 19:09 UTC (permalink / raw)
  To: Alex Riesen; +Cc: Johannes.Schindelin, msysgit, git, lznuaa


Alex Riesen said the following on 14.09.2009 16:06:
> On Mon, Sep 14, 2009 at 15:11, Marius Storm-Olsen <mstormo@gmail.com> wrote:
>> @@ -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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/17] Test for WIN32 instead of __MINGW32_
  2009-09-14 13:11               ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Marius Storm-Olsen
  2009-09-14 13:11                 ` [PATCH 09/17] Add empty header files for MSVC port Marius Storm-Olsen
@ 2009-09-14 19:31                 ` Junio C Hamano
  2009-09-14 19:42                   ` Marius Storm-Olsen
  1 sibling, 1 reply; 35+ messages in thread
From: Junio C Hamano @ 2009-09-14 19:31 UTC (permalink / raw)
  To: Marius Storm-Olsen; +Cc: Johannes.Schindelin, msysgit, git, lznuaa

Marius Storm-Olsen <mstormo@gmail.com> writes:

> From: Frank Li <lznuaa@gmail.com>
>
> 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 <lznuaa@gmail.com>
> Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>

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?

> ---
>  help.c        |    2 +-
>  pager.c       |    4 ++--
>  run-command.c |    8 ++++----
>  run-command.h |    2 +-
>  setup.c       |    2 +-
>  5 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/help.c b/help.c
> index fd51b8e..e8db31f 100644
> --- a/help.c
> +++ b/help.c
> @@ -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;
> diff --git a/pager.c b/pager.c
> index f416d38..86facec 100644
> --- a/pager.c
> +++ b/pager.c
> @@ -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))
> diff --git a/run-command.c b/run-command.c
> index 91f6d2e..cb006e7 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -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, const
>  	return 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;
> diff --git a/run-command.h b/run-command.h
> index 0c00b25..fb34209 100644
> --- a/run-command.h
> +++ b/run-command.h
> @@ -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;
> diff --git a/setup.c b/setup.c
> index e3781b6..029371e 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -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);
> -- 
> 1.6.2.1.418.g33d56.dirty

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 08/17] Test for WIN32 instead of __MINGW32_
  2009-09-14 19:31                 ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Junio C Hamano
@ 2009-09-14 19:42                   ` Marius Storm-Olsen
  0 siblings, 0 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-14 19:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes.Schindelin, msysgit, git, lznuaa

Junio C Hamano said the following on 14.09.2009 21:31:
> Marius Storm-Olsen <mstormo@gmail.com> writes:
> 
>> From: Frank Li <lznuaa@gmail.com>
>>
>> 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 <lznuaa@gmail.com>
>> Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
> 
> 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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 14/17] Add ftruncate implementation for MSVC
  2009-09-14 13:11                           ` [PATCH 14/17] Add ftruncate implementation " Marius Storm-Olsen
  2009-09-14 13:11                             ` [PATCH 15/17] Add MSVC to Makefile Marius Storm-Olsen
  2009-09-14 14:18                             ` [PATCH 14/17] Add ftruncate implementation for MSVC Alex Riesen
@ 2009-09-14 19:48                             ` Junio C Hamano
  2 siblings, 0 replies; 35+ messages in thread
From: Junio C Hamano @ 2009-09-14 19:48 UTC (permalink / raw)
  To: Marius Storm-Olsen; +Cc: Johannes.Schindelin, msysgit, git, lznuaa


Marius Storm-Olsen <mstormo@gmail.com> writes:

> 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 <mstormo@gmail.com>
> ---
>  compat/msvc.c |    8 ++++++++
>  compat/msvc.h |    2 ++
>  2 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/compat/msvc.c b/compat/msvc.c
> index ac04a4c..b96b045 100644
> --- a/compat/msvc.c
> +++ b/compat/msvc.c
> @@ -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;
> +}
> +


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.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype
  2009-09-14 13:11             ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Marius Storm-Olsen
  2009-09-14 13:11               ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Marius Storm-Olsen
@ 2009-09-14 20:00               ` Johannes Sixt
  2009-09-15  0:24                 ` [msysGit] " Johannes Schindelin
  1 sibling, 1 reply; 35+ messages in thread
From: Johannes Sixt @ 2009-09-14 20:00 UTC (permalink / raw)
  To: Marius Storm-Olsen; +Cc: msysgit, Johannes.Schindelin, git, lznuaa


On Montag, 14. September 2009, Marius Storm-Olsen wrote:
> WINAPI is a macro which translates into the proper calling convention, so
> replace __stdcall with 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:

> -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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [msysGit] [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype
  2009-09-14 20:00               ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Johannes Sixt
@ 2009-09-15  0:24                 ` Johannes Schindelin
  2009-09-15  5:59                   ` Marius Storm-Olsen
  0 siblings, 1 reply; 35+ messages in thread
From: Johannes Schindelin @ 2009-09-15  0:24 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Marius Storm-Olsen, msysgit, git, lznuaa

Hi,

On Mon, 14 Sep 2009, Johannes Sixt wrote:

> On Montag, 14. September 2009, Marius Storm-Olsen wrote:
> > WINAPI is a macro which translates into the proper calling convention, so
> > replace __stdcall with 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:
> 
> > -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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [msysGit] [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype
  2009-09-15  0:24                 ` [msysGit] " Johannes Schindelin
@ 2009-09-15  5:59                   ` Marius Storm-Olsen
  0 siblings, 0 replies; 35+ messages in thread
From: Marius Storm-Olsen @ 2009-09-15  5:59 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Johannes Sixt, msysgit, git, lznuaa

Johannes Schindelin said the following on 15.09.2009 02:24:
> Hi,
> 
> On Mon, 14 Sep 2009, Johannes Sixt wrote:
> 
>> On Montag, 14. September 2009, Marius Storm-Olsen wrote:
>>> WINAPI is a macro which translates into the proper calling convention, so
>>> replace __stdcall with 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:
>>
>>> -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

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2009-09-15  5:59 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-14 13:11 [RFC/PATCH v2 00/17] Build Git with MSVC Marius Storm-Olsen
2009-09-14 13:11 ` [PATCH 01/17] Avoid declaration after statement Marius Storm-Olsen
2009-09-14 13:11   ` [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean' Marius Storm-Olsen
2009-09-14 13:11     ` [PATCH 03/17] Define SNPRINTF_SIZE_CORR=1 for Microsoft Visual C++ Marius Storm-Olsen
2009-09-14 13:11       ` [PATCH 04/17] Add define guards to compat/win32.h Marius Storm-Olsen
2009-09-14 13:11         ` [PATCH 05/17] Change regerror() declaration from K&R style to ANSI C (C89) Marius Storm-Olsen
2009-09-14 13:11           ` [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files Marius Storm-Olsen
2009-09-14 13:11             ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Marius Storm-Olsen
2009-09-14 13:11               ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Marius Storm-Olsen
2009-09-14 13:11                 ` [PATCH 09/17] Add empty header files for MSVC port Marius Storm-Olsen
2009-09-14 13:11                   ` [PATCH 10/17] Add MinGW header files to build git with MSVC Marius Storm-Olsen
2009-09-14 13:11                     ` [PATCH 11/17] Add platform files for MSVC porting Marius Storm-Olsen
2009-09-14 13:11                       ` [PATCH 12/17] Make usage of windows.h lean and mean Marius Storm-Olsen
2009-09-14 13:11                         ` [PATCH 13/17] Define strncasecmp as _strnicmp for MSVC Marius Storm-Olsen
2009-09-14 13:11                           ` [PATCH 14/17] Add ftruncate implementation " Marius Storm-Olsen
2009-09-14 13:11                             ` [PATCH 15/17] Add MSVC to Makefile Marius Storm-Olsen
2009-09-14 13:11                               ` [PATCH 16/17] Add README for MSVC build Marius Storm-Olsen
2009-09-14 13:11                                 ` [PATCH 17/17] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Marius Storm-Olsen
2009-09-14 14:06                               ` [PATCH 15/17] Add MSVC to Makefile Alex Riesen
2009-09-14 19:09                                 ` Marius Storm-Olsen
2009-09-14 14:18                             ` [PATCH 14/17] Add ftruncate implementation for MSVC Alex Riesen
2009-09-14 19:03                               ` Marius Storm-Olsen
2009-09-14 19:48                             ` Junio C Hamano
2009-09-14 19:31                 ` [PATCH 08/17] Test for WIN32 instead of __MINGW32_ Junio C Hamano
2009-09-14 19:42                   ` Marius Storm-Olsen
2009-09-14 20:00               ` [PATCH 07/17] Fix __stdcall/WINAPI placement and function prototype Johannes Sixt
2009-09-15  0:24                 ` [msysGit] " Johannes Schindelin
2009-09-15  5:59                   ` Marius Storm-Olsen
2009-09-14 19:06             ` [msysGit] [PATCH 06/17] mingw.c: Use the O_BINARY flag to open files Alexey Borzenkov
2009-09-14 13:41     ` [PATCH 02/17] boolean is a typedef under MSVC, so rename variable to 'i_boolean' Marius Storm-Olsen
2009-09-14 13:59   ` [PATCH 01/17] Avoid declaration after statement Alex Riesen
2009-09-14 14:01     ` Marius Storm-Olsen
2009-09-14 14:04     ` Frank Li
2009-09-14 14:10       ` Alex Riesen
2009-09-14 19:00         ` Marius Storm-Olsen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.