Skip to content

Commit 164a5e3

Browse files
mstormogitster
authored andcommitted
Add MSVC to Makefile
Enable MSVC builds with GNU Make by simply calling make MSVC=1 (Debug build possible by adding DEBUG=1 as well) Two scripts, clink.pl and lib.pl, are used to convert certain GCC specific command line options into something MSVC understands. By building for MSVC with GNU Make, we can ensure that the MSVC port always follows the latest code, and does not lag behind due to unmaintained NMake Makefile or IDE projects. Signed-off-by: Marius Storm-Olsen <[email protected]> Acked-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 386ac45 commit 164a5e3

File tree

3 files changed

+128
-1
lines changed

3 files changed

+128
-1
lines changed

Makefile

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,58 @@ ifneq (,$(findstring CYGWIN,$(uname_S)))
876876
COMPAT_OBJS += compat/cygwin.o
877877
UNRELIABLE_FSTAT = UnfortunatelyYes
878878
endif
879+
ifdef MSVC
880+
pathsep = ;
881+
NO_PREAD = YesPlease
882+
NO_OPENSSL = YesPlease
883+
NO_LIBGEN_H = YesPlease
884+
NO_SYMLINK_HEAD = YesPlease
885+
NO_IPV6 = YesPlease
886+
NO_SETENV = YesPlease
887+
NO_UNSETENV = YesPlease
888+
NO_STRCASESTR = YesPlease
889+
NO_STRLCPY = YesPlease
890+
NO_MEMMEM = YesPlease
891+
# NEEDS_LIBICONV = YesPlease
892+
NO_ICONV = YesPlease
893+
NO_C99_FORMAT = YesPlease
894+
NO_STRTOUMAX = YesPlease
895+
NO_STRTOULL = YesPlease
896+
NO_MKDTEMP = YesPlease
897+
NO_MKSTEMPS = YesPlease
898+
SNPRINTF_RETURNS_BOGUS = YesPlease
899+
NO_SVN_TESTS = YesPlease
900+
NO_PERL_MAKEMAKER = YesPlease
901+
RUNTIME_PREFIX = YesPlease
902+
NO_POSIX_ONLY_PROGRAMS = YesPlease
903+
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
904+
NO_NSEC = YesPlease
905+
USE_WIN32_MMAP = YesPlease
906+
# USE_NED_ALLOCATOR = YesPlease
907+
UNRELIABLE_FSTAT = UnfortunatelyYes
908+
OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
909+
NO_REGEX = YesPlease
910+
NO_CURL = YesPlease
911+
NO_PTHREADS = YesPlease
912+
913+
CC = compat/vcbuild/scripts/clink.pl
914+
AR = compat/vcbuild/scripts/lib.pl
915+
CFLAGS =
916+
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
917+
COMPAT_OBJS = compat/msvc.o compat/fnmatch/fnmatch.o compat/winansi.o
918+
COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/fnmatch -Icompat/regex -Icompat/fnmatch -DSTRIP_EXTENSION=\".exe\"
919+
BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib
920+
EXTLIBS = advapi32.lib shell32.lib wininet.lib ws2_32.lib
921+
lib =
922+
ifndef DEBUG
923+
BASIC_CFLAGS += -GL -Os -MT
924+
BASIC_LDFLAGS += -LTCG
925+
AR += -LTCG
926+
else
927+
BASIC_CFLAGS += -Zi -MTd
928+
endif
929+
X = .exe
930+
else
879931
ifneq (,$(findstring MINGW,$(uname_S)))
880932
pathsep = ;
881933
NO_PREAD = YesPlease
@@ -924,6 +976,7 @@ else
924976
NO_PTHREADS = YesPlease
925977
endif
926978
endif
979+
endif
927980

928981
-include config.mak.autogen
929982
-include config.mak
@@ -1326,7 +1379,7 @@ strip: $(PROGRAMS) git$X
13261379
git.o: git.c common-cmds.h GIT-CFLAGS
13271380
$(QUIET_CC)$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
13281381
'-DGIT_HTML_PATH="$(htmldir_SQ)"' \
1329-
$(ALL_CFLAGS) -c $(filter %.c,$^)
1382+
$(ALL_CFLAGS) -o $@ -c $(filter %.c,$^)
13301383

13311384
git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
13321385
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \

compat/vcbuild/scripts/clink.pl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/perl -w
2+
######################################################################
3+
# Compiles or links files
4+
#
5+
# This is a wrapper to facilitate the compilation of Git with MSVC
6+
# using GNU Make as the build system. So, instead of manipulating the
7+
# Makefile into something nasty, just to support non-space arguments
8+
# etc, we use this wrapper to fix the command line options
9+
#
10+
# Copyright (C) 2009 Marius Storm-Olsen <[email protected]>
11+
######################################################################
12+
use strict;
13+
my @args = ();
14+
my @cflags = ();
15+
my $is_linking = 0;
16+
while (@ARGV) {
17+
my $arg = shift @ARGV;
18+
if ("$arg" =~ /^-[DIMGO]/) {
19+
push(@cflags, $arg);
20+
} elsif ("$arg" eq "-o") {
21+
my $file_out = shift @ARGV;
22+
if ("$file_out" =~ /exe$/) {
23+
$is_linking = 1;
24+
push(@args, "-OUT:$file_out");
25+
} else {
26+
push(@args, "-Fo$file_out");
27+
}
28+
} elsif ("$arg" eq "-lz") {
29+
push(@args, "zlib.lib");
30+
} elsif ("$arg" eq "-liconv") {
31+
push(@args, "iconv.lib");
32+
} elsif ("$arg" =~ /^-L/ && "$arg" ne "-LTCG") {
33+
$arg =~ s/^-L/-LIBPATH:/;
34+
push(@args, $arg);
35+
} elsif ("$arg" =~ /^-R/) {
36+
# eat
37+
} else {
38+
push(@args, $arg);
39+
}
40+
}
41+
if ($is_linking) {
42+
unshift(@args, "link.exe");
43+
} else {
44+
unshift(@args, "cl.exe");
45+
push(@args, @cflags);
46+
}
47+
#printf("**** @args\n");
48+
exit system(@args);

compat/vcbuild/scripts/lib.pl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/perl -w
2+
######################################################################
3+
# Libifies files on Windows
4+
#
5+
# This is a wrapper to facilitate the compilation of Git with MSVC
6+
# using GNU Make as the build system. So, instead of manipulating the
7+
# Makefile into something nasty, just to support non-space arguments
8+
# etc, we use this wrapper to fix the command line options
9+
#
10+
# Copyright (C) 2009 Marius Storm-Olsen <[email protected]>
11+
######################################################################
12+
use strict;
13+
my @args = ();
14+
while (@ARGV) {
15+
my $arg = shift @ARGV;
16+
if ("$arg" eq "rcs") {
17+
# Consume the rcs option
18+
} elsif ("$arg" =~ /\.a$/) {
19+
push(@args, "-OUT:$arg");
20+
} else {
21+
push(@args, $arg);
22+
}
23+
}
24+
unshift(@args, "lib.exe");
25+
# printf("**** @args\n");
26+
exit system(@args);

0 commit comments

Comments
 (0)