Installing Math::Pari and Crypt::DSA for Movable Type under Mac OS X

What and Why?

I am not now a programmer and haven’t been one, real or surreal, for at least fifteen years. So WHY have I just spent two days solid trying to get a single perl module compiled for my server? Rhetorical question –  any smartarse answers should be placed in the usual wormhole on a piece of EBCDIC punch-tape.
The Challenge: install the perl module Crypt::DSA on a shiny new Movable Type 3.11 installation, to allow us to make full use of the features and get best performance from the comment registration mechanism. So I go to CPAN and try installing Crypt::DSA. It tells me I need the Math::Pari module first and then falls over in grand style on trying to install it. That was four days ago. I have just got it all working (or installed, at least) and this is for anyone going through a similar process –  hopefully you’ll find this before you acquire significant bruising on your forehead, much like the one I’m currently nursing.

Resources

Firstly, useful resources:
The starting point for all this is Benjamin Boksa’s description of installing Math::Pari, taken together with some hints and pointers found on a Mac thread on the Pari site. That tutorial was then corrected by David Jacob’s blog on installing Math::Pari on Mac OS X.
Whilst pointing me in the right general direction, none of these actually worked. So here’s what did, with my system configuration of:

  • Mac OS X Server 10.3.5 installed and up-to-date (according to Software Update)
  • Xcode Tools installed and up-to-date
  • Perl 5.8.1 (default Mac OS X installation)
  • Movable Type 3.11
  • Pari 2.1.5 –  as of today, this is the latest stable release of Pari. If you’re using an earlier or later one, you’ll need to change the process to suit the names. D’uh…

So, for those who are trying to install Crypt::DSA, or anything else that needs the Math::Pari module and libraries, here’s what worked for me, presented in step-by-step fashion, with minimal geekspeak, although it does require some familiarity with the Unix command line. using the tcsh shell. Some of this may be overkill, but I’m being deliberately pedantic here and describing every step that led me to a working installation.

Using Terminal and Shells

First, open a Terminal window on the machine you’re installing on. Then make sure you’re running in the tcsh shell environment (the default for Mac OS 10.3 is the bash shell), so that you can set the environment variables that are needed. To check which shell you’re running, type echo $shell If it replies with /bin/tcsh, you’re in business. If not, simply type tcsh. Now set the environment variables – the easiest way to do this is to create a file in your own top-level folder called .tcshrc (note that the file name starts with a period –  this makes it invisible in ‘normal’ use. This file should contain (or have appended to it) the following lines:
setenv LD_LIBRARY_PATH /usr/lib:/usr/local/lib
setenv DYLD_LIBRARY_PATH ${LD_LIBRARY_PATH}
setenv LDFLAGS -flat_namespace
setenv CPPFLAGS -no-cpp-precomp

then log out of your terminal session and back in with a new one. You’ll also be mostly using the sudo command to execute other commands with administrator privileges –  if your account doesn’t have such privileges, you’ll need to either set ’em or go get ’em.

Getting Rid of the Gubbins

If, like me, you’ve been making multiple and non-productive attempts to install all this, the first step (assuming that you’ve retrieved your keyboard from the bin/flower bed/cat) is to clear the output of any prior failed attempts to build the modules –  if you’re a command-line maven, you can simply grep out all file and folder references to pari from your system. If you haven’t a clue what I’m on about, then you can use the search -F facility in Mac OS X – search for anything containing the string pari, making sure you also use the Visibility selector, set to visible and invisible items. Then chuck away anything in the search results that looks plausible (paranote: you did back your system up before starting this, didn’t you?).

Installing Pari

Now you’ll be wanting to install the core Pari software. To do so:

  • Go to the appropriate code directory: cd /usr/local/src
  • Download the Pari source code: sudo curl -O ftp://www.gn-50uma.de/gn/gn-50uma.de/pari-2.1/pari-2.1.5.tar.gz
  • Unpack the archive you’ve just downloaded: sudo tar xvfz pari-2.1.5.tar.gz
  • Move to the folder that’s just been created: cd pari-2.1.5

Now you’ve got to edit two of the source files, or download and replace them with the contents of
the archive I prepared earlier
(and please note that this is for Pari version 2.1.5 ONLY – horrible things might just happen if you mix’n’match). These are in the directory /usr/local/src/pari-2.1.5/src/kernel/none and are:
level0.h
mp.c
Edit these using your favourite text editor (I use BBEdit) with the following changes:
In level0.h, change lines 53:54 from:
ulong overflow;
ulong hiremainder;
to:
extern ulong overflow;
extern ulong hiremainder;

In mp.c, insert the following two lines after line 23: ‘#include “pari.h”‘:
ulong overflow;
ulong hiremainder;

Now comes a series of commands:
Compile the module: ./Configure –host=darwin
Compile the GP scripting system: sudo make gp
Install the final libraries: sudo make install – you may get some errors here of the form, “Third arg errors”. Don’t worry about these –  I didn’t, and it didn’t seem to make any difference to the outcome.
Do something obscure: sudo ranlib /usr/local/lib/libpari.a
That’s Pari itself installed.

Installing Math::Pari

Now we want to get and install the Math::Pari perl module. This time we’re using the CPAN perl archive to retrieve the source code, and only to retrieve it – attempting to install it from within CPAN will fail. So, assuming that you’ve already set up CPAN by using it interactively (sudo perl -MCPAN -eshell), here’s what to do:
Get the source code: sudo perl -MCPAN -e”get Math::Pari”
Go to the directory where CPAN has placed the source: cd ~/.cpan/build/Math-Pari-2.010501
Create the Makefile for Math::Pari: sudo perl Makefile.PL paridir=/usr/local/src/pari-2.1.5 –  if you miss out the ‘paridir’ argument, it’ll simply bugger off and load a generic version that ignores your patches. This is not a good thing, and rather defeats the object of the exercise.
Build it: sudo make
Run the built-in tests: sudo make test
Install the binaries: sudo make install
By now, you either have a working installation or a terminal window that looks like the aftermath of an explosion in a type foundry. Possibly both.
The final proof of is now to go back to where we started – go to CPAN and install Crypt::DSA and any other Crypt modules you need:
invoke the CPAN shell: sudo perl -MCPAN -eshell
Finally: install Crypt::DSA
And that’s all, folks.
Except –  and there’s always an ‘except’ –  to note that Benjamin Boksa’s article describes a couple of additional compilation steps needed. The way I’ve described doing things doesn’t require these. YMMV and, should you try them, remember to replace the version strings with the version of Pari that you’re actually installing.
This approach worked for me. If you try it and it doesn’t work for you, or you want to suggest an infinitely more elegant way of doing it, please post a comment to let me know.

One thought on “Installing Math::Pari and Crypt::DSA for Movable Type under Mac OS X”

  1. Update: After updating perl to 5.8.6 under Mac OS X 10.3.8, the installation of Crypt::DSA and Math::Pari worked just fine from CPAN.
    Richard

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.