
			   Macaulay 2
	    by Daniel R. Grayson <dan@math.uiuc.edu>
	 and Michael E. Stillman <mike@math.cornell.edu>

	available from http://www.math.uiuc.edu/Macaulay2/

We thank the United States National Science Foundation for generous funding
to develop Macaulay 2.

Macaulay 2 is copyright 1993-2009 by Daniel R. Grayson and Michael
E. Stillman.  We permit you to use it under the terms of the GNU General
Public License, version 2, as published by the Free Software Foundation; see
the file Macaulay2/COPYING.  This is free software.  There is no warranty;
not even for merchantability or fitness for a particular purpose.

This file describes how to build the software from sources and is not included
in binary distributions.  Most users will prefer to download a binary
distribution.

---------
Programs
---------

Here are programs you may have to install on your system to build Macaulay 2.

   program: fakeroot
    get at: http://ftp.debian.org/debian/pool/main/f/fakeroot
     notes: You need this only if you intend to make a debian distribution
            package for Macaulay2.

   program: rpmbuild
     notes: needed only if you want to make an rpm distribution file

---------
Libraries
---------

Here are some libraries you may have to install on your system to build
Macaulay 2.  If your operating system distinguished between development
versions and run-time versions of the libraries, you will need the development
version.

   library: libxml2
     notes: if absent, there will be an error message about the file
     	    libxml/tree.h not being found     
    get at: Mac OS X : already present, if you've installed Xcode
    	    ubuntu, debian : install the package libxml2-dev

----------------------
Getting the source code
----------------------

The best way to get the source code is to download a tar file from our web site
that contains the source code corresponding to a major release.

To get the very latest source code (which may not always work):

	svn export svn://macaulay2.math.uiuc.edu/Macaulay2/trunk/M2

-----------------------
Compiling
-----------------------

Begin with these commands:

	cd M2
	make

The "make" command above runs the commands "autoconf" and "autoheader", which
create the "configure" script and the "include/config.h.in" file, needed in the
next steps.  Once those files are created, it is not necessary to make them
again.  The "make" command on your system should be a recent version of GNU
make.

Now continute building the program this way:

	./configure
	make
	make check			# optional
	make install

Alternatively, especially if you would like to build versions for multiple
architectures, or if you want confidence that "make clean" and "make distclean"
will really work, you can make a separate "build directory" somewhere else and
compile it there, for example, in a subdirectory of the subdirectory BUILD,
provided for that purpose:

	mkdir BUILD/normal
	cd BUILD/normal
	../../configure
	make
	make check			# optional
	make install

By default, the files are installed in appropriate subdirectories of
/usr/local.  To specify a different location (prefix) you may use an option to
the configure script:

	../../configure --prefix=/foo/bar

Or, to specify a different location temporarily you may add an option to the
"make install" line:

	make prefix=/foo/bar install

In either case, files will be installed in the following directories:

	/foo/bar/bin
	/foo/bar/share/Macaulay2
	/foo/bar/share/doc/Macaulay2
	/foo/bar/share/man/man1
	/foo/bar/share/emacs/site-lisp
	/foo/bar/lib/Macaulay2

