| File: | config/auto/env.pm |
| Coverage: | 91.4% |
| line | stmt | bran | cond | sub | code |
|---|---|---|---|---|---|
| 1 | # Copyright (C) 2001-2009, Parrot Foundation. | ||||
| 2 | |||||
| 3 - 15 | =head1 NAME config/auto/env.pm - System Environment =head1 DESCRIPTION Determining if the C library has C<setenv()> and C<unsetenv()>. More information about these functions can be found at L<http://www.gnu.org/software/libc/manual/html_node/Environment-Access.html>, among other locations. =cut | ||||
| 16 | |||||
| 17 | package auto::env; | ||||
| 18 | |||||
| 19 | 2 2 2 | use strict; | |||
| 20 | 2 2 2 | use warnings; | |||
| 21 | |||||
| 22 | 2 2 2 | use base qw(Parrot::Configure::Step); | |||
| 23 | |||||
| 24 | 2 2 2 | use Parrot::Configure::Utils ':auto'; | |||
| 25 | |||||
| 26 | sub _init { | ||||
| 27 | 4 | my $self = shift; | |||
| 28 | 4 | my %data; | |||
| 29 | 4 | $data{description} = q{Does your C library have setenv / unsetenv}; | |||
| 30 | 4 | $data{result} = q{}; | |||
| 31 | 4 | return \%data; | |||
| 32 | } | ||||
| 33 | |||||
| 34 | sub runstep { | ||||
| 35 | 2 | my ( $self, $conf ) = ( shift, shift ); | |||
| 36 | |||||
| 37 | 2 | my ( $setenv, $unsetenv ) = ( 0, 0 ); | |||
| 38 | |||||
| 39 | 2 | $conf->cc_gen('config/auto/env/test_setenv_c.in'); | |||
| 40 | 2 2 | eval { $conf->cc_build(); }; | |||
| 41 | 2 | unless ( $@ || $conf->cc_run() !~ /ok/ ) { | |||
| 42 | 2 | $setenv = 1; | |||
| 43 | } | ||||
| 44 | 2 | $conf->cc_clean(); | |||
| 45 | 2 | $conf->cc_gen('config/auto/env/test_unsetenv_c.in'); | |||
| 46 | 2 2 | eval { $conf->cc_build(); }; | |||
| 47 | 2 | unless ( $@ || $conf->cc_run() !~ /ok/ ) { | |||
| 48 | 2 | $unsetenv = 1; | |||
| 49 | } | ||||
| 50 | 2 | $conf->cc_clean(); | |||
| 51 | |||||
| 52 | 2 | $self->_evaluate_env($conf, $setenv, $unsetenv); | |||
| 53 | |||||
| 54 | 2 | return 1; | |||
| 55 | } | ||||
| 56 | |||||
| 57 | sub _evaluate_env { | ||||
| 58 | 10 | my ($self, $conf, $setenv, $unsetenv) = @_; | |||
| 59 | 10 | $conf->data->set( | |||
| 60 | setenv => $setenv, | ||||
| 61 | unsetenv => $unsetenv | ||||
| 62 | ); | ||||
| 63 | |||||
| 64 | 10 | if ( $setenv && $unsetenv ) { | |||
| 65 | 4 | $conf->debug(" (both) "); | |||
| 66 | 4 | $self->set_result('both'); | |||
| 67 | } | ||||
| 68 | elsif ($setenv) { | ||||
| 69 | 2 | $conf->debug(" (setenv) "); | |||
| 70 | 2 | $self->set_result('setenv'); | |||
| 71 | } | ||||
| 72 | elsif ($unsetenv) { | ||||
| 73 | 2 | $conf->debug(" (unsetenv) "); | |||
| 74 | 2 | $self->set_result('unsetenv'); | |||
| 75 | } | ||||
| 76 | else { | ||||
| 77 | 2 | $conf->debug(" (no) "); | |||
| 78 | 2 | $self->set_result('no'); | |||
| 79 | } | ||||
| 80 | } | ||||
| 81 | |||||
| 82 | 1; | ||||
| 83 | |||||
| 84 | # Local Variables: | ||||
| 85 | # mode: cperl | ||||
| 86 | # cperl-indent-level: 4 | ||||
| 87 | # fill-column: 100 | ||||
| 88 | # End: | ||||
| 89 | # vim: expandtab shiftwidth=4: | ||||