blib/lib/SPVM/Builder/Config/Linker.pm

filter: Statementstmt 77.6% 309 / 398 Branchbran 49.4% 95 / 192 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 33 / 44 Podpod 93.7% 30 / 32 totaltotal 69.4% 471 / 678 CC 105 SCAR 38.5
CC
105
Cov
68%
new
82.1
new
82.1
use_resource
11.7
CRAP 47.2
« blib/lib/SPVM/Builder.pm ↑ Summary blib/lib/SPVM/Builder/LibInfo.pm »
1 package SPVM::Builder::Config::Linker;
2  
3 895 ▶use parent 'SPVM::Builder::Config::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 895 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1072 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1072 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 895 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 895 ▶use SPVM::Builder::Accessor 'has';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10450 ▶use SPVM::Builder::LibInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1061 ▶use SPVM::Builder::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1061 ▶use SPVM::Builder::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 915 ▶use SPVM::Builder::Config::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 895 my $fields = [qw(
16 ld
17 ldflags
18 ld_optimize
19 output_type
20 copyright_print_ldflags
21 warn_ldflags
22 debug_info_ldflags
23 symbol_strip_ldflags
24 dynamic_lib_ldflags
25 thread_ldflags
26 libgcc_ldflags
27 libbcrypt_ldflags
28 libcpp_ldflags
29 extra_ldflags
30 static_lib_braces
31 lib_dirs
32 libs
33 lib_prefix
34 lib_option_name
35 lib_option_suffix
36 lib_dir_option_name
37 long_option_sep
38 dynamic_lib_ext
39 static_lib_ext
40 exe_ext
41 ld_output_option_name
42 output_file
43 external_object_files
44 hint_cc
45 resources
46 ld_version
47 ld_debug_output_option_name
48 debug_output_file
49 enable_ld_debug_output_option
50 debug_output_file_ext
51 debug_output_file_ldflags
52 link_to
53 )];
54  
55 895 has($fields);
56  
57 33739 ▶sub option_names {
Subroutine option_names: called CC=1 SCAR=0.0
Pod undocumented
58 22 ▶ my ($self) = @_;
Subroutine option_names: called CC=1 SCAR=0.0
Pod undocumented
59 22 return [@{$self->SUPER::option_names}, @$fields];
60 }
61  
62 3747 ▶sub new {
Subroutine new: called CC=41 SCAR=44.1
Pod documented
63 22 ▶ my $class = shift;
Subroutine new: called CC=41 SCAR=44.1
Pod documented
64 22 my $self = $class->SUPER::new(@_);
65  
66 22 ▶ unless (exists $self->{ld}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"ld"}) 166 0 166
unless (exists $self->{"ld"}) 3747 0 3747
67 22 my $config_gcc_version = $Config{gccversion};
68 22 ▶ if ($config_gcc_version =~ /\bclang\b/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($config_gcc_version =~ /\bclang\b/i) { } 0 166 166
if ($config_gcc_version =~ /\bclang\b/i) { } 0 3747 3747
69 0 $self->ld('clang++');
70 }
71 else {
72 22 $self->ld('g++');
73 }
74 }
75  
76 22 ▶ unless (exists $self->{ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"ldflags"}) 166 0 166
unless (exists $self->{"ldflags"}) 3747 0 3747
77 22 $self->ldflags([]);
78 }
79  
80 22 ▶ unless (exists $self->{dynamic_lib_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"dynamic_lib_ldflags"}) 166 0 166
unless (exists $self->{"dynamic_lib_ldflags"}) 3747 0 3747
81 22 ▶ if (SPVM::Builder::Util::is_windows()) {
Branch: 4 branches
BranchTrueFalseTotal
if (SPVM::Builder::Util::is_windows()) { } 0 166 166
elsif ($^O eq 'darwin') { } 0 166 166
if (SPVM::Builder::Util::is_windows()) { } 0 3747 3747
elsif ($^O eq 'darwin') { } 0 3747 3747
82 0 $self->dynamic_lib_ldflags(['-mdll']);
83 }
84 elsif ($^O eq 'darwin') {
85 0 $self->dynamic_lib_ldflags(['-bundle']);
86 }
87 else {
88 22 $self->dynamic_lib_ldflags(['-shared']);
89 }
90 }
91  
92 22 ▶ unless (exists $self->{thread_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"thread_ldflags"}) 166 0 166
unless (exists $self->{"thread_ldflags"}) 3747 0 3747
93 22 $self->thread_ldflags(['-pthread']);
94 22 ▶ if (SPVM::Builder::Util::is_windows()) {
Branch: 2 branches
BranchTrueFalseTotal
if (SPVM::Builder::Util::is_windows()) 0 166 166
if (SPVM::Builder::Util::is_windows()) 0 3747 3747
95 0 push @{$self->thread_ldflags}, '-Wl,-Bstatic', '-lwinpthread', '-Wl,-Bdynamic';
96 }
97 }
98  
99 22 ▶ unless (exists $self->{static_lib_braces}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"static_lib_braces"}) 166 0 166
unless (exists $self->{"static_lib_braces"}) 3747 0 3747
100 22 my $begin = '-Wl,-Bstatic';
101 22 my $end = '-Wl,-Bdynamic';
102 22 $self->static_lib_braces([$begin, $end]);
103 }
104  
105 22 ▶ unless (exists $self->{ld_optimize}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"ld_optimize"}) 166 0 166
unless (exists $self->{"ld_optimize"}) 3747 0 3747
106 22 $self->ld_optimize('');
107 }
108
109 22 ▶ unless (exists $self->{lib_dirs}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"lib_dirs"}) 166 0 166
unless (exists $self->{"lib_dirs"}) 3747 0 3747
110 22 $self->lib_dirs([]);
111 }
112  
113 1494 ▶ unless (exists $self->{libs}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"libs"}) 166 0 166
unless (exists $self->{"libs"}) 3747 0 3747
114 1494 $self->libs([]);
115 }
116  
117 1494 ▶ unless (exists $self->{output_type}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"output_type"}) 166 0 166
unless (exists $self->{"output_type"}) 3747 0 3747
118 166 $self->output_type('dynamic_lib');
119 }
120  
121 166 ▶ unless (exists $self->{copyright_print_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"copyright_print_ldflags"}) 166 0 166
unless (exists $self->{"copyright_print_ldflags"}) 3747 0 3747
122 166 $self->copyright_print_ldflags([]);
123 }
124  
125 # warn_ldflags
126 166 ▶ unless (exists $self->{warn_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"warn_ldflags"}) 166 0 166
unless (exists $self->{"warn_ldflags"}) 3747 0 3747
127 166 $self->warn_ldflags([]);
128 }
129
130 # debug_info_ldflags
131 0 ▶ unless (exists $self->{debug_info_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"debug_info_ldflags"}) 166 0 166
unless (exists $self->{"debug_info_ldflags"}) 3747 0 3747
132 166 $self->debug_info_ldflags([]);
133 }
134  
135 # symbol_strip_ldflags
136 166 ▶ unless (exists $self->{symbol_strip_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"symbol_strip_ldflags"}) 166 0 166
unless (exists $self->{"symbol_strip_ldflags"}) 3747 0 3747
137 166 $self->symbol_strip_ldflags([]);
138 }
139
140 166 ▶ unless (exists $self->{libcpp_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"libcpp_ldflags"}) 166 0 166
unless (exists $self->{"libcpp_ldflags"}) 3747 0 3747
141 166 ▶ if (SPVM::Builder::Util::is_windows()) {
Branch: 4 branches
BranchTrueFalseTotal
if (SPVM::Builder::Util::is_windows()) { } 0 166 166
elsif ($^O eq 'darwin') { } 0 166 166
if (SPVM::Builder::Util::is_windows()) { } 0 3747 3747
elsif ($^O eq 'darwin') { } 0 3747 3747
142 0 $self->libcpp_ldflags(['-Wl,-Bstatic', '-lstdc++', '-Wl,-Bdynamic']);
143 }
144 elsif ($^O eq 'darwin') {
145 0 $self->libcpp_ldflags(['-nostdlib++', '-lc++']);
146 }
147 else {
148 166 $self->libcpp_ldflags(['-lstdc++']);
149 }
150 }
151
152 # libgcc_ldflags
153 166 ▶ unless (exists $self->{libgcc_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"libgcc_ldflags"}) 166 0 166
unless (exists $self->{"libgcc_ldflags"}) 3747 0 3747
154 166 ▶ if (SPVM::Builder::Util::is_windows()) {
Branch: 2 branches
BranchTrueFalseTotal
if (SPVM::Builder::Util::is_windows()) { } 0 166 166
if (SPVM::Builder::Util::is_windows()) { } 0 3747 3747
155 0 $self->libgcc_ldflags(['-Wl,-Bstatic', '-lgcc', '-Wl,-Bdynamic']);
156 }
157 else {
158 0 $self->libgcc_ldflags([]);
159 }
160 }
161  
162 # libbcrypt_ldflags
163 0 ▶ unless (exists $self->{libbcrypt_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"libbcrypt_ldflags"}) 166 0 166
unless (exists $self->{"libbcrypt_ldflags"}) 3747 0 3747
164 166 ▶ if (SPVM::Builder::Util::is_windows()) {
Branch: 2 branches
BranchTrueFalseTotal
if (SPVM::Builder::Util::is_windows()) { } 0 166 166
if (SPVM::Builder::Util::is_windows()) { } 0 3747 3747
165 0 $self->libbcrypt_ldflags(['-lbcrypt']);
166 }
167 else {
168 166 $self->libbcrypt_ldflags([]);
169 }
170 }
171  
172 # extra_ldflags
173 166 ▶ unless (exists $self->{extra_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"extra_ldflags"}) 166 0 166
unless (exists $self->{"extra_ldflags"}) 3747 0 3747
174 166 $self->extra_ldflags([]);
175 }
176  
177 166 ▶ unless (exists $self->{lib_dir_option_name}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"lib_dir_option_name"}) 166 0 166
unless (exists $self->{"lib_dir_option_name"}) 3747 0 3747
178 166 $self->lib_dir_option_name("-L");
179 }
180  
181 166 ▶ unless (exists $self->{dynamic_lib_ext}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"dynamic_lib_ext"}) 166 0 166
unless (exists $self->{"dynamic_lib_ext"}) 3747 0 3747
182 166 my $ext = $Config{so};
183 166 $ext =~ s/^\.//;
184 166 $self->dynamic_lib_ext($ext);
185 }
186
187 166 ▶ unless (exists $self->{static_lib_ext}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"static_lib_ext"}) 166 0 166
unless (exists $self->{"static_lib_ext"}) 3747 0 3747
188 166 my $ext = $Config{_a};
189 166 $ext =~ s/^\.//;
190 166 $self->static_lib_ext($ext);
191 }
192
193 166 ▶ unless (exists $self->{exe_ext}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"exe_ext"}) 166 0 166
unless (exists $self->{"exe_ext"}) 3747 0 3747
194 166 my $ext = $Config{_exe};
195 166 ▶ if (length $ext) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $ext) { } 0 166 166
if (length $ext) { } 0 3747 3747
196 0 $ext =~ s/^\.//;
197 0 $self->exe_ext($ext);
198 }
199 else {
200 166 $self->exe_ext(undef);
201 }
202 }
203  
204 166 ▶ unless (exists $self->{lib_prefix}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"lib_prefix"}) 166 0 166
unless (exists $self->{"lib_prefix"}) 3747 0 3747
205 0 $self->lib_prefix("lib");
206 }
207  
208 0 ▶ unless (exists $self->{lib_option_suffix}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"lib_option_suffix"}) 166 0 166
unless (exists $self->{"lib_option_suffix"}) 3747 0 3747
209 166 $self->lib_option_suffix("");
210 }
211  
212 166 ▶ unless (exists $self->{lib_option_name}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"lib_option_name"}) 166 0 166
unless (exists $self->{"lib_option_name"}) 3747 0 3747
213 166 $self->lib_option_name("-l");
214 }
215  
216 0 ▶ unless (exists $self->{ld_output_option_name}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"ld_output_option_name"}) 166 0 166
unless (exists $self->{"ld_output_option_name"}) 3747 0 3747
217 166 $self->ld_output_option_name("-o");
218 }
219
220 # resources
221 166 ▶ unless (exists $self->{resources}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"resources"}) 166 0 166
unless (exists $self->{"resources"}) 3747 0 3747
222 166 $self->{resources} = {};
223 }
224
225 0 ▶ unless (exists $self->{external_object_files}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"external_object_files"}) 166 0 166
unless (exists $self->{"external_object_files"}) 3747 0 3747
226 166 $self->{external_object_files} = [];
227 }
228
229 # hint_cc
230 {
231 166 my $config_gcc_version = $Config{gccversion};
232 166 ▶ if ($config_gcc_version =~ /\bclang\b/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($config_gcc_version =~ /\bclang\b/i) { } 0 166 166
if ($config_gcc_version =~ /\bclang\b/i) { } 0 3747 3747
233 0 $self->hint_cc('clang++');
234 }
235 else {
236 166 $self->hint_cc('g++');
237 }
238 }
239
240 # long_option_sep
241 166 ▶ unless (exists $self->{long_option_sep}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"long_option_sep"}) 166 0 166
unless (exists $self->{"long_option_sep"}) 3747 0 3747
242 166 $self->long_option_sep("=");
243 }
244
245 166 ▶ unless (exists $self->{ld_version}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"ld_version"}) 166 0 166
unless (exists $self->{"ld_version"}) 3747 0 3747
246 166 $self->ld_version($self->create_ld_version);
247 }
248
249 166 ▶ unless (exists $self->{debug_output_file_ldflags}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{"debug_output_file_ldflags"}) 166 0 166
unless (exists $self->{"debug_output_file_ldflags"}) 3747 0 3747
250 166 $self->debug_output_file_ldflags([]);
251 }
252
253 166 return $self;
254 }
255  
256 2 ▶sub add_ldflag {
Subroutine add_ldflag: called CC=1 SCAR=0.0
Pod documented
257 166 ▶ my ($self, @ldflags) = @_;
Subroutine add_ldflag: called CC=1 SCAR=0.0
Pod documented
258 166 push @{$self->{ldflags}}, @ldflags;
259 }
260  
261 6 ▶sub add_lib_dir {
Subroutine add_lib_dir: called CC=1 SCAR=0.4
Pod documented
262 0 ▶ my ($self, @lib_dirs) = @_;
Subroutine add_lib_dir: called CC=1 SCAR=0.4
Pod documented
263 0 push @{$self->{lib_dirs}}, @lib_dirs;
264 }
265  
266 0 ▶sub add_lib {
Subroutine add_lib: not called CC=1 SCAR=1.2
Pod documented
267 0 ▶ my ($self, @libs) = @_;
Subroutine add_lib: called CC=1 SCAR=1.2
Pod documented
268 0 push @{$self->{libs}}, @libs;
269 }
270  
271 0 ▶sub add_lib_abs {
Subroutine add_lib_abs: not called CC=1 SCAR=1.2
Pod documented
272 0 ▶ my ($self, @libs) = @_;
Subroutine add_lib_abs: called CC=1 SCAR=1.2
Pod documented
273 0 $self->_add_lib_info({is_abs => 1}, @libs);
274 }
275  
276 0 ▶sub add_static_lib_abs {
Subroutine add_static_lib_abs: not called CC=1 SCAR=1.2
Pod documented
277 0 ▶ my ($self, @libs) = @_;
Subroutine add_static_lib_abs: called CC=1 SCAR=1.2
Pod documented
278 0 $self->_add_lib_info({is_static => 1, is_abs => 1}, @libs);
279 }
280  
281 0 ▶sub add_static_lib {
Subroutine add_static_lib: not called CC=1 SCAR=1.2
Pod documented
282 0 ▶ my ($self, @libs) = @_;
Subroutine add_static_lib: called CC=1 SCAR=1.2
Pod documented
283 0 $self->_add_lib_info({is_static => 1}, @libs);
284 }
285  
286 0 ▶sub _add_lib_info {
Subroutine _add_lib_info: not called CC=3 SCAR=16.1
287 0 ▶ my ($self, $options, @libs) = @_;
Subroutine _add_lib_info: called CC=3 SCAR=16.1
288 0 my @lib_infos;
289 0 for my $lib (@libs) {
290 0 my $lib_info;
291 0 ▶ if (ref $lib eq 'SPVM::Builder::LibInfo') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $lib eq 'SPVM::Builder::LibInfo') { } 0 0 0
if (ref $lib eq 'SPVM::Builder::LibInfo') { } 0 0 0
292 0 $lib_info = $lib;
293 }
294 else {
295 0 my $lib_name = $lib;
296 0 $lib_info = SPVM::Builder::LibInfo->new(config => $self, name => $lib_name);
297 }
298 0 $lib_info->is_static($options->{is_static});
299 0 $lib_info->is_abs($options->{is_abs});
300 0 push @lib_infos, $lib_info;
301 }
302 0 $self->add_lib(@lib_infos);
303 }
304  
305 94 ▶sub use_resource {
Subroutine use_resource: called CC=6 SCAR=24.6
Pod documented
306 166 ▶ my ($self, @args) = @_;
Subroutine use_resource: called CC=6 SCAR=24.6
Pod documented
307
308 166 my $first_arg;
309 166 ▶ unless (@args % 2 == 0) {
Branch: 2 branches
BranchTrueFalseTotal
unless (@args % 2 == 0) 1 0 1
unless (@args % 2 == 0) 94 0 94
310 0 $first_arg = shift @args;
311 }
312
313 0 my $resource;
314 0 ▶ if (ref $first_arg) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $first_arg) { } 0 1 1
if (ref $first_arg) { } 0 94 94
315 0 $resource = $first_arg;
316 }
317 else {
318 0 my $class_name = $first_arg;
319 0 my %args = @args;
320 0 ▶ if (exists $args{class_name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args{"class_name"}) 0 1 1
if (exists $args{"class_name"}) 0 94 94
321 0 $class_name = delete $args{class_name};
322 }
323 0 $resource = SPVM::Builder::Resource->new(class_name => $class_name, %args);
324 }
325
326 0 my $resource_class_name = $resource->class_name;
327
328 0 my $config_file = SPVM::Builder::Util::search_config_file($resource_class_name);
329
330 0 ▶ unless (defined $config_file) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $config_file) 0 1 1
unless (defined $config_file) 0 94 94
331 0 my $config_ext = SPVM::Builder::Config::Util::get_config_ext();
332 0 my $config_rel_file = SPVM::Builder::Util::convert_class_name_to_rel_file($resource_class_name, $config_ext);
333
334 0 confess("The config file '$config_rel_file' is not found in (@INC)");
335 }
336
337 0 my $config = SPVM::Builder::Config::Util::load_config($config_file);
338
339 0 ▶ unless ($config->isa('SPVM::Builder::Config')) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($config->isa("SPVM::Builder::Config")) 0 1 1
unless ($config->isa("SPVM::Builder::Config")) 0 94 94
340 0 confess("[Unexpected Error]The config must be an SPVM::Builder::Config object");
341 }
342
343 0 $config->file($config_file);
344
345 0 $resource->config($config);
346
347 0 $config->resource_loader_config($self);
348
349 0 my $index = keys %{$self->{resources}};
350
351 0 $self->{resources}->{$resource_class_name} = {resource => $resource, index => $index};
352
353 0 return $resource;
354 }
355  
356 216 ▶sub get_resource {
Subroutine get_resource: called CC=2 SCAR=8.4
Pod documented
357 0 ▶ my ($self, $resource_class_name) = @_;
Subroutine get_resource: called CC=2 SCAR=8.4
Pod documented
358
359 0 ▶ unless (defined $self->{resources}{$resource_class_name}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $self->{"resources"}{$resource_class_name}) 0 0 0
unless (defined $self->{"resources"}{$resource_class_name}) 0 216 216
360 0 return;
361 }
362
363 1 my $resource = $self->{resources}{$resource_class_name}{resource};
364
365 1 return $resource;
366 }
367  
368 3266 ▶sub get_resource_names {
Subroutine get_resource_names: called CC=1 SCAR=0.0
Pod documented
369 1 ▶ my ($self) = @_;
Subroutine get_resource_names: called CC=1 SCAR=0.0
Pod documented
370
371 0 my @resource_names = sort { $self->{resources}{$a}{index} <=> $self->{resources}{$b}{index} } keys %{$self->{resources}};
372
373 1 return \@resource_names;
374 }
375  
376 56893 ▶sub get_ld_system_field_names {
Subroutine get_ld_system_field_names: called CC=1 SCAR=0.0
Pod documented
377 1 ▶ my $self = shift;
Subroutine get_ld_system_field_names: not called CC=1 SCAR=0.0
Pod documented
378
379 1 return [qw(
380 dynamic_lib_ldflags
381 thread_ldflags
382 libcpp_ldflags
383 copyright_print_ldflags
384 warn_ldflags
385 debug_info_ldflags
386 symbol_strip_ldflags
387 libgcc_ldflags
388 libbcrypt_ldflags
389 extra_ldflags
390 debug_output_file_ldflags
391 )];
392 }
393  
394 0 ▶sub clear_system_fields {
Subroutine clear_system_fields: not called CC=2 SCAR=10.9
Pod documented
395 0 ▶ my $self = shift;
Subroutine clear_system_fields: not called CC=2 SCAR=10.9
Pod documented
396
397 0 my $field_names = $self->get_ld_system_field_names;
398
399 0 for my $field_name (@$field_names) {
400 0 $self->$field_name([]);
401 }
402 }
403  
404 # Connect directly (e.g. -oFILE, -I/path)
405 354559 ▶sub create_option_short {
Subroutine create_option_short: called CC=1 SCAR=0.2
Pod documented
406 1 ▶ my ($self, $name, $value) = @_;
Subroutine create_option_short: not called CC=1 SCAR=0.2
Pod documented
407
408 0 return "$name$value";
409 }
410  
411 # Connect using long_option_sep (e.g. --prefix=/usr, -out:FILE)
412 303632 ▶sub create_option_long {
Subroutine create_option_long: called CC=1 SCAR=0.4
Pod documented
413 0 ▶ my ($self, $name, $value) = @_;
Subroutine create_option_long: not called CC=1 SCAR=0.4
Pod documented
414
415 0 my $sep = $self->long_option_sep;
416
417 1 return "$name$sep$value";
418 }
419  
420 895 my %LD_VERSION_CACHE;
421 3747 ▶sub create_ld_version {
Subroutine create_ld_version: called CC=4 SCAR=14.0
Pod documented
422 1 ▶ my ($self) = @_;
Subroutine create_ld_version: not called CC=4 SCAR=14.0
Pod documented
423
424 0 my $ld = $self->ld;
425 1 ▶ my $path_env = $ENV{PATH} // '';
Condition50%2/4
$ENV{"PATH"} // ""
l!l
1660
$ENV{"PATH"} // ""
l!l
37470
MC/DC0%0/1
$ENV{"PATH"} // ""
$ENV{"PATH"}
MC/DC0%0/1
$ENV{"PATH"} // ""
$ENV{"PATH"}
Truth table50%1/2
A
A= $ENV{"PATH"}
Aresult
11
00
Truth table50%1/2
A
A= $ENV{"PATH"}
Aresult
11
00
426
427 1 ▶ if (exists $LD_VERSION_CACHE{$ld}{$path_env}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $LD_VERSION_CACHE{$ld}{$path_env}) 146 20 166
if (exists $LD_VERSION_CACHE{$ld}{$path_env}) 3146 601 3747
428 1 return $LD_VERSION_CACHE{$ld}{$path_env};
429 }
430
431 1 ▶ my $ld_version = `$ld --version 2>&1` // '';
Condition50%2/4
`$ld --version 2>&1` // ""
l!l
200
`$ld --version 2>&1` // ""
l!l
6010
MC/DC0%0/1
`$ld --version 2>&1` // ""
`$ld --version 2>&1`
MC/DC0%0/1
`$ld --version 2>&1` // ""
`$ld --version 2>&1`
Truth table50%1/2
A
A= `$ld --version 2>&1`
Aresult
11
00
Truth table50%1/2
A
A= `$ld --version 2>&1`
Aresult
11
00
432
433 1 $ld_version =~ s/\n.*//s;
434
435 1 $LD_VERSION_CACHE{$ld}{$path_env} = $ld_version;
436
437 1 return $ld_version;
438 }
439  
440 895 1;
441  
442 =head1 Name
443  
444 SPVM::Builder::Config::Linker - Config for Linking Native Classes
445  
446 =head1 Inheritance
447  
448 L<SPVM::Builder::Config::Base>
449  
450 =head1 Fields
451  
452 =head2 ld
453  
454 my $ld = $config->ld;
455 $config->ld($ld);
456  
457 Gets and sets C<ld> field, a linker name.
458  
459 Examples:
460  
461 $config->ld('g++');
462  
463 =head2 hint_cc
464  
465 my $hint_cc = $config->hint_cc;
466 $config->hint_cc($hint_cc);
467  
468 Gets and sets C<hint_cc> field, a compiler name that is used as a hint for the linker.
469  
470 The linker may use this field to determine how to link object files created by this compiler.
471  
472 Examples:
473  
474 $config->hint_cc('gcc');
475  
476 =head2 lib_dirs
477  
478 my $lib_dirs = $config->lib_dirs;
479 $config->lib_dirs($lib_dirs);
480  
481 Gets and sets C<lib_dirs> field, an array reference containing library search directories.
482  
483 The values of this field are converted to C<-L> options when the arguments of the linker L</"ld"> are created.
484  
485 # -L /path1 -L /path2
486 $config->lib_dirs(['/path1', '/path2']);
487  
488 =head2 libs
489  
490 my $libs = $config->libs;
491 $config->libs($libs);
492  
493 Gets and sets C<libs> field, an array reference containing library names such as C<z>, and C<png> or L<SPVM::Builder::LibInfo> objects.
494  
495 The values of this field are converted to C<-l> options when the arguments of the linker L</"ld"> are created.
496  
497 See L</"Library Path Resolution"> about resolving library paths.
498  
499 Examples:
500  
501 # -l libz -l libpng
502 $config->libs(['z', 'png']);
503  
504 =head2 ldflags
505  
506 my ldflags = $config->ldflags;
507 $config->ldflags(ldflags);
508  
509 Gets and sets C<ldflags> field, an array reference containing arguments of the linker L</"ld">.
510  
511 =head2 dynamic_lib_ldflags
512  
513 my dynamic_lib_ldflags = $config->dynamic_lib_ldflags;
514 $config->dynamic_lib_ldflags(dynamic_lib_ldflags);
515  
516 Gets and sets C<dynamic_lib_ldflags> field, an array reference containing arguments of the linker L</"ld"> for dynamic libraries.
517  
518 This field is automatically set and users nomally do not change it.
519  
520 =head2 thread_ldflags
521  
522 my thread_ldflags = $config->thread_ldflags;
523 $config->thread_ldflags(thread_ldflags);
524  
525 Gets and sets C<thread_ldflags> field, an array reference containing arguments of the linker L</"ld"> for threads.
526  
527 This field is automatically set and users nomally do not change it.
528  
529 =head2 libcpp_ldflags
530  
531 my $libcpp_ldflags = $config->libcpp_ldflags;
532 $config->libcpp_ldflags($libcpp_ldflags);
533  
534 Gets and sets C<libcpp_ldflags> field, an array reference containing arguments of the linker L</"ld"> for the C++ standard library.
535  
536 =head2 static_lib_braces
537  
538 my static_lib_braces = $config->static_lib_braces;
539 $config->static_lib_braces(static_lib_braces);
540  
541 Gets and sets C<static_lib_braces> field, an array reference containing a pair of arguments to start statically linking and end it.
542  
543 The library name added by the L</"add_static_lib"> are surrounded by the values of the pair.
544  
545 # -Wl,-Bstatic -llibfoo -Wl,-Bdynamic
546 $config->static_lib_braces(['-Wl,-Bstatic', '-Wl,-Bdynamic']);
547 $config->add_static_lib('foo');
548  
549 This field is automatically set and users nomally do not change it.
550  
551 This field only works correctly in Linux/Unix.
552  
553 Mac does not support these options. If you want to search a static library, create a new library search directory, copy a static library to there, and add the new library search directory.
554
555 # /path_for_static_lib/libz.a
556 $config->add_lib_dir('/path_for_static_lib');
557 $config->add_lib('z');
558  
559 MinGW on Windows supports these options, but instead of linking statically, it links dynamically with absolute paths. This is usually not the intended behavior. If you want to do static linking on Windows, you need to use C<-static> option.
560  
561 =head2 ld_optimize
562  
563 my $ld_optimize = $config->ld_optimize;
564 $config->ld_optimize($ld_optimize);
565  
566 Gets and sets C<ld_optimize> field, an argument of the linker L</"ld"> for optimization.
567  
568 Examples:
569  
570 $config->ld_optimize("-O2");
571  
572 =head2 ld_version
573  
574 my $ld_version = $config->ld_version;
575 $config->ld_version($ld_version);
576  
577 Gets and sets C<ld_version> field, the linker version to be used for the build cache digest.
578  
579 =head2 output_type
580  
581 my $output_type = $config->output_type;
582 $config->output_type($output_type);
583  
584 Gets and sets the C<"output_type"> field, which is the type of the output file generated by the linker C<"ld">.
585  
586 The following values are available:
587  
588 =over 2
589  
590 =item * C<"exe">
591  
592 The output file is an executable file.
593  
594 =item * C<"dynamic_lib">
595  
596 The output file is a dynamic link library.
597  
598 =item * C<"static_lib">
599  
600 The output file is a static link library.
601  
602 =back
603  
604 =head2 copyright_print_ldflags
605  
606 my $copyright_print_ldflags = $config->copyright_print_ldflags;
607 $config->copyright_print_ldflags(['-nologo']);
608  
609 Gets and sets the C<copyright_print_ldflags> field, an array reference containing linker arguments to control the printing of the copyright banner or logo (e.g., C<-nologo> in MSVC linker).
610  
611 =head2 warn_ldflags
612  
613 my $warn_ldflags = $config->warn_ldflags;
614 $config->warn_ldflags(['-Wl,--warn-common']);
615  
616 Gets and sets the C<warn_ldflags> field, an array reference containing linker arguments for warning settings.
617  
618 =head2 debug_info_ldflags
619  
620 my $debug_info_ldflags = $config->debug_info_ldflags;
621 $config->debug_info_ldflags(['-g']);
622  
623 Gets and sets the C<debug_info_ldflags> field, an array reference containing linker arguments for generating debug information.
624  
625 =head2 symbol_strip_ldflags
626  
627 my $symbol_strip_ldflags = $config->symbol_strip_ldflags;
628 $config->symbol_strip_ldflags(['-s']);
629  
630 Gets and sets the C<symbol_strip_ldflags> field, an array reference containing linker arguments to strip symbols.
631  
632 =head2 libgcc_ldflags
633  
634 my $libgcc_ldflags = $config->libgcc_ldflags;
635 $config->libgcc_ldflags(['-lgcc']);
636  
637 Gets and sets the C<libgcc_ldflags> field, an array reference containing linker arguments for the gcc library.
638  
639 =head2 libbcrypt_ldflags
640  
641 my $libbcrypt_ldflags = $config->libbcrypt_ldflags;
642 $config->libbcrypt_ldflags(['-lbcrypt']);
643  
644 Gets and sets the C<libbcrypt_ldflags> field, an array reference containing linker arguments for the bcrypt library.
645  
646 =head2 extra_ldflags
647  
648 my $extra_ldflags = $config->extra_ldflags;
649 $config->extra_ldflags(['-lextra']);
650  
651 Gets and sets the C<extra_ldflags> field, an array reference containing extra linker arguments.
652  
653 =head2 lib_dir_option_name
654  
655 my $lib_dir_option_name = $config->lib_dir_option_name;
656 $config->lib_dir_option_name($lib_dir_option_name);
657  
658 Gets and sets C<lib_dir_option_name> field, a string that is an option name to specify a library search path.
659  
660 =head2 dynamic_lib_ext
661  
662 my $dynamic_lib_ext = $config->dynamic_lib_ext;
663 $config->dynamic_lib_ext($dynamic_lib_ext);
664  
665 Gets and sets C<dynamic_lib_ext> field, the extension of a dynamic library such as C<so> or C<dll>.
666  
667 The dot C<.> is not included.
668  
669 =head2 static_lib_ext
670  
671 my $static_lib_ext = $config->static_lib_ext;
672 $config->static_lib_ext($static_lib_ext);
673  
674 Gets and sets C<static_lib_ext> field, the extension of a static library such as C<a> or C<lib>.
675  
676 The dot C<.> is not included.
677  
678 =head2 exe_ext
679  
680 my $exe_ext = $config->exe_ext;
681 $config->exe_ext($exe_ext);
682  
683 Gets and sets C<exe_ext> field, the extension of an executable file such as C<exe>.
684  
685 The dot C<.> is not included.
686  
687 =head2 lib_prefix
688  
689 my $lib_prefix = $config->lib_prefix;
690 $config->lib_prefix($lib_prefix);
691  
692 Gets and sets C<lib_prefix> field, the prefix of a library name such as C<lib>.
693  
694 =head2 lib_option_suffix
695  
696 my $lib_option_suffix = $config->lib_option_suffix;
697 $config->lib_option_suffix($lib_option_suffix);
698  
699 Gets and sets C<lib_option_suffix> field, the suffix of a library name such as C<.lib>.
700  
701 =head2 lib_option_name
702  
703 my $lib_option_name = $config->lib_option_name;
704 $config->lib_option_name($lib_option_name);
705  
706 Gets and sets C<lib_option_name> field, a string that is an option name to specify a library name.
707  
708 =head2 ld_output_option_name
709  
710 my $ld_output_option_name = $config->ld_output_option_name;
711 $config->ld_output_option_name($ld_output_option_name);
712  
713 Gets and sets C<ld_output_option_name> field, a string that is an option name to specify a linker output file name.
714  
715 =head2 ld_debug_output_option_name
716  
717 my $ld_debug_output_option_name = $config->ld_debug_output_option_name;
718 $config->ld_debug_output_option_name($ld_debug_output_option_name);
719  
720 Gets and sets C<ld_debug_output_option_name> field, a string that is an option name to specify a linker debug output file name such as C</PDB> in MSVC.
721  
722 =head2 output_file
723  
724 my $output_file = $config->output_file;
725 $config->output_file($output_file);
726  
727 Gets and sets C<output_file> field. A path of a dinamic link library or an executable file generated by the linker L</"ld">.
728  
729 =head2 debug_output_file
730  
731 my $debug_output_file = $config->debug_output_file;
732 $config->debug_output_file($debug_output_file);
733  
734 Gets and sets C<debug_output_file> field. A path of a debug information file (e.g., .pdb) generated by the linker L</"ld">.
735  
736 =head2 debug_output_file_ext
737  
738 my $debug_output_file_ext = $config->debug_output_file_ext;
739 $config->debug_output_file_ext($debug_output_file_ext);
740  
741 Gets and sets C<debug_output_file_ext> field. An extension of a debug information file (e.g., .pdb) generated by the linker L</"ld">.
742  
743 =head2 enable_ld_debug_output_option
744  
745 my $enable_ld_debug_output_option = $config->enable_ld_debug_output_option;
746 $config->enable_ld_debug_output_option($enable_ld_debug_output_option);
747  
748 Gets and sets C<enable_ld_debug_output_option> field. If this field is true, the linker L</"ld"> generates a debug information file.
749  
750 =head2 external_object_files
751  
752 my $external_object_files = $config->external_object_files;
753 $config->external_object_files($external_object_files);
754  
755 Gets and sets C<external_object_files> field, an array reference containing additinal external object files linked to an executable file.
756  
757 =head2 long_option_sep
758  
759 my $long_option_sep = $config->long_option_sep;
760 $config->long_option_sep($long_option_sep);
761  
762 Gets and sets C<long_option_sep> field, a string that is a separator between an option name and its value.
763  
764 =head2 debug_output_file_ldflags
765  
766 my $debug_output_file_ldflags = $config->debug_output_file_ldflags;
767 $config->debug_output_file_ldflags($debug_output_file_ldflags);
768  
769 Gets and sets C<debug_output_file_ldflags> field, an array reference containing arguments of the linker L</"ld"> for the debug information file.
770  
771 =head2 link_to
772  
773 my $link_to = $config->link_to;
774 $config->link_to($link_to);
775  
776 Gets and sets C<link_to> field, which is the class name to link to.
777  
778 =head1 Class Methods
779  
780 =head2 new
781  
782 my $config = SPVM::Builder::Config::Linker->new(%fields);
783  
784 Creates a new C<SPVM::Builder::Config::Linker> object. This method calls the C<new> method of the super class L<SPVM::Builder::Config::Base>.
785  
786 Field Default Values:
787  
788 =over 2
789  
790 =item * L</"ld">
791  
792 If C<$Config{gccversion}> contains C<clang>, L</"ld"> field are set to C<clang++>. Otherwise, it is set to C<g++>.
793  
794 =item * L</"ldflags">
795  
796 []
797  
798 =item * L</"ld_optimize">
799  
800 ""
801  
802 =item * L</"ld_version">
803  
804 The return value of L</"create_ld_version">.
805  
806 =item * L</"output_type">
807  
808 "dynamic_lib"
809  
810 =item * L</"copyright_print_ldflags">
811  
812 []
813  
814 =item * L</"warn_ldflags">
815  
816 []
817  
818 =item * L</"debug_info_ldflags">
819  
820 []
821  
822 =item * L</"symbol_strip_ldflags">
823  
824 []
825  
826 =item * L</"libgcc_ldflags">
827  
828 Windows:
829  
830 ["-Wl,-Bstatic", "-lgcc", "-Wl,-Bdynamic"]
831  
832 Other OSs:
833  
834 []
835  
836 =item * L</"extra_ldflags">
837  
838 []
839  
840 =item * L</"dynamic_lib_ldflags">
841  
842 Windows:
843  
844 ["-mdll"]
845  
846 Other OSs:
847  
848 ["-shared"]
849  
850 =item * L</"thread_ldflags">
851  
852 Windows:
853  
854 ["-pthread", "-Wl,-Bstatic", "-lwinpthread", "-Wl,-Bdynamic"]
855  
856 Other OSs:
857  
858 ["-pthread"]
859  
860 =item * L</"libbcrypt_ldflags">
861  
862 Windows:
863  
864 ["-lbcrypt"]
865  
866 Other OSs:
867  
868 []
869  
870 =item * L</"libcpp_ldflags">
871  
872 Windows:
873  
874 ["-Wl,-Bstatic", "-lstdc++", "-Wl,-Bdynamic"]
875  
876 Mac:
877  
878 ["-nostdlib++", "-lc++"]
879  
880 Other OSs:
881  
882 ["-lstdc++"]
883  
884 =item * L</"static_lib_braces">
885  
886 ["-Wl,-Bstatic", "-Wl,-Bdynamic"]
887  
888 =item * L</"lib_dirs">
889  
890 []
891  
892 =item * L</"libs">
893  
894 []
895  
896 =item * L</"lib_prefix">
897  
898 "lib"
899  
900 =item * L</"lib_option_name">
901  
902 "-l"
903  
904 =item * L</"lib_option_suffix">
905  
906 ""
907  
908 =item * L</"lib_dir_option_name">
909  
910 "-L"
911  
912 =item * L</"dynamic_lib_ext">
913  
914 $Config{so} without the leading dot.
915  
916 =item * L</"exe_ext">
917  
918 $Config{_exe} without the leading dot. If $Config{_exe} is an empty string, it is set to undef.
919  
920 =item * L</"ld_output_option_name">
921  
922 "-o"
923  
924 =item * L</"hint_cc">
925  
926 The default value is C<clang++> if C<$Config{gccversion}> contains C<clang> (case-insensitive). Otherwise, it is C<g++>.
927  
928 =item * L</"long_option_sep">
929  
930 "="
931  
932 =back
933  
934 =cut
935  
936 =head1 Instance Methods
937  
938 =head2 add_ldflag
939  
940 $config->add_ldflag(@ldflags);
941  
942 Adds @ldflags to the end of L</"ldflags"> field.
943  
944 =head2 add_lib_dir
945  
946 $config->add_lib_dir(@lib_dirs);
947  
948 Adds @lib_dirs to the end of L</"lib_dirs"> field.
949  
950 =head2 add_lib
951  
952 $config->add_lib(@libs);
953  
954 Adds @libs to the end of L</"libs"> field.
955  
956 Examples:
957  
958 $config->add_lib('gsl');
959 $config->add_lib('gsl', 'z');
960 $config->add_lib(
961 SPVM::Builder::LibInfo->new(config => $config, name => 'gsl'),
962 SPVM::Builder::LibInfo->new(config => $config, name => 'z', is_abs => 1),
963 );
964  
965 =head2 add_lib_abs
966  
967 $config->add_lib_abs(@libs);
968  
969 Adds @libs to the end of L</"libs"> field with L<SPVM::Builder::LibInfo#is_abs|SPVM::Builder::LibInfo/"is_abs"> field set to a true value.
970  
971 If a value in @libs is not an L<SPVM::Builder::LibInfo> object, an L<SPVM::Builder::LibInfo> object is created from the library name.
972  
973 If the library is located in your user directory, it is good to use L</"add_lib_abs"> method instead of L</"add_lib"> method.
974  
975 This is because if the generated dynamic link library has a relative path, that path cannot be resolved when it is loaded.
976  
977 For system libraries, there is no problem because the linker knows the search directory for the library.
978  
979 =head2 add_static_lib
980  
981 $config->add_static_lib(@libs);
982  
983 Adds @libs to the end of L</"libs"> field with L<SPVM::Builder::LibInfo#is_static|SPVM::Builder::LibInfo/"is_static"> field set to a true value.
984  
985 If a value in @libs is not an L<SPVM::Builder::LibInfo> object, an L<SPVM::Builder::LibInfo> object is created from the library name.
986  
987 Examples:
988  
989 $config->add_static_lib('gsl');
990 $config->add_static_lib('gsl', 'z');
991  
992 =head2 add_static_lib_abs
993  
994 $config->add_static_lib_abs(@libs);
995  
996 Adds @libs to the end of L</"libs"> field with L<SPVM::Builder::LibInfo#is_static|SPVM::Builder::LibInfo/"is_static"> field and L<SPVM::Builder::LibInfo#is_abs|SPVM::Builder::LibInfo/"is_abs"> field set to a true value.
997  
998 If a value in @libs is not an L<SPVM::Builder::LibInfo> object, an L<SPVM::Builder::LibInfo> object is created from the library name.
999  
1000 =head2 use_resource
1001  
1002 my $resource = $config->use_resource($resource_name);
1003 my $resource = $config->use_resource($resource_name, %options);
1004  
1005 Loads a L<resource|SPVM::Document::Resource> given a resource class name, and returns it. The return value is an L<SPVM::Builder::Resource> object.
1006  
1007 Examples:
1008  
1009 $config->use_resource('Resource::MyResource');
1010  
1011 =head2 get_resource
1012  
1013 my $resource = $config->get_resource($resource_name);
1014  
1015 Gets a resource loaded by L</"use_resource"> method given a resource name, and returns it. The return value is an L<SPVM::Builder::Resource> object.
1016  
1017 =head2 get_resource_names
1018  
1019 my $resource_names = $config->get_resource_names;
1020  
1021 Returns resource names loaded by L</"use_resource"> method.
1022  
1023 =head2 get_ld_system_field_names
1024  
1025 my $field_names = $config->get_ld_system_field_names;
1026  
1027 Returns the field names of the linker settings that are set by default for a specific environment.
1028  
1029 These fields might be updated in the future to support appropriate settings for different environments.
1030  
1031 The field names returned by this method are used by the L<clear_system_fields|/"clear_system_fields"> method to clear the linker settings.
1032  
1033 The following field names are returned:
1034  
1035 =over 2
1036  
1037 =item * C<dynamic_lib_ldflags>
1038  
1039 =item * C<thread_ldflags>
1040  
1041 =item * C<libcpp_ldflags>
1042  
1043 =item * C<copyright_print_ldflags>
1044  
1045 =item * C<warn_ldflags>
1046  
1047 =item * C<debug_info_ldflags>
1048  
1049 =item * C<symbol_strip_ldflags>
1050  
1051 =item * C<libgcc_ldflags>
1052  
1053 =item * C<libbcrypt_ldflags>
1054  
1055 =item * C<extra_ldflags>
1056  
1057 =item * C<debug_output_file_ldflags>
1058  
1059 =back
1060  
1061 =cut
1062  
1063 =head2 clear_system_fields
1064  
1065 $config->clear_system_fields;
1066  
1067 Clears the fields that are set by default for a specific environment.
1068  
1069 These fields might be updated in the future to support appropriate settings for different environments.
1070  
1071 This method clears the linker settings whose field names are returned by the L<get_ld_system_field_names|/"get_ld_system_field_names"> method by setting them to C<[]>.
1072  
1073 =over 2
1074  
1075 =item * L</"thread_ldflags">
1076  
1077 =item * L</"dynamic_lib_ldflags">
1078  
1079 =item * L</"copyright_print_ldflags">
1080  
1081 =item * L</"warn_ldflags">
1082  
1083 =item * L</"debug_info_ldflags">
1084  
1085 =item * L</"symbol_strip_ldflags">
1086  
1087 =item * L</"libgcc_ldflags">
1088  
1089 =item * L</"extra_ldflags">
1090  
1091 =item * L</"libcpp_ldflags">
1092  
1093 =item * L</"libbcrypt_ldflags">
1094  
1095 =item * L</"debug_output_file_ldflags">
1096  
1097 =back
1098  
1099 =head2 add_external_object_file
1100  
1101 $config->add_external_object_file(@external_object_files);
1102  
1103 Adds @external_object_files to the end of L</"external_object_files"> field.
1104  
1105 =head2 create_option
1106  
1107 my $option = $config->create_option("-std", "c11");
1108  
1109 Builds a command line option from the option name and the value.
1110  
1111 If the length of the option name (excluding leading C<-> and C</>) is 1, the option name and the value are connected without a separator.
1112  
1113 # Results in "-Ic:/path"
1114 my $option = $config->create_option("-I", "c:/path");
1115  
1116 If the length of the option name is greater than 1, they are connected using L</"long_option_sep">.
1117  
1118 # Results in "-std=c11" (if long_option_sep is "=")
1119 my $option = $config->create_option("-std", "c11");
1120  
1121 This method is useful for supporting different compiler conventions such as GCC/Clang and MSVC.
1122  
1123 =head2 create_option_short
1124  
1125 my $option = $config->create_option_short("-I", "c:/path");
1126  
1127 Builds a command line option by connecting the option name and the value directly without a separator.
1128  
1129 # Results in "-Ic:/path"
1130 my $option = $config->create_option_short("-I", "c:/path");
1131  
1132 # Results in "-Foc:/path" (Useful for MSVC even if the option name length > 1)
1133 my $option = $config->create_option_short("-Fo", "c:/path");
1134  
1135 =head2 create_option_long
1136  
1137 my $option = $config->create_option_long("-std", "c11");
1138  
1139 Builds a command line option by connecting the option name and the value using L</"long_option_sep">.
1140  
1141 # Results in "-std=c11" (if long_option_sep is "=")
1142 my $option = $config->create_option_long("-std", "c11");
1143  
1144 # Results in "-out:c:/path" (if long_option_sep is ":")
1145 my $option = $config->create_option_long("-out", "c:/path");
1146  
1147 =head2 create_ld_version
1148  
1149 my $cc_version = $config->create_ld_version;
1150  
1151 Executes the linker defined in L</"ld"> with the C<--version> option and returns the output.
1152  
1153 The return value contains the linker command itself and its version information (the first line of the output).
1154  
1155 If the execution fails, an empty string is returned.
1156  
1157 This information is intended to be used as a part of the digest for the build cache.
1158  
1159 =head1 Library Path Resolution
1160  
1161 The following is the rule of library path resolution.
1162  
1163 Library names are converted to L<SPVM::Builder::LibInfo> objects.
1164  
1165 If L<SPVM::Builder::LibInfo#is_abs|SPVM::Builder::LibInfo/"is_abs"> field is a false value, the linker L</"ld"> resolves libaray paths.
1166  
1167 If L<SPVM::Builder::LibInfo#is_abs|SPVM::Builder::LibInfo/"is_abs"> field is a true value, libaray paths are resolved by the following rules.
1168  
1169 A library is searched in the library search directories contained in L</"lib_dir"> field from the beginning.
1170  
1171 If L<SPVM::Builder::LibInfo#is_static|SPVM::Builder::LibInfo/"is_static"> field is a false value, the search is performed in the order of a dynamic library, a static library.
1172  
1173 If L<SPVM::Builder::LibInfo#is_static|SPVM::Builder::LibInfo/"is_static"> field is a true value, the search is performed only in static libraries.
1174  
1175 If a library is found, C<-l> option of the linker L</"ld"> is created using the found absolute path.
1176  
1177  
1178 =head1 Copyright & License
1179  
1180 Copyright (c) 2023 Yuki Kimoto
1181  
1182 MIT License
« blib/lib/SPVM/Builder.pm ↑ Summary blib/lib/SPVM/Builder/LibInfo.pm »