How to change default CFLAGS for MakeMaker

3.1k views Asked by At

How do I get Perl MakeMaker to change the default value for CFLAGS that it inserts into Makefiles? Based on this post, I tried this:

export CFLAGS=...

then inside cpan, I confirmed it with

! print $ENV{CFLAGS}

but it still uses whatever CFLAGS Perl was built with.

I looked in lib/perl/.../Config.pm as suggested by this post but CFLAGS doesn't appear to be set there.

I have a related question that got answered: How to tell CPAN about path to make and cc

I made a little headway in CPAN/Config.pm

'makepl_arg' => q[ CCFLAGS="-D_REENTRANT -O2 -m32  -I/opt/csw/bdb48/include -I/opt/csw/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -m32 -DVERSION=\"1.616\" -DXS_VERSION=\"1.616\" -fPIC -I/opt/csw/lib/perl/5.10.1/CORE"],

but this only appends the value to whatever was already in CFLAGS, which gcc doesn't understand (like "-x03" and "-KPIC").

3

There are 3 answers

1
Lawrence I. Siden On

I have successfully modified /opt/csw/lib/perl/5.10.1/Config_heavy.pl so that MakeMaker can generate Makefiles that will work on a solaris system under OpenCSW.

Others who are having similar problems may download it here: https://gist.github.com/1569718

I have also posted this back to maintainers at opencsw.org so that they will hopefully update the OpenCSW release of Perl. I noted in my post that the right way to do this is to rebuild Perl entirely with tools belonging to the OpenCSW distro, because I believe that this file gets generated automatically by other scripts when any given Perl distro is built (although I haven't verified how it actually gets built). This patched file is merely an expedient so that I could get my work done, which is under a deadline.

I would have greatly preferred to accomplish my goal by modifying settings in CPAN/Config.pm. This worked for setting the correct paths to gcc and gmake, but not for changing the command-line flags to gcc, because CPAN would append these flags to the previously set argument string. gcc would quit after encountering those flags, some of which were incompatible (e.g. "-xO3" and "-KPIC").

For the record, CSWperl 5.10.1,REV=2011.01.15 is the current release of Perl from CSW that I have installed from OpenCSW.

Hope this may help someone else.

0
Karl On

I ran into this problem while testing the Inline module.

I found I could change the optimization flags like this (Perl v5.32.0):

use Inline Pdlpp => 'DATA' => BUILD_NOISY =>  0 =>  OPTIMIZE =>  "-O3";

Stuff after ’DATA’ are configuration options which I think are passed to MakeMaker. So I am guessing you can do the same args OPTIMIZE => "-O3" in your MakeMaker.PL file.

0
brian d foy On

It sounds like the original problem is actually about compiling new code with one set of tools (gcc) for a perl built with a different set of tools (whatever Solaris uses). Mixing build tools like that sometimes leads to weird problems down the line.

My first approach would try to use the same tools that compiled the perl I want to use. My second approach would be to compile a new perl with the tools I want to use. It's very easy to maintain several version of perl on a system at the same time.

Generally I avoid the system-installed perl, but sometimes there are vendor libraries that I might want to use.