This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bump the perl version in various places ready for 5.35.3
[perl5.git] / dist / ExtUtils-CBuilder / lib / ExtUtils / CBuilder / Platform / Windows / GCC.pm
CommitLineData
506098d4 1package ExtUtils::CBuilder::Platform::Windows::GCC;
c39276c1 2
4371f648 3our $VERSION = '0.280236'; # VERSION
c39276c1 4
83dcc064
SH
5use warnings;
6use strict;
7
506098d4
DG
8sub format_compiler_cmd {
9 my ($self, %spec) = @_;
10
11 foreach my $path ( @{ $spec{includes} || [] },
12 @{ $spec{perlinc} || [] } ) {
13 $path = '-I' . $path;
14 }
15
16 # split off any -arguments included in cc
17 my @cc = split / (?=-)/, $spec{cc};
18
19 return [ grep {defined && length} (
20 @cc, '-c' ,
21 @{$spec{includes}} ,
22 @{$spec{cflags}} ,
23 @{$spec{optimize}} ,
24 @{$spec{defines}} ,
25 @{$spec{perlinc}} ,
26 '-o', $spec{output} ,
27 $spec{source} ,
28 ) ];
29}
30
31sub format_linker_cmd {
32 my ($self, %spec) = @_;
33 my $cf = $self->{config};
34
35 # The Config.pm variable 'libperl' is hardcoded to the full name
36 # of the perl import library (i.e. 'libperl56.a'). GCC will not
37 # find it unless the 'lib' prefix & the extension are stripped.
38 $spec{libperl} =~ s/^(?:lib)?([^.]+).*$/-l$1/;
39
40 unshift( @{$spec{other_ldflags}}, '-nostartfiles' )
41 if ( $spec{startup} && @{$spec{startup}} );
42
506098d4
DG
43 %spec = $self->write_linker_script(%spec)
44 if $spec{use_scripts};
45
46 foreach my $path ( @{$spec{libpath}} ) {
47 $path = "-L$path";
48 }
49
50 my @cmds; # Stores the series of commands needed to build the module.
51
52 my $DLLTOOL = $cf->{dlltool} || 'dlltool';
53
54 push @cmds, [
55 $DLLTOOL, '--def' , $spec{def_file},
56 '--output-exp' , $spec{explib}
57 ];
58
59 # split off any -arguments included in ld
60 my @ld = split / (?=-)/, $spec{ld};
61
62 push @cmds, [ grep {defined && length} (
63 @ld ,
64 '-o', $spec{output} ,
65 "-Wl,--base-file,$spec{base_file}" ,
4371f648 66 "-Wl,--enable-auto-image-base" ,
506098d4
DG
67 @{$spec{lddlflags}} ,
68 @{$spec{libpath}} ,
69 @{$spec{startup}} ,
70 @{$spec{objects}} ,
71 @{$spec{other_ldflags}} ,
72 $spec{libperl} ,
73 @{$spec{perllibs}} ,
74 $spec{explib} ,
75 $spec{map_file} ? ('-Map', $spec{map_file}) : ''
76 ) ];
77
78 push @cmds, [
79 $DLLTOOL, '--def' , $spec{def_file},
80 '--output-exp' , $spec{explib},
81 '--base-file' , $spec{base_file}
82 ];
83
84 push @cmds, [ grep {defined && length} (
85 @ld ,
86 '-o', $spec{output} ,
4371f648 87 "-Wl,--enable-auto-image-base" ,
506098d4
DG
88 @{$spec{lddlflags}} ,
89 @{$spec{libpath}} ,
90 @{$spec{startup}} ,
91 @{$spec{objects}} ,
92 @{$spec{other_ldflags}} ,
93 $spec{libperl} ,
94 @{$spec{perllibs}} ,
95 $spec{explib} ,
96 $spec{map_file} ? ('-Map', $spec{map_file}) : ''
97 ) ];
98
99 return @cmds;
100}
101
102sub 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 ( 'SEARCH_DIR(' . $_ . ")\n" )
116 for @{delete $spec{libpath} || []};
117
118 # gcc takes only one startup file, so the first object in startup is
119 # specified as the startup file and any others are shifted into the
120 # beginning of the list of objects.
121 if ( $spec{startup} && @{$spec{startup}} ) {
122 print $SCRIPT 'STARTUP(' . shift( @{$spec{startup}} ) . ")\n";
123 unshift @{$spec{objects}},
124 @{delete $spec{startup} || []};
125 }
126
127 print $SCRIPT 'INPUT(' . join( ',',
128 @{delete $spec{objects} || []}
129 ) . ")\n";
130
131 print $SCRIPT 'INPUT(' . join( ' ',
132 (delete $spec{libperl} || ''),
133 @{delete $spec{perllibs} || []},
134 ) . ")\n";
135
136 #it is important to keep the order 1.linker_script - 2.other_ldflags
137 unshift @{$spec{other_ldflags}}, '"' . $script . '"';
138
139 return %spec;
140}
141
1421;
143
144