msvc: support building Git using MS Visual C++

With this patch, Git can be built using the Microsoft toolchain, via: make MSVC=1 [DEBUG=1] Third party libraries are built from source using the open source "vcpkg" tool set. See https://github.com/Microsoft/vcpkg On a first build, the vcpkg tools and the third party libraries are automatically downloaded and built. DLLs for the third party libraries are copied to the top-level (and t/helper) directory to facilitate debugging. See compat/vcbuild/README. A series of .bat files are invoked by the Makefile to find the location of the installed version of Visual Studio and the associated compiler tools (essentially replicating the environment setup performed by a "Developer Command Prompt"). This should find the most recent VS2015 or VS2017 installation. Output from these scripts are used by the Makefile to define compiler and linker pathnames and -I and -L arguments. The build produces .pdb files for both debug and release builds. Note: This commit was squashed from an organic series of commits developed between 2016 and 2018 in Git for Windows' `master` branch. This combined commit eliminates the obsolete commits related to fetching NuGet packages for third party libraries. It is difficult to use NuGet packages for C/C++ sources because they may be built by earlier versions of the MSVC compiler and have CRT version and linking issues. Additionally, the C/C++ NuGet packages that we were using tended to not be updated concurrently with the sources. And in the case of cURL and OpenSSL, this could expose us to security issues. Helped-by: Yue Lin Ho <b8732003@student.nsysu.edu.tw> Helped-by: Philip Oakley <philipoakley@iee.org> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed Jun 25, 2019 at 07:49 UTC dce7d295514f0acebb897cc37a451963d60588f5
9 files changed +473 -15
Makefile
+40
@@ -2858,6 +2858,33 @@ install: all
2858 $(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2859 $(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2860 $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
2861 +ifdef MSVC
2862 + # We DO NOT install the individual foo.o.pdb files because they
2863 + # have already been rolled up into the exe's pdb file.
2864 + # We DO NOT have pdb files for the builtin commands (like git-status.exe)
2865 + # because it is just a copy/hardlink of git.exe, rather than a unique binary.
2866 + $(INSTALL) git.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2867 + $(INSTALL) git-shell.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2868 + $(INSTALL) git-upload-pack.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2869 + $(INSTALL) git-credential-store.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2870 + $(INSTALL) git-daemon.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2871 + $(INSTALL) git-fast-import.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2872 + $(INSTALL) git-http-backend.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2873 + $(INSTALL) git-http-fetch.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2874 + $(INSTALL) git-http-push.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2875 + $(INSTALL) git-imap-send.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2876 + $(INSTALL) git-remote-http.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2877 + $(INSTALL) git-remote-testsvn.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2878 + $(INSTALL) git-sh-i18n--envsubst.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2879 + $(INSTALL) git-show-index.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2880 +ifndef DEBUG
2881 + $(INSTALL) $(vcpkg_rel_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2882 + $(INSTALL) $(vcpkg_rel_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2883 +else
2884 + $(INSTALL) $(vcpkg_dbg_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
2885 + $(INSTALL) $(vcpkg_dbg_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
2886 +endif
2887 +endif
2888 $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
2889 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
2890 $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
@@ -3070,6 +3097,19 @@ endif
3097 $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
3098 $(RM) GIT-USER-AGENT GIT-PREFIX
3099 $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
3100 +ifdef MSVC
3101 + $(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
3102 + $(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))
3103 + $(RM) $(patsubst %.exe,%.iobj,$(OTHER_PROGRAMS))
3104 + $(RM) $(patsubst %.exe,%.ipdb,$(OTHER_PROGRAMS))
3105 + $(RM) $(patsubst %.exe,%.pdb,$(PROGRAMS))
3106 + $(RM) $(patsubst %.exe,%.iobj,$(PROGRAMS))
3107 + $(RM) $(patsubst %.exe,%.ipdb,$(PROGRAMS))
3108 + $(RM) $(patsubst %.exe,%.pdb,$(TEST_PROGRAMS))
3109 + $(RM) $(patsubst %.exe,%.iobj,$(TEST_PROGRAMS))
3110 + $(RM) $(patsubst %.exe,%.ipdb,$(TEST_PROGRAMS))
3111 + $(RM) compat/vcbuild/MSVC-DEFS-GEN
3112 +endif
3113
3114 .PHONY: all install profile-clean cocciclean clean strip
3115 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
compat/mingw.c
+6
@@ -2388,6 +2388,12 @@ static void maybe_redirect_std_handles(void)
2388 GENERIC_WRITE, FILE_FLAG_NO_BUFFERING);
2389 }
2390
2391 +#ifdef _MSC_VER
2392 +#ifdef _DEBUG
2393 +#include <crtdbg.h>
2394 +#endif
2395 +#endif
2396 +
2397 /*
2398 * We implement wmain() and compile with -municode, which would
2399 * normally ignore main(), but we call the latter from the former
compat/vcbuild/.gitignore new
+3
@@ -0,0 +1,3 @@
1 +/vcpkg/
2 +/MSVC-DEFS-GEN
3 +/VCPKG-DEFS
compat/vcbuild/README
+39
@@ -1,3 +1,42 @@
1 +The Steps to Build Git with VS2015 or VS2017 from the command line.
2 +
3 +1. Install the "vcpkg" open source package manager and build essential
4 + third-party libraries. The steps for this have been captured in a
5 + set of convenience scripts. These can be run from a stock Command
6 + Prompt or from an SDK bash window:
7 +
8 + $ cd <repo_root>
9 + $ ./compat/vcbuild/vcpkg_install.bat
10 +
11 + The vcpkg tools and all of the third-party sources will be installed
12 + in this folder:
13 + <repo_root>/compat/vcbuild/vcpkg/
14 +
15 + A file will be created with a set of Makefile macros pointing to a
16 + unified "include", "lib", and "bin" directory (release and debug) for
17 + all of the required packages. This file will be included by the main
18 + Makefile:
19 + <repo_root>/compat/vcbuild/MSVC-DEFS-GEN
20 +
21 +2. OPTIONALLY copy the third-party *.dll and *.pdb files into the repo
22 + root to make it easier to run and debug git.exe without having to
23 + manipulate your PATH. This is especially true for debug sessions in
24 + Visual Studio.
25 +
26 + Use ONE of the following forms which should match how you want to
27 + compile git.exe.
28 +
29 + $ ./compat/vcbuild/vcpkg_copy_packages.bat debug
30 + $ ./compat/vcbuild/vcpkg_copy_packages.bat release
31 +
32 +3. Build git using MSVC from an SDK bash window using one of the
33 + following commands:
34 +
35 + $ make MSVC=1
36 + $ make MSVC=1 DEBUG=1
37 +
38 +================================================================
39 +
40 The Steps of Build Git with VS2008
41
42 1. You need the build environment, which contains the Git dependencies
compat/vcbuild/find_vs_env.bat new
+168
@@ -0,0 +1,168 @@
1 +@ECHO OFF
2 +REM ================================================================
3 +REM You can use either GCC (the default) or MSVC to build git
4 +REM using the GIT-SDK command line tools.
5 +REM $ make
6 +REM $ make MSVC=1
7 +REM
8 +REM GIT-SDK BASH windows inherit environment variables with all of
9 +REM the bin/lib/include paths for GCC. It DOES NOT inherit values
10 +REM for the corresponding MSVC tools.
11 +REM
12 +REM During normal (non-git) Windows development, you launch one
13 +REM of the provided "developer command prompts" to set environment
14 +REM variables for the MSVC tools.
15 +REM
16 +REM Therefore, to allow MSVC command line builds of git from BASH
17 +REM and MAKE, we must blend these two different worlds. This script
18 +REM attempts to do that.
19 +REM ================================================================
20 +REM This BAT file starts in a plain (non-developer) command prompt,
21 +REM searches for the "best" commmand prompt setup script, installs
22 +REM it into the current CMD process, and exports the various MSVC
23 +REM environment variables for use by MAKE.
24 +REM
25 +REM The output of this script should be written to a make "include
26 +REM file" and referenced by the top-level Makefile.
27 +REM
28 +REM See "config.mak.uname" (look for compat/vcbuild/MSVC-DEFS-GEN).
29 +REM ================================================================
30 +REM The provided command prompts are custom to each VS release and
31 +REM filled with lots of internal knowledge (such as Registry settings);
32 +REM even their names vary by release, so it is not appropriate for us
33 +REM to look inside them. Rather, just run them in a subordinate
34 +REM process and extract the settings we need.
35 +REM ================================================================
36 +REM
37 +REM Current (VS2017 and beyond)
38 +REM -------------------
39 +REM Visual Studio 2017 introduced a new installation layout and
40 +REM support for side-by-side installation of multiple versions of
41 +REM VS2017. Furthermore, these can all coexist with installations
42 +REM of previous versions of VS (which have a completely different
43 +REM layout on disk).
44 +REM
45 +REM VS2017 Update 2 introduced a "vswhere.exe" command:
46 +REM https://github.com/Microsoft/vswhere
47 +REM https://blogs.msdn.microsoft.com/heaths/2017/02/25/vswhere-available/
48 +REM https://blogs.msdn.microsoft.com/vcblog/2017/03/06/finding-the-visual-c-compiler-tools-in-visual-studio-2017/
49 +REM
50 +REM VS2015
51 +REM ------
52 +REM Visual Studio 2015 uses the traditional VcVarsAll.
53 +REM
54 +REM Earlier Versions
55 +REM ----------------
56 +REM Currently unsupported.
57 +REM
58 +REM ================================================================
59 +REM Note: Throughout this script we use "dir <path> && <cmd>" rather
60 +REM than "if exist <path>" because of script problems with pathnames
61 +REM containing spaces.
62 +REM ================================================================
63 +
64 +REM Sanitize PATH to prevent git-sdk paths from confusing "wmic.exe"
65 +REM (called internally in some of the system BAT files).
66 +SET PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;
67 +
68 +REM ================================================================
69 +
70 +:current
71 + SET vs_where=C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe
72 + dir "%vs_where%" >nul 2>nul && GOTO have_vs_where
73 + GOTO not_2017
74 +
75 +:have_vs_where
76 + REM Try to use VsWhere to get the location of VsDevCmd.
77 +
78 + REM Keep VsDevCmd from cd'ing away.
79 + SET VSCMD_START_DIR=.
80 +
81 + REM Get the root of the VS product installation.
82 + FOR /F "usebackq tokens=*" %%i IN (`"%vs_where%" -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -property installationPath`) DO @SET vs_ip=%%i
83 +
84 + SET vs_devcmd=%vs_ip%\Common7\Tools\VsDevCmd.bat
85 + dir "%vs_devcmd%" >nul 2>nul && GOTO have_vs_devcmd
86 + GOTO not_2017
87 +
88 +:have_vs_devcmd
89 + REM Use VsDevCmd to setup the environment of this process.
90 + REM Setup CL for building 64-bit apps using 64-bit tools.
91 + @call "%vs_devcmd%" -no_logo -arch=x64 -host_arch=x64
92 +
93 + SET tgt=%VSCMD_ARG_TGT_ARCH%
94 +
95 + SET mn=%VCToolsInstallDir%
96 + SET msvc_includes=-I"%mn%INCLUDE"
97 + SET msvc_libs=-L"%mn%lib\%tgt%"
98 + SET msvc_bin_dir=%mn%bin\Host%VSCMD_ARG_HOST_ARCH%\%tgt%
99 +
100 + SET sdk_dir=%WindowsSdkDir%
101 + SET sdk_ver=%WindowsSDKVersion%
102 + SET si=%sdk_dir%Include\%sdk_ver%
103 + SET sdk_includes=-I"%si%ucrt" -I"%si%um" -I"%si%shared"
104 + SET sl=%sdk_dir%lib\%sdk_ver%
105 + SET sdk_libs=-L"%sl%ucrt\%tgt%" -L"%sl%um\%tgt%"
106 +
107 + SET vs_ver=%VisualStudioVersion%
108 +
109 + GOTO print_vars
110 +
111 +REM ================================================================
112 +
113 +:not_2017
114 + REM See if VS2015 is installed.
115 +
116 + SET vs_2015_bat=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
117 + dir "%vs_2015_bat%" >nul 2>nul && GOTO have_vs_2015
118 + GOTO not_2015
119 +
120 +:have_vs_2015
121 + REM Use VcVarsAll like the "x64 Native" command prompt.
122 + REM Setup CL for building 64-bit apps using 64-bit tools.
123 + @call "%vs_2015_bat%" amd64
124 +
125 + REM Note that in VS2015 they use "x64" in some contexts and "amd64" in others.
126 + SET mn=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\
127 + SET msvc_includes=-I"%mn%INCLUDE"
128 + SET msvc_libs=-L"%mn%lib\amd64"
129 + SET msvc_bin_dir=%mn%bin\amd64
130 +
131 + SET sdk_dir=%WindowsSdkDir%
132 + SET sdk_ver=%WindowsSDKVersion%
133 + SET si=%sdk_dir%Include\%sdk_ver%
134 + SET sdk_includes=-I"%si%ucrt" -I"%si%um" -I"%si%shared" -I"%si%winrt"
135 + SET sl=%sdk_dir%lib\%sdk_ver%
136 + SET sdk_libs=-L"%sl%ucrt\x64" -L"%sl%um\x64"
137 +
138 + SET vs_ver=%VisualStudioVersion%
139 +
140 + GOTO print_vars
141 +
142 +REM ================================================================
143 +
144 +:not_2015
145 + echo "ERROR: unsupported VS version (older than VS2015)" >&2
146 + EXIT /B 1
147 +
148 +REM ================================================================
149 +
150 +:print_vars
151 + REM Dump the essential vars to stdout to allow the main
152 + REM Makefile to include it. See config.mak.uname.
153 + REM Include DOS-style and BASH-style path for bin dir.
154 +
155 + echo msvc_bin_dir=%msvc_bin_dir%
156 + SET X1=%msvc_bin_dir:C:=/C%
157 + SET X2=%X1:\=/%
158 + echo msvc_bin_dir_msys=%X2%
159 +
160 + echo msvc_includes=%msvc_includes%
161 + echo msvc_libs=%msvc_libs%
162 +
163 + echo sdk_includes=%sdk_includes%
164 + echo sdk_libs=%sdk_libs%
165 +
166 + echo vs_ver=%vs_ver%
167 +
168 + EXIT /B 0
compat/vcbuild/scripts/clink.pl
+36 -5
@@ -12,32 +12,62 @@
12 use strict;
13 my @args = ();
14 my @cflags = ();
15 +my @lflags = ();
16 my $is_linking = 0;
17 +my $is_debug = 0;
18 while (@ARGV) {
19 my $arg = shift @ARGV;
18 - if ("$arg" =~ /^-[DIMGO]/) {
20 + if ("$arg" eq "-DDEBUG") {
21 + # Some vcpkg-based libraries have different names for release
22 + # and debug versions. This hack assumes that -DDEBUG comes
23 + # before any "-l*" flags.
24 + $is_debug = 1;
25 + }
26 + if ("$arg" =~ /^-[DIMGOZ]/) {
27 push(@cflags, $arg);
28 } elsif ("$arg" eq "-o") {
29 my $file_out = shift @ARGV;
30 if ("$file_out" =~ /exe$/) {
31 $is_linking = 1;
32 + # Create foo.exe and foo.pdb
33 push(@args, "-OUT:$file_out");
34 } else {
35 + # Create foo.o and foo.o.pdb
36 push(@args, "-Fo$file_out");
37 + push(@args, "-Fd$file_out.pdb");
38 }
39 } elsif ("$arg" eq "-lz") {
40 + if ($is_debug) {
41 + push(@args, "zlibd.lib");
42 + } else{
43 push(@args, "zlib.lib");
44 + }
45 } elsif ("$arg" eq "-liconv") {
31 - push(@args, "iconv.lib");
46 + push(@args, "libiconv.lib");
47 } elsif ("$arg" eq "-lcrypto") {
48 push(@args, "libeay32.lib");
49 } elsif ("$arg" eq "-lssl") {
50 push(@args, "ssleay32.lib");
51 } elsif ("$arg" eq "-lcurl") {
37 - push(@args, "libcurl.lib");
52 + my $lib = "";
53 + # Newer vcpkg definitions call this libcurl_imp.lib; Do we
54 + # need to use that instead?
55 + foreach my $flag (@lflags) {
56 + if ($flag =~ /^-LIBPATH:(.*)/) {
57 + foreach my $l ("libcurl_imp.lib", "libcurl.lib") {
58 + if (-f "$1/$l") {
59 + $lib = $l;
60 + last;
61 + }
62 + }
63 + }
64 + }
65 + push(@args, $lib);
66 + } elsif ("$arg" eq "-lexpat") {
67 + push(@args, "expat.lib");
68 } elsif ("$arg" =~ /^-L/ && "$arg" ne "-LTCG") {
69 $arg =~ s/^-L/-LIBPATH:/;
40 - push(@args, $arg);
70 + push(@lflags, $arg);
71 } elsif ("$arg" =~ /^-R/) {
72 # eat
73 } else {
@@ -45,10 +75,11 @@ while (@ARGV) {
75 }
76 }
77 if ($is_linking) {
78 + push(@args, @lflags);
79 unshift(@args, "link.exe");
80 } else {
81 unshift(@args, "cl.exe");
82 push(@args, @cflags);
83 }
53 -#printf("**** @args\n");
84 +printf(STDERR "**** @args\n\n\n") if (!defined($ENV{'QUIET_GEN'}));
85 exit (system(@args) != 0);
compat/vcbuild/vcpkg_copy_dlls.bat new
+39
@@ -0,0 +1,39 @@
1 +@ECHO OFF
2 +REM ================================================================
3 +REM This script is an optional step. It copies the *.dll and *.pdb
4 +REM files (created by vcpkg_install.bat) into the top-level directory
5 +REM of the repo so that you can type "./git.exe" and find them without
6 +REM having to fixup your PATH.
7 +REM
8 +REM NOTE: Because the names of some DLL files change between DEBUG and
9 +REM NOTE: RELEASE builds when built using "vcpkg.exe", you will need
10 +REM NOTE: to copy up the corresponding version.
11 +REM ================================================================
12 +
13 + SETLOCAL EnableDelayedExpansion
14 +
15 + @FOR /F "delims=" %%D IN ("%~dp0") DO @SET cwd=%%~fD
16 + cd %cwd%
17 +
18 + SET arch=x64-windows
19 + SET inst=%cwd%vcpkg\installed\%arch%
20 +
21 + IF [%1]==[release] (
22 + echo Copying RELEASE mode DLLs to repo root...
23 + ) ELSE IF [%1]==[debug] (
24 + SET inst=%inst%\debug
25 + echo Copying DEBUG mode DLLs to repo root...
26 + ) ELSE (
27 + echo ERROR: Invalid argument.
28 + echo Usage: %~0 release
29 + echo Usage: %~0 debug
30 + EXIT /B 1
31 + )
32 +
33 + xcopy /e/s/v/y %inst%\bin\*.dll ..\..\
34 + xcopy /e/s/v/y %inst%\bin\*.pdb ..\..\
35 +
36 + xcopy /e/s/v/y %inst%\bin\*.dll ..\..\t\helper\
37 + xcopy /e/s/v/y %inst%\bin\*.pdb ..\..\t\helper\
38 +
39 + EXIT /B 0
compat/vcbuild/vcpkg_install.bat new
+80
@@ -0,0 +1,80 @@
1 +@ECHO OFF
2 +REM ================================================================
3 +REM This script installs the "vcpkg" source package manager and uses
4 +REM it to build the third-party libraries that git requires when it
5 +REM is built using MSVC.
6 +REM
7 +REM [1] Install VCPKG.
8 +REM [a] Create <root>/compat/vcbuild/vcpkg/
9 +REM [b] Download "vcpkg".
10 +REM [c] Compile using the currently installed version of VS.
11 +REM [d] Create <root>/compat/vcbuild/vcpkg/vcpkg.exe
12 +REM
13 +REM [2] Install third-party libraries.
14 +REM [a] Download each (which may also install CMAKE).
15 +REM [b] Compile in RELEASE mode and install in:
16 +REM vcpkg/installed/<arch>/{bin,lib}
17 +REM [c] Compile in DEBUG mode and install in:
18 +REM vcpkg/installed/<arch>/debug/{bin,lib}
19 +REM [d] Install headers in:
20 +REM vcpkg/installed/<arch>/include
21 +REM
22 +REM [3] Create a set of MAKE definitions for the top-level
23 +REM Makefile to allow "make MSVC=1" to find the above
24 +REM third-party libraries.
25 +REM [a] Write vcpkg/VCPGK-DEFS
26 +REM
27 +REM https://blogs.msdn.microsoft.com/vcblog/2016/09/19/vcpkg-a-tool-to-acquire-and-build-c-open-source-libraries-on-windows/
28 +REM https://github.com/Microsoft/vcpkg
29 +REM https://vcpkg.readthedocs.io/en/latest/
30 +REM ================================================================
31 +
32 + SETLOCAL EnableDelayedExpansion
33 +
34 + @FOR /F "delims=" %%D IN ("%~dp0") DO @SET cwd=%%~fD
35 + cd %cwd%
36 +
37 + dir vcpkg\vcpkg.exe >nul 2>nul && GOTO :install_libraries
38 +
39 + echo Fetching vcpkg in %cwd%vcpkg
40 + git.exe clone https://github.com/Microsoft/vcpkg vcpkg
41 + IF ERRORLEVEL 1 ( EXIT /B 1 )
42 +
43 + cd vcpkg
44 + echo Building vcpkg
45 + powershell -exec bypass scripts\bootstrap.ps1
46 + IF ERRORLEVEL 1 ( EXIT /B 1 )
47 +
48 + echo Successfully installed %cwd%vcpkg\vcpkg.exe
49 +
50 +:install_libraries
51 + SET arch=x64-windows
52 +
53 + echo Installing third-party libraries...
54 + FOR %%i IN (zlib expat libiconv openssl libssh2 curl) DO (
55 + cd %cwd%vcpkg
56 + IF NOT EXIST "packages\%%i_%arch%" CALL :sub__install_one %%i
57 + IF ERRORLEVEL 1 ( EXIT /B 1 )
58 + )
59 +
60 +:install_defines
61 + cd %cwd%
62 + SET inst=%cwd%vcpkg\installed\%arch%
63 +
64 + echo vcpkg_inc=-I"%inst%\include">VCPKG-DEFS
65 + echo vcpkg_rel_lib=-L"%inst%\lib">>VCPKG-DEFS
66 + echo vcpkg_rel_bin="%inst%\bin">>VCPKG-DEFS
67 + echo vcpkg_dbg_lib=-L"%inst%\debug\lib">>VCPKG-DEFS
68 + echo vcpkg_dbg_bin="%inst%\debug\bin">>VCPKG-DEFS
69 +
70 + EXIT /B 0
71 +
72 +
73 +:sub__install_one
74 + echo Installing package %1...
75 +
76 + .\vcpkg.exe install %1:%arch%
77 + IF ERRORLEVEL 1 ( EXIT /B 1 )
78 +
79 + echo Finished %1
80 + goto :EOF
config.mak.uname
+62 -10
@@ -1,5 +1,9 @@
1 # Platform specific Makefile tweaks based on uname detection
2
3 +# Define NO_SAFESEH if you need MSVC/Visual Studio to ignore the lack of
4 +# Microsoft's Safe Exception Handling in libraries (such as zlib).
5 +# Typically required for VS2013+/32-bit compilation on Vista+ versions.
6 +
7 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
8 uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
9 uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
@@ -11,6 +15,19 @@ ifdef MSVC
15 # avoid the MingW and Cygwin configuration sections
16 uname_S := Windows
17 uname_O := Windows
18 +
19 + # Generate and include makefile variables that point to the
20 + # currently installed set of MSVC command line tools.
21 +compat/vcbuild/MSVC-DEFS-GEN: compat/vcbuild/find_vs_env.bat
22 + @"$<" | tr '\\' / >"$@"
23 +include compat/vcbuild/MSVC-DEFS-GEN
24 +
25 + # See if vcpkg and the vcpkg-build versions of the third-party
26 + # libraries that we use are installed. We include the result
27 + # to get $(vcpkg_*) variables defined for the Makefile.
28 +compat/vcbuild/VCPKG-DEFS: compat/vcbuild/vcpkg_install.bat
29 + @"$<"
30 +include compat/vcbuild/VCPKG-DEFS
31 endif
32
33 # We choose to avoid "if .. else if .. else .. endif endif"
@@ -356,6 +373,19 @@ endif
373 ifeq ($(uname_S),Windows)
374 GIT_VERSION := $(GIT_VERSION).MSVC
375 pathsep = ;
376 + # Assume that this is built in Git for Windows' SDK
377 + ifeq (MINGW32,$(MSYSTEM))
378 + prefix = /mingw32
379 + else
380 + prefix = /mingw64
381 + endif
382 + # Prepend MSVC 64-bit tool-chain to PATH.
383 + #
384 + # A regular Git Bash *does not* have cl.exe in its $PATH. As there is a
385 + # link.exe next to, and required by, cl.exe, we have to prepend this
386 + # onto the existing $PATH.
387 + #
388 + SANE_TOOL_PATH ?= $(msvc_bin_dir_msys)
389 HAVE_ALLOCA_H = YesPlease
390 NO_PREAD = YesPlease
391 NEEDS_CRYPTO_WITH_SSL = YesPlease
@@ -368,11 +398,14 @@ ifeq ($(uname_S),Windows)
398 NO_STRCASESTR = YesPlease
399 NO_STRLCPY = YesPlease
400 NO_MEMMEM = YesPlease
371 - # NEEDS_LIBICONV = YesPlease
372 - NO_ICONV = YesPlease
401 + NEEDS_LIBICONV = YesPlease
402 NO_STRTOUMAX = YesPlease
403 NO_MKDTEMP = YesPlease
375 - SNPRINTF_RETURNS_BOGUS = YesPlease
404 + NO_INTTYPES_H = YesPlease
405 + # VS2015 with UCRT claims that snprintf and friends are C99 compliant,
406 + # so we don't need this:
407 + #
408 + # SNPRINTF_RETURNS_BOGUS = YesPlease
409 NO_SVN_TESTS = YesPlease
410 RUNTIME_PREFIX = YesPlease
411 HAVE_WPGMPTR = YesWeDo
@@ -385,7 +418,6 @@ ifeq ($(uname_S),Windows)
418 NO_REGEX = YesPlease
419 NO_GETTEXT = YesPlease
420 NO_PYTHON = YesPlease
388 - BLK_SHA1 = YesPlease
421 ETAGS_TARGET = ETAGS
422 NO_POSIX_GOODIES = UnfortunatelyYes
423 NATIVE_CRLF = YesPlease
@@ -394,24 +426,44 @@ ifeq ($(uname_S),Windows)
426 CC = compat/vcbuild/scripts/clink.pl
427 AR = compat/vcbuild/scripts/lib.pl
428 CFLAGS =
397 - 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
429 + BASIC_CFLAGS = -nologo -I. -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE
430 COMPAT_OBJS = compat/msvc.o compat/winansi.o \
431 compat/win32/path-utils.o \
432 compat/win32/pthread.o compat/win32/syslog.o \
433 compat/win32/trace2_win32_process_info.o \
434 compat/win32/dirent.o
403 - COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
435 + COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DDETECT_MSYS_TTY -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
436 BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -ENTRY:wmainCRTStartup -SUBSYSTEM:CONSOLE
405 - EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj
437 + # invalidcontinue.obj allows Git's source code to close the same file
438 + # handle twice, or to access the osfhandle of an already-closed stdout
439 + # See https://msdn.microsoft.com/en-us/library/ms235330.aspx
440 + EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj kernel32.lib ntdll.lib
441 PTHREAD_LIBS =
442 lib =
443 + BASIC_CFLAGS += $(vcpkg_inc) $(sdk_includes) $(msvc_includes)
444 +ifndef DEBUG
445 + BASIC_CFLAGS += $(vcpkg_rel_lib)
446 +else
447 + BASIC_CFLAGS += $(vcpkg_dbg_lib)
448 +endif
449 + BASIC_CFLAGS += $(sdk_libs) $(msvc_libs)
450 +
451 BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
452 + # Always give "-Zi" to the compiler and "-debug" to linker (even in
453 + # release mode) to force a PDB to be generated (like RelWithDebInfo).
454 + BASIC_CFLAGS += -Zi
455 + BASIC_LDFLAGS += -debug -Zf
456 +
457 +ifdef NO_SAFESEH
458 + LDFLAGS += -SAFESEH:NO
459 +endif
460 +
461 ifndef DEBUG
410 - BASIC_CFLAGS += -GL -Os -MD
411 - BASIC_LDFLAGS += -LTCG
462 + BASIC_CFLAGS += -GL -Gy -O2 -Oy- -MD -DNDEBUG
463 + BASIC_LDFLAGS += -release -LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:CV,FIXUP
464 AR += -LTCG
465 else
414 - BASIC_CFLAGS += -Zi -MDd
466 + BASIC_CFLAGS += -MDd -DDEBUG -D_DEBUG
467 endif
468 X = .exe
469