git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC] Enable compilation by Makefile for the MSVC toolchain

From
Marius Storm-Olsen <mstormo@gmail.com>
Date
Aug 18, 2009, 12:58 UTC
Message-ID
<1250600335-8642-1-git-send-email-mstormo@gmail.com>
In-Reply-To
<alpine.DEB.1.00.0908172149480.8306@pacific.mpi-cbg.de>
From: Marius Storm-Olsen <mstormo@gmail.com>

By using GNU Make we can also compile with the MSVC toolchain. This is a rudementary patch, only meant as an RFC for now!!

!! DO NOT COMMIT THIS UPSTREAM !!
---
 So, instead of rely on these vcproj files which *will* go stale, we can
 simply use the same Makefile system which everyone else is using. :)
 After all, we're just compiling with a different compiler. The end result
 will still rely on the *msysGit environment* to function, so we already
 require it. Thus, GNU Make is present, and we can use it.
 This implementation is a quick hack to make it compile (hence the RFC
 subject), so please don't even consider basing anything ontop of it ;)
 But, do point out all the do's and don'ts, and I'll try to polish it up
 to something which we can add to Frank's series..
 
 Makefile      |   97 +++++++++++++++++++++++++++++++++++++++++++++++---------
 compat/msvc.h |   77 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 158 insertions(+), 16 deletions(-)
diff --git a/Makefile b/Makefile
index daf4296..2e14976 100644
--- a/Makefile
+++ b/Makefile
@@ -214,9 +214,13 @@ uname_V := $(shell sh -c 'uname -v 2>/dev/null || echo not')
 
 CFLAGS = -g -O2 -Wall
 LDFLAGS =
+ARFLAGS = rcs\ # whitespace intentional
 ALL_CFLAGS = $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
 STRIP ?= strip
+COMPFLAG = -c
+COBJFLAG = -o\ # whitespace intended
+LOBJFLAG = -o\ # whitespace intended
 
 # Among the variables below, these:
 #   gitexecdir
@@ -874,6 +878,58 @@ ifneq (,$(findstring CYGWIN,$(uname_S)))
 	COMPAT_OBJS += compat/cygwin.o
 	UNRELIABLE_FSTAT = UnfortunatelyYes
 endif
+ifneq (,$(findstring Microsoft Visual Studio, $(INCLUDE)))
+	pathsep = ;
+	MOZILLA_SHA1 = 1
+	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
+	OLD_ICONV = YesPlease
+	NO_C99_FORMAT = YesPlease
+	NO_STRTOUMAX = 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
+	UNRELIABLE_FSTAT = UnfortunatelyYes
+	OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
+	NO_REGEX = YesPlease
+
+	NO_CURL = YesPlease
+	NO_PTHREADS = YesPlease
+        
+	CC = cl 
+	COBJFLAG = -Fo
+	LOBJFLAG = -OUT:
+	CFLAGS =
+	BASIC_CFLAGS += -nologo -MT -I. -I../zlib -Icompat/vcbuild -Icompat/vcbuild/include -DWIN32 -D_CONSOLE
+	COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/fnmatch -Icompat/regex -Icompat/fnmatch
+	COMPAT_OBJS += compat/mingw.o compat/msvc.o compat/fnmatch/fnmatch.o compat/winansi.o
+	COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
+
+	LINK = link
+	BASIC_LDFLAGS += -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib ../zlib/projects/vc9/Win32_LIB_Release/zlib.lib
+	NO_CFLAGS_TO_LINKER = YesPlease
+	EXTLIBS = 
+	AR = lib
+	ARFLAGS = -OUT:
+
+	X = .exe
+else
 ifneq (,$(findstring MINGW,$(uname_S)))
 	pathsep = ;
 	NO_PREAD = YesPlease
@@ -922,6 +978,7 @@ else
 	NO_PTHREADS = YesPlease
 endif
 endif
+endif
 ifneq (,$(findstring arm,$(uname_M)))
 	ARM_SHA1 = YesPlease
 	NO_MKSTEMPS = YesPlease
@@ -1298,6 +1355,14 @@ LIB_OBJS += $(COMPAT_OBJS)
 ALL_CFLAGS += $(BASIC_CFLAGS)
 ALL_LDFLAGS += $(BASIC_LDFLAGS)
 
+ifndef LINK
+LINK = $(CC)
+endif
+
+ifndef NO_CFLAGS_TO_LINKER
+LINKER_CFLAGS += $(ALL_CFLAGS)
+endif
+
 export TAR INSTALL DESTDIR SHELL_PATH
 
 
