File Coverage

File:config/init/defaults.pm
Coverage:93.3%

linestmtbrancondsubcode
1# Copyright (C) 2001-2011, Parrot Foundation.
2
3 - 11
=head1 NAME

config/init/defaults.pm - Configuration Defaults

=head1 DESCRIPTION

Sets up the configuration system's default values and data structures.

=cut
12
13package init::defaults;
14
15
7
7
7
use strict;
16
7
7
7
use warnings;
17
18
7
7
7
use base qw(Parrot::Configure::Step);
19
20
7
7
7
use Config;
21
7
7
7
use File::Which;
22
7
7
7
use FindBin; # see build_dir
23
7
7
7
use Parrot::BuildUtil;
24
7
7
7
use Parrot::Configure::Step;
25
7
7
7
use Parrot::Harness::DefaultTests ();
26
7
7
7
use Cwd qw(abs_path);
27
7
7
7
use File::Spec;
28
29
30sub _init {
31
18
    my $self = shift;
32
18
    my %data;
33
18
    $data{description} = q{Set Configure's default values};
34
18
    $data{result} = q{};
35
18
    return \%data;
36}
37
38my $parrot_version = Parrot::BuildUtil::parrot_version();
39my @parrot_version = Parrot::BuildUtil::parrot_version();
40
41sub runstep {
42
16
    my ( $self, $conf ) = @_;
43
44    # Later configuration steps need access to values from the Perl 5
45    # %Config. However, other later configuration steps may change
46    # the corresponding values in the Parrot::Configure object. In
47    # order to provide access to the original values from Perl 5
48    # %Config, we grab those settings we need now and store them in
49    # special keys within the Parrot::Configure object. We label these keys
50    # '_provisional' to alert users that these should only be used during
51    # configuration and testing of configuration steps. They should not be
52    # used during Parrot's build, nor should they be used in 'make test'.
53    #
54    # This is a multi-stage process.
55
56    # Stage 1:
57
16
    foreach my $orig ( qw|
58        archname
59        ccflags
60        d_socklen_t
61        optimize
62        osvers
63        scriptdirexp
64        sig_name
65        sPRIgldbl
66    | ) {
67
128
        $conf->data->set( qq|${orig}_provisional| => $Config{$orig} );
68    }
69
70    # Stage 2 (anticipating needs of config/auto/headers.pm):
71    $conf->data->set_p5(
72
16
1392
17584
        map { $_ => $Config{$_} } grep { /^i_/ } keys %Config
73    );
74
75    # Stage 3 (Along similar lines, look up values from Perl 5 special
76    # variables and stash them for later lookups. Name them according
77    # to their 'use English' names as documented in 'perlvar'.)
78
16
    $conf->data->set( OSNAME_provisional => $^O );
79
80
16
    my $ccdlflags = $Config{ccdlflags};
81
16
    $ccdlflags =~ s/\s*-Wl,-rpath,\S*//g if $conf->options->get('disable-rpath');
82
83
16
    my $build_dir = abs_path($FindBin::Bin);
84
85
16
    my $cc_option = $conf->options->get('cc');
86    # We need a Glossary somewhere!
87
16
    $conf->data->set(
88        debugging => $conf->options->get('debugging') ? 1 : 0,
89        optimize => '',
90        verbose => $conf->options->get('verbose'),
91        build_dir => $build_dir,
92        configured_from_file =>
93            $conf->options->get('configured_from_file') || '',
94        configuration_steps => ( join q{ } => $conf->get_list_of_steps() ),
95
96        # Compiler -- used to turn .c files into object files.
97        # (Usually cc or cl, or something like that.)
98        cc => $cc_option ? $cc_option : $Config{cc},
99        # If we specify a compiler, we can't use existing ccflags.
100        ccflags => $cc_option ? '' : $Config{ccflags},
101        ccwarn => '',
102
103        # Flags used to indicate this object file is to be compiled
104        # with position-independent code suitable for dynamic loading.
105        cc_shared => $Config{cccdlflags}, # e.g. -fpic for GNU cc.
106
107        # C++ compiler -- used to compile parts of ICU. ICU's configure
108        # will try to find a suitable compiler, but it prefers GNU c++ over
109        # a system c++, which might not be appropriate. This setting
110        # allows you to override ICU's guess, but is otherwise currently
111        # unset. Ultimately, it should be set to whatever ICU figures
112        # out, or parrot should look for it and always tell ICU what to
113        # use.
114        cxx => 'c++',
115
116        # Linker, used to link object files (plus libraries) into
117        # an executable. It is usually $cc on Unix-ish systems.
118        # VMS and Win32 might use "Link".
119        # Perl5's Configure doesn't distinguish linking from loading, so
120        # make a reasonable guess at defaults.
121        link => $Config{cc},
122        linkflags => $Config{ldflags},
123
124        # Linker Flags to have this binary work with the shared and dynamically
125        # loadable libraries we're building. On HP-UX, for example, we need to
126        # allow dynamic libraries to access the binary's symbols
127        link_dynamic => $ccdlflags, # e.g. -Wl,-E on HP-UX
128
129        # ld: Tool used to build shared libraries and dynamically loadable
130        # modules. Often $cc on Unix-ish systems, but apparently sometimes
131        # it's ld.
132        ld => $Config{ld},
133        ldflags => $Config{ldflags},
134
135        # Some operating systems (e.g. Darwin) distinguish between shared
136        # libraries and modules that can be dynamically loaded. Flags to tell
137        # ld to build a shared library, e.g. -shared for GNU ld.
138        ld_share_flags => $Config{lddlflags},
139
140        # Flags to tell ld to build a dynamically loadable module, e.g.
141        # -shared for GNU ld.
142        ld_load_flags => $Config{lddlflags},
143
144        libs => $Config{libs},
145
146        cc_inc => "-I./include -I./include/pmc",
147        cc_debug => '-g',
148        link_debug => '',
149
150        o => $Config{_o}, # object files extension
151        share_ext => ".$Config{so}", # shared library extension
152
153        # dynamically loadable module extension
154        load_ext => ".$Config{so}",
155        a => $Config{_a}, # library or archive extension
156        exe => $Config{_exe}, # executable files extension
157        cc_o_out => '-o ', # cc object output file
158
159        # cc executable output file (different on Win32)
160        cc_exe_out => '-o ',
161
162        # prefix for ldflags (necessary for Win32)
163        cc_ldflags => '',
164
165        # ld output file. Keep the trailing space.
166        ld_out => '-o ',
167
168        # include debug info in executable
169        ld_debug => '',
170
171        # Way to decorate a function to mark it as an exportable or
172        # importable symbol.
173        sym_export => '',
174        sym_import => '',
175
176        # Library build directory
177        blib_dir => 'blib/lib',
178
179        # libparrot library names
180        libparrot_static => 'libparrot' . $Config{_a},
181        libparrot_shared => 'libparrot.' . $Config{so},
182
183        # does the system know about static/dynamic linking?
184        has_static_linking => 1,
185        has_dynamic_linking => 0,
186
187        # default behaviour for linking parrot to a static or shared libparrot
188        parrot_is_shared => 0,
189
190        #avoid a warning during Configure.pl
191        libparrot_soname => '',
192
193        perl => $^X,
194        test_prog => 'parrot',
195
196        # some utilities in Makefile
197        cat => '$(PERL) -MExtUtils::Command -e cat',
198        chmod => '$(PERL) -MExtUtils::Command -e chmod',
199        cp => '$(PERL) -MExtUtils::Command -e cp',
200        mkpath => '$(PERL) -MExtUtils::Command -e mkpath',
201        mv => '$(PERL) -MExtUtils::Command -e mv',
202        rm_f => '$(PERL) -MExtUtils::Command -e rm_f',
203        rm_rf => '$(PERL) -MExtUtils::Command -e rm_rf',
204        touch => '$(PERL) -MExtUtils::Command -e touch',
205
206        # tar is currently used only in 'make release'.
207        tar => which('tar') || '',
208
209        ar => $Config{ar},
210        arflags => 'cr',
211
212        # for Win32
213        ar_out => '',
214
215        # for Borland C
216        ar_extra => '',
217        ranlib => $Config{ranlib},
218        rpath => '',
219        make => $Config{make},
220        make_set_make => $Config{make_set_make},
221        make_and => '&&',
222
223        # make_c: Command to emulate GNU make's C<-C directory> option: chdir
224        # to C<directory> before executing $(MAKE)
225        make_c => '$(PERL) -e \'chdir shift @ARGV; system q{$(MAKE)}, @ARGV; exit $$? >> 8;\'',
226
227        # if platform has a .s file that needs to be assembled
228        platform_asm => 0,
229        as => 'as', # assembler
230
231        lns => $Config{lns}, # soft link
232        slash => '/',
233
234        VERSION => $parrot_version,
235        MAJOR => $parrot_version[0],
236        MINOR => $parrot_version[1],
237        PATCH => $parrot_version[2],
238        DEVEL => ( -e 'DEVELOPING' ? '-devel' : '' ),
239
240        configdate => scalar gmtime() . " GMT",
241        PQ => "'",
242        dquote => "\\\"",
243
244        # yacc = Automatic parser generator
245        # lex = Automatic lexer generator
246        # Some systems may lack these
247        yacc => 'bison -v -y',
248        lex => 'flex',
249
250        # Extra flags needed for libnci_test.so
251        ncilib_link_extra => '',
252
253        # Flag determines if pmc2c.pl and ops2c.pl also
254        # generate #line directives. These can confuse
255        # debugging internals.
256        no_lines_flag => $conf->options->get('no-line-directives') ? '--no-lines' : '',
257
258        tempdir => File::Spec->tmpdir,
259
260        coveragedir => $conf->options->get('coveragedir') || $build_dir,
261    );
262
263    # GH #383: Profiling options are too specific to GCC
264
15
    if ( $conf->options->get('profile') ) {
265
1
        $conf->data->set(
266            cc_debug => " -pg ",
267            ld_debug => " -pg ",
268        );
269    }
270
271
15
    $conf->data->set( clock_best => "" );
272
273
15
    $conf->data->set( 'archname', $Config{archname});
274
275
15
    $conf->data->set( has_core_nci_thunks => 1 );
276
15
    $conf->data->set( HAS_CORE_NCI_THUNKS => 1 );
277
15
    if ( $conf->options->get( 'without-core-nci-thunks' ) ) {
278
2
        $conf->data->set( has_core_nci_thunks => 0 );
279
2
        $conf->data->set( HAS_CORE_NCI_THUNKS => 0 );
280    }
281
282
15
    $conf->data->set( has_extra_nci_thunks => 1 );
283
15
    $conf->data->set( HAS_EXTRA_NCI_THUNKS => 1 );
284
15
    if ( $conf->options->get( 'without-extra-nci-thunks' ) ) {
285
1
        $conf->data->set( has_extra_nci_thunks => 0 );
286
1
        $conf->data->set( HAS_EXTRA_NCI_THUNKS => 0 );
287    }
288
289    # adjust archname, cc and libs for e.g. --m=32
290    # remember corrected archname - jit.pm was using $Config('archname')
291
15
    _64_bit_adjustments($conf);
292
293
15
    _set_default_tests($conf);
294
295
15
    return 1;
296}
297
298sub _64_bit_adjustments {
299
17
    my $conf = shift;
300
17
    my $m = $conf->options->get('m');
301
17
    if ($m) {
302
2
        my $archname = $conf->data->get('archname');
303
2
        if ( $archname =~ /x86_64/ && $m eq '32' ) {
304
1
            $archname =~ s/x86_64/i386/;
305
306            # adjust gcc?
307            ## add parentheses around qw(...)
308            ## to remove deprecation warning in perl 5.14.0
309
1
            for my $cc (qw(cc cxx link ld)) {
310
4
                $conf->data->add( ' ', $cc, '-m32' );
311            }
312
313            # and lib flags
314
1
            for my $lib (qw(ld_load_flags ld_share_flags ldflags linkflags)) {
315
4
                my $item = $conf->data->get($lib);
316
4
                ( my $ni = $item ) =~ s/lib64/lib/g;
317
4
                $conf->data->set( $lib, $ni );
318            }
319        }
320
2
        $conf->data->set( 'archname', $archname );
321    }
322
17
    return 1;
323}
324
325sub _set_default_tests {
326
15
    my $conf = shift;
327
15
    $conf->data->set( 'runcore_tests' =>
328        ( join ' ' => @Parrot::Harness::DefaultTests::runcore_tests ) );
329
15
    $conf->data->set( 'core_tests' =>
330        ( join ' ' => @Parrot::Harness::DefaultTests::core_tests ) );
331
15
    $conf->data->set( 'library_tests' =>
332        ( join ' ' => @Parrot::Harness::DefaultTests::library_tests ) );
333
15
    $conf->data->set( 'configure_tests' =>
334        ( join ' ' => @Parrot::Harness::DefaultTests::configure_tests ) );
335
15
    $conf->data->set( 'developing_tests' =>
336        ( join ' ' => @Parrot::Harness::DefaultTests::developing_tests ) );
337}
338
3391;
340
341# Local Variables:
342# mode: cperl
343# cperl-indent-level: 4
344# fill-column: 100
345# End:
346# vim: expandtab shiftwidth=4: