git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Marius Storm-Olsen <mstormo@gmail.com>
To: git@vger.kernel.org
Cc: Johannes.Schindelin@gmx.de, msysgit@googlegroups.com,
	gitster@pobox.com, j6t@kdbg.org, lznuaa@gmail.com,
	raa.lkml@gmail.com, snaury@gmail.com,
	Marius Storm-Olsen <mstormo@gmail.com>
Subject: [PATCH 12/15] Add MSVC to Makefile
Date: Wed, 16 Sep 2009 10:20:28 +0200	[thread overview]
Message-ID: <49b1712beea2ac9eb00c61c8d92c035a7c412d69.1253088099.git.mstormo@gmail.com> (raw)
In-Reply-To: <e9ffbe6e71d7f27c4ee5d31f59f860827c5a2f94.1253088099.git.mstormo@gmail.com>
In-Reply-To: <cover.1253088099.git.mstormo@gmail.com>


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                        |   55 ++++++++++++++++++++++++++++++++++++++-
 compat/vcbuild/scripts/clink.pl |   48 ++++++++++++++++++++++++++++++++++
 compat/vcbuild/scripts/lib.pl   |   26 ++++++++++++++++++
 3 files changed, 128 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..aa918eb 100644
--- a/Makefile
+++ b/Makefile
@@ -877,6 +877,58 @@ 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
+	AR += -LTCG
+else
+	BASIC_CFLAGS += -Zi -MTd
+endif
+	X = .exe
+else
 ifneq (,$(findstring MINGW,$(uname_S)))
 	pathsep = ;
 	NO_PREAD = YesPlease
@@ -925,6 +977,7 @@ else
 	NO_PTHREADS = YesPlease
 endif
 endif
+endif
 
 -include config.mak.autogen
 -include config.mak
@@ -1327,7 +1380,7 @@ strip: $(PROGRAMS) git$X
 git.o: git.c common-cmds.h GIT-CFLAGS
 	$(QUIET_CC)$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
 		'-DGIT_HTML_PATH="$(htmldir_SQ)"' \
-		$(ALL_CFLAGS) -c $(filter %.c,$^)
+		$(ALL_CFLAGS) -o $@ -c $(filter %.c,$^)
 
 git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
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

  reply	other threads:[~2009-09-16  8:21 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-16  8:20 [PATCH v4 00/15] Build Git with MSVC Marius Storm-Olsen
2009-09-16  8:20 ` [PATCH 01/15] Avoid declaration after statement Marius Storm-Olsen
2009-09-16  8:20   ` [PATCH 02/15] Add define guards to compat/win32.h Marius Storm-Olsen
2009-09-16  8:20     ` [PATCH 03/15] Change regerror() declaration from K&R style to ANSI C (C89) Marius Storm-Olsen
2009-09-16  8:20       ` [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and MSVC Marius Storm-Olsen
2009-09-16  8:20         ` [PATCH 05/15] Fix __stdcall placement and function prototype Marius Storm-Olsen
2009-09-16  8:20           ` [PATCH 06/15] Test for WIN32 instead of __MINGW32_ Marius Storm-Olsen
2009-09-16  8:20             ` [PATCH 07/15] Add empty header files for MSVC port Marius Storm-Olsen
2009-09-16  8:20               ` [PATCH 08/15] Add MinGW header files to build git with MSVC Marius Storm-Olsen
2009-09-16  8:20                 ` [PATCH 09/15] Add platform files for MSVC porting Marius Storm-Olsen
2009-09-16  8:20                   ` [PATCH 10/15] Make usage of windows.h lean and mean Marius Storm-Olsen
2009-09-16  8:20                     ` [PATCH 11/15] Define strncasecmp and ftruncate for MSVC Marius Storm-Olsen
2009-09-16  8:20                       ` Marius Storm-Olsen [this message]
2009-09-16  8:20                         ` [PATCH 13/15] Add README for MSVC build Marius Storm-Olsen
2009-09-16  8:20                           ` [PATCH 14/15] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Marius Storm-Olsen
2009-09-16  8:20                             ` [RFC 15/15] Tag GIT_VERSION when Git is built with MSVC Marius Storm-Olsen
2009-09-17 20:18                               ` Johannes Sixt
2009-09-18  6:44                                 ` Marius Storm-Olsen
2009-09-17 20:28                             ` [PATCH 14/15] Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake) Johannes Sixt
2009-09-18  6:59                               ` Marius Storm-Olsen
2009-09-18  8:21                                 ` Johannes Sixt
2009-09-23 15:04                             ` Sebastian Schuberth
2009-09-23 20:37                               ` Johannes Schindelin
2009-09-24  6:05                                 ` Marius Storm-Olsen
2009-09-23 10:03                 ` Add MinGW header files to build git with MSVC Sebastian Schuberth
2009-09-23 11:29                   ` Marius Storm-Olsen
2009-09-25  0:18                     ` [msysGit] " Frank Li
2009-09-16 16:14         ` [PATCH 04/15] Set _O_BINARY as default fmode for both MinGW and MSVC Johannes Sixt
2009-09-16 20:00           ` Alexey Borzenkov
2009-09-17  7:11             ` Johannes Sixt
2009-09-17  7:25               ` Junio C Hamano
2009-09-17  7:27               ` Marius Storm-Olsen
2009-09-17  7:36                 ` Johannes Sixt
2009-09-17  7:53                   ` Marius Storm-Olsen
2009-09-17  8:10                     ` Johannes Sixt
2009-09-17  8:14                       ` Marius Storm-Olsen
2009-09-17  8:39                       ` Alexey Borzenkov
2009-09-17  8:45                         ` Marius Storm-Olsen
2009-09-17  8:57                           ` Alexey Borzenkov
2009-09-17  9:03                         ` Johannes Sixt
2009-09-17  9:28                           ` Marius Storm-Olsen
2009-09-17 13:02                           ` Alexey Borzenkov
2009-09-17 13:30                             ` Johannes Sixt
2009-09-17  8:02         ` Marius Storm-Olsen
2009-09-17 10:44           ` Johannes Sixt
     [not found]             ` <4AB212FA.9080102@viscovery.netm>
2009-09-17 11:04               ` Marius Storm-Olsen
2009-09-16  9:42     ` [msysGit] [PATCH 02/15] Add define guards to compat/win32.h Erik Faye-Lund
2009-09-16 10:10       ` Marius Storm-Olsen
2009-09-23  9:44   ` Avoid declaration after statement Sebastian Schuberth
2009-09-25 13:34     ` Erik Faye-Lund

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49b1712beea2ac9eb00c61c8d92c035a7c412d69.1253088099.git.mstormo@gmail.com \
    --to=mstormo@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=lznuaa@gmail.com \
    --cc=msysgit@googlegroups.com \
    --cc=raa.lkml@gmail.com \
    --cc=snaury@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).