@@ -1331,14 +1396,14 @@ 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) $(COMPFLAG) $(COBJFLAG)git.o $(filter %.c,$^)
 
 git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
+	$(QUIET_LINK)$(LINK) $(LINKER_CFLAGS) $(LOBJFLAG)$@ git.o \
 		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
 
 builtin-help.o: builtin-help.c common-cmds.h GIT-CFLAGS
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
+	$(QUIET_CC)$(CC) $(COBJFLAG)$*.o $(COMPFLAG) $(ALL_CFLAGS) \
 		'-DGIT_HTML_PATH="$(htmldir_SQ)"' \
 		'-DGIT_MAN_PATH="$(mandir_SQ)"' \
 		'-DGIT_INFO_PATH="$(infodir_SQ)"' $<
@@ -1450,44 +1515,44 @@ git.o git.spec \
 	: GIT-VERSION-FILE
 
 %.o: %.c GIT-CFLAGS
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
+	$(QUIET_CC)$(CC) $(COBJFLAG)$*.o $(COMPFLAG) $(ALL_CFLAGS) $<
 %.s: %.c GIT-CFLAGS
 	$(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
 %.o: %.S
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
+	$(QUIET_CC)$(CC) $(COBJFLAG)$*.o $(COMPFLAG) $(ALL_CFLAGS) $<
 
 exec_cmd.o: exec_cmd.c GIT-CFLAGS
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
+	$(QUIET_CC)$(CC) $(COBJFLAG)$*.o $(COMPFLAG) $(ALL_CFLAGS) \
 		'-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
 		'-DBINDIR="$(bindir_relative_SQ)"' \
 		'-DPREFIX="$(prefix_SQ)"' \
 		$<
 
 builtin-init-db.o: builtin-init-db.c GIT-CFLAGS
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
+	$(QUIET_CC)$(CC) $(COBJFLAG)$*.o $(COMPFLAG) $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
 
 config.o: config.c GIT-CFLAGS
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $<
+	$(QUIET_CC)$(CC) $(COBJFLAG)$*.o $(COMPFLAG) $(ALL_CFLAGS) -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $<
 
 http.o: http.c GIT-CFLAGS
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $<
+	$(QUIET_CC)$(CC) $(COBJFLAG)$*.o $(COMPFLAG) $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $<
 
 ifdef NO_EXPAT
 http-walker.o: http-walker.c http.h GIT-CFLAGS
-	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DNO_EXPAT $<
+	$(QUIET_CC)$(CC) $(COBJFLAG)$*.o $(COMPFLAG) $(ALL_CFLAGS) -DNO_EXPAT $<
 endif
 
 git-%$X: %.o $(GITLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
+	$(QUIET_LINK)$(LINK) $(LINKER_CFLAGS) $(LOBJFLAG)$@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
 git-imap-send$X: imap-send.o $(GITLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
+	$(QUIET_LINK)$(LINK) $(LINKER_CFLAGS) $(LOBJFLAG)$@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL)
 
 http.o http-walker.o http-push.o transport.o: http.h
 
 git-http-push$X: revision.o http.o http-push.o $(GITLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
+	$(QUIET_LINK)$(LINK) $(LINKER_CFLAGS) $(LOBJFLAG)$@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
 
 $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
@@ -1495,7 +1560,7 @@ $(patsubst git-%$X,%.o,$(PROGRAMS)) git.o: $(LIB_H) $(wildcard */*.h)
 builtin-revert.o wt-status.o: wt-status.h
 
 $(LIB_FILE): $(LIB_OBJS)
-	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
+	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS)$@ $(LIB_OBJS)
 
 XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
 	xdiff/xmerge.o xdiff/xpatience.o
@@ -1503,7 +1568,7 @@ $(XDIFF_OBJS): xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
 	xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h
 
 $(XDIFF_LIB): $(XDIFF_OBJS)
-	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(XDIFF_OBJS)
+	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS)$@ $(XDIFF_OBJS)
 
 
 doc:
@@ -1605,7 +1670,7 @@ test-parse-options.o: parse-options.h
 .PRECIOUS: $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS))
 
 test-%$X: test-%.o $(GITLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
+	$(QUIET_LINK)$(LINK) $(LINKER_CFLAGS) $(LOBJFLAG)$@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
 check-sha1:: test-sha1$X
 	./test-sha1.sh
diff --git a/compat/msvc.h b/compat/msvc.h
index 6071565..a9d5f7f 100644
--- a/compat/msvc.h
+++ b/compat/msvc.h
@@ -10,50 +10,120 @@
 
 /*Configuration*/
 
+#ifndef NO_PREAD
 #define NO_PREAD
+#endif
+#ifndef NO_OPENSSL
 #define NO_OPENSSL
+#endif
+#ifndef NO_LIBGEN_H
 #define NO_LIBGEN_H
+#endif
+#ifndef NO_SYMLINK_HEAD
 #define NO_SYMLINK_HEAD
+#endif
+#ifndef NO_IPV6
 #define NO_IPV6
+#endif
+#ifndef NO_SETENV
 #define NO_SETENV
+#endif
+#ifndef NO_UNSETENV
 #define NO_UNSETENV
+#endif
+#ifndef NO_STRCASESTR
 #define NO_STRCASESTR
+#endif
+#ifndef NO_STRLCPY
 #define NO_STRLCPY
+#endif
+#ifndef NO_MEMMEM
 #define NO_MEMMEM
+#endif
+#ifndef NO_C99_FORMAT
 #define NO_C99_FORMAT
+#endif
+#ifndef NO_STRTOUMAX
 #define NO_STRTOUMAX
+#endif
+#ifndef NO_MKDTEMP
 #define NO_MKDTEMP
+#endif
+#ifndef NO_MKSTEMPS
 #define NO_MKSTEMPS
+#endif
 
+
+#ifndef RUNTIME_PREFIX
 #define RUNTIME_PREFIX
+#endif
+#ifndef NO_ST_BLOCKS_IN_STRUCT_STAT
 #define NO_ST_BLOCKS_IN_STRUCT_STAT
+#endif
+#ifndef NO_NSEC
 #define NO_NSEC
+#endif
+#ifndef USE_WIN32_MMAP
 #define USE_WIN32_MMAP
+#endif
+#ifndef USE_NED_ALLOCATOR
 #define USE_NED_ALLOCATOR
+#endif
+
 
+#ifndef NO_REGEX
 #define NO_REGEX
+#endif
 
+
+#ifndef NO_SYS_SELECT_H
 #define NO_SYS_SELECT_H
+#endif
+#ifndef NO_PTHEADS
 #define NO_PTHEADS
+#endif
+#ifndef HAVE_STRING_H
 #define HAVE_STRING_H 1
+#endif
+#ifndef STDC_HEADERS
 #define STDC_HEADERS
+#endif
+#ifndef NO_ICONV
 #define NO_ICONV
+#endif
+
 
 #define inline __inline
 #define __inline__ __inline
 
+#ifndef SNPRINTF_RETURNS_BOGUS
 #define SNPRINTF_RETURNS_BOGUS
+#endif
 
+
+#ifndef SHA1_HEADER
 #define SHA1_HEADER "mozilla-sha1\\sha1.h"
+#endif
 
+#ifndef ETC_GITCONFIG
 #define ETC_GITCONFIG "%HOME%"
+#endif
+
 
+#ifndef NO_PTHREADS
 #define NO_PTHREADS
+#endif
+#ifndef NO_CURL
 #define NO_CURL
+#endif
 
 
+#ifndef NO_STRTOUMAX
 #define NO_STRTOUMAX
+#endif
+#ifndef REGEX_MALLOC
 #define REGEX_MALLOC
+#endif
 
 
 #define GIT_EXEC_PATH "bin"
@@ -65,9 +135,16 @@
 #define GIT_HTML_PATH "html"
 #define DEFAULT_GIT_TEMPLATE_DIR "templates"
 
+#ifndef NO_STRLCPY
 #define NO_STRLCPY
+#endif
+#ifndef NO_UNSETENV
 #define NO_UNSETENV
+#endif
+#ifndef NO_SETENV
 #define NO_SETENV
+#endif
+
 
 #define strdup _strdup
 #define read _read
-- 
1.6
Previous: Pau Garcia i QuilesNext: Marius Storm-Olsen
Message 32 of 91 in “Add miss git-compat-util.h at regex.c and fnmatch.c Add git-compat-util.h to enable build at MSVC environment”
  1. 06/11 Add miss git-compat-util.h at regex.c and fnmatch.c Add git-compat-util.h to enable build at MSVC environmentFrank Li, Aug 17, 2009
  2. 07/11 Add O_BINARY flag to open flag at mingw.cFrank Li, Aug 17, 2009
  3. 08/11 Place __stdcall to correct position.Frank Li, Aug 17, 2009
  4. 09/11 Add MSVC porting header files.Frank Li, Aug 17, 2009
  5. 10/11 Add MSVC Project fileFrank Li, Aug 17, 2009
  6. Johannes SchindelinAug 17, 2009
  7. Paolo BonziniAug 17, 2009
  8. Erik Faye-LundAug 17, 2009
  9. Paolo BonziniAug 17, 2009
  10. Johannes SchindelinAug 17, 2009
  11. Paolo BonziniAug 17, 2009
  12. Johannes SchindelinAug 17, 2009
  13. Pau Garcia i QuilesAug 17, 2009
  14. Reece DunnAug 17, 2009
  15. Pau Garcia i QuilesAug 17, 2009
  16. Reece DunnAug 17, 2009
  17. Johan 't HartAug 17, 2009
  18. Johannes SchindelinAug 17, 2009
  19. Pau Garcia i QuilesAug 17, 2009
  20. Johannes SchindelinAug 17, 2009
  21. Pau Garcia i QuilesAug 17, 2009
  22. Paolo BonziniAug 17, 2009
  23. Thiago FarinaAug 17, 2009
  24. Thiago FarinaAug 17, 2009
  25. Johannes SchindelinAug 17, 2009
  26. Pau Garcia i QuilesAug 17, 2009
  27. Johannes SchindelinAug 17, 2009
  28. Johan 't HartAug 17, 2009
  29. Pau Garcia i QuilesAug 17, 2009
  30. Johannes SchindelinAug 17, 2009
  31. Pau Garcia i QuilesAug 17, 2009
  32. [RFC] Enable compilation by Makefile for the MSVC toolchainMarius Storm-Olsen, Aug 18, 2009
  33. Marius Storm-OlsenAug 18, 2009
  34. Erik Faye-LundAug 18, 2009
  35. Johannes SchindelinAug 18, 2009
  36. Pau Garcia i QuilesAug 18, 2009
  37. Johannes SchindelinAug 18, 2009
  38. Marius Storm-OlsenAug 18, 2009
  39. Daniel BarkalowAug 18, 2009
  40. Johannes SchindelinAug 18, 2009
  41. Johannes SchindelinAug 19, 2009
  42. Johan 't HartAug 18, 2009
  43. Reece DunnAug 18, 2009
  44. Pau Garcia i QuilesAug 18, 2009
  45. Paolo BonziniAug 18, 2009
  46. Junio C HamanoAug 18, 2009
  47. Marius Storm-OlsenAug 18, 2009
  48. Johan 't HartAug 18, 2009
  49. Marius Storm-OlsenAug 18, 2009
  50. Johannes SchindelinAug 18, 2009
  51. Erik Faye-LundAug 18, 2009
  52. Johannes SchindelinAug 18, 2009
  53. Erik Faye-LundAug 18, 2009
  54. Johannes SchindelinAug 19, 2009
  55. Marius Storm-OlsenAug 19, 2009
  56. Johannes SchindelinAug 19, 2009
  57. Thomas BergAug 19, 2009
  58. Marius Storm-OlsenAug 19, 2009
  59. Johannes SchindelinAug 19, 2009
  60. Marius Storm-OlsenAug 19, 2009
  61. Erik Faye-LundAug 19, 2009
  62. Joshua JensenAug 19, 2009
  63. Daniel BarkalowAug 18, 2009
  64. Marius Storm-OlsenAug 18, 2009
  65. Thiago FarinaAug 17, 2009
  66. Thiago FarinaAug 17, 2009
  67. Johannes SchindelinAug 17, 2009
  68. Thiago FarinaAug 17, 2009
  69. Johannes SchindelinAug 17, 2009
  70. Pau Garcia i QuilesAug 17, 2009
  71. CMake, was Re: [PATCH 09/11] Add MSVC porting header files.Johannes Schindelin, Aug 17, 2009
  72. Pau Garcia i QuilesAug 17, 2009
  73. Pau Garcia i QuilesAug 17, 2009
  74. Johannes SchindelinAug 17, 2009
  75. Pau Garcia i QuilesAug 17, 2009
  76. Reece DunnAug 17, 2009
  77. Pau Garcia i QuilesAug 17, 2009
  78. Johannes SixtAug 17, 2009
  79. Frank LiAug 18, 2009
  80. Johannes SchindelinAug 18, 2009
  81. Junio C HamanoAug 18, 2009
  82. Johannes SchindelinAug 18, 2009
  83. Johannes SixtAug 17, 2009
  84. Johannes SchindelinAug 17, 2009
  85. Frank LiAug 18, 2009
  86. Johannes SchindelinAug 18, 2009
  87. Johannes SchindelinAug 17, 2009
  88. Frank LiAug 18, 2009
  89. Johannes SchindelinAug 18, 2009
  90. Johannes SchindelinAug 17, 2009
  91. Johannes SixtAug 17, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.