You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2012/11/13 03:13:13 UTC
[lucy-commits] [10/16] git commit: refs/heads/master - Hack to fix 'for' scoping
under MSVC6
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.
Since the macro contains a space character, some additional quoting is
needed. The extra_compiler_flags also have to be passed as an array.
Clean up setting of compiler 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/f7a75583
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/f7a75583
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/f7a75583
Branch: refs/heads/master
Commit: f7a755837747a8db550c3bbd9fca09c253651768
Parents: c899a7f
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun Nov 4 01:31:48 2012 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Nov 12 21:06:44 2012 +0100
----------------------------------------------------------------------
.../compiler/perl/buildlib/Clownfish/CFC/Build.pm | 46 ++++++--------
.../compiler/perl/lib/Clownfish/CFC/Perl/Build.pm | 4 +-
.../perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm | 4 +-
perl/buildlib/Lucy/Build.pm | 3 +-
4 files changed, 27 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/f7a75583/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 9f30796..7e2d3ce 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,39 +49,34 @@ 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.
+ # Turn off stupid warnings, too.
+ # Redefine 'for' to fix broken 'for' scoping under MSVC6.
if ( $self->config('cc') =~ /^cl\b/ ) {
- $extra_ccflags .= '/TP -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 -D_CRT_SECURE_NO_WARNINGS );
+ push @extra_ccflags, '-Dfor="if(0);else for"';
}
- return $extra_ccflags;
+ return \@extra_ccflags;
}
sub new {
http://git-wip-us.apache.org/repos/asf/lucy/blob/f7a75583/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm b/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
index 97e85cd..099838f 100644
--- a/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
+++ b/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
@@ -65,8 +65,10 @@ sub new {
elsif ( $self->config('cc') =~ /^cl\b/ ) {
# Compile as C++ under MSVC.
push @$extra_ccflags, qw(
- /TP -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
+ -TP -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
);
+ # Redefine 'for' to fix broken 'for' scoping under MSVC6.
+ push @$extra_ccflags, '-Dfor="if(0);else for"';
}
$self->extra_compiler_flags(@$extra_ccflags);
http://git-wip-us.apache.org/repos/asf/lucy/blob/f7a75583/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm b/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm
index 21db471..13abca9 100644
--- a/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm
+++ b/clownfish/compiler/perl/lib/Clownfish/CFC/Perl/Build/Charmonic.pm
@@ -77,7 +77,7 @@ sub ACTION_charmony {
'--enable-perl',
'--',
$self->config('ccflags'),
- @{ $self->extra_compiler_flags },
+ map { _quotify($_) } @{ $self->extra_compiler_flags },
);
if ( $ENV{CHARM_VALGRIND} ) {
unshift @command, "valgrind", "--leak-check=yes";
@@ -91,7 +91,7 @@ sub _quotify {
my $string = shift;
$string =~ s/\\/\\\\/g;
$string =~ s/"/\\"/g;
- return qq|"$string"|;
+ return $string =~ /\s/ ? qq|"$string"| : $string;
}
1;
http://git-wip-us.apache.org/repos/asf/lucy/blob/f7a75583/perl/buildlib/Lucy/Build.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build.pm b/perl/buildlib/Lucy/Build.pm
index 52cf3ff..59dac46 100644
--- a/perl/buildlib/Lucy/Build.pm
+++ b/perl/buildlib/Lucy/Build.pm
@@ -115,9 +115,10 @@ sub ACTION_charmonizer_tests {
'-I' . rel2abs( getcwd() ),
);
$flags =~ s/"/\\"/g;
+ my $defs = $^O =~ /mswin/i ? qq|DEFS="$flags"| : "DEFS=$flags";
$self->_run_make(
dir => $CHARMONIZER_ORIG_DIR,
- args => [ "DEFS=$flags", "tests" ],
+ args => [ $defs, "tests" ],
);
}