Building Perl on Mac OS X
Notes by Dan Allen
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.
- Download from http://www.perl.com/CPAN/src/ perl 5.8.0.
- Unpack it with tar xzf perl-5.8.0.tar.gz.
- cd into the new directory
- Type ./Configure -d
- Type make
- Type make test
You should have results like "Failed 2 test scripts out of 657, 99.70% okay", wth 68176 tests run.
- Type sudo make install
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:
- sh Configure -de
- make test
- 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:
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).
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.
The .tgz file should disappear and a Perl5.6.1.tar file should appear in its place.
tar xf Perl5.6.1.tar
This creates a directory with zillions of files which are the Perl sources.
Go into the directory that was just created. This is the main Perl dir.
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.
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.
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.
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.
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.
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.
This is a directory with a few tools that cause the build to hang up if not edited.
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.
Get back to the main Perl directory where config.sh is.
Build Perl! This takes 5-15 minutes. You need to do this as root, hence the use of sudo.
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!
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.
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!
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.
This checks to see if Perl actually is installed and works. You should see about 30 lines of version info.
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.
I found the following on the
which is somewhat simpler than my steps above.
SUMMARY: installing perl-5.6.1 on Mac OS X 10.1
* To: email@example.com
* 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 firstname.lastname@example.org
* Mailing-List: contact email@example.com; 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
(2) Unpack with tar, not via StuffIt Expander or anything
tar zxvf perl-5.6.1.tar.gz
(3) Configure, build, and test it ...
# 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"
(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