Commit | Line | Data |
---|---|---|
506098d4 DG |
1 | package ExtUtils::CBuilder::Platform::Windows::MSVC; |
2 | ||
3 | use vars qw($VERSION); | |
d3413324 | 4 | $VERSION = '0.2802'; |
506098d4 DG |
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 | ||
68 | $spec{def_file} &&= '-def:' . $spec{def_file}; | |
69 | $spec{output} &&= '-out:' . $spec{output}; | |
70 | $spec{manifest} &&= '-manifest ' . $spec{manifest}; | |
71 | $spec{implib} &&= '-implib:' . $spec{implib}; | |
72 | $spec{map_file} &&= '-map:' . $spec{map_file}; | |
73 | ||
74 | %spec = $self->write_linker_script(%spec) | |
75 | if $spec{use_scripts}; | |
76 | ||
77 | my @cmds; # Stores the series of commands needed to build the module. | |
78 | ||
79 | push @cmds, [ grep {defined && length} ( | |
80 | $spec{ld} , | |
81 | @{$spec{lddlflags}} , | |
82 | @{$spec{libpath}} , | |
83 | @{$spec{other_ldflags}} , | |
84 | @{$spec{startup}} , | |
85 | @{$spec{objects}} , | |
86 | $spec{map_file} , | |
87 | $spec{libperl} , | |
88 | @{$spec{perllibs}} , | |
89 | $spec{def_file} , | |
90 | $spec{implib} , | |
91 | $spec{output} , | |
92 | ) ]; | |
93 | ||
94 | # Embed the manifest file if it exists | |
95 | push @cmds, [ | |
96 | 'if', 'exist', $spec{manifest}, 'mt', '-nologo', $spec{manifest}, '-outputresource:' . "$output;2" | |
97 | ]; | |
98 | ||
99 | return @cmds; | |
100 | } | |
101 | ||
102 | sub write_linker_script { | |
103 | my ($self, %spec) = @_; | |
104 | ||
105 | my $script = File::Spec->catfile( $spec{srcdir}, | |
106 | $spec{basename} . '.lds' ); | |
107 | ||
108 | $self->add_to_cleanup($script); | |
109 | ||
110 | print "Generating script '$script'\n" if !$self->{quiet}; | |
111 | ||
112 | my $SCRIPT = IO::File->new( ">$script" ) | |
113 | or die( "Could not create script '$script': $!" ); | |
114 | ||
115 | print $SCRIPT join( "\n", | |
116 | map { ref $_ ? @{$_} : $_ } | |
117 | grep defined, | |
118 | delete( | |
119 | @spec{ qw(lddlflags libpath other_ldflags | |
120 | startup objects libperl perllibs | |
121 | def_file implib map_file) } ) | |
122 | ); | |
123 | ||
124 | push @{$spec{lddlflags}}, '@"' . $script . '"'; | |
125 | ||
126 | return %spec; | |
127 | } | |
128 | ||
129 | 1; | |
130 | ||
131 |