tagged release 0.6.4
[parrot.git] / config / auto / memalign.pm
blob39635dc9df3b71cc747954b35e919302fb2b0473
1 # Copyright (C) 2001-2003, The Perl Foundation.
2 # $Id$
4 =head1 NAME
6 config/auto/memalign.pm - Memory Alignment
8 =head1 DESCRIPTION
10 Determines if the C library supports C<memalign()>.
12 =cut
14 package auto::memalign;
16 use strict;
17 use warnings;
19 use base qw(Parrot::Configure::Step);
21 use Parrot::Configure::Utils ':auto';
24 sub _init {
25 my $self = shift;
26 my %data;
27 $data{description} = q{Determining if your C library supports memalign};
28 $data{result} = q{};
29 return \%data;
32 sub runstep {
33 my ( $self, $conf ) = @_;
35 if ( $conf->options->get('miniparrot') ) {
36 $conf->data->set( memalign => '' );
37 $self->set_result('skipped');
38 return 1;
41 if ( defined $conf->data->get('memalign') ) {
43 # already set; leave it alone
44 $self->set_result('already set');
45 return 1;
47 my $test = 0;
49 _set_malloc_header($conf);
51 _set_ptrcast($conf);
53 $conf->cc_gen('config/auto/memalign/test_c.in');
54 eval { $conf->cc_build(); };
55 unless ( $@ || $conf->cc_run_capture() !~ /ok/ ) {
56 $test = 1;
58 $conf->cc_clean();
60 my $test2 = 0;
62 $conf->cc_gen('config/auto/memalign/test_c2.in');
63 eval { $conf->cc_build(); };
64 unless ( $@ || $conf->cc_run_capture() !~ /ok/ ) {
65 $test2 = 1;
67 $conf->cc_clean();
69 $self->_set_memalign($conf, $test, $test2);
71 return 1;
74 sub _set_malloc_header {
75 my $conf = shift;
76 if ( $conf->data->get('i_malloc') ) {
77 $conf->data->set( malloc_header => 'malloc.h' );
79 else {
80 $conf->data->set( malloc_header => 'stdlib.h' );
84 sub _set_ptrcast {
85 my $conf = shift;
86 if ( $conf->data->get('ptrsize') == $conf->data->get('intsize') ) {
87 $conf->data->set( ptrcast => 'int' );
89 else {
90 $conf->data->set( ptrcast => 'long' );
94 sub _set_memalign {
95 my $self = shift;
96 my ($conf, $test, $test2) = @_;
97 $conf->data->set( malloc_header => undef );
99 my $f =
100 $test2 ? 'posix_memalign'
101 : $test ? 'memalign'
102 : '';
103 $conf->data->set( memalign => $f );
104 print( $test ? " (Yep:$f) " : " (no) " ) if $conf->options->get('verbose');
105 $self->set_result( $test ? 'yes' : 'no' );
110 # Local Variables:
111 # mode: cperl
112 # cperl-indent-level: 4
113 # fill-column: 100
114 # End:
115 # vim: expandtab shiftwidth=4: