| 1 | package ExtUtils::CBuilder::Platform::Windows::MSVC; | ||
| 2 | $ExtUtils::CBuilder::Platform::Windows::MSVC::VERSION = '0.280224'; | ||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | sub arg_exec_file { | ||
| 7 | my ($self, $file) = @_; | ||
| 8 | return "/OUT:$file"; | ||
| 9 | } | ||
| 10 | |||
| 11 | sub format_compiler_cmd { | ||
| 12 | my ($self, %spec) = @_; | ||
| 13 | |||
| 14 | foreach my $path ( @{ $spec{includes} || [] }, | ||
| 15 | @{ $spec{perlinc} || [] } ) { | ||
| 16 | $path = '-I' . $path; | ||
| 17 | } | ||
| 18 | |||
| 19 | %spec = $self->write_compiler_script(%spec) | ||
| 20 | if $spec{use_scripts}; | ||
| 21 | |||
| 22 | return [ grep {defined && length} ( | ||
| 23 | $spec{cc},'-nologo','-c', | ||
| 24 | @{$spec{includes}} , | ||
| 25 | @{$spec{cflags}} , | ||
| 26 | @{$spec{optimize}} , | ||
| 27 | @{$spec{defines}} , | ||
| 28 | @{$spec{perlinc}} , | ||
| 29 | "-Fo$spec{output}" , | ||
| 30 | $spec{source} , | ||
| 31 | ) ]; | ||
| 32 | } | ||
| 33 | |||
| 34 | sub write_compiler_script { | ||
| 35 | my ($self, %spec) = @_; | ||
| 36 | |||
| 37 | my $script = File::Spec->catfile( $spec{srcdir}, | ||
| 38 | $spec{basename} . '.ccs' ); | ||
| 39 | |||
| 40 | $self->add_to_cleanup($script); | ||
| 41 | print "Generating script '$script'\n" if !$self->{quiet}; | ||
| 42 | |||
| 43 | my $SCRIPT = IO::File->new( ">$script" ) | ||
| 44 | or die( "Could not create script '$script': $!" ); | ||
| 45 | |||
| 46 | print $SCRIPT join( "\n", | ||
| 47 | map { ref $_ ? @{$_} : $_ } | ||
| 48 | grep defined, | ||
| 49 | delete( | ||
| 50 | @spec{ qw(includes cflags optimize defines perlinc) } ) | ||
| 51 | ); | ||
| 52 | |||
| 53 | push @{$spec{includes}}, '@"' . $script . '"'; | ||
| 54 | |||
| 55 | return %spec; | ||
| 56 | } | ||
| 57 | |||
| 58 | sub format_linker_cmd { | ||
| 59 | my ($self, %spec) = @_; | ||
| 60 | my $cf = $self->{config}; | ||
| 61 | |||
| 62 | foreach my $path ( @{$spec{libpath}} ) { | ||
| 63 | $path = "-libpath:$path"; | ||
| 64 | } | ||
| 65 | |||
| 66 | my $output = $spec{output}; | ||
| 67 | my $manifest = $spec{manifest}; | ||
| 68 | |||
| 69 | $spec{def_file} &&= '-def:' . $spec{def_file}; | ||
| 70 | $spec{output} &&= '-out:' . $spec{output}; | ||
| 71 | $spec{manifest} &&= '-manifest ' . $spec{manifest}; | ||
| 72 | $spec{implib} &&= '-implib:' . $spec{implib}; | ||
| 73 | $spec{map_file} &&= '-map:' . $spec{map_file}; | ||
| 74 | |||
| 75 | %spec = $self->write_linker_script(%spec) | ||
| 76 | if $spec{use_scripts}; | ||
| 77 | |||
| 78 | my @cmds; # Stores the series of commands needed to build the module. | ||
| 79 | |||
| 80 | push @cmds, [ grep {defined && length} ( | ||
| 81 | $spec{ld} , | ||
| 82 | @{$spec{lddlflags}} , | ||
| 83 | @{$spec{libpath}} , | ||
| 84 | @{$spec{other_ldflags}} , | ||
| 85 | @{$spec{startup}} , | ||
| 86 | @{$spec{objects}} , | ||
| 87 | $spec{map_file} , | ||
| 88 | $spec{libperl} , | ||
| 89 | @{$spec{perllibs}} , | ||
| 90 | $spec{def_file} , | ||
| 91 | $spec{implib} , | ||
| 92 | $spec{output} , | ||
| 93 | ) ]; | ||
| 94 | |||
| 95 | # Embed the manifest file if it exists | ||
| 96 | push @cmds, [ | ||
| 97 | 'if', 'exist', $manifest, 'mt', '-nologo', $spec{manifest}, '-outputresource:' . "$output;2" | ||
| 98 | ]; | ||
| 99 | |||
| 100 | return @cmds; | ||
| 101 | } | ||
| 102 | |||
| 103 | sub write_linker_script { | ||
| 104 | my ($self, %spec) = @_; | ||
| 105 | |||
| 106 | my $script = File::Spec->catfile( $spec{srcdir}, | ||
| 107 | $spec{basename} . '.lds' ); | ||
| 108 | |||
| 109 | $self->add_to_cleanup($script); | ||
| 110 | |||
| 111 | print "Generating script '$script'\n" if !$self->{quiet}; | ||
| 112 | |||
| 113 | my $SCRIPT = IO::File->new( ">$script" ) | ||
| 114 | or die( "Could not create script '$script': $!" ); | ||
| 115 | |||
| 116 | print $SCRIPT join( "\n", | ||
| 117 | map { ref $_ ? @{$_} : $_ } | ||
| 118 | grep defined, | ||
| 119 | delete( | ||
| 120 | @spec{ qw(lddlflags libpath other_ldflags | ||
| 121 | startup objects libperl perllibs | ||
| 122 | def_file implib map_file) } ) | ||
| 123 | ); | ||
| 124 | |||
| 125 | push @{$spec{lddlflags}}, '@"' . $script . '"'; | ||
| 126 | |||
| 127 | return %spec; | ||
| 128 | } | ||
| 129 | |||
| 130 | 1; | ||
| 131 | |||
| 132 |