Building for Macintosh platform
or, How to Minimalistically GNUify Mac OS X For Building Octave From Scratch
Using package managerEdit
If you are looking for an already built version of Octave for Mac OS X, at the present there doesn't exist a reliable one. Instead, use a package manager.
Source-CompilationEdit
Before building Octave from scratch on a Mac OS X platform you need to install several GNU programs and libraries that are not shipped with your Mac. This description will guide you through the procedure of GNUifying your Mac OS X step by step, so that you are then be able to configure, compile, install and run the Octave program.
If available, then binary-releases of the necessary programs are preferred by this description, otherwise there is no other way as to configure, compile and install other source-releases of these programs. The minimalistical requirements for installing these programs on your Mac are that you have at least Mac OS X version 10.4.x running on your Mac (either Core Duo or PPC).
The section "Step-By-Step Procedure" describes which programs resp. packages have to be installed at least before trying to compile Octave. The section "Extensions" describes which programs resp. packages have to be installed before trying to compile Octave to reach full functionality. The section "Troubleshooting" describes what to do if one ore more package creation processes fail.
The scripts used to build the octave-forge Octave.app can be found in the sourceforge subversion repository.
Step-By-Step ProcedureEdit
(1) Install the Xcode-Tools (ie. the gcc-suite, the c-library and other tools) that are shipped with your computer from "Mac OS X Install Disc 1". Optionally you can get the latest version of these tools from http://developer.apple.com/tools/download. Follow the instructions from the "About Xcode Tools.pdf" file on how to install these tools. Make sure that you have installed the latest releases.
Also read the troubleshooting part at the bottom of this file for further details about which build tools could also make troubles.
(2) Install the X11 environment (ie. the Xserver application etc.) that are shipped with your computer from "Mac OS X Install Disc 1". The X11 environment can be installed via the "Optional Installs.mpkg" program and is needed by various graphics programs (10). Make sure that you have installed the latest release. Choose "Software-Update" in your menu bar to download and to reinstall the latest versions.
(3) Prepare a directory and the settings on your environment for installing the following programs and libraries. Create the directory /usr/local that is not present by default on your new Mac and set up some variables in either your .profile file (if you plan to use the Terminal.app from Mac OS X for compiling Octave) or your .bashrc file (if you plan to use the terminal application from your X11 environment). Do this the following way:
sudo mkdir /usr/local
Edit .profile or .bashrc
export PATH=$PATH:/usr/local/bin:/usr/X11R6/bin export CFLAGS="-I/usr/local/include" export CPPFLAGS="-I/usr/local/include" export LDFLAGS="-L/usr/local/lib"
(4) Download and install a binary-release of a Tex environment for your Mac in order to build the documentation for Octave. One of the binary-distributions that can be downloaded from Internet at this time is the Mac-Tex environment that can be found there http://tug.org/mactex. Follow the installation instructions provided by this package. Either edit your .profile or .bashrc file (3) the following way:
export PATH=$PATH:/usr/local/teTeX/bin/i386-apple-darwin-current
With the Mactex-2007 package the binary path has been changed. Use the following line if you have a new Mactex-2007 package and a IA:
export PATH=$PATH:/usr/local/texlive/2007/bin/i386-darwin
or on PPC use this line
export PATH=$PATH:/usr/local/texlive/2007/bin/powerpc-darwin
(5) Download and install a binary-release of a Fortran-compiler environment for your Mac. One of the binary-distributions that can be downloaded from Internet at this time is the GFortran environment. It is hosted at http://www.macresearch.org. The GFortran compiler is shipped in a binary-tar.gz file. Unpack and install this program the following way:
tar -xzf gfortran-intel-bin.tar.gz sudo cp -r ./usr/local/* /usr/local
Also read the troubleshooting part at the bottom of this file for further details about which Fortran compiler to use for Mac OS X.
(6) Download and install a source-release of the program "sed" because the one that is implied in Mac OS X is a BSD-flavoured POSIX version and a GNU version is required to build Octave. The source-release of the latest sed program can be downloaded from Internet at http://ftp.gnu.org/pub/gnu/sed. Unpack, configure, compile and install this program the following way:
tar -xzf sed-X.x.x.tar.gz cd sed-X.x.x ./configure --prefix=/usr/local --with-included-regex --with-included-gettext make && sudo make install
and then move your old /usr/bin/sed program to another name, eg.:
sudo mv /usr/bin/sed /usr/bin/__sed
Also read the troubleshooting part at the bottom of this file for further details if an error occurs at compilation.
(7) Download and install a source-release of the program "bison" because the one that is implied in Mac OS X a BSD-flavoured POSIX version and a GNU version is required to build Octave. The source-release of the latest bison program can be downloaded from Internet at http://ftp.gnu.org/pub/gnu/bison. Unpack, configure, compile and install this program the following way:
tar -xzf bison-X.x.tar.gz cd bison-X.x ./configure --prefix=/usr/local make && sudo make install
and then move your old /usr/bin/bison program to another name, eg.:
sudo mv /usr/bin/bison /usr/bin/__bison
(8) Download and install a source-release of the program "gawk". Gawk is not included in Mac OS X (the program "awk" is included in Mac OS X but "gawk" is needed to compile Octave). The source-version of the latest gawk-release can be downloaded from Internet at http://ftp.gnu.org/pub/gnu/gawk. Unpack, configure, compile and install this program the following way:
tar -xzf gawk-X.x.x.tar.gz cd gawk-X.x.x ./configure --disable-nls --prefix=/usr/local make && sudo make install
(9) Download and install a source-release of the "readline" library. There is already a readline-library included in Mac OS X but by now I do not know how to include the installed version in the compilation procedure of Octave. The source-version of the latest readline-release can be downloaded from Internet at http://ftp.gnu.org/pub/gnu/readline. Unpack, configure, compile and install this program the following way:
tar -xzf readline-X.x.tar.gz cd readline-X.x ./configure --prefix=/usr/local --enable-shared make && sudo make install
(10) Download and install a source-release of the program "gnuplot". The source-release of the latest gnuplot program can be downloaded from Internet at http://www.gnuplot.info. Unpack, configure, compile and install this program the following way:
tar -xzf gnuplot-X.x.x.tar.gz cd gnuplot-X.x.x ./configure --prefix=/usr/local make && sudo make install
(**) You are already done setting up your Mac OS X for configuring, building, installing and running the minimalistic version of Octave. If you want full Octave functionality you need to download and install more source packages before building Octave, read the EXTENSIONS part of this file at the bottom.
(11) Download and install a source-release of the latest "octave" program. The latest release can always be found at http://www.octave.org. Unpack, configure, compile and install this program the following way:
tar -xzf octave-X.x.x.tar.gz cd octave-X.x.x ./configure --prefix=/usr/local --enable-shared make && make check && sudo make install
Also read the troubleshooting part at the bottom of this file for further details if an error occurs at compilation.
(12) Enjoy using Octave!
ExtensionsEdit
For using the full functionality of Octave some more source-packages need to be installed on your Mac.
(+A) Download and install a source-release of the "pcre" library. There is no pcre-library included in Mac OS X. The source-version of the latest pcre-release can be downloaded from Internet at http://www.pcre.org. Unpack, configure, compile and install this program the following way:
tar -xzf pcre-X.x.tar.gz cd pcre-X.x ./configure --prefix=/usr/local make && sudo make install
(+B) Download and install a source-release of the "hdf5" library. There is no hdf5-library included in Mac OS X. The source-version of the latest hdf5-release can be downloaded from Internet at ftp://ftp.hdfgroup.org/HDF5/current/. Unpack, configure, compile and install this program the following way:
tar -xzf hdf5-X.x.x.tar.gz cd hdf5-X.x.x ./configure --prefix=/usr/local make && sudo make install
Note for HDF5 version 1.8.0: Make sure CPPFLAGS contains "-DH5_USE_16_API" when configuring Octave.
(+C) Download and install a source-release of the "fftw" library. There is no fftw-library included in Mac OS X. The source-version of the latest fftw-release can be downloaded from Internet at http://www.fftw.org. Unpack, configure, compile and install this program the following way:
tar -xzf fftw-X.x.x.tar.gz cd fftw-X.x.x ./configure --prefix=/usr/local --enable-shared make && make check && sudo make install
(+D) Download and install a source-release of the "curl" library. There is no curl-library included in Mac OS X. The source-version of the latest curl-release can be downloaded from Internet at http://curl.haxx.se. Unpack, configure, compile and install this program the following way
tar -xzf curl-X.x.x.tar.gz cd curl-X.x.x ./configure --prefix=/usr/local --enable-shared make && make check && sudo make install
(+E) Download and install a source-release of the "glpk" library. There is no glpk-library included in Mac OS X. The source-version of the latest glpk-release can be downloaded from Internet at http://ftp.gnu.org/gnu/glpk. Unpack, configure, compile and install this program the following way
tar -xzf glpk-X.x.x.tar.gz cd glpk-X.x.x ./configure --prefix=/usr/local --enable-shared make && make check && sudo make install
(+F) Download and install a source-release of the "suitesparse" library. There is no suitesparse-library included in Mac OS X. The source-version of the latest release can be downloaded from Internet at http://www.cise.ufl.edu/research/sparse/SuiteSparse. Edit file UFconfig/UFconfig.mk and replace (in about line 76) "-lgoto" with "-lblas". The metis source package is also needed to build the "suitesparse" library, it can be downloaded from internet at http://glaros.dtc.umn.edu/gkhome/views/metis. Unpack, configure, compile and install this program the following way
tar -xzf SuiteSparse.tar.gz cd SuiteSparse mv metis-X.x.tar.gz . # mv into suitesparse directory tar -xzf metis-X.x.tar.gz make && make cx export LDFLAGS="$LDFLAGS -lmetis"
The problem after compiling the "suitesparse" is, that a make install script does not exist. A shell script like the following one could be used to copy all header files and libraries to the /usr/local directory. Run this script in the suitesparse directory as "sudo":
INSTALL_DIR=/usr/local # Make sure the install directories exist if !(test -d $INSTALL_DIR/include); then echo $INSTALL_DIR/include did not exist, creating $INSTALL_DIR/include mkdir $INSTALL_DIR/include fi; if !(test -d $INSTALL_DIR/include/suitesparse); then echo $INSTALL_DIR/include/suitesparse did not exist, creating $INSTALL_DIR/include/suitesparse mkdir $INSTALL_DIR/include/suitesparse fi; if !(test -d $INSTALL_DIR/lib); then echo $INSTALL_DIR/lib did not exist, creating $INSTALL_DIR/lib mkdir $INSTALL_DIR/lib fi; # Copy all the files to the new directories echo Copying UMFPACK files into $INSTALL_DIR... cp UFconfig/UFconfig.h $INSTALL_DIR/include/suitesparse cp UMFPACK/Include/*.h $INSTALL_DIR/include/suitesparse cp UMFPACK/Lib/libumfpack.a $INSTALL_DIR/lib ranlib $INSTALL_DIR/lib/libumfpack.a echo Copying AMD files into $INSTALL_DIR/... cp AMD/Include/*.h $INSTALL_DIR/include/suitesparse cp AMD/Lib/libamd.a $INSTALL_DIR/lib ranlib $INSTALL_DIR/lib/libamd.a echo Copying CAMD files into $INSTALL_DIR/... cp CAMD/Include/*.h $INSTALL_DIR/include/suitesparse cp CAMD/Lib/libcamd.a $INSTALL_DIR/lib ranlib $INSTALL_DIR/lib/libcamd.a echo Copying COLAMD files into $INSTALL_DIR/... cp COLAMD/*.h $INSTALL_DIR/include/suitesparse cp COLAMD/libcolamd.a $INSTALL_DIR/lib ranlib $INSTALL_DIR/lib/libcolamd.a echo Copying CCOLAMD files into $INSTALL_DIR/... cp CCOLAMD/*.h $INSTALL_DIR/include/suitesparse cp CCOLAMD/libccolamd.a $INSTALL_DIR/lib ranlib $INSTALL_DIR/lib/libccolamd.a echo Copying CXSPARSE files into $INSTALL_DIR/... cp CHOLMOD/Source/*.h $INSTALL_DIR/include/suitesparse cp CHOLMOD/Lib/libcholmod.a $INSTALL_DIR/lib ranlib $INSTALL_DIR/lib/libcholmod.a echo Copying CHOLMOD files into $INSTALL_DIR/... cp CXSparse/Include/*h $INSTALL_DIR/include/suitesparse cp CXSparse/Source/libcxsparse.a $INSTALL_DIR/lib ranlib $INSTALL_DIR/lib/libcxsparse.a echo Copying METIS files into $INSTALL_DIR/... cp metis-4.0/Lib/*.h $INSTALL_DIR/include/suitesparse cp metis-4.0/libmetis.a $INSTALL_DIR/lib ranlib $INSTALL_DIR/lib/libmetis.a
TroubleshootingEdit
(1) There are reports on the mailing lists of Octave, that automake also needs to be updated because the version that is shipped with Mac OS X doesn't work (especially with G5 Macs this problem may occur). So you might need to install a newer version than the one shipped with your Mac.
On Core Duo Macs it might appear, that compilation of libcruft/misc/machar.c fails because of a missing define, resp. a define that is in the code but is missinterpreted by the make program of your Mac. So you should do the following before configuring Octave:
export CPPFLAGS="$CPPFLAGS -DDP"
(2) When compiling Octave there may occur an error eg.
ld: Undefined symbols: restFP saveFP /usr/bin/libtool: internal link edit command failed
This is a known Mac OS X problem for over years now and may occur if you have multiply version of Fortran compilers installed on your system. GFortran is one of the known Fortran compilers that do work very well with the gcc-suite that is shipped with your computer. When running "./configure" in your Octave path then make sure that GFortran is the one and only Fortran compiler on your system (the fink version of gfortran installed with the package gcc42 also works).
(3) When installing sed there may occur an error that sed cannot be build. This is a known problem, you first need a working sed (the one implied in Mac OS X a BSD-flavoured POSIX version and a GNU version is required to build Octave) to build another sed for your system, so do the following:
(a) Enter the sed directory and edit config.h ca. line 14: #define ENABLE_NLS 0 (b) Call ./bootstrap.sh (c) sudo mv /usr/bin/sed /usr/bin/__sed (d) sudo ln -s /Users/YourHOME/sed-X.x.x/sed/sed /usr/bin/sed (e) ./configure --prefix=/usr/local/ --with-included-regex --with-included-gettext (f) make && sudo make install (g) sudo rm /usr/bin/sed
(4) On PPC Macs it seems like you need to add another linker option that will not be added by default. If you see an error like
ld: Undefined symbols: _do_fio _e_wsfe...
you should better do at step ( 3) for also taking the libg2c.dylib library at linking time and that the linker finds the desired functions:
export LDFLAGS="$LDFLAGS -lg2c"
(5) I have found that when using recent versions from CVS (cerca 02/26/2007) that I have to add the following directories to the DYLD_LIBRARY_PATH in order for Gnuplot to work properly. This may be a simple artifact of how I have Fink setup, but may be helpful to someone in the future. Wihout these directories specified, plotting functions gave errors about incompatibilities between libgd and the fontconfig or freetype libraries:
export DYLD_LIBRARY_PATH=/sw/lib/fontconfig2/lib:/sw/lib/freetype219/lib