2009-09-16 10:20:28 +02:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
######################################################################
|
|
|
|
# Compiles or links files
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
# Copyright (C) 2009 Marius Storm-Olsen <mstormo@gmail.com>
|
|
|
|
######################################################################
|
|
|
|
use strict;
|
|
|
|
my @args = ();
|
|
|
|
my @cflags = ();
|
2019-06-25 16:49:39 +02:00
|
|
|
my @lflags = ();
|
2009-09-16 10:20:28 +02:00
|
|
|
my $is_linking = 0;
|
2019-06-25 16:49:39 +02:00
|
|
|
my $is_debug = 0;
|
2009-09-16 10:20:28 +02:00
|
|
|
while (@ARGV) {
|
|
|
|
my $arg = shift @ARGV;
|
2019-06-25 16:49:39 +02:00
|
|
|
if ("$arg" eq "-DDEBUG") {
|
|
|
|
# Some vcpkg-based libraries have different names for release
|
|
|
|
# and debug versions. This hack assumes that -DDEBUG comes
|
|
|
|
# before any "-l*" flags.
|
|
|
|
$is_debug = 1;
|
|
|
|
}
|
2020-06-04 23:09:56 +02:00
|
|
|
if ("$arg" =~ /^-I\/mingw(32|64)/) {
|
|
|
|
# eat
|
|
|
|
} elsif ("$arg" =~ /^-[DIMGOZ]/) {
|
2009-09-16 10:20:28 +02:00
|
|
|
push(@cflags, $arg);
|
|
|
|
} elsif ("$arg" eq "-o") {
|
|
|
|
my $file_out = shift @ARGV;
|
|
|
|
if ("$file_out" =~ /exe$/) {
|
|
|
|
$is_linking = 1;
|
2019-06-25 16:49:39 +02:00
|
|
|
# Create foo.exe and foo.pdb
|
2009-09-16 10:20:28 +02:00
|
|
|
push(@args, "-OUT:$file_out");
|
|
|
|
} else {
|
2019-06-25 16:49:39 +02:00
|
|
|
# Create foo.o and foo.o.pdb
|
2009-09-16 10:20:28 +02:00
|
|
|
push(@args, "-Fo$file_out");
|
2019-06-25 16:49:39 +02:00
|
|
|
push(@args, "-Fd$file_out.pdb");
|
2009-09-16 10:20:28 +02:00
|
|
|
}
|
|
|
|
} elsif ("$arg" eq "-lz") {
|
2019-06-25 16:49:39 +02:00
|
|
|
if ($is_debug) {
|
|
|
|
push(@args, "zlibd.lib");
|
|
|
|
} else{
|
2009-09-16 10:20:28 +02:00
|
|
|
push(@args, "zlib.lib");
|
2019-06-25 16:49:39 +02:00
|
|
|
}
|
2009-09-16 10:20:28 +02:00
|
|
|
} elsif ("$arg" eq "-liconv") {
|
2020-12-04 15:22:20 +01:00
|
|
|
push(@args, "iconv.lib");
|
2009-10-21 19:04:51 +02:00
|
|
|
} elsif ("$arg" eq "-lcrypto") {
|
2020-01-15 23:57:34 +01:00
|
|
|
push(@args, "libcrypto.lib");
|
2010-01-20 20:25:51 +01:00
|
|
|
} elsif ("$arg" eq "-lssl") {
|
2020-01-15 23:57:34 +01:00
|
|
|
push(@args, "libssl.lib");
|
2014-03-27 08:34:27 +01:00
|
|
|
} elsif ("$arg" eq "-lcurl") {
|
2019-06-25 16:49:39 +02:00
|
|
|
my $lib = "";
|
|
|
|
# Newer vcpkg definitions call this libcurl_imp.lib; Do we
|
|
|
|
# need to use that instead?
|
|
|
|
foreach my $flag (@lflags) {
|
|
|
|
if ($flag =~ /^-LIBPATH:(.*)/) {
|
|
|
|
foreach my $l ("libcurl_imp.lib", "libcurl.lib") {
|
|
|
|
if (-f "$1/$l") {
|
|
|
|
$lib = $l;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
push(@args, $lib);
|
|
|
|
} elsif ("$arg" eq "-lexpat") {
|
2020-09-02 22:16:38 +02:00
|
|
|
push(@args, "libexpat.lib");
|
2009-09-16 10:20:28 +02:00
|
|
|
} elsif ("$arg" =~ /^-L/ && "$arg" ne "-LTCG") {
|
|
|
|
$arg =~ s/^-L/-LIBPATH:/;
|
2019-06-25 16:49:39 +02:00
|
|
|
push(@lflags, $arg);
|
2019-10-04 17:09:29 +02:00
|
|
|
} elsif ("$arg" =~ /^-[Rl]/) {
|
2009-09-16 10:20:28 +02:00
|
|
|
# eat
|
2019-10-04 17:09:30 +02:00
|
|
|
} elsif ("$arg" eq "-Werror") {
|
|
|
|
push(@cflags, "-WX");
|
|
|
|
} elsif ("$arg" eq "-Wall") {
|
|
|
|
# cl.exe understands -Wall, but it is really overzealous
|
|
|
|
push(@cflags, "-W4");
|
|
|
|
# disable the "signed/unsigned mismatch" warnings; our source code violates that
|
|
|
|
push(@cflags, "-wd4018");
|
|
|
|
push(@cflags, "-wd4245");
|
|
|
|
push(@cflags, "-wd4389");
|
|
|
|
# disable the "unreferenced formal parameter" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4100");
|
|
|
|
# disable the "conditional expression is constant" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4127");
|
|
|
|
# disable the "const object should be initialized" warning; these warnings affect only objects that are `static`
|
|
|
|
push(@cflags, "-wd4132");
|
|
|
|
# disable the "function/data pointer conversion in expression" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4152");
|
|
|
|
# disable the "non-constant aggregate initializer" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4204");
|
|
|
|
# disable the "cannot be initialized using address of automatic variable" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4221");
|
|
|
|
# disable the "possible loss of data" warnings; our source code violates that
|
|
|
|
push(@cflags, "-wd4244");
|
|
|
|
push(@cflags, "-wd4267");
|
|
|
|
# disable the "array is too small to include a terminating null character" warning; we ab-use strings to initialize OIDs
|
|
|
|
push(@cflags, "-wd4295");
|
|
|
|
# disable the "'<<': result of 32-bit shift implicitly converted to 64 bits" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4334");
|
|
|
|
# disable the "declaration hides previous local declaration" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4456");
|
|
|
|
# disable the "declaration hides function parameter" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4457");
|
|
|
|
# disable the "declaration hides global declaration" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4459");
|
|
|
|
# disable the "potentially uninitialized local variable '<name>' used" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4701");
|
|
|
|
# disable the "unreachable code" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4702");
|
|
|
|
# disable the "potentially uninitialized local pointer variable used" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4703");
|
|
|
|
# disable the "assignment within conditional expression" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4706");
|
|
|
|
# disable the "'inet_ntoa': Use inet_ntop() or InetNtop() instead" warning; our source code violates that
|
|
|
|
push(@cflags, "-wd4996");
|
|
|
|
} elsif ("$arg" =~ /^-W[a-z]/) {
|
|
|
|
# let's ignore those
|
2009-09-16 10:20:28 +02:00
|
|
|
} else {
|
|
|
|
push(@args, $arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($is_linking) {
|
2019-06-25 16:49:39 +02:00
|
|
|
push(@args, @lflags);
|
2009-09-16 10:20:28 +02:00
|
|
|
unshift(@args, "link.exe");
|
|
|
|
} else {
|
|
|
|
unshift(@args, "cl.exe");
|
|
|
|
push(@args, @cflags);
|
|
|
|
}
|
2019-06-25 16:49:39 +02:00
|
|
|
printf(STDERR "**** @args\n\n\n") if (!defined($ENV{'QUIET_GEN'}));
|
Fix the exit code of MSVC build scripts on cygwin
During an MSVC build on cygwin, the make program did not notice
when the compiler or linker exited with an error. This was caused
by the scripts exiting with the value returned by system() directly.
On POSIX-like systems, such as cygwin, the return value of system()
has the exit code of the executed command encoded in the first byte
(ie the value is shifted up by 8 bits). This allows the bottom
7 bits to contain the signal number of a terminated process, while
the eighth bit indicates whether a core-dump was produced. (A value
of -1 indicates that the command failed to execute.)
The make program, however, expects the exit code to be encoded in the
bottom byte. Futhermore, it apparently masks off and ignores anything
in the upper bytes.
However, these scripts are (naturally) intended to be used on the
windows platform, where we can not assume POSIX-like semantics from
a perl implementation (eg ActiveState). So, in general, we can not
assume that shifting the return value right by eight will get us
the exit code.
In order to improve portability, we assume that a zero return from
system() indicates success, whereas anything else indicates failure.
Since we don't need to know the exact exit code from the compiler
or linker, we simply exit with 0 (success) or 1 (failure).
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-10-08 17:33:31 +02:00
|
|
|
exit (system(@args) != 0);
|