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')
@@ -362,6 +366,7 @@ ifeq ($(uname_S),Windows)
362366 NO_STRTOUMAX = YesPlease
363367 NO_MKDTEMP = YesPlease
364368 NO_MKSTEMPS = YesPlease
369+ NO_INTTYPES_H = YesPlease
365370 # VS2015 with UCRT claims that snprintf and friends are C99 compliant,
366371 # so we don't need this.
367372 #
@@ -395,6 +400,9 @@ ifeq ($(uname_S),Windows)
395400 compat/win32/dirent.o compat/win32/fscache.o
396401 COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DDETECT_MSYS_TTY -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
397402 BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE
403+ # invalidcontinue.obj allows Git's source code to close the same file
404+ # handle twice, or to access the osfhandle of an already-closed stdout
405+ # See https://msdn.microsoft.com/en-us/library/ms235330.aspx
398406 EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj kernel32.lib ntdll.lib
399407 PTHREAD_LIBS =
400408 lib =
@@ -427,6 +435,11 @@ ifeq ($(uname_S),Windows)
427435 # release mode) to force a PDB to be generated (like RelWithDebInfo).
428436 BASIC_CFLAGS += -Zi
429437 BASIC_LDFLAGS += -debug
438+
439+ ifdef NO_SAFESEH
440+ LDFLAGS += -SAFESEH:NO
441+ endif
442+
430443ifndef DEBUG
431444 BASIC_CFLAGS += -GL -Gy -O2 -Oy- -MD -DNDEBUG
432445 BASIC_LDFLAGS += -release -LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:CV,FIXUP
@@ -437,6 +450,65 @@ endif
437450 X = .exe
438451
439452compat/msvc.o: compat/msvc.c compat/mingw.c GIT-CFLAGS
453+
454+ vcxproj:
455+ # Require clean work tree
456+ git update-index -q --refresh && \
457+ git diff-files --quiet && \
458+ git diff-index --cached --quiet HEAD --
459+
460+ # Make .vcxproj files and add them
461+ unset QUIET_GEN QUIET_BUILT_IN; \
462+ perl contrib/buildsystems/generate -g Vcxproj
463+ git add -f git.sln {*,*/lib,t/helper/*}/{packages.config,*.vcxproj}
464+
465+ # Add common-cmds.h
466+ $(MAKE) MSVC=1 prefix=/mingw64 common-cmds.h
467+ git add -f common-cmds.h
468+
469+ # Add scripts
470+ rm -f perl/perl.mak
471+ $(MAKE) MSVC=1 prefix=/mingw64 \
472+ $(SCRIPT_LIB) $(SCRIPT_SH_GEN) $(SCRIPT_PERL_GEN)
473+ # Strip out the sane tool path, needed only for building
474+ sed -i '/^git_broken_path_fix ".*/d' git-sh-setup
475+ git add -f $(SCRIPT_LIB) $(SCRIPT_SH_GEN) $(SCRIPT_PERL_GEN)
476+
477+ # Add Perl module
478+ $(MAKE) -C perl
479+ git add -f perl/blib/lib
480+
481+ # Add bin-wrappers, for testing
482+ rm -rf bin-wrappers/
483+ $(MAKE) MSVC=1 prefix=/mingw64 $(test_bindir_programs)
484+ # Ensure that the GIT_EXEC_PATH is a Unix-y one, and that the absolute
485+ # path of the repository is not hard-coded (GIT_EXEC_PATH will be set
486+ # by test-lib.sh according to the current setup)
487+ sed -i -e 's/^\(GIT_EXEC_PATH\)=.*/test -n "$${\1##*:*}" ||\
488+ \1="$$(cygpath -u "$$\1")"/' \
489+ -e "s|'$$(pwd)|\"\$$GIT_EXEC_PATH\"'|g" bin-wrappers/*
490+ # Ensure that test-* helpers find the .dll files copied to top-level
491+ sed -i 's|^PATH=.*|&:"$$GIT_EXEC_PATH"|' bin-wrappers/test-*
492+ # We do not want to force hard-linking builtins
493+ sed -i 's|\(git\)-\([-a-z]*\)\.exe"|\1.exe" \2|g' \
494+ bin-wrappers/git-{receive-pack,upload-archive}
495+ git add -f $(test_bindir_programs)
496+ # remote-ext is a builtin, but invoked as if it were external
497+ sed 's|receive-pack|remote-ext|g' \
498+ <bin-wrappers/git-receive-pack >bin-wrappers/git-remote-ext
499+ git add -f bin-wrappers/git-remote-ext
500+
501+ # Add templates
502+ $(MAKE) -C templates
503+ git add -f templates/boilerplates.made templates/blt/
504+
505+ # Add build options
506+ $(MAKE) MSVC=1 prefix=/mingw64 GIT-BUILD-OPTIONS
507+ git add -f GIT-BUILD-OPTIONS
508+
509+ # Commit the whole shebang
510+ git commit -m "Generate Visual Studio solution" \
511+ -m "Auto-generated by \`$(MAKE)$(MAKEFLAGS) $@\`"
440512endif
441513ifeq ($(uname_S),Interix)
442514 NO_INITGROUPS = YesPlease
0 commit comments