mirror of
https://github.com/git-for-windows/git.git
synced 2026-03-17 04:23:29 -05:00
Merge branch 'maintenance-and-headless-and-msvc-and-vcxproj'
This contains a couple of fixes required to allow compiling `headless-git.exe` using `MSVC=1` and with `make vcxproj`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
11
Makefile
11
Makefile
@@ -2527,12 +2527,12 @@ compat/nedmalloc/nedmalloc.sp compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \
|
||||
compat/nedmalloc/nedmalloc.sp: SP_EXTRA_FLAGS += -Wno-non-pointer-null
|
||||
endif
|
||||
|
||||
headless-git.o: compat/win32/headless.c
|
||||
headless-git.o: compat/win32/headless.c GIT-CFLAGS
|
||||
$(QUIET_CC)$(CC) $(ALL_CFLAGS) $(COMPAT_CFLAGS) \
|
||||
-fno-stack-protector -o $@ -c -Wall -Wwrite-strings $<
|
||||
|
||||
headless-git$X: headless-git.o git.res
|
||||
$(QUIET_LINK)$(CC) $(ALL_LDFLAGS) -mwindows $(COMPAT_CFLAGS) -o $@ $^
|
||||
headless-git$X: headless-git.o git.res GIT-LDFLAGS
|
||||
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -mwindows -o $@ $< git.res
|
||||
|
||||
git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
|
||||
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
|
||||
@@ -3180,6 +3180,7 @@ cocciclean:
|
||||
clean: profile-clean coverage-clean cocciclean
|
||||
$(RM) *.res
|
||||
$(RM) $(OBJECTS)
|
||||
$(RM) headless-git.o
|
||||
$(RM) $(LIB_FILE) $(XDIFF_LIB)
|
||||
$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
|
||||
$(RM) $(TEST_PROGRAMS)
|
||||
@@ -3208,13 +3209,17 @@ endif
|
||||
$(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
|
||||
ifdef MSVC
|
||||
$(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
|
||||
$(RM) headless-git.o.pdb
|
||||
$(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.ilk,$(OTHER_PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.iobj,$(OTHER_PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.ipdb,$(OTHER_PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.pdb,$(PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.ilk,$(PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.iobj,$(PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.ipdb,$(PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.pdb,$(TEST_PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.ilk,$(TEST_PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.iobj,$(TEST_PROGRAMS))
|
||||
$(RM) $(patsubst %.exe,%.ipdb,$(TEST_PROGRAMS))
|
||||
$(RM) compat/vcbuild/MSVC-DEFS-GEN
|
||||
|
||||
@@ -99,6 +99,7 @@ REM ================================================================
|
||||
|
||||
SET sdk_dir=%WindowsSdkDir%
|
||||
SET sdk_ver=%WindowsSDKVersion%
|
||||
SET sdk_ver_bin_dir=%WindowsSdkVerBinPath%%tgt%
|
||||
SET si=%sdk_dir%Include\%sdk_ver%
|
||||
SET sdk_includes=-I"%si%ucrt" -I"%si%um" -I"%si%shared"
|
||||
SET sl=%sdk_dir%lib\%sdk_ver%
|
||||
@@ -130,6 +131,7 @@ REM ================================================================
|
||||
|
||||
SET sdk_dir=%WindowsSdkDir%
|
||||
SET sdk_ver=%WindowsSDKVersion%
|
||||
SET sdk_ver_bin_dir=%WindowsSdkVerBinPath%bin\amd64
|
||||
SET si=%sdk_dir%Include\%sdk_ver%
|
||||
SET sdk_includes=-I"%si%ucrt" -I"%si%um" -I"%si%shared" -I"%si%winrt"
|
||||
SET sl=%sdk_dir%lib\%sdk_ver%
|
||||
@@ -160,6 +162,11 @@ REM ================================================================
|
||||
echo msvc_includes=%msvc_includes%
|
||||
echo msvc_libs=%msvc_libs%
|
||||
|
||||
echo sdk_ver_bin_dir=%sdk_ver_bin_dir%
|
||||
SET X1=%sdk_ver_bin_dir:C:=/C%
|
||||
SET X2=%X1:\=/%
|
||||
echo sdk_ver_bin_dir_msys=%X2%
|
||||
|
||||
echo sdk_includes=%sdk_includes%
|
||||
echo sdk_libs=%sdk_libs%
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ my @cflags = ();
|
||||
my @lflags = ();
|
||||
my $is_linking = 0;
|
||||
my $is_debug = 0;
|
||||
my $is_gui = 0;
|
||||
while (@ARGV) {
|
||||
my $arg = shift @ARGV;
|
||||
if ("$arg" eq "-DDEBUG") {
|
||||
@@ -67,7 +68,11 @@ while (@ARGV) {
|
||||
}
|
||||
push(@args, $lib);
|
||||
} elsif ("$arg" eq "-lexpat") {
|
||||
if ($is_debug) {
|
||||
push(@args, "libexpatd.lib");
|
||||
} else {
|
||||
push(@args, "libexpat.lib");
|
||||
}
|
||||
} elsif ("$arg" =~ /^-L/ && "$arg" ne "-LTCG") {
|
||||
$arg =~ s/^-L/-LIBPATH:/;
|
||||
push(@lflags, $arg);
|
||||
@@ -119,11 +124,23 @@ while (@ARGV) {
|
||||
push(@cflags, "-wd4996");
|
||||
} elsif ("$arg" =~ /^-W[a-z]/) {
|
||||
# let's ignore those
|
||||
} elsif ("$arg" eq "-fno-stack-protector") {
|
||||
# eat this
|
||||
} elsif ("$arg" eq "-mwindows") {
|
||||
$is_gui = 1;
|
||||
} else {
|
||||
push(@args, $arg);
|
||||
}
|
||||
}
|
||||
if ($is_linking) {
|
||||
if ($is_gui) {
|
||||
push(@args, "-ENTRY:wWinMainCRTStartup");
|
||||
push(@args, "-SUBSYSTEM:WINDOWS");
|
||||
} else {
|
||||
push(@args, "-ENTRY:wmainCRTStartup");
|
||||
push(@args, "-SUBSYSTEM:CONSOLE");
|
||||
}
|
||||
|
||||
push(@args, @lflags);
|
||||
unshift(@args, "link.exe");
|
||||
} else {
|
||||
|
||||
46
compat/vcbuild/scripts/rc.pl
Normal file
46
compat/vcbuild/scripts/rc.pl
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/perl -w
|
||||
######################################################################
|
||||
# Compile Resources on Windows
|
||||
#
|
||||
# This is a wrapper to facilitate the compilation of Git with MSVC
|
||||
# using GNU Make as the build system. So, instead of manipulating the
|
||||
# Makefile into something nasty, just to support non-space arguments
|
||||
# etc, we use this wrapper to fix the command line options
|
||||
#
|
||||
######################################################################
|
||||
use strict;
|
||||
my @args = ();
|
||||
my @input = ();
|
||||
|
||||
while (@ARGV) {
|
||||
my $arg = shift @ARGV;
|
||||
if ("$arg" =~ /^-[dD]/) {
|
||||
# GIT_VERSION gets passed with too many
|
||||
# layers of dquote escaping.
|
||||
$arg =~ s/\\"/"/g;
|
||||
|
||||
push(@args, $arg);
|
||||
|
||||
} elsif ("$arg" eq "-i") {
|
||||
my $arg = shift @ARGV;
|
||||
# TODO complain if NULL or is dashed ??
|
||||
push(@input, $arg);
|
||||
|
||||
} elsif ("$arg" eq "-o") {
|
||||
my $arg = shift @ARGV;
|
||||
# TODO complain if NULL or is dashed ??
|
||||
push(@args, "-fo$arg");
|
||||
|
||||
} else {
|
||||
push(@args, $arg);
|
||||
}
|
||||
}
|
||||
|
||||
push(@args, "-nologo");
|
||||
push(@args, "-v");
|
||||
push(@args, @input);
|
||||
|
||||
unshift(@args, "rc.exe");
|
||||
printf("**** @args\n");
|
||||
|
||||
exit (system(@args) != 0);
|
||||
@@ -401,7 +401,7 @@ ifeq ($(uname_S),Windows)
|
||||
# link.exe next to, and required by, cl.exe, we have to prepend this
|
||||
# onto the existing $PATH.
|
||||
#
|
||||
SANE_TOOL_PATH ?= $(msvc_bin_dir_msys)
|
||||
SANE_TOOL_PATH ?= $(msvc_bin_dir_msys):$(sdk_ver_bin_dir_msys)
|
||||
HAVE_ALLOCA_H = YesPlease
|
||||
NO_PREAD = YesPlease
|
||||
NEEDS_CRYPTO_WITH_SSL = YesPlease
|
||||
@@ -456,12 +456,14 @@ endif
|
||||
compat/win32/trace2_win32_process_info.o \
|
||||
compat/win32/dirent.o compat/win32/fscache.o
|
||||
COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DDETECT_MSYS_TTY -DENSURE_MSYSTEM_IS_SET -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
|
||||
BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -ENTRY:wmainCRTStartup -SUBSYSTEM:CONSOLE
|
||||
BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO
|
||||
# invalidcontinue.obj allows Git's source code to close the same file
|
||||
# handle twice, or to access the osfhandle of an already-closed stdout
|
||||
# See https://msdn.microsoft.com/en-us/library/ms235330.aspx
|
||||
EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj kernel32.lib ntdll.lib
|
||||
GITLIBS += git.res
|
||||
PTHREAD_LIBS =
|
||||
RC = compat/vcbuild/scripts/rc.pl
|
||||
lib =
|
||||
BASIC_CFLAGS += $(vcpkg_inc) $(sdk_includes) $(msvc_includes)
|
||||
ifndef DEBUG
|
||||
|
||||
@@ -76,7 +76,7 @@ sub createProject {
|
||||
|
||||
my $libs_release = "\n ";
|
||||
my $libs_debug = "\n ";
|
||||
if (!$static_library) {
|
||||
if (!$static_library && $name ne 'headless-git') {
|
||||
$libs_release = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib|vcs-svn\/lib\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}}));
|
||||
$libs_debug = $libs_release;
|
||||
$libs_debug =~ s/zlib\.lib/zlibd\.lib/g;
|
||||
@@ -89,6 +89,16 @@ sub createProject {
|
||||
$defines =~ s/>/>/g;
|
||||
$defines =~ s/\'//g;
|
||||
|
||||
my $rcdefines = $defines;
|
||||
$rcdefines =~ s/(?<!\\)"/\\$&/g;
|
||||
|
||||
my $entrypoint = 'wmainCRTStartup';
|
||||
my $subsystem = 'Console';
|
||||
if (grep /^-mwindows$/, @{$$build_structure{"$prefix${name}_LFLAGS"}}) {
|
||||
$entrypoint = 'wWinMainCRTStartup';
|
||||
$subsystem = 'Windows';
|
||||
}
|
||||
|
||||
my $dir = $vcxproj;
|
||||
$dir =~ s/\/[^\/]*$//;
|
||||
die "Could not create the directory $dir for $label project!\n" unless (-d "$dir" || mkdir "$dir");
|
||||
@@ -185,9 +195,9 @@ sub createProject {
|
||||
<AdditionalLibraryDirectories>\$(VCPKGLibDirectory);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>\$(VCPKGLibs);\$(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalOptions>invalidcontinue.obj %(AdditionalOptions)</AdditionalOptions>
|
||||
<EntryPointSymbol>wmainCRTStartup</EntryPointSymbol>
|
||||
<EntryPointSymbol>$entrypoint</EntryPointSymbol>
|
||||
<ManifestFile>$cdup\\compat\\win32\\git.manifest</ManifestFile>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<SubSystem>$subsystem</SubSystem>
|
||||
</Link>
|
||||
EOM
|
||||
if ($target eq 'libgit') {
|
||||
@@ -212,6 +222,9 @@ EOM
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;$defines;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;$rcdefines;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
@@ -225,6 +238,9 @@ EOM
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;$rcdefines;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
@@ -234,14 +250,20 @@ EOM
|
||||
<ItemGroup>
|
||||
EOM
|
||||
foreach(@sources) {
|
||||
print F << "EOM";
|
||||
if (/\.rc$/) {
|
||||
print F << "EOM";
|
||||
<ResourceCompile Include="$_" />
|
||||
EOM
|
||||
} else {
|
||||
print F << "EOM";
|
||||
<ClCompile Include="$_" />
|
||||
EOM
|
||||
}
|
||||
}
|
||||
print F << "EOM";
|
||||
</ItemGroup>
|
||||
EOM
|
||||
if (!$static_library || $target =~ 'vcs-svn' || $target =~ 'xdiff') {
|
||||
if ((!$static_library || $target =~ 'vcs-svn' || $target =~ 'xdiff') && !($name =~ /headless-git/)) {
|
||||
my $uuid_libgit = $$build_structure{"LIBS_libgit_GUID"};
|
||||
my $uuid_xdiff_lib = $$build_structure{"LIBS_xdiff/lib_GUID"};
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ sub parseMakeOutput
|
||||
next;
|
||||
}
|
||||
|
||||
if($text =~ / -c /) {
|
||||
if($text =~ / -c / || $text =~ / -i \S+\.rc /) {
|
||||
# compilation
|
||||
handleCompileLine($text, $line);
|
||||
|
||||
@@ -263,16 +263,15 @@ sub handleCompileLine
|
||||
if ("$part" eq "-o") {
|
||||
# ignore object file
|
||||
shift @parts;
|
||||
} elsif ("$part" eq "-c") {
|
||||
} elsif ("$part" eq "-c" || "$part" eq "-i" || "$part" =~ /^-fno-/) {
|
||||
# ignore compile flag
|
||||
} elsif ("$part" eq "-c") {
|
||||
} elsif ($part =~ /^.?-I/) {
|
||||
push(@incpaths, $part);
|
||||
} elsif ($part =~ /^.?-D/) {
|
||||
push(@defines, $part);
|
||||
} elsif ($part =~ /^-/) {
|
||||
push(@cflags, $part);
|
||||
} elsif ($part =~ /\.(c|cc|cpp)$/) {
|
||||
} elsif ($part =~ /\.(c|cc|cpp|rc)$/) {
|
||||
$sourcefile = $part;
|
||||
} else {
|
||||
die "Unhandled compiler option @ line $lineno: $part";
|
||||
@@ -359,7 +358,7 @@ sub handleLinkLine
|
||||
push(@libs, $part);
|
||||
} elsif ($part eq 'invalidcontinue.obj') {
|
||||
# ignore - known to MSVC
|
||||
} elsif ($part =~ /\.o$/) {
|
||||
} elsif ($part =~ /\.(o|res)$/) {
|
||||
push(@objfiles, $part);
|
||||
} elsif ($part =~ /\.obj$/) {
|
||||
# do nothing, 'make' should not be producing .obj, only .o files
|
||||
@@ -371,7 +370,9 @@ sub handleLinkLine
|
||||
# exit(1);
|
||||
foreach (@objfiles) {
|
||||
my $sourcefile = $_;
|
||||
$sourcefile =~ s/^headless-git\.o$/compat\/win32\/headless.c/;
|
||||
$sourcefile =~ s/\.o$/.c/;
|
||||
$sourcefile =~ s/\.res$/.rc/;
|
||||
push(@sources, $sourcefile);
|
||||
push(@cflags, @{$compile_options{"${sourcefile}_CFLAGS"}});
|
||||
push(@defines, @{$compile_options{"${sourcefile}_DEFINES"}});
|
||||
|
||||
Reference in New Issue
Block a user