Building perl on OS X with XCode 4 and Lion

So. I had 5.12 installed on my MacBook Pro, and wanted to build the latest and greatest perl. Unfortunately, the nm that comes with XCode 4 doesn’t play nice with perl’s Configure script, causing it to wonder if you’re using a Cray. Nice upgrade, but it doesn’t get the perl installed.

Everyone seems to be using perlbrew nowadays and there’s information on how to make perlbrew work under these conditions at http://www.perlbrew.pl/FixLion.html.

If, like me, you want to actually build perl the usual way (i.e. without any brewing), you need to patch your perl source. You could, of course, dig into perl-bleed and work out the needed patch yourself, but that would be work. Quite insufficiently lazy.

This is where Devel::PatchPerl comes in, as noted on the perlbrew FixLion page. But instead of setting all those environment variables and such, you can use Devel::PatchPerl directly. First, make sure you’ve got the latest version (or at least 0.42, where this particular patch went in). then all you have to do is:

perl -mDevel::PerlPatch -e "Devel::PerlPatch->patch_source('5.14.1', '/path/to/perl/source');"

The parameters for patch_source() are the version number of the perl you wish to build and the path to the source you are patching. If you’re not building 5.14.1 and your source isn’t in /path/to/perl/source, you should, of course, change those to appropriate values.

Easy, once you know how. But as I had a heck of a time trying to search for this info, I figured I’d write a blog post with appropriate words in the title, so maybe others will have an easier time finding it than I did.