]> git.ipfire.org Git - thirdparty/git.git/blame - compat/vcbuild/scripts/clink.pl
The sixth batch
[thirdparty/git.git] / compat / vcbuild / scripts / clink.pl
CommitLineData
164a5e3f
MSO
1#!/usr/bin/perl -w
2######################################################################
3# Compiles or links files
4#
5# This is a wrapper to facilitate the compilation of Git with MSVC
6# using GNU Make as the build system. So, instead of manipulating the
7# Makefile into something nasty, just to support non-space arguments
8# etc, we use this wrapper to fix the command line options
9#
10# Copyright (C) 2009 Marius Storm-Olsen <mstormo@gmail.com>
11######################################################################
12use strict;
13my @args = ();
14my @cflags = ();
dce7d295 15my @lflags = ();
164a5e3f 16my $is_linking = 0;
dce7d295 17my $is_debug = 0;
164a5e3f
MSO
18while (@ARGV) {
19 my $arg = shift @ARGV;
dce7d295
JH
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 }
bb0e43d8
JS
26 if ("$arg" =~ /^-I\/mingw(32|64)/) {
27 # eat
28 } elsif ("$arg" =~ /^-[DIMGOZ]/) {
164a5e3f
MSO
29 push(@cflags, $arg);
30 } elsif ("$arg" eq "-o") {
31 my $file_out = shift @ARGV;
32 if ("$file_out" =~ /exe$/) {
33 $is_linking = 1;
dce7d295 34 # Create foo.exe and foo.pdb
164a5e3f
MSO
35 push(@args, "-OUT:$file_out");
36 } else {
dce7d295 37 # Create foo.o and foo.o.pdb
164a5e3f 38 push(@args, "-Fo$file_out");
dce7d295 39 push(@args, "-Fd$file_out.pdb");
164a5e3f
MSO
40 }
41 } elsif ("$arg" eq "-lz") {
dce7d295
JH
42 if ($is_debug) {
43 push(@args, "zlibd.lib");
44 } else{
164a5e3f 45 push(@args, "zlib.lib");
dce7d295 46 }
164a5e3f 47 } elsif ("$arg" eq "-liconv") {
e6659034 48 push(@args, "iconv.lib");
c36e1638 49 } elsif ("$arg" eq "-lcrypto") {
b6d4d82b 50 push(@args, "libcrypto.lib");
38743b7d 51 } elsif ("$arg" eq "-lssl") {
b6d4d82b 52 push(@args, "libssl.lib");
da8daa36 53 } elsif ("$arg" eq "-lcurl") {
dce7d295
JH
54 my $lib = "";
55 # Newer vcpkg definitions call this libcurl_imp.lib; Do we
56 # need to use that instead?
57 foreach my $flag (@lflags) {
58 if ($flag =~ /^-LIBPATH:(.*)/) {
59 foreach my $l ("libcurl_imp.lib", "libcurl.lib") {
60 if (-f "$1/$l") {
61 $lib = $l;
62 last;
63 }
64 }
65 }
66 }
67 push(@args, $lib);
68 } elsif ("$arg" eq "-lexpat") {
c2f3ef8d 69 push(@args, "libexpat.lib");
164a5e3f
MSO
70 } elsif ("$arg" =~ /^-L/ && "$arg" ne "-LTCG") {
71 $arg =~ s/^-L/-LIBPATH:/;
dce7d295 72 push(@lflags, $arg);
ed712ef8 73 } elsif ("$arg" =~ /^-[Rl]/) {
164a5e3f 74 # eat
e4347c94
JS
75 } elsif ("$arg" eq "-Werror") {
76 push(@cflags, "-WX");
77 } elsif ("$arg" eq "-Wall") {
78 # cl.exe understands -Wall, but it is really overzealous
79 push(@cflags, "-W4");
80 # disable the "signed/unsigned mismatch" warnings; our source code violates that
81 push(@cflags, "-wd4018");
82 push(@cflags, "-wd4245");
83 push(@cflags, "-wd4389");
84 # disable the "unreferenced formal parameter" warning; our source code violates that
85 push(@cflags, "-wd4100");
86 # disable the "conditional expression is constant" warning; our source code violates that
87 push(@cflags, "-wd4127");
88 # disable the "const object should be initialized" warning; these warnings affect only objects that are `static`
89 push(@cflags, "-wd4132");
90 # disable the "function/data pointer conversion in expression" warning; our source code violates that
91 push(@cflags, "-wd4152");
92 # disable the "non-constant aggregate initializer" warning; our source code violates that
93 push(@cflags, "-wd4204");
94 # disable the "cannot be initialized using address of automatic variable" warning; our source code violates that
95 push(@cflags, "-wd4221");
96 # disable the "possible loss of data" warnings; our source code violates that
97 push(@cflags, "-wd4244");
98 push(@cflags, "-wd4267");
99 # disable the "array is too small to include a terminating null character" warning; we ab-use strings to initialize OIDs
100 push(@cflags, "-wd4295");
101 # disable the "'<<': result of 32-bit shift implicitly converted to 64 bits" warning; our source code violates that
102 push(@cflags, "-wd4334");
103 # disable the "declaration hides previous local declaration" warning; our source code violates that
104 push(@cflags, "-wd4456");
105 # disable the "declaration hides function parameter" warning; our source code violates that
106 push(@cflags, "-wd4457");
107 # disable the "declaration hides global declaration" warning; our source code violates that
108 push(@cflags, "-wd4459");
109 # disable the "potentially uninitialized local variable '<name>' used" warning; our source code violates that
110 push(@cflags, "-wd4701");
111 # disable the "unreachable code" warning; our source code violates that
112 push(@cflags, "-wd4702");
113 # disable the "potentially uninitialized local pointer variable used" warning; our source code violates that
114 push(@cflags, "-wd4703");
115 # disable the "assignment within conditional expression" warning; our source code violates that
116 push(@cflags, "-wd4706");
117 # disable the "'inet_ntoa': Use inet_ntop() or InetNtop() instead" warning; our source code violates that
118 push(@cflags, "-wd4996");
119 } elsif ("$arg" =~ /^-W[a-z]/) {
120 # let's ignore those
164a5e3f
MSO
121 } else {
122 push(@args, $arg);
123 }
124}
125if ($is_linking) {
dce7d295 126 push(@args, @lflags);
164a5e3f
MSO
127 unshift(@args, "link.exe");
128} else {
129 unshift(@args, "cl.exe");
130 push(@args, @cflags);
131}
dce7d295 132printf(STDERR "**** @args\n\n\n") if (!defined($ENV{'QUIET_GEN'}));
b5d18b8e 133exit (system(@args) != 0);