Subject: | PERL_MM_OPT truncates multiple arguments to CCFLAGS at first whitespace |
I'd like to build cpan distributions with a few custom CCFLAGS set. One module is Imager
(https://metacpan.org/release/Imager), but this applies to any CPAN dist based on EU::MM that
compiles code. So say I configure it like this on the cmdline:
$ perl Makefile.PL CCFLAGS="-Wl,-rpath -Wl,/foo/bar/lib"
$ grep 'CCFLAGS =' Makefile
CCFLAGS = -Wl,-rpath -Wl,/foo/bar/lib
That does the right thing: make works as expected. Things compile, everyone's happy.
But if I try the same thing with PERL_MM_OPT, it gets truncated at the first space. This results
in invalid CCFLAGS in the Makefile generated:
$ PERL_MM_OPT="CCFLAGS=\"-Wl,-rpath -Wl,/foo/bar/lib\"" perl Makefile.PL
$ grep 'CCFLAGS =' Makefile
CCFLAGS = "-Wl,-rpath
With the un-terminated quote, make fails with errors like:
I've tried various combinations of this, all fail:
PERL_MM_OPT="CCFLAGS=-Wl,-rpath\ -Wl,/foo/bar/lib"
PERL_MM_OPT="CCFLAGS='-Wl,-rpath -Wl,/foo/bar/lib'"
PERL_MM_OPT="CCFLAGS=-Wl,-rpath CCFLAGS=-Wl,/foo/bar/lib"
Of course, this is working as documented:
PERL_MM_OPT
Command line options used by MakeMaker?->new() , and
thus by WriteMakefile?() . The string is split on whitespace,
and the result is processed before any actual command line
arguments are processed."
- http://perldoc.perl.org/ExtUtils/MakeMaker.html#PERL_MM_OPT
But I'd argue this is broken: in an ideal world, passing arguments in PERL_MM_OPT should use
the same syntax as on the command line (but that may be unfeasible as shell syntaxes vary).
At the very least, there should be some way of achieving the same ends. The impact is: users
of automation tools like cpanm cannot install many modules with these params. That causes a
major maintenance headache -- in our case, we'd have to find all relevant dists and build them
manually.
I'd propose allowing space character escapes, e.g.:
PERL_MM_OPT="CCFLAGS=-Wl,-rpath\ -Wl,/foo/bar/lib"
@mm_opt = split(/(?<!\\) /, $ENV{PERL_MM_OPT} || '');
s/\\ / /g for @mm_opt;
parse_args($self, @mm_opt, @ARGV);
While there are more precise solutions, this seems unintrusive and is easily implemented.
I know EU::MM has been end-of-lifed, before I take time preparing a patch: is there a chance of
this being taken on?