@matheusbsbs / matheus-bagliano / commits / 164a5e3faa
Fork 0

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 <mstormo@gmail.com> Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Marius Storm-Olsen committed Sep 16, 2009 at 10:20 UTC 164a5e3faab931a6c6459b56acae7f91dde6337d
3 files changed +128 -1
Makefile
+54 -1
@@ -876,6 +876,58 @@ ifneq (,$(findstring CYGWIN,$(uname_S)))
876 COMPAT_OBJS += compat/cygwin.o
877 UNRELIABLE_FSTAT = UnfortunatelyYes
878 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
931 ifneq (,$(findstring MINGW,$(uname_S)))
932 pathsep = ;
933 NO_PREAD = YesPlease
@@ -924,6 +976,7 @@ else
976 NO_PTHREADS = YesPlease
977 endif
978 endif
979 +endif
980
981 -include config.mak.autogen
982 -include config.mak
@@ -1326,7 +1379,7 @@ strip: $(PROGRAMS) git$X
1379 git.o: git.c common-cmds.h GIT-CFLAGS
1380 $(QUIET_CC)$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
1381 '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
1329 - $(ALL_CFLAGS) -c $(filter %.c,$^)
1382 + $(ALL_CFLAGS) -o $@ -c $(filter %.c,$^)
1383
1384 git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
1385 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
compat/vcbuild/scripts/clink.pl new
+48
@@ -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 <mstormo@gmail.com>
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 new
+26
@@ -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 <mstormo@gmail.com>
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);