line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SPVM::Builder::CC; |
2
|
|
|
|
|
|
|
|
3
|
279
|
|
|
279
|
|
91953
|
use strict; |
|
279
|
|
|
|
|
559
|
|
|
279
|
|
|
|
|
8053
|
|
4
|
279
|
|
|
279
|
|
1441
|
use warnings; |
|
279
|
|
|
|
|
521
|
|
|
279
|
|
|
|
|
9017
|
|
5
|
279
|
|
|
279
|
|
1520
|
use Carp 'confess'; |
|
279
|
|
|
|
|
610
|
|
|
279
|
|
|
|
|
12309
|
|
6
|
279
|
|
|
279
|
|
1656
|
use Config; |
|
279
|
|
|
|
|
567
|
|
|
279
|
|
|
|
|
13469
|
|
7
|
|
|
|
|
|
|
|
8
|
279
|
|
|
279
|
|
138385
|
use ExtUtils::CBuilder; |
|
279
|
|
|
|
|
22945244
|
|
|
279
|
|
|
|
|
12108
|
|
9
|
279
|
|
|
279
|
|
138616
|
use File::Copy 'copy', 'move'; |
|
279
|
|
|
|
|
629623
|
|
|
279
|
|
|
|
|
18930
|
|
10
|
279
|
|
|
279
|
|
2284
|
use File::Path 'mkpath'; |
|
279
|
|
|
|
|
871
|
|
|
279
|
|
|
|
|
12890
|
|
11
|
279
|
|
|
279
|
|
2097
|
use File::Find 'find'; |
|
279
|
|
|
|
|
736
|
|
|
279
|
|
|
|
|
11768
|
|
12
|
279
|
|
|
279
|
|
2004
|
use File::Basename 'dirname', 'basename'; |
|
279
|
|
|
|
|
737
|
|
|
279
|
|
|
|
|
13235
|
|
13
|
|
|
|
|
|
|
|
14
|
279
|
|
|
279
|
|
170029
|
use SPVM::Builder::Util; |
|
279
|
|
|
|
|
1320
|
|
|
279
|
|
|
|
|
13693
|
|
15
|
279
|
|
|
279
|
|
134257
|
use SPVM::Builder::Util::API; |
|
279
|
|
|
|
|
760
|
|
|
279
|
|
|
|
|
8576
|
|
16
|
279
|
|
|
279
|
|
1811
|
use SPVM::Builder::Config; |
|
279
|
|
|
|
|
531
|
|
|
279
|
|
|
|
|
5667
|
|
17
|
279
|
|
|
279
|
|
124011
|
use SPVM::Builder::CompileInfo; |
|
279
|
|
|
|
|
1925
|
|
|
279
|
|
|
|
|
12977
|
|
18
|
279
|
|
|
279
|
|
121481
|
use SPVM::Builder::ObjectFileInfo; |
|
279
|
|
|
|
|
801
|
|
|
279
|
|
|
|
|
8081
|
|
19
|
279
|
|
|
279
|
|
124459
|
use SPVM::Builder::LinkInfo; |
|
279
|
|
|
|
|
796
|
|
|
279
|
|
|
|
|
8798
|
|
20
|
279
|
|
|
279
|
|
1820
|
use SPVM::Builder::Resource; |
|
279
|
|
|
|
|
642
|
|
|
279
|
|
|
|
|
954634
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Fields |
23
|
|
|
|
|
|
|
sub build_dir { |
24
|
693
|
|
|
693
|
0
|
2588
|
my $self = shift; |
25
|
693
|
50
|
|
|
|
2960
|
if (@_) { |
26
|
0
|
|
|
|
|
0
|
$self->{build_dir} = $_[0]; |
27
|
0
|
|
|
|
|
0
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
693
|
|
|
|
|
3213
|
return $self->{build_dir}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub force { |
35
|
995
|
|
|
995
|
0
|
3244
|
my $self = shift; |
36
|
995
|
100
|
|
|
|
3907
|
if (@_) { |
37
|
3
|
|
|
|
|
5
|
$self->{force} = $_[0]; |
38
|
3
|
|
|
|
|
9
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
992
|
|
|
|
|
17316
|
return $self->{force}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub quiet { |
46
|
614
|
|
|
614
|
0
|
2317
|
my $self = shift; |
47
|
614
|
100
|
|
|
|
2146
|
if (@_) { |
48
|
4
|
|
|
|
|
10
|
$self->{quiet} = $_[0]; |
49
|
4
|
|
|
|
|
8
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
610
|
|
|
|
|
10061
|
return $self->{quiet}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub at_runtime { |
57
|
605
|
|
|
605
|
0
|
1659
|
my $self = shift; |
58
|
605
|
100
|
|
|
|
2126
|
if (@_) { |
59
|
4
|
|
|
|
|
9
|
$self->{at_runtime} = $_[0]; |
60
|
4
|
|
|
|
|
13
|
return $self; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
601
|
|
|
|
|
3447
|
return $self->{at_runtime}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub debug { |
68
|
871
|
|
|
871
|
0
|
5754
|
my $self = shift; |
69
|
871
|
100
|
|
|
|
4134
|
if (@_) { |
70
|
2
|
|
|
|
|
4
|
$self->{debug} = $_[0]; |
71
|
2
|
|
|
|
|
4
|
return $self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
869
|
|
|
|
|
40621
|
return $self->{debug}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Class Methods |
79
|
|
|
|
|
|
|
sub new { |
80
|
825
|
|
|
825
|
0
|
2929
|
my $class = shift; |
81
|
|
|
|
|
|
|
|
82
|
825
|
|
|
|
|
3443
|
my $self = {@_}; |
83
|
|
|
|
|
|
|
|
84
|
825
|
|
|
|
|
2053
|
bless $self, $class; |
85
|
|
|
|
|
|
|
|
86
|
825
|
|
|
|
|
3666
|
my $env_spvm_cc_debug = SPVM::Builder::Util::get_normalized_env('SPVM_CC_DEBUG'); |
87
|
825
|
50
|
|
|
|
2598
|
if (defined $env_spvm_cc_debug) { |
88
|
0
|
|
|
|
|
0
|
$self->debug(1); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
825
|
|
|
|
|
2098
|
my $env_spvm_cc_quiet = SPVM::Builder::Util::get_normalized_env('SPVM_CC_QUIET'); |
92
|
825
|
50
|
|
|
|
2636
|
if (defined $env_spvm_cc_quiet) { |
93
|
0
|
|
|
|
|
0
|
$self->quiet(!!$env_spvm_cc_quiet); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
825
|
|
|
|
|
2091
|
my $env_spvm_cc_force = SPVM::Builder::Util::get_normalized_env('SPVM_CC_FORCE'); |
97
|
825
|
50
|
|
|
|
2440
|
if (defined $env_spvm_cc_force) { |
98
|
0
|
|
|
|
|
0
|
$self->force(1); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
825
|
|
|
|
|
2552
|
return $self; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Instance Methods |
105
|
|
|
|
|
|
|
sub resource_src_dir_from_basic_type_name { |
106
|
10
|
|
|
10
|
0
|
36
|
my ($self, $basic_type_name) = @_; |
107
|
|
|
|
|
|
|
|
108
|
10
|
|
|
|
|
153
|
my $config_file = SPVM::Builder::Util::get_config_file_from_basic_type_name($basic_type_name); |
109
|
10
|
|
|
|
|
57
|
my $config_rel_file = SPVM::Builder::Util::convert_basic_type_name_to_rel_file($basic_type_name, 'config'); |
110
|
|
|
|
|
|
|
|
111
|
10
|
|
|
|
|
34
|
my $resource_src_dir = $config_file; |
112
|
10
|
|
|
|
|
600
|
$resource_src_dir =~ s|/\Q$config_rel_file\E$||; |
113
|
|
|
|
|
|
|
|
114
|
10
|
|
|
|
|
70
|
return $resource_src_dir; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub get_resource_object_dir_from_basic_type_name { |
118
|
10
|
|
|
10
|
0
|
63
|
my ($self, $basic_type_name) = @_; |
119
|
|
|
|
|
|
|
|
120
|
10
|
|
|
|
|
47
|
my $module_rel_dir = SPVM::Builder::Util::convert_basic_type_name_to_rel_file($basic_type_name); |
121
|
|
|
|
|
|
|
|
122
|
10
|
|
|
|
|
51
|
my $resource_object_dir = SPVM::Builder::Util::create_build_object_path($self->build_dir, "$module_rel_dir.resource"); |
123
|
|
|
|
|
|
|
|
124
|
10
|
|
|
|
|
78
|
return $resource_object_dir; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub detect_force { |
128
|
989
|
|
|
989
|
0
|
4519
|
my ($self, $config) = @_; |
129
|
|
|
|
|
|
|
|
130
|
989
|
|
|
|
|
2275
|
my $force; |
131
|
|
|
|
|
|
|
|
132
|
989
|
100
|
100
|
|
|
5214
|
if (defined $self->force) { |
|
|
100
|
|
|
|
|
|
133
|
3
|
|
|
|
|
6
|
$force = $self->force; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
elsif (defined $config && defined $config->force) { |
136
|
3
|
|
|
|
|
8
|
$force = $config->force; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else { |
139
|
983
|
|
|
|
|
2213
|
$force = 0; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
989
|
|
|
|
|
3365
|
return $force; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub detect_quiet { |
146
|
609
|
|
|
609
|
0
|
2528
|
my ($self, $config) = @_; |
147
|
|
|
|
|
|
|
|
148
|
609
|
|
|
|
|
1183
|
my $quiet; |
149
|
|
|
|
|
|
|
|
150
|
609
|
100
|
66
|
|
|
3715
|
if (defined $self->debug) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
151
|
2
|
|
|
|
|
3
|
$quiet = 0; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
elsif (defined $self->quiet) { |
154
|
3
|
|
|
|
|
8
|
$quiet = $self->quiet; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
elsif (defined $config && defined $config->quiet) { |
157
|
3
|
|
|
|
|
9
|
$quiet = $config->quiet; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
elsif ($self->at_runtime) { |
160
|
521
|
|
|
|
|
1416
|
$quiet = 1; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
else { |
163
|
80
|
|
|
|
|
226
|
$quiet = 0; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
609
|
|
|
|
|
1715
|
return $quiet; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub build_precompile_module_source_file { |
170
|
309
|
|
|
309
|
0
|
1296
|
my ($self, $basic_type_name, $options) = @_; |
171
|
|
|
|
|
|
|
|
172
|
309
|
|
|
|
|
827
|
my $precompile_source = $options->{precompile_source}; |
173
|
309
|
|
|
|
|
826
|
my $class_file = $options->{class_file}; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# Force |
176
|
309
|
|
|
|
|
1907
|
my $force = $self->detect_force; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# Output - Precompile C source file |
179
|
309
|
|
|
|
|
889
|
my $output_dir = $options->{output_dir}; |
180
|
309
|
|
|
|
|
3110
|
my $source_rel_file = SPVM::Builder::Util::convert_basic_type_name_to_rel_file($basic_type_name, 'precompile.c'); |
181
|
309
|
|
|
|
|
1628
|
my $source_file = "$output_dir/$source_rel_file"; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# Check if generating is needed |
184
|
309
|
|
|
|
|
1161
|
my $spvm_include_dir = $INC{'SPVM/Builder.pm'}; |
185
|
309
|
|
|
|
|
3083
|
$spvm_include_dir =~ s/\.pm$//; |
186
|
309
|
|
|
|
|
1096
|
$spvm_include_dir .= '/src'; |
187
|
309
|
|
|
|
|
1693
|
my $spvm_precompile_soruce_file = "$spvm_include_dir/spvm_precompile.c"; |
188
|
309
|
50
|
|
|
|
8571
|
unless (-f $spvm_precompile_soruce_file) { |
189
|
0
|
|
|
|
|
0
|
confess "Can't find $spvm_precompile_soruce_file"; |
190
|
|
|
|
|
|
|
} |
191
|
309
|
|
|
|
|
5945
|
my $need_generate = SPVM::Builder::Util::need_generate({ |
192
|
|
|
|
|
|
|
force => $force, |
193
|
|
|
|
|
|
|
output_file => $source_file, |
194
|
|
|
|
|
|
|
input_files => [$class_file, $spvm_precompile_soruce_file], |
195
|
|
|
|
|
|
|
}); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# Generate precompile C source file |
198
|
309
|
100
|
|
|
|
2469
|
if ($need_generate) { |
199
|
247
|
|
|
|
|
56729
|
mkpath dirname $source_file; |
200
|
247
|
50
|
|
|
|
52657
|
open my $fh, '>', $source_file |
201
|
|
|
|
|
|
|
or die "Can't create $source_file"; |
202
|
247
|
|
|
|
|
58470
|
print $fh $precompile_source; |
203
|
247
|
|
|
|
|
15252
|
close $fh; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub compile_source_file { |
208
|
339
|
|
|
339
|
0
|
1424
|
my ($self, $compile_info) = @_; |
209
|
|
|
|
|
|
|
|
210
|
339
|
|
|
|
|
2326
|
my $config = $compile_info->config; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# Quiet output |
213
|
339
|
|
|
|
|
2452
|
my $quiet = $self->detect_quiet($config); |
214
|
|
|
|
|
|
|
|
215
|
339
|
|
|
|
|
1964
|
my $source_file = $compile_info->source_file; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# Execute compile command |
218
|
339
|
|
|
|
|
7165
|
my $cbuilder = ExtUtils::CBuilder->new(quiet => 1); |
219
|
339
|
|
|
|
|
15711722
|
my $cc_cmd = $compile_info->create_compile_command; |
220
|
|
|
|
|
|
|
|
221
|
339
|
100
|
|
|
|
1427
|
unless ($quiet) { |
222
|
78
|
|
|
|
|
12129
|
warn "@$cc_cmd\n"; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
339
|
50
|
|
|
|
4867
|
$cbuilder->do_system(@$cc_cmd) |
226
|
|
|
|
|
|
|
or confess "$source_file file cannnot be compiled by the following command:\n@$cc_cmd\n"; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub compile_source_files { |
230
|
342
|
|
|
342
|
0
|
1484
|
my ($self, $basic_type_name, $options) = @_; |
231
|
|
|
|
|
|
|
|
232
|
342
|
|
50
|
|
|
1344
|
$options ||= {}; |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# Category |
235
|
342
|
|
|
|
|
949
|
my $category = $options->{category}; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# Build directory |
238
|
342
|
|
|
|
|
1931
|
my $build_dir = $self->build_dir; |
239
|
342
|
50
|
|
|
|
1232
|
if (defined $build_dir) { |
240
|
342
|
|
|
|
|
10651
|
mkpath $build_dir; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
else { |
243
|
0
|
|
|
|
|
0
|
confess "Build directory is not specified. Maybe forget to set \"SPVM_BUILD_DIR\" environment variable?"; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
# Input directory |
247
|
342
|
|
|
|
|
2159
|
my $input_dir = $options->{input_dir}; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
# Object directory |
250
|
342
|
|
|
|
|
966
|
my $output_dir = $options->{output_dir}; |
251
|
342
|
50
|
33
|
|
|
7492
|
unless (defined $output_dir && -d $output_dir) { |
252
|
0
|
|
|
|
|
0
|
confess "Output directory must exists for " . $options->{category} . " build"; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
# Config |
256
|
342
|
|
|
|
|
1697
|
my $config = $options->{config}; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
# Force compile |
259
|
342
|
|
|
|
|
1645
|
my $force = $self->detect_force($config); |
260
|
|
|
|
|
|
|
|
261
|
342
|
|
|
|
|
929
|
my $ignore_native_module = $options->{ignore_native_module}; |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
# Native class file |
264
|
342
|
|
|
|
|
625
|
my $native_class_file; |
265
|
342
|
100
|
|
|
|
1403
|
unless ($ignore_native_module) { |
266
|
|
|
|
|
|
|
# Native class file |
267
|
332
|
|
|
|
|
1150
|
my $native_module_ext = $config->ext; |
268
|
332
|
50
|
|
|
|
1842
|
unless (defined $native_module_ext) { |
269
|
0
|
|
|
|
|
0
|
confess "Source extension is not specified"; |
270
|
|
|
|
|
|
|
} |
271
|
332
|
|
|
|
|
2156
|
my $native_class_rel_file = SPVM::Builder::Util::convert_basic_type_name_to_category_rel_file($basic_type_name, $category, $native_module_ext); |
272
|
332
|
|
|
|
|
1857
|
$native_class_file = "$input_dir/$native_class_rel_file"; |
273
|
|
|
|
|
|
|
|
274
|
332
|
50
|
|
|
|
6450
|
unless (-f $native_class_file) { |
275
|
0
|
|
|
|
|
0
|
confess "Can't find source file $native_class_file"; |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
# Own resource source files |
280
|
342
|
|
|
|
|
2057
|
my $own_source_files = $config->source_files; |
281
|
342
|
|
|
|
|
1266
|
my $native_src_dir = $config->native_src_dir; |
282
|
342
|
|
|
|
|
885
|
my $resource_src_files; |
283
|
342
|
100
|
|
|
|
1415
|
if (defined $native_src_dir) { |
284
|
33
|
|
|
|
|
154
|
$resource_src_files = [map { "$native_src_dir/$_" } @$own_source_files ]; |
|
28
|
|
|
|
|
167
|
|
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
# Compile source files |
288
|
342
|
|
|
|
|
1014
|
my $object_files = []; |
289
|
342
|
|
|
|
|
833
|
my $is_native_module = 1; |
290
|
342
|
|
|
|
|
1899
|
for my $source_file ($native_class_file, @$resource_src_files) { |
291
|
370
|
|
|
|
|
1039
|
my $current_is_native_module = $is_native_module; |
292
|
370
|
|
|
|
|
810
|
$is_native_module = 0; |
293
|
|
|
|
|
|
|
|
294
|
370
|
100
|
|
|
|
1219
|
next unless defined $source_file; |
295
|
|
|
|
|
|
|
|
296
|
360
|
|
|
|
|
696
|
my $object_file_name; |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
# Object file of native class |
299
|
360
|
100
|
|
|
|
1175
|
if ($current_is_native_module) { |
300
|
332
|
|
|
|
|
1263
|
my $object_rel_file = SPVM::Builder::Util::convert_basic_type_name_to_category_rel_file($basic_type_name, $category, 'o'); |
301
|
332
|
|
|
|
|
2521
|
$object_file_name = "$output_dir/$object_rel_file"; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
# Object file of resource source file |
304
|
|
|
|
|
|
|
else { |
305
|
28
|
|
|
|
|
412
|
my $object_rel_file = SPVM::Builder::Util::convert_basic_type_name_to_category_rel_file($basic_type_name, $category, 'native'); |
306
|
|
|
|
|
|
|
|
307
|
28
|
|
|
|
|
171
|
my $object_file_base = $source_file; |
308
|
28
|
|
|
|
|
851
|
$object_file_base =~ s/^\Q$native_src_dir//; |
309
|
28
|
|
|
|
|
339
|
$object_file_base =~ s/^[\\\/]//; |
310
|
|
|
|
|
|
|
|
311
|
28
|
|
|
|
|
437
|
$object_file_base =~ s/\.[^\.]+$/.o/; |
312
|
28
|
|
|
|
|
236
|
$object_file_name = "$output_dir/$object_rel_file/$object_file_base"; |
313
|
|
|
|
|
|
|
|
314
|
28
|
|
|
|
|
3037
|
my $output_dir = dirname $object_file_name; |
315
|
28
|
|
|
|
|
6275
|
mkpath $output_dir; |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# Check if object file need to be generated |
319
|
360
|
|
|
|
|
979
|
my $need_generate; |
320
|
|
|
|
|
|
|
{ |
321
|
|
|
|
|
|
|
# Own resource header files |
322
|
360
|
|
|
|
|
778
|
my @own_header_files; |
|
360
|
|
|
|
|
746
|
|
323
|
360
|
|
|
|
|
1550
|
my $native_include_dir = $config->native_include_dir; |
324
|
360
|
100
|
100
|
|
|
4352
|
if (defined $native_include_dir && -d $native_include_dir) { |
325
|
|
|
|
|
|
|
find( |
326
|
|
|
|
|
|
|
{ |
327
|
|
|
|
|
|
|
wanted => sub { |
328
|
128
|
|
|
128
|
|
407
|
my $include_file_name = $File::Find::name; |
329
|
128
|
100
|
|
|
|
9691
|
if (-f $include_file_name) { |
330
|
83
|
|
|
|
|
1498
|
push @own_header_files, $include_file_name; |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
}, |
333
|
33
|
|
|
|
|
6753
|
no_chdir => 1, |
334
|
|
|
|
|
|
|
}, |
335
|
|
|
|
|
|
|
$native_include_dir, |
336
|
|
|
|
|
|
|
); |
337
|
|
|
|
|
|
|
} |
338
|
360
|
|
|
|
|
1652
|
my $input_files = [$source_file, @own_header_files]; |
339
|
360
|
100
|
|
|
|
1519
|
if (defined $config->file) { |
340
|
51
|
|
|
|
|
220
|
push @$input_files, $config->file; |
341
|
|
|
|
|
|
|
}; |
342
|
360
|
100
|
|
|
|
1420
|
if ($current_is_native_module) { |
343
|
332
|
|
|
|
|
701
|
my $class_file = $source_file; |
344
|
332
|
|
|
|
|
3049
|
$class_file =~ s/\.[^\/\\]+$//; |
345
|
332
|
|
|
|
|
928
|
$class_file .= '.spvm'; |
346
|
|
|
|
|
|
|
|
347
|
332
|
|
|
|
|
1024
|
push @$input_files, $class_file; |
348
|
|
|
|
|
|
|
} |
349
|
360
|
|
|
|
|
2966
|
$need_generate = SPVM::Builder::Util::need_generate({ |
350
|
|
|
|
|
|
|
force => $force, |
351
|
|
|
|
|
|
|
output_file => $object_file_name, |
352
|
|
|
|
|
|
|
input_files => $input_files, |
353
|
|
|
|
|
|
|
}); |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
# Compile-information |
357
|
360
|
|
|
|
|
7314
|
my $compile_info = SPVM::Builder::CompileInfo->new( |
358
|
|
|
|
|
|
|
output_file => $object_file_name, |
359
|
|
|
|
|
|
|
source_file => $source_file, |
360
|
|
|
|
|
|
|
config => $config, |
361
|
|
|
|
|
|
|
); |
362
|
|
|
|
|
|
|
|
363
|
360
|
|
|
|
|
1579
|
my $before_compile_cbs = $config->before_compile_cbs; |
364
|
360
|
|
|
|
|
1365
|
for my $before_compile_cb (@$before_compile_cbs) { |
365
|
10
|
|
|
|
|
154
|
$before_compile_cb->($config, $compile_info); |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
# Compile a source file |
369
|
360
|
100
|
|
|
|
1425
|
if ($need_generate) { |
370
|
284
|
|
|
|
|
1342
|
my $module_rel_dir = SPVM::Builder::Util::convert_basic_type_name_to_rel_dir($basic_type_name); |
371
|
284
|
|
|
|
|
1405
|
my $work_output_dir = "$output_dir/$module_rel_dir"; |
372
|
284
|
|
|
|
|
32440
|
mkpath dirname $object_file_name; |
373
|
|
|
|
|
|
|
|
374
|
284
|
|
|
|
|
2450
|
$self->compile_source_file($compile_info); |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
# Object file information |
378
|
360
|
|
|
|
|
144374116
|
my $compile_info_cc = $compile_info->{cc}; |
379
|
360
|
|
|
|
|
2922
|
my $compile_info_ccflags = $compile_info->{ccflags}; |
380
|
360
|
|
|
|
|
17903
|
my $object_file = SPVM::Builder::ObjectFileInfo->new( |
381
|
|
|
|
|
|
|
file => $object_file_name, |
382
|
|
|
|
|
|
|
compile_info => $compile_info, |
383
|
|
|
|
|
|
|
); |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
# Add object file information |
386
|
360
|
|
|
|
|
5387
|
push @$object_files, $object_file; |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
|
389
|
342
|
|
|
|
|
8987
|
return $object_files; |
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
sub create_link_info { |
393
|
331
|
|
|
331
|
0
|
2918
|
my ($self, $basic_type_name, $object_files, $config, $options) = @_; |
394
|
|
|
|
|
|
|
|
395
|
331
|
|
|
|
|
1758
|
my $category = $options->{category}; |
396
|
|
|
|
|
|
|
|
397
|
331
|
|
|
|
|
2045
|
my $all_object_files = [@$object_files]; |
398
|
|
|
|
|
|
|
|
399
|
331
|
|
50
|
|
|
2784
|
$options ||= {}; |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
# Linker |
402
|
331
|
|
|
|
|
4768
|
my $ld = $config->ld; |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
# Output type |
405
|
331
|
|
|
|
|
5185
|
my $output_type = $config->output_type; |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
# Libraries |
408
|
331
|
|
|
|
|
2105
|
my $lib_infos = []; |
409
|
331
|
|
|
|
|
3897
|
my $libs = $config->libs; |
410
|
331
|
|
|
|
|
3666
|
my $lib_dirs = $config->lib_dirs; |
411
|
331
|
|
|
|
|
3036
|
for my $lib (@$libs) { |
412
|
3
|
|
|
|
|
40
|
my $lib_info; |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
# Library is linked by file path |
415
|
|
|
|
|
|
|
my $static; |
416
|
3
|
|
|
|
|
0
|
my $lib_name; |
417
|
3
|
|
|
|
|
0
|
my $is_abs; |
418
|
3
|
50
|
|
|
|
61
|
if (ref $lib) { |
419
|
0
|
|
|
|
|
0
|
$static = $lib->is_static; |
420
|
0
|
|
|
|
|
0
|
$lib_name = $lib->name; |
421
|
0
|
|
|
|
|
0
|
$is_abs = $lib->is_abs; |
422
|
0
|
|
|
|
|
0
|
$lib_info = $lib; |
423
|
|
|
|
|
|
|
} |
424
|
|
|
|
|
|
|
else { |
425
|
3
|
|
|
|
|
27
|
$lib_name = $lib; |
426
|
3
|
|
|
|
|
122
|
$lib_info = SPVM::Builder::LibInfo->new; |
427
|
3
|
|
|
|
|
38
|
$lib_info->name($lib_name); |
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
|
430
|
3
|
50
|
|
|
|
57
|
if ($is_abs) { |
431
|
0
|
|
|
|
|
0
|
my $found_lib_file; |
432
|
0
|
|
|
|
|
0
|
for my $lib_dir (@$lib_dirs) { |
433
|
0
|
|
|
|
|
0
|
$lib_dir =~ s|[\\/]$||; |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
# Search dynamic library |
436
|
0
|
0
|
|
|
|
0
|
unless ($static) { |
437
|
0
|
|
|
|
|
0
|
my $dynamic_lib_file_base = "lib$lib_name.$Config{dlext}"; |
438
|
0
|
|
|
|
|
0
|
my $dynamic_lib_file = "$lib_dir/$dynamic_lib_file_base"; |
439
|
|
|
|
|
|
|
|
440
|
0
|
0
|
|
|
|
0
|
if (-f $dynamic_lib_file) { |
441
|
0
|
|
|
|
|
0
|
$found_lib_file = $dynamic_lib_file; |
442
|
0
|
|
|
|
|
0
|
last; |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
} |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
# Search static library |
447
|
0
|
|
|
|
|
0
|
my $static_lib_file_base = "lib$lib_name.a"; |
448
|
0
|
|
|
|
|
0
|
my $static_lib_file = "$lib_dir/$static_lib_file_base"; |
449
|
0
|
0
|
|
|
|
0
|
if (-f $static_lib_file) { |
450
|
0
|
|
|
|
|
0
|
$found_lib_file = $static_lib_file; |
451
|
0
|
|
|
|
|
0
|
last; |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
} |
454
|
|
|
|
|
|
|
|
455
|
0
|
0
|
|
|
|
0
|
if (defined $found_lib_file) { |
456
|
0
|
|
|
|
|
0
|
$lib_info->file = $found_lib_file; |
457
|
|
|
|
|
|
|
} |
458
|
|
|
|
|
|
|
} |
459
|
|
|
|
|
|
|
|
460
|
3
|
|
|
|
|
23
|
push @$lib_infos, $lib_info; |
461
|
|
|
|
|
|
|
} |
462
|
331
|
|
|
|
|
3023
|
$config->libs($lib_infos); |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
# Use resources |
465
|
331
|
|
|
|
|
5234
|
my $resource_names = $config->get_resource_names; |
466
|
331
|
|
|
|
|
2699
|
my $resource_include_dirs = []; |
467
|
331
|
|
|
|
|
1860
|
for my $resource_name (@$resource_names) { |
468
|
10
|
|
|
|
|
91
|
my $resource = $config->get_resource($resource_name); |
469
|
10
|
|
|
|
|
99
|
my $resource_config = $resource->config; |
470
|
10
|
|
|
|
|
96
|
my $resource_include_dir = $resource_config->native_include_dir; |
471
|
10
|
50
|
|
|
|
336
|
if (defined $resource_include_dir) { |
472
|
10
|
|
|
|
|
51
|
push @$resource_include_dirs, $resource_include_dir; |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
|
476
|
331
|
|
|
|
|
1832
|
for my $resource_name (@$resource_names) { |
477
|
10
|
|
|
|
|
113
|
my $resource = $config->get_resource($resource_name); |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
# Build native classes |
480
|
10
|
|
|
|
|
86
|
my $builder_cc_resource = SPVM::Builder::CC->new( |
481
|
|
|
|
|
|
|
build_dir => $self->build_dir, |
482
|
|
|
|
|
|
|
); |
483
|
|
|
|
|
|
|
|
484
|
10
|
|
|
|
|
87
|
my $resource_src_dir = $self->resource_src_dir_from_basic_type_name($resource); |
485
|
10
|
|
|
|
|
68
|
my $resource_object_dir = $self->get_resource_object_dir_from_basic_type_name($basic_type_name); |
486
|
10
|
|
|
|
|
2508
|
mkpath $resource_object_dir; |
487
|
|
|
|
|
|
|
|
488
|
10
|
|
|
|
|
46
|
my $resource_basic_type_name; |
489
|
|
|
|
|
|
|
my $resource_config; |
490
|
10
|
50
|
|
|
|
112
|
if (ref $resource) { |
491
|
10
|
|
|
|
|
60
|
$resource_basic_type_name = $resource->class_name; |
492
|
10
|
|
|
|
|
70
|
$resource_config = $resource->config; |
493
|
|
|
|
|
|
|
} |
494
|
|
|
|
|
|
|
else { |
495
|
0
|
|
|
|
|
0
|
$resource_basic_type_name = $resource; |
496
|
|
|
|
|
|
|
} |
497
|
|
|
|
|
|
|
|
498
|
10
|
|
|
|
|
137
|
$resource_config->add_include_dir(@$resource_include_dirs); |
499
|
|
|
|
|
|
|
|
500
|
10
|
|
|
|
|
76
|
$resource_config->disable_resource(1); |
501
|
10
|
|
|
|
|
152
|
my $compile_options = { |
502
|
|
|
|
|
|
|
input_dir => $resource_src_dir, |
503
|
|
|
|
|
|
|
output_dir => $resource_object_dir, |
504
|
|
|
|
|
|
|
ignore_native_module => 1, |
505
|
|
|
|
|
|
|
config => $resource_config, |
506
|
|
|
|
|
|
|
category => $category, |
507
|
|
|
|
|
|
|
}; |
508
|
|
|
|
|
|
|
|
509
|
10
|
|
|
|
|
177
|
my $object_files = $builder_cc_resource->compile_source_files($resource_basic_type_name, $compile_options); |
510
|
|
|
|
|
|
|
|
511
|
10
|
|
|
|
|
527
|
push @$all_object_files, @$object_files; |
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
# Output file |
515
|
331
|
|
|
|
|
1807
|
my $output_file = $options->{output_file}; |
516
|
331
|
100
|
|
|
|
2557
|
unless (defined $output_file) { |
517
|
|
|
|
|
|
|
# Dynamic library directory |
518
|
329
|
|
|
|
|
1550
|
my $output_dir = $options->{output_dir}; |
519
|
329
|
50
|
33
|
|
|
11633
|
unless (defined $output_dir && -d $output_dir) { |
520
|
0
|
|
|
|
|
0
|
confess "Shared lib directory must be specified for link"; |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
# Dynamic library file |
524
|
329
|
|
|
|
|
6780
|
my $output_rel_file = SPVM::Builder::Util::convert_basic_type_name_to_category_rel_file($basic_type_name, $options->{category}); |
525
|
329
|
|
|
|
|
5138
|
$output_file = "$output_dir/$output_rel_file"; |
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
# Add output file extension |
529
|
331
|
|
|
|
|
56785
|
my $output_file_base = basename $output_file; |
530
|
331
|
50
|
66
|
|
|
7232
|
if ($output_file_base =~ /\.precompile$/ || $output_file_base !~ /\./) { |
531
|
331
|
|
|
|
|
1540
|
my $exe_ext; |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
# Dynamic library |
534
|
331
|
100
|
|
|
|
2633
|
if ($output_type eq 'dynamic_lib') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
535
|
329
|
|
|
|
|
15309
|
$exe_ext = ".$Config{dlext}" |
536
|
|
|
|
|
|
|
} |
537
|
|
|
|
|
|
|
# Static library |
538
|
|
|
|
|
|
|
elsif ($output_type eq 'static_lib') { |
539
|
0
|
|
|
|
|
0
|
$exe_ext = '.a'; |
540
|
|
|
|
|
|
|
} |
541
|
|
|
|
|
|
|
# Executable file |
542
|
|
|
|
|
|
|
elsif ($output_type eq 'exe') { |
543
|
2
|
|
|
|
|
90
|
$exe_ext = $Config{exe_ext}; |
544
|
|
|
|
|
|
|
} |
545
|
|
|
|
|
|
|
|
546
|
331
|
|
|
|
|
3069
|
$output_file .= $exe_ext; |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
# Optimize |
550
|
331
|
|
|
|
|
3981
|
my $ld_optimize = $config->ld_optimize; |
551
|
|
|
|
|
|
|
|
552
|
331
|
|
|
|
|
7468
|
my $link_info = SPVM::Builder::LinkInfo->new( |
553
|
|
|
|
|
|
|
class_name => $basic_type_name, |
554
|
|
|
|
|
|
|
config => $config, |
555
|
|
|
|
|
|
|
object_files => $all_object_files, |
556
|
|
|
|
|
|
|
output_file => $output_file, |
557
|
|
|
|
|
|
|
); |
558
|
|
|
|
|
|
|
|
559
|
331
|
|
|
|
|
2418
|
return $link_info; |
560
|
|
|
|
|
|
|
} |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
sub link { |
563
|
331
|
|
|
331
|
0
|
3252
|
my ($self, $basic_type_name, $object_files, $options) = @_; |
564
|
|
|
|
|
|
|
|
565
|
331
|
|
|
|
|
1768
|
my $dl_func_list = $options->{dl_func_list}; |
566
|
|
|
|
|
|
|
|
567
|
331
|
|
|
|
|
1842
|
my $category = $options->{category}; |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
# Build directory |
570
|
331
|
|
|
|
|
5089
|
my $build_dir = $self->build_dir; |
571
|
331
|
50
|
|
|
|
3192
|
if (defined $build_dir) { |
572
|
331
|
|
|
|
|
34644
|
mkpath $build_dir; |
573
|
|
|
|
|
|
|
} |
574
|
|
|
|
|
|
|
else { |
575
|
0
|
|
|
|
|
0
|
confess "The \"build_dir\" field must be defined to build the native class for $category methods. Perhaps the setting of the SPVM_BUILD_DIR environment variable is forgotten"; |
576
|
|
|
|
|
|
|
} |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
# Config |
579
|
331
|
|
|
|
|
2505
|
my $config = $options->{config}; |
580
|
331
|
50
|
|
|
|
3403
|
unless ($config) { |
581
|
0
|
|
|
|
|
0
|
confess "Need config option"; |
582
|
|
|
|
|
|
|
} |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
# Force link |
585
|
331
|
|
|
|
|
4688
|
my $force = $self->detect_force($config); |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
# Link information |
588
|
331
|
|
|
|
|
3529
|
my $link_info = $self->create_link_info($basic_type_name, $object_files, $config, $options); |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
# Output file |
591
|
331
|
|
|
|
|
3007
|
my $output_file = $link_info->output_file; |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
# Execute the callback before this link |
594
|
331
|
|
|
|
|
3510
|
my $before_link_cbs = $config->before_link_cbs; |
595
|
331
|
|
|
|
|
2258
|
for my $before_link_cb (@$before_link_cbs) { |
596
|
3
|
|
|
|
|
62
|
$before_link_cb->($config, $link_info); |
597
|
|
|
|
|
|
|
} |
598
|
|
|
|
|
|
|
|
599
|
331
|
|
|
|
|
1398
|
my @object_files = map { "$_" } @{$link_info->object_files}; |
|
468
|
|
|
|
|
9122
|
|
|
331
|
|
|
|
|
2087
|
|
600
|
331
|
|
|
|
|
1865
|
my $input_files = [@object_files]; |
601
|
331
|
100
|
|
|
|
3799
|
if (defined $config->file) { |
602
|
23
|
|
|
|
|
188
|
push @$input_files, $config->file; |
603
|
|
|
|
|
|
|
} |
604
|
331
|
|
|
|
|
8181
|
my $need_generate = SPVM::Builder::Util::need_generate({ |
605
|
|
|
|
|
|
|
force => $force, |
606
|
|
|
|
|
|
|
output_file => $output_file, |
607
|
|
|
|
|
|
|
input_files => $input_files, |
608
|
|
|
|
|
|
|
}); |
609
|
|
|
|
|
|
|
|
610
|
331
|
100
|
|
|
|
2450
|
if ($need_generate) { |
611
|
|
|
|
|
|
|
# Move temporary dynamic library file to blib directory |
612
|
260
|
|
|
|
|
45883
|
mkpath dirname $output_file; |
613
|
|
|
|
|
|
|
|
614
|
260
|
|
|
|
|
2459
|
my $ld = $config->ld; |
615
|
|
|
|
|
|
|
|
616
|
260
|
|
|
|
|
7318
|
my $cbuilder_config = { |
617
|
|
|
|
|
|
|
ld => $ld, |
618
|
|
|
|
|
|
|
lddlflags => '', |
619
|
|
|
|
|
|
|
shrpenv => '', |
620
|
|
|
|
|
|
|
libpth => '', |
621
|
|
|
|
|
|
|
libperl => '', |
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
# "perllibs" should be empty string, but ExtUtils::CBuiler outputs "INPUT()" into |
624
|
|
|
|
|
|
|
# Linker Script File(.lds) when "perllibs" is empty string. |
625
|
|
|
|
|
|
|
# This is syntax error in Linker Script File(.lds) |
626
|
|
|
|
|
|
|
# For the reason, libm is linked which seems to have no effect. |
627
|
|
|
|
|
|
|
perllibs => '-lm', |
628
|
|
|
|
|
|
|
}; |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
# Quiet output |
631
|
260
|
|
|
|
|
2714
|
my $quiet = $self->detect_quiet($config); |
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
# ExtUtils::CBuilder object |
634
|
260
|
|
|
|
|
5794
|
my $cbuilder = ExtUtils::CBuilder->new(quiet => 1, config => $cbuilder_config); |
635
|
|
|
|
|
|
|
|
636
|
260
|
|
|
|
|
2659397
|
my $link_info_output_file = $link_info->output_file; |
637
|
260
|
|
|
|
|
1812
|
my $link_info_object_files = $link_info->object_files; |
638
|
|
|
|
|
|
|
|
639
|
260
|
|
|
|
|
3147
|
my $link_command_args = $link_info->create_link_command_args; |
640
|
|
|
|
|
|
|
|
641
|
260
|
|
|
|
|
1331
|
my $link_info_object_file_names = [map { $_->to_string; } @$link_info_object_files]; |
|
338
|
|
|
|
|
1930
|
|
642
|
|
|
|
|
|
|
|
643
|
260
|
|
|
|
|
1152
|
my @tmp_files; |
644
|
|
|
|
|
|
|
|
645
|
260
|
|
|
|
|
1699
|
my $output_type = $config->output_type; |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
# Create a dynamic library |
648
|
260
|
100
|
|
|
|
1799
|
if ($output_type eq 'dynamic_lib') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
649
|
259
|
|
|
|
|
6687
|
(undef, @tmp_files) = $cbuilder->link( |
650
|
|
|
|
|
|
|
objects => $link_info_object_file_names, |
651
|
|
|
|
|
|
|
module_name => $basic_type_name, |
652
|
|
|
|
|
|
|
lib_file => $link_info_output_file, |
653
|
|
|
|
|
|
|
extra_linker_flags => "@$link_command_args", |
654
|
|
|
|
|
|
|
dl_func_list => $dl_func_list, |
655
|
|
|
|
|
|
|
); |
656
|
259
|
50
|
|
|
|
10718837
|
unless ($quiet) { |
657
|
0
|
|
|
|
|
0
|
my $link_command = $link_info->to_cmd; |
658
|
0
|
|
|
|
|
0
|
warn "$link_command\n"; |
659
|
|
|
|
|
|
|
} |
660
|
|
|
|
|
|
|
} |
661
|
|
|
|
|
|
|
# Create a static library |
662
|
|
|
|
|
|
|
elsif ($output_type eq 'static_lib') { |
663
|
0
|
|
|
|
|
0
|
my @object_files = map { "$_" } @$link_info_object_file_names; |
|
0
|
|
|
|
|
0
|
|
664
|
0
|
|
|
|
|
0
|
my @ar_cmd = ('ar', 'rc', $link_info_output_file, @object_files); |
665
|
0
|
0
|
|
|
|
0
|
$cbuilder->do_system(@ar_cmd) |
666
|
|
|
|
|
|
|
or confess "Can't execute command @ar_cmd"; |
667
|
0
|
0
|
|
|
|
0
|
unless ($quiet) { |
668
|
0
|
|
|
|
|
0
|
warn "@ar_cmd\n"; |
669
|
|
|
|
|
|
|
} |
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
# Create an executable file |
672
|
|
|
|
|
|
|
elsif ($output_type eq 'exe') { |
673
|
1
|
|
|
|
|
54
|
(undef, @tmp_files) = $cbuilder->link_executable( |
674
|
|
|
|
|
|
|
objects => $link_info_object_file_names, |
675
|
|
|
|
|
|
|
module_name => $basic_type_name, |
676
|
|
|
|
|
|
|
exe_file => $link_info_output_file, |
677
|
|
|
|
|
|
|
extra_linker_flags => "@$link_command_args", |
678
|
|
|
|
|
|
|
); |
679
|
1
|
50
|
|
|
|
89539
|
unless ($quiet) { |
680
|
1
|
|
|
|
|
47
|
my $link_command = $link_info->to_cmd; |
681
|
1
|
|
|
|
|
195
|
warn "$link_command\n"; |
682
|
|
|
|
|
|
|
} |
683
|
|
|
|
|
|
|
} |
684
|
|
|
|
|
|
|
else { |
685
|
0
|
|
|
|
|
0
|
confess "Unknown output_type \"$output_type\""; |
686
|
|
|
|
|
|
|
} |
687
|
|
|
|
|
|
|
|
688
|
260
|
50
|
|
|
|
10348
|
if ($self->debug) { |
689
|
0
|
0
|
|
|
|
0
|
if ($^O eq 'MSWin32') { |
690
|
0
|
|
|
|
|
0
|
my $def_file; |
691
|
|
|
|
|
|
|
my $lds_file; |
692
|
0
|
|
|
|
|
0
|
for my $tmp_file (@tmp_files) { |
693
|
|
|
|
|
|
|
# Remove double quote |
694
|
0
|
|
|
|
|
0
|
$tmp_file =~ s/^"//; |
695
|
0
|
|
|
|
|
0
|
$tmp_file =~ s/"$//; |
696
|
|
|
|
|
|
|
|
697
|
0
|
0
|
|
|
|
0
|
if ($tmp_file =~ /\.def$/) { |
698
|
0
|
|
|
|
|
0
|
$def_file = $tmp_file; |
699
|
0
|
|
|
|
|
0
|
$lds_file = $def_file; |
700
|
0
|
|
|
|
|
0
|
$lds_file =~ s/\.def$/.lds/; |
701
|
0
|
|
|
|
|
0
|
last; |
702
|
|
|
|
|
|
|
} |
703
|
|
|
|
|
|
|
} |
704
|
0
|
0
|
0
|
|
|
0
|
if (defined $def_file && -f $def_file) { |
705
|
0
|
|
|
|
|
0
|
my $def_content = SPVM::Builder::Util::slurp_binary($def_file); |
706
|
0
|
|
|
|
|
0
|
warn "[$def_file]\n$def_content\n"; |
707
|
|
|
|
|
|
|
} |
708
|
0
|
0
|
0
|
|
|
0
|
if (defined $lds_file && -f $lds_file) { |
709
|
0
|
|
|
|
|
0
|
my $lds_content = SPVM::Builder::Util::slurp_binary($lds_file); |
710
|
0
|
|
|
|
|
0
|
warn "[$lds_file]\n$lds_content\n"; |
711
|
|
|
|
|
|
|
} |
712
|
|
|
|
|
|
|
} |
713
|
|
|
|
|
|
|
} |
714
|
|
|
|
|
|
|
} |
715
|
|
|
|
|
|
|
|
716
|
331
|
|
|
|
|
1463160
|
return $output_file; |
717
|
|
|
|
|
|
|
} |
718
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
1; |
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
=head1 Name |
722
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
SPVM::Builder::CC - Compilation and Link of Native Class |
724
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
=head1 Description |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
The SPVM::Builder::CC class has methods to compile and link a SPVM native class. |
728
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
=head1 Copyright & License |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
Copyright (c) 2023 Yuki Kimoto |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
MIT License |