]> git.ipfire.org Git - thirdparty/git.git/blame - compat/vcbuild/scripts/clink.pl
compat/win32/path-utils.h: add #include guards
[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 }
26 if ("$arg" =~ /^-[DIMGOZ]/) {
164a5e3f
MSO
27 push(@cflags, $arg);
28 } elsif ("$arg" eq "-o") {
29 my $file_out = shift @ARGV;
30 if ("$file_out" =~ /exe$/) {
31 $is_linking = 1;
dce7d295 32 # Create foo.exe and foo.pdb
164a5e3f
MSO
33 push(@args, "-OUT:$file_out");
34 } else {
dce7d295 35 # Create foo.o and foo.o.pdb
164a5e3f 36 push(@args, "-Fo$file_out");
dce7d295 37 push(@args, "-Fd$file_out.pdb");
164a5e3f
MSO
38 }
39 } elsif ("$arg" eq "-lz") {
dce7d295
JH
40 if ($is_debug) {
41 push(@args, "zlibd.lib");
42 } else{
164a5e3f 43 push(@args, "zlib.lib");
dce7d295 44 }
164a5e3f 45 } elsif ("$arg" eq "-liconv") {
dce7d295 46 push(@args, "libiconv.lib");
c36e1638
MSO
47 } elsif ("$arg" eq "-lcrypto") {
48 push(@args, "libeay32.lib");
38743b7d 49 } elsif ("$arg" eq "-lssl") {
c36e1638 50 push(@args, "ssleay32.lib");
da8daa36 51 } elsif ("$arg" eq "-lcurl") {
dce7d295
JH
52 my $lib = "";
53 # Newer vcpkg definitions call this libcurl_imp.lib; Do we
54 # need to use that instead?
55 foreach my $flag (@lflags) {
56 if ($flag =~ /^-LIBPATH:(.*)/) {
57 foreach my $l ("libcurl_imp.lib", "libcurl.lib") {
58 if (-f "$1/$l") {
59 $lib = $l;
60 last;
61 }
62 }
63 }
64 }
65 push(@args, $lib);
66 } elsif ("$arg" eq "-lexpat") {
67 push(@args, "expat.lib");
164a5e3f
MSO
68 } elsif ("$arg" =~ /^-L/ && "$arg" ne "-LTCG") {
69 $arg =~ s/^-L/-LIBPATH:/;
dce7d295 70 push(@lflags, $arg);
164a5e3f
MSO
71 } elsif ("$arg" =~ /^-R/) {
72 # eat
73 } else {
74 push(@args, $arg);
75 }
76}
77if ($is_linking) {
dce7d295 78 push(@args, @lflags);
164a5e3f
MSO
79 unshift(@args, "link.exe");
80} else {
81 unshift(@args, "cl.exe");
82 push(@args, @cflags);
83}
dce7d295 84printf(STDERR "**** @args\n\n\n") if (!defined($ENV{'QUIET_GEN'}));
b5d18b8e 85exit (system(@args) != 0);