| File: | config/auto/memalign.pm |
| Coverage: | 92.5% |
| line | stmt | bran | cond | sub | code |
|---|---|---|---|---|---|
| 1 | # Copyright (C) 2001-2009, Parrot Foundation. | ||||
| 2 | |||||
| 3 - 11 | =head1 NAME config/auto/memalign.pm - Memory Alignment =head1 DESCRIPTION Determines if the C library supports C<memalign()>. =cut | ||||
| 12 | |||||
| 13 | package auto::memalign; | ||||
| 14 | |||||
| 15 | 2 2 2 | use strict; | |||
| 16 | 2 2 2 | use warnings; | |||
| 17 | |||||
| 18 | 2 2 2 | use base qw(Parrot::Configure::Step); | |||
| 19 | |||||
| 20 | 2 2 2 | use Parrot::Configure::Utils ':auto'; | |||
| 21 | |||||
| 22 | |||||
| 23 | sub _init { | ||||
| 24 | 4 | my $self = shift; | |||
| 25 | 4 | my %data; | |||
| 26 | 4 | $data{description} = q{Does your C library support memalign}; | |||
| 27 | 4 | $data{result} = q{}; | |||
| 28 | 4 | return \%data; | |||
| 29 | } | ||||
| 30 | |||||
| 31 | sub runstep { | ||||
| 32 | 2 | my ( $self, $conf ) = @_; | |||
| 33 | |||||
| 34 | 2 | if ( defined $conf->data->get('memalign') ) { | |||
| 35 | |||||
| 36 | # already set; leave it alone | ||||
| 37 | 1 | $self->set_result('already set'); | |||
| 38 | 1 | return 1; | |||
| 39 | } | ||||
| 40 | 1 | my $test = 0; | |||
| 41 | |||||
| 42 | 1 | _set_malloc_header($conf); | |||
| 43 | |||||
| 44 | 1 | $conf->cc_gen('config/auto/memalign/test_c.in'); | |||
| 45 | 1 1 | eval { $conf->cc_build(); }; | |||
| 46 | 1 | unless ( $@ || $conf->cc_run_capture() !~ /ok/ ) { | |||
| 47 | 1 | $test = 1; | |||
| 48 | } | ||||
| 49 | 1 | $conf->cc_clean(); | |||
| 50 | |||||
| 51 | 1 | my $test2 = 0; | |||
| 52 | |||||
| 53 | 1 | $conf->cc_gen('config/auto/memalign/test2_c.in'); | |||
| 54 | 1 1 | eval { $conf->cc_build(); }; | |||
| 55 | 1 | unless ( $@ || $conf->cc_run_capture() !~ /ok/ ) { | |||
| 56 | 1 | $test2 = 1; | |||
| 57 | } | ||||
| 58 | 1 | $conf->cc_clean(); | |||
| 59 | |||||
| 60 | 1 | $self->_set_memalign($conf, $test, $test2); | |||
| 61 | |||||
| 62 | 1 | return 1; | |||
| 63 | } | ||||
| 64 | |||||
| 65 | sub _set_malloc_header { | ||||
| 66 | 3 | my $conf = shift; | |||
| 67 | 3 | if ( $conf->data->get('i_malloc') ) { | |||
| 68 | 2 | $conf->data->set( malloc_header => 'malloc.h' ); | |||
| 69 | } | ||||
| 70 | else { | ||||
| 71 | 1 | $conf->data->set( malloc_header => 'stdlib.h' ); | |||
| 72 | } | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | sub _set_memalign { | ||||
| 76 | 9 | my $self = shift; | |||
| 77 | 9 | my ($conf, $test, $test2) = @_; | |||
| 78 | 9 | $conf->data->set( malloc_header => undef ); | |||
| 79 | |||||
| 80 | 9 | my $f = | |||
| 81 | $test2 ? 'posix_memalign' | ||||
| 82 | : $test ? 'memalign' | ||||
| 83 | : ''; | ||||
| 84 | 9 | $conf->data->set( memalign => $f ); | |||
| 85 | 9 | my $test_str = $test ? " (Yep:$f) " : " (no) "; | |||
| 86 | 9 | $conf->debug($test_str); | |||
| 87 | 9 | $self->set_result( $test ? 'yes' : 'no' ); | |||
| 88 | } | ||||
| 89 | |||||
| 90 | 1; | ||||
| 91 | |||||
| 92 | # Local Variables: | ||||
| 93 | # mode: cperl | ||||
| 94 | # cperl-indent-level: 4 | ||||
| 95 | # fill-column: 100 | ||||
| 96 | # End: | ||||
| 97 | # vim: expandtab shiftwidth=4: | ||||