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