To make an encapsulated directory tree or distribution tarball suitable for use
with the program "epkg" (see http://www.encap.org/epkg/), replace the
configuration command above with:

	./configure --enable-encap

The effect is to insert one more component into the path names used at
installation time, so that in response to 

	make prefix=/foo/bar install

files will be installed in the following directories:

	/foo/bar/Macaulay2-*/bin
	/foo/bar/Macaulay2-*/share/Macaulay2
	/foo/bar/Macaulay2-*/share/doc/Macaulay2
	/foo/bar/Macaulay2-*/share/man/man1
	/foo/bar/Macaulay2-*/share/emacs/site-lisp
	/foo/bar/Macaulay2-*/lib/Macaulay2

Each * above is replaced by the current version number.  There will
also be a few extra files placed in the directory /foo/bar/Macaulay2-*
which instruct epkg how to make appropriate symbolic links to install
our program, and how to initialize the dumped data file, if present:

	/foo/bar/Macaulay2-*/encapinfo
	/foo/bar/Macaulay2-*/postinstall
	/foo/bar/Macaulay2-*/preremove

To use a different prefix, say /mnt/local, for finding libraries and include
files installed in a nonstandard location:

	../configure LDFLAGS=-L/mnt/local/lib CPPFLAGS=-I/mnt/local/include ...

where ... represents the remaining arguments, as above.  As an example, if
you have compiled the libraries with fink, then you could use this line:

        ../configure LDFLAGS=-L/sw/lib CPPFLAGS=-I/sw/include ...

To specify libraries to link against during configuration, use the
LIBS environment variable, as described in documentation for autoconf.
Example:

	../configure LIBS=-lfoo ...

To see descriptions of all the environment variables that influence
configuration, run this command and look at the section of the output
entitled "Some influential environment variables":

	../configure --help

The only one of these variables with a nonempty default value is
CFLAGS, and its default value is "-g -O2".  That will be supplanted if
you override it.

-------------------------------------------
Compiling on multiple machine architectures
-------------------------------------------

If multiple machine architectures are supported by your hardware and operating
system, a good way to specify which one to use is to use the build option to
autoconf's configure script with an architecture in config.guess format, as
well as to specify names for the compilers that include the additional options
for the architecture to be used.  This will work with gmp, for example, as it
knows how to produce the additional options to the compilers:

   ../configure --build=x86_64-apple-darwin CC="gcc -m64" CXX="g++ -m64"

Another way to do it is to add the architecture option to CFLAGS and to
CXXFLAGS.  The disadvantage of that approach is that the package might have its
own idea about what values to use for those options and ignore these settings:

   ../configure CFLAGS="-O2 -m64" CXXFLAGS="-O2 -m64"

Sometimes a library will get confused by values for CC and CXX with spaces in
them, or will try to parse the options, and get confused by the "-m64" option.
In that case, the work-around is to create shell scripts on your path called
something like gcc-m64 and g++-m64 that can be used as the compilers, and to
use this instead.  In the shell script gcc-m64 put this single line:

     exec gcc -m64 "$@"

In the shell script g++-m64 put this single line:

     exec g++ -m64 "$@"

Mark both shell scripts executable.

-----------------------
Microsoft Windows XP and Vista notes
-----------------------

    ----------------------
    Cygwin
    ----------------------

    Notes:

      - Some configure scripts, notably that of "libtool", assume ccp is in /lib
        on every system.  Work around:

	   ln -s /usr/bin/cpp /lib

----------------------
Linux notes
----------------------

----------------------
MacOS X notes
----------------------

There are several methods for installing Macaulay2 under Mac OS X.

(1) Download the ppc or i386 disk images and follow the directions in
    the read me file.  This is the easiest and fastest method.

(2) Use the fink system (http://fink.sourceforge.net).

    Follow the instructions at the Fink website to install Fink itself,
    add unstable/main to the appropriate line in /sw/etc/fink.conf, and
    then install Fink's "macaulay2" package.  You can choose the binary
    installation method or the source installation method (which will
    download the source files and compile them on your machine).  You may
    also wish to install emacs or xemacs using Fink, for the best
    interface to Macaulay2.

    Fink can also be used to install other software of interest to
    mathematicians, and is highly recommended. 

(3) Build from source yourself.  
    
    For specific scripts that we use to build the disk images,
    see BUILD/mike/Makefile and BUILD/mike/darwin64/Makefile.

-------------------------------
-- Ubuntu linux, from source --
-------------------------------

Here are the steps to take a newly installed ubuntu 7.10 system (64 bit),
and to get Macaulay2 running (either via an ubuntu package or via source.

From the package file:

     You may prepare for installing Macaulay 2 (with apt-get, gdebi-gtk, or the
     Synaptic Package Manager) by adding the following line to the file
     /etc/apt/sources.list:

         deb http://www.math.uiuc.edu/Macaulay2/Repositories/Debian stable main

     One way to add this line to that file is with the Synaptic Package
     Manager. Pull down the "Settings" menu, and select "Repositories".

     You may see a tab labelled "Third Party Software" (for example, under
     Debian). Click on it, then click on "Add", and add the entry. If you make
     a mistake, be prepared to use an editor to edit the file to correct it.

     Alternatively, you may see a tab labelled "Installation Media" (for
     example, under Debian 4.0). Click on it, then click on "Add" and then
     "Custom", and add the entry.

     Having added the line, now reload the package lists from the repositories
     (i.e., click on the "Reload" button) and then click on the Mathematics
     (Math) section. You should see "macaulay2" on the list, available for
     download. (The package manager will consult
     http://www.math.uiuc.edu/Macaulay2/Repositories/Debian/dists/.)

     Another way to install Macaulay 2, after those lines are added to
     /etc/apt/sources.list, is with this command line.

	sudo apt-get install macaulay2

From source:

     Install required packages (via the command line, as here, or via the
     synaptic package manager):

     On Ubuntu 9.04, here is what I think is the complete set needed:

     	     sudo apt-get install subversion
     	     sudo apt-get install build-essential
	     sudo apt-get install autoconf
	     sudo apt-get install libncurses5-dev
	     sudo apt-get install gfortran
	     sudo apt-get install bison
	     sudo apt-get install flex

     Now grab, configure, compile and install Macaulay2:

	  svn co svn://Macaulay2.math.uiuc.edu/Macaulay2/trunk/M2 M2
	  cd M2; make
	  mkdir BUILD/opt64; cd BUILD/opt64
	  ../../configure
          make
	  make install # places M2 into /usr/local
	  make check # optional, but recommended

