11# Platform specific Makefile tweaks based on uname detection
22
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+
37uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
48uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
59uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
@@ -383,6 +387,7 @@ ifeq ($(uname_S),Windows)
383387 NEEDS_LIBICONV = YesPlease
384388 NO_STRTOUMAX = YesPlease
385389 NO_MKDTEMP = YesPlease
390+ NO_INTTYPES_H = YesPlease
386391 # VS2015 with UCRT claims that snprintf and friends are C99 compliant,
387392 # so we don't need this.
388393 #
@@ -416,6 +421,9 @@ ifeq ($(uname_S),Windows)
416421 compat/win32/dirent.o compat/win32/fscache.o
417422 COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DDETECT_MSYS_TTY -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
418423 BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE
424+ # invalidcontinue.obj allows Git's source code to close the same file
425+ # handle twice, or to access the osfhandle of an already-closed stdout
426+ # See https://msdn.microsoft.com/en-us/library/ms235330.aspx
419427 EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj kernel32.lib ntdll.lib
420428 PTHREAD_LIBS =
421429 lib =
@@ -434,6 +442,11 @@ ifeq ($(uname_S),Windows)
434442 # release mode) to force a PDB to be generated (like RelWithDebInfo).
435443 BASIC_CFLAGS += -Zi
436444 BASIC_LDFLAGS += -debug
445+
446+ ifdef NO_SAFESEH
447+ LDFLAGS += -SAFESEH:NO
448+ endif
449+
437450ifndef DEBUG
438451 BASIC_CFLAGS += -GL -Gy -O2 -Oy- -MD -DNDEBUG
439452 BASIC_LDFLAGS += -release -LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:CV,FIXUP
@@ -444,6 +457,65 @@ endif
444457 X = .exe
445458
446459compat/msvc.o: compat/msvc.c compat/mingw.c GIT-CFLAGS
460+
461+ vcxproj:
462+ # Require clean work tree
463+ git update-index -q --refresh && \
464+ git diff-files --quiet && \
465+ git diff-index --cached --quiet HEAD --
466+
467+ # Make .vcxproj files and add them
468+ unset QUIET_GEN QUIET_BUILT_IN; \
469+ perl contrib/buildsystems/generate -g Vcxproj
470+ git add -f git.sln {*,*/lib,t/helper/*}/{packages.config,*.vcxproj}
471+
472+ # Add command-list.h
473+ $(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 command-list.h
474+ git add -f command-list.h
475+
476+ # Add scripts
477+ rm -f perl/perl.mak
478+ $(MAKE) MSVC=1 prefix=/mingw64 \
479+ $(SCRIPT_LIB) $(SCRIPT_SH_GEN) $(SCRIPT_PERL_GEN)
480+ # Strip out the sane tool path, needed only for building
481+ sed -i '/^git_broken_path_fix ".*/d' git-sh-setup
482+ git add -f $(SCRIPT_LIB) $(SCRIPT_SH_GEN) $(SCRIPT_PERL_GEN)
483+
484+ # Add Perl module
485+ $(MAKE) $(LIB_PERL_GEN)
486+ git add -f perl/build
487+
488+ # Add bin-wrappers, for testing
489+ rm -rf bin-wrappers/
490+ $(MAKE) MSVC=1 prefix=/mingw64 $(test_bindir_programs)
491+ # Ensure that the GIT_EXEC_PATH is a Unix-y one, and that the absolute
492+ # path of the repository is not hard-coded (GIT_EXEC_PATH will be set
493+ # by test-lib.sh according to the current setup)
494+ sed -i -e 's/^\(GIT_EXEC_PATH\)=.*/test -n "$${\1##*:*}" ||\
495+ \1="$$(cygpath -u "$$\1")"/' \
496+ -e "s|'$$(pwd)|\"\$$GIT_EXEC_PATH\"'|g" bin-wrappers/*
497+ # Ensure that test-* helpers find the .dll files copied to top-level
498+ sed -i 's|^PATH=.*|&:"$$GIT_EXEC_PATH"|' bin-wrappers/test-*
499+ # We do not want to force hard-linking builtins
500+ sed -i 's|\(git\)-\([-a-z]*\)\.exe"|\1.exe" \2|g' \
501+ bin-wrappers/git-{receive-pack,upload-archive}
502+ git add -f $(test_bindir_programs)
503+ # remote-ext is a builtin, but invoked as if it were external
504+ sed 's|receive-pack|remote-ext|g' \
505+ <bin-wrappers/git-receive-pack >bin-wrappers/git-remote-ext
506+ git add -f bin-wrappers/git-remote-ext
507+
508+ # Add templates
509+ $(MAKE) -C templates
510+ git add -f templates/boilerplates.made templates/blt/
511+
512+ # Add build options
513+ $(MAKE) MSVC=1 prefix=/mingw64 GIT-BUILD-OPTIONS
514+ git add -f GIT-BUILD-OPTIONS
515+
516+ # Commit the whole shebang
517+ git commit -m "Generate Visual Studio solution" \
518+ -m "Auto-generated by \`$(MAKE)$(MAKEFLAGS) $@\`"
447519endif
448520ifeq ($(uname_S),Interix)
449521 NO_INITGROUPS = YesPlease
0 commit comments