On Tue Jun 07 06:34:23 2011, alex@earth.li wrote:
Show quoted text> I'm trying to build a module which links to libraries which get
> installed under c:\program files (x86)\blah\include but cannot do so
> under strawberry perl as the brackets get escaped, then passed
> complete with escapes to gcc, which croaks. The following patch fixes
> this, but in a violent way:
This is a less violent way as it leaves alone () not in quotes, which I
think is sensible, it should manage to only mess with quoted stuff, I
also have some tests for the included little function(below the patch),
but I'm not sure which test file to put them in.
--- ExtUtils-MakeMaker-6.57_11/lib/ExtUtils/MM_Unix.pm Fri May 20
12:27:11 2011
+++ ../ExtUtils-MakeMaker-6.57_11/lib/ExtUtils/MM_Unix.pm Tue Jun
7 23:23:52 2011
@@ -264,8 +264,14 @@
$pollute = '$(PERL_MALLOC_DEF)';
}
- $self->{CCFLAGS} = quote_paren($self->{CCFLAGS});
- $self->{OPTIMIZE} = quote_paren($self->{OPTIMIZE});
+ if ($Config{make} eq 'dmake') {
+ $self->{CCFLAGS} = quote_paren_not_quoted($self->{CCFLAGS});
+ $self->{OPTIMIZE} = quote_paren_not_quoted($self->{OPTIMIZE});
+ }
+ else {
+ $self->{CCFLAGS} = quote_paren($self->{CCFLAGS});
+ $self->{OPTIMIZE} = quote_paren($self->{OPTIMIZE});
+ }
return $self->{CFLAGS} = qq{
CCFLAGS = $self->{CCFLAGS}
@@ -3089,6 +3095,31 @@
$arg =~ s{(?<!\\)([()])}{\\$1}g; # quote unprotected
$arg =~ s{\$\\\\\((.+?)\\\\\)}{\$($1)}g; # unprotect $(...)
return $arg;
+}
+
+=item quote_paren_not_quoted
+
+Backslashes parentheses C<()> in command line arguments.
+Doesn't handle recursive Makefile C<$(...)> constructs,
+but handles simple ones. Leaves alone anything in unprotected
+quotes.
+
+=cut
+
+sub quote_paren_not_quoted {
+ my $arg = shift;
+ my @parts = split(/(?<!\\)(")/, $arg);
+ push(@parts, '') if (substr($arg, -1, 1) eq q{"});
+
+ if (@parts == 1) {
+ return quote_paren($arg);
+ }
+ else {
+ for my $i (0..@parts-1) {
+ $parts[$i] = quote_paren($parts[$i]) if $i % 4 == 0;
+ }
+ return join(q{}, @parts);
+ }
}
=item replace_manpage_separator
############################
Tests:
is(quote_paren_not_quoted(q{}), q{});
is(quote_paren_not_quoted(q{()}), q{\\(\\)});
is(quote_paren_not_quoted(q{"()"}), q{"()"});
is(quote_paren_not_quoted(q{()""()}), q{\\(\\)""\\(\\)});
is(quote_paren_not_quoted(q{"()""()"}), q{"()""()"});
is(quote_paren_not_quoted(q{"()" ("}), q{"()" \\("});
is(quote_paren_not_quoted(q{"\\""}), q{"\\""});
is(quote_paren_not_quoted(q{"(\\"("}), q{"(\\"("});
is(quote_paren_not_quoted(q{"(\\"(" ( ""}), q{"(\\"(" \\( ""});
is(quote_paren_not_quoted(q{\\" () \\"}), q{\\" \\(\\) \\"});
is(quote_paren_not_quoted(q{"\\" () \\""}), q{"\\" () \\""});