1 # Copyright (C) 2007-2008, The Perl Foundation.
6 config/auto/warnings.pm - Warning flags detection
10 Automagically detect what warning flags, like -Wall, -Wextra,
11 -Wchar-subscripts, etc., that the compiler can support. Directly hacked
12 from F<config/auto/attributes.pm>.
20 package auto
::warnings
;
26 use base
qw(Parrot::Configure::Step);
28 use Parrot
::Configure
::Utils
();
29 use Parrot
::BuildUtil
;
34 $data{description
} = q{Detecting supported compiler warnings (-Wxxx)};
37 # potential addition? -fvisibility=hidden
38 # Please keep these sorted by flag name, such that "-Wno-foo" is
39 # sorted as "-Wfoo", so we can turn off/on as needed.
40 my @potential_warnings = qw(
43 -maccumulate-outgoing-args
51 -Wdisabled-optimization
66 -Wmissing-field-initializers
67 -Wno-missing-format-attribute
68 -Wmissing-include-dirs
88 my @potential_warnings_no_cpp = qw(
91 -Wdeclaration-after-statement
92 -Wimplicit-function-declaration
95 -Wmissing-declarations
99 -Wold-style-definition
103 my @cage_warnings = qw(
106 -Werror-implicit-function-declaration
110 -Wmissing-format-attribute
112 -Wno-deprecated-declarations
114 -Wno-format-extra-args
118 -Wold-style-definition
131 my @nice_to_have_but_too_noisy_for_now = qw(
133 -Wint-to-pointer-cast
138 $data{potential_warnings
} = \
@potential_warnings;
139 $data{potential_warnings_no_cpp
} = \
@potential_warnings_no_cpp;
140 $data{cage_warnings
} = \
@cage_warnings;
146 my ( $self, $conf ) = @_;
148 my $verbose = $conf->options->get('verbose');
149 print "\n" if $verbose;
150 if ( defined $conf->data->get('gccversion') ) {
152 # Dirty way of checking if compiling with c++
153 my $nocpp = index($conf->data->get('cc'), '++') < 0;
155 # add on some extra warnings if requested
156 $self->_add_cage_warnings($conf);
157 $self->_add_maintainer_warnings($conf);
159 # now try out our warnings
160 for my $maybe_warning (@
{ $self->{potential_warnings
} }) {
161 $self->try_warning( $conf, $maybe_warning, $verbose );
164 for my $maybe_warning (@
{ $self->{potential_warnings_no_cpp
} }) {
165 $self->try_warning( $conf, $maybe_warning, $verbose );
170 $self->set_result("set for gcc");
173 $self->set_result("set for g++");
177 print "Currently we only set warnings if using gcc as C compiler\n"
179 $self->set_result("skipped");
184 sub _add_cage_warnings
{
185 my ($self, $conf) = @_;
186 push @
{ $self->{potential_warnings
} }, @
{ $self->{cage_warnings
} }
187 if $conf->options->get('cage');
190 sub _add_maintainer_warnings
{
191 my ($self, $conf) = @_;
192 push @
{ $self->{potential_warnings
} }, '-Wlarger-than-4096'
193 if $conf->options->get('maintainer');
198 Try a given warning to see if it is supported by the compiler. The compiler
199 is determined by the C<cc> value of the C<Parrot::Configure> object passed
200 in as the first argument to the method (not counting C<$self>. The warning
201 to be checked is passed in as the second argument to the method.
203 Returns true if the warning flag is recognised by the compiler and undef
209 my ( $self, $conf, $warning, $verbose ) = @_;
211 my $output_file = 'test.cco';
213 $verbose and print "trying attribute '$warning'\n";
215 my $cc = $conf->option_or_data('cc');
216 $conf->cc_gen('config/auto/warnings/test_c.in');
218 my $ccflags = $conf->data->get('ccflags');
219 my $tryflags = "$ccflags $warning";
221 my $command_line = Parrot
::Configure
::Utils
::_build_compile_command
( $cc, $tryflags );
222 $verbose and print " ", $command_line, "\n";
224 # Don't use cc_build, because failure is expected.
225 my $exit_code = Parrot
::Configure
::Utils
::_run_command
(
226 $command_line, $output_file, $output_file
228 _set_warning
($conf, $warning, $exit_code, $verbose);
230 return if $exit_code;
232 my $output = Parrot
::BuildUtil
::slurp_file
($output_file);
233 return _set_ccflags
($conf, $output, $tryflags, $verbose);
237 my ($conf, $warning, $exit_code, $verbose) = @_;
238 $verbose and print " exit code: $exit_code\n";
239 $conf->data->set( $warning => !$exit_code || 0 );
243 my ($conf, $output, $tryflags, $verbose) = @_;
244 $verbose and print " output: $output\n";
246 if ( $output !~ /error|warning|not supported/i ) {
247 $conf->data->set( ccflags
=> $tryflags );
248 $verbose and print " ccflags: ", $conf->data->get("ccflags"), "\n";
260 Paul Cochrane <paultcochrane at gmail dot com>
268 # cperl-indent-level: 4
271 # vim: expandtab shiftwidth=4: