# MINC/Tutorials/SourceInstall
## Installing MINC from sources, using cmake superbuild

Read installation instructions at https://github.com/BIC-MNI/minc-toolkit

## Installing MINC from sources , using big makefile (outdated)

The MINC tools have been successfully compiled on a wide variety of systems. Including SGI, Sun, Linux, Windows, Mac OS X and VAX. This tutorial covers how to install the minc tools by compiling the sources. The tutorial presumes that you are using GNU/Linux, the procedure to build on other platforms is sometimes subtly different but will largely follow the example below.

## Prerequisites

The MINC tools have a relatively large number of dependencies. The exact list of packages that needs to be installed before successfully compiling all the tools will depend on the target system, as every distribution of Linux/BSD comes with a different package set. In a new installation of Debian or Ubuntu, the following packages might be missing and need to be installed using apt-get or synaptic :
* HDF5
* NetCDF
* flex
* g++ (older versions of N3 require g++ 4.2, yet there is no such restriction for the latest N3 release)
* zlib1g-dev
* libnetpbm9-dev
* libxmu-dev
* libxi-dev
* libtext-format-perl
* autoconf
* byacc
also, latex tools might be necessary to build the documentation. The following packages are required only if installing Display and/or register:
* opengl (libGL) dev
* glut (libglut) dev
This does not apply, however, for Nvidia-based video cards, which have their own libraries installed with the drivers. To check for these libraries, type:
A window with rotating gears should appear.
To install everything in one go via apt-get on Ubuntu or Debian, this should suffice:
In order to build the packages you might also need to install the compiler and GNU make:

## Building from the source code using one big makefile

A very large Makefile has been constructed, which builds much of the MNI-BIC content found on http://packages.bic.mni.mcgill.ca/tgz, in addition to a few other bits and pieces (notably parts of ITK). Please note that this process downloads, builds, and installs from source, and as such, if used, should be used instead of the aforementioned binary options (e.g. apt-getting minc-bundle). In addition, the presence of other minc libs from previous binary installs might result in the linker grabbing an older library, so it's best ensure that all previously installed minc components (e.g. netcdf, hdf5, etc) are removed prior to building. This method has been tested on several recent Linux distributions: Debian 5, Ubuntu 10.04, 10.10 & 11.04.

#### Step 1: Download the Make file

This file is currently part of Vlad Fonov's EZminc package, so that's where to find it. If problems, contact Vladimir Fonov <vladimir.fonov @NOSPAM@ mcgill.ca>.

#### Step 2: Decide on what you want to build

The Makefile provides quite a few build targets, the two extremes being make minc-only and make minc-full. Type make help to get a little help info, or take a look at the Makefile header with your favorite text editor in order to read details on all targets.

#### Step 3: Create your build and install directories

The Makefile downloads source packages and builds them in a user-defined build directory, specified via the BUILD_DIR argument. Create this directory prior to starting the build. If not specified, the build will occur in your current directory (which is messy). All build products will be installed to the specified INSTALL_DIR. Note that if you want to install to a system directory, say, /usr/local/bic, you will need to run the Makefile under sudo.

#### Step 4: Ensure that prerequisite packages are installed

Even though the big Makefile builds a lot of stuff, there are still some non-MNI-BIC packages that will need to be installed prior to the Make. Simply apt-get these packages; the Makefile header contains the apt-get statement that should do the job.

#### Step 5: Run your build(s)

OK, now for the moment of truth. Here are some build examples:
* Minimal build: netcdf, hdf5, minc
* Full build: Build lots of stuff, plus register and Display, and install the MNI-BIC fitting models
Please note that if anything goes wrong in one of the builds, the building of all dependent packages will not be attempted. To fix build errors, simply go into your BUILD_DIR/package_name directory and have a fiddle. As a matter of fact, this sort of fiddling is currently required when building Display under Ubuntu Lucid LTS (make visual), due to problems with libtool.

## Building individual packages

It's possible to compile the MINC tools from individual packages. A typical installation will require:
* minc-2
* mni_autoreg
* bicpl
* conglomerate
* ebtks
* classify
* inormalize
* Register
* mincblob
* mincmorph
* mni_perllib
* N3
* ray_trace
* Display
Valuable additional scripts can be found here: http://packages.bic.mni.mcgill.ca/scripts/; these can be downloaded after the MINC tools have been installed.
First download the latest version of the MINC 2.x toolchain from http://packages.bic.mni.mcgill.ca/tgz
Then untar the package
Enter the directory
At this stage you should of course read the README file, and NEWS and ChangeLog files to discern what changes have been made since the last release. Lets presume you have done this.
In our case we want to install all the MINC Tools in /usr/local/bic and know that NetCDF and HDF5 have been previously installed in /usr/local. As such we will configure the package like this:
Note that with the minc2 libraries you will need to add an additional flag:
A bunch of output will result from this command as configure checks for various libraries on your system. Running configure should generate a makefile. Which we can now use
This will build all the MINC files and now we can run the inbuilt checks that come with the MINC package. This is one of the advantages of building MINC from source as you can run the checks yourself, binary packages do not afford this possibility as the presumption is make that a build on one system will be fine on another system of the same platform. To run the checks type:
The checks that are running will determine if underlying MINC API is self consistent plus a few other checks. Once the checks are complete the status is returned. You should see a line similar to this:
It is now time to install MINC, given that we provided configure with a prefix argument this is the directory where the MINC API and base tools will be installed. In our case this is /usr/local/bic to do this type the following:
This will install a number of things into four subdirectories in /usr/local/bic. Executable programs in bin/ header files in include/ library files in lib/ and manual pages in man/.
We can test the installation with something like this:
This should return both the version number of the program and the underlying libraries.