Building Perl on Mac OS X

Notes by Dan Allen

Topics include:


Perl 5.8.0 on Mac OS X 10.2

21 October 2002

Perl 5.6.0 ships with all versions of Mac OS X from 10.0 through 10.2. The latest stable Perl as of today is 5.8.0. When I built 5.8 using the April 2002 beta Dev Tools on 10.1.5 I got a Perl that was much slower than 5.6.1 built with the same tools. However, when I built 5.8.0 on 10.2 with the July 2002 Dev Tools I ended up with a Perl that once again was exactly the same speed at 5.6.1, so I have now upgraded to Perl 5.8.0. The build is setup very nicely for OS X now. Here's what you do:

and you are done. I like to run Configure without -d so I can answer the questions to tweak locations where Perl is installed, to build it statically, etc.

You can have two Perl installations on the same machine at the same time, but it is a hassle keeping them apart. I personally nuke the standard Perl from /System/Library/Perl and /Library/Perl. I then build 5.8 and put all of Perl in /usr/local, with an extra copy of the main Perl binary at /usr/bin/perl, overwriting the old 5.6.0 perl, but unless you know what you are doing you may want to leave the system perl alone.


Perl 5.6.1 on Mac OS X 10.1

3 October 2001

From the INSTALL file that comes with Perl, building Perl is easy. It is 4 simple steps:

  1. sh Configure -de
  2. make
  3. make test
  4. make install

Unfortunately these steps do not work on Mac OS X. Perl N does not build on Mac OS X from the default net distributions. This is true in my experience with 5.6.0 or 5.6.1 for values of N, and 10.0 through 10.1 for values of X.

For this you need to have the Developer Tools installed on your Mac. Here's what to do to get Perl 5.6.1 to build on Mac OS 10.1:

  1. Get a copy of the Perl sources.

    Try getting them from http://www.perl.com.
    The file downloaded is usually named stable.tar.gz (use the Unix version).

  2. mv stable.tar.gz Perl5.6.1.tgz

    I like to rename the downloaded file so I know what version it is when I archive the file.
    Let's call this source distribution Perl5.6.1.tgz for purposes of this document.

  3. gunzip Perl5.6.1.tgz

    The .tgz file should disappear and a Perl5.6.1.tar file should appear in its place.

  4. tar xf Perl5.6.1.tar

    This creates a directory with zillions of files which are the Perl sources.

  5. cd perl-5.6.1/

    Go into the directory that was just created. This is the main Perl dir.

  6. ./Configure -de

    This creates a file called config.sh which contains a set of options for Mac OS X. It can take a bit to run this. If you want to answer the questions yourself, leave off the options, but be prepared for a lengthy interview. The default answers are largely correct for "darwin", but there are a few other changes needed, which the next several steps will correct.

  7. Edit config.sh to have the variable firstmakefile='firstmakefile'.

    Perl expects a case-sensitive file system. HFS+ disks are not case-sensitive, although they do preserve case, but that doesn't help the Perl build rules which think that 'Makefile' and 'makefile' are two separate files. On most Macs the one file clobbers the other and the build stops before it has even started. The Perl build is way too complicated. It should be a simple single Makefile. I can wish for things, can't I? ;-) Anyway, defining this allows the build to proceed, which is good.

  8. Edit config.sh to have the variable ldflags='-flat_namespace'.

    This change is needed to build on 10.1. The loader at /usr/bin/ld in 10.1 now supports a multilevel namespace by default which confuses the Perl build. This change returns the linked images back to the way they were in 10.0.4 and earlier. These flat namespace images work in all versions of Mac OS X released thus far.

  9. Edit config.sh to have the variable lddlflags='-bundle -undefined suppress -force_flat_namespace'.

    This change is needed to build on 10.1 as well, and is more of the previous fix.

  10. Optional: edit config.sh to change default Perl directory locations.

    The default locations for Perl's libraries are everywhere, including many places that do not exist normally on Mac OS X! Search config.sh for things like /System/Library/Perl and /Library/Perl and /Local/Perl and change them all to /System/Library/Perl. I also delete any references to the darwin architecture in paths. One does not need to do this but I like having my Perl modules in one place and this is how to do it.

  11. ./Configure -S

    This creates Makefile, config.h, and x2p/Makefile and other files from the variables in config.sh. If you ever want to make any changes in these options you should always edit config.sh and then re-run Configure which the -S option which generates all of the downstream files. Note also that doing a make distclean will delete your precious config.sh file, so make sure to back it up elsewhere.

  12. cd x2p

    This is a directory with a few tools that cause the build to hang up if not edited.

  13. Delete the last 3 lines of the Makefile in x2p

    The lines you want to delete are at the end, just below the line that says

    # AUTOMATICALLY GENERATED MAKE DEPENDENCIES--PUT NOTHING BELOW THIS LINE

    If you use vi, use sudo vi Makefile because the Makefile will be read-only. This means a set of include dependencies will not be in the Makefile, which is no big deal.

  14. cd ..

    Get back to the main Perl directory where config.sh is.

  15. sudo make

    Build Perl! This takes 5-15 minutes. You need to do this as root, hence the use of sudo.

  16. sudo make test

    Test the Perl you just built. At the conclusion of the test pass, I see the following summary:

    Failed 4 test scripts out of 251, 98.41% okay.

    You should get similar results. Note too that these 251 scripts actually run 12,791 different tests!

  17. sudo mkdir -p /System/Library/Perl/CORE

    At this point you should be able to do a make install, but it too is broken. So we have to do it by hand. This step will create a place for Perl's main shared library to go.

  18. sudo cp libperl.dylib /System/Library/Perl/CORE/

    Put a copy of Perl's shared library in the System directory. Note that normally libperl.dylib goes into /System/Library/Perl/darwin/CORE, or something like that. Due to my streamlined directory structure the "darwin" component of the path is gone. I wish shared libraries were gone as well, as Perl should be a single file like Awk is!

  19. sudo ./installperl

    This copies the built Perl binaries to /usr/bin/perl and the libs go to /System/Library/Perl/ in my streamlined world. Root privledges are needed here as well as these dirs are normally off limits.

  20. perl -V

    This checks to see if Perl actually is installed and works. You should see about 30 lines of version info.

  21. sudo perl -MCPAN -e shell

    This starts up CPAN and is a good final test of everything working. There will be several modules that need updating which you can get a list of with the 'r' command at the CPAN prompt. You're on your way!

I will here point out that Awk builds just fine on Mac OS X and is much simpler and usually faster than Perl. When in doubt, use Awk.


POSTSCRIPT

I found the following on the net which is somewhat simpler than my steps above.

SUMMARY: installing perl-5.6.1 on Mac OS X 10.1
------------------------------------------------------------------------


*	To: [email protected]
*	Subject: SUMMARY: installing perl-5.6.1 on Mac OS X 10.1
*	From: Ray Zimmerman 
*	Date: Wed, 3 Oct 2001 10:35:10 -0400
*	Delivered-To: mailing list [email protected]
*	Mailing-List: contact [email protected]; run by ezmlm


------------------------------------------------------------------------


Given all the time I spent looking through mailing list archives and
re-Configure-ing, recompiling, reinstalling, etc ... I thought I'd
share what worked for me (borrowing from previous posts on the list)
...


(1) Install the Developer Tools for 10.1 if you haven't already (a
free download from http://developer.apple.com/ with a free membership
sign-up).


(2) Unpack with tar, not via StuffIt Expander or anything


   tar zxvf perl-5.6.1.tar.gz


(3) Configure, build, and test it ...


   cd perl-5.6.1


   # set locale stuff
   setenv LC_ALL C
   setenv LANG "en_US"


   # fix sitelib in hints
   perl -i.bak -p -e 's|Local/Library|Library|g' hints/darwin.sh


   sh Configure -des -Dfirstmakefile=GNUmakefile -Dldflags="-flat_namespace"
   make
   make test


(4) Install it ...


   mv INSTALL INSTALL.txt  # so 'make install' won't try to 'make INSTALL'
   sudo make install



Back to Dan Allen's home page.
Created:   3 Oct 2001
Modified: 27 Dec 2002