Hack to fix 'for' scoping under MSVC6 MSVC6 doesn't allow redefinition of iteration variables in 'for' statements. This ugly hack redefines 'for' as 'if(0);else for' to make this work. For now, this is applied to all versions of MSVC but it shouldn't hurt.
This requires using an array for extra_compiler_flags. Clean up setting of flags along the way. Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/bc8af2dc Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/bc8af2dc Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/bc8af2dc Branch: refs/heads/msvc6 Commit: bc8af2dc23b25ef95cf671e38fe968cb626f486c Parents: 9c2212a Author: Nick Wellnhofer <[email protected]> Authored: Sun Nov 4 01:31:48 2012 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Sun Nov 4 01:31:48 2012 +0100 ---------------------------------------------------------------------- .../compiler/perl/buildlib/Clownfish/CFC/Build.pm | 46 ++++++-------- 1 files changed, 20 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/bc8af2dc/clownfish/compiler/perl/buildlib/Clownfish/CFC/Build.pm ---------------------------------------------------------------------- diff --git a/clownfish/compiler/perl/buildlib/Clownfish/CFC/Build.pm b/clownfish/compiler/perl/buildlib/Clownfish/CFC/Build.pm index 0bde871..6fe0ffc 100644 --- a/clownfish/compiler/perl/buildlib/Clownfish/CFC/Build.pm +++ b/clownfish/compiler/perl/buildlib/Clownfish/CFC/Build.pm @@ -39,8 +39,7 @@ my $CFC_SOURCE_DIR = catdir( updir(), 'src' ); sub extra_ccflags { my $self = shift; - my $extra_ccflags = "-DCFCPERL "; - $extra_ccflags .= "$ENV{CFLAGS} " if defined $ENV{CFLAGS}; + my @extra_ccflags = qw( -DCFCPERL ); my $gcc_version = $ENV{REAL_GCC_VERSION} @@ -50,40 +49,35 @@ sub extra_ccflags { $gcc_version =~ /^(\d+(\.\d+))/ or die "Invalid GCC version: $gcc_version"; $gcc_version = $1; - } - if ( defined $ENV{LUCY_DEBUG} ) { - if ( defined $gcc_version ) { - $extra_ccflags .= "-DLUCY_DEBUG "; - $extra_ccflags - .= "-DPERL_GCC_PEDANTIC -std=gnu99 -pedantic -Wall "; - $extra_ccflags .= "-Wextra " if $gcc_version >= 3.4; # correct - $extra_ccflags .= "-Wno-variadic-macros " + # Tell GCC explicitly to run with maximum options. + push @extra_ccflags, qw( -std=gnu99 -D_GNU_SOURCE ); + + if ( defined $ENV{LUCY_DEBUG} ) { + push @extra_ccflags, qw( + -DLUCY_DEBUG -DPERL_GCC_PEDANTIC -pedantic -Wall + ); + push @extra_ccflags, qw( -Wextra ) + if $gcc_version >= 3.4; # correct + push @extra_ccflags, qw( -Wno-variadic-macros ) if $gcc_version > 3.4; # at least not on gcc 3.4 } - } - if ( $ENV{LUCY_VALGRIND} and defined $gcc_version ) { - $extra_ccflags .= "-fno-inline-functions "; + if ( $ENV{LUCY_VALGRIND} ) { + push @extra_ccflags, qw( -fno-inline-functions ); + } } - # Compile as C++ under MSVC. Turn off stupid warnings, too. + # Compile as C++ under MSVC. # NO_XSLOCKS is required for some ActivePerl setups. + # Turn off stupid warnings, too. + # Redefine 'for' to fix broken 'for' scoping under MSVC6. if ( $self->config('cc') =~ /^cl\b/ ) { - $extra_ccflags .= '-TP -DNO_XSLOCKS -D_CRT_SECURE_NO_WARNINGS '; - } - - if ( defined $gcc_version ) { - # Tell GCC explicitly to run with maximum options. - if ( $extra_ccflags !~ m/-std=/ ) { - $extra_ccflags .= "-std=gnu99 "; - } - if ( $extra_ccflags !~ m/-D_GNU_SOURCE/ ) { - $extra_ccflags .= "-D_GNU_SOURCE "; - } + push @extra_ccflags, qw( -TP -DNO_XSLOCKS -D_CRT_SECURE_NO_WARNINGS ); + push @extra_ccflags, '-Dfor="if(0);else for"'; } - return $extra_ccflags; + return \@extra_ccflags; } sub new {
