*********************
**** PREPARATION ****
*********************

The compilation of Normaliz requires some c++11 features, supported by:

	gcc 4.4, clang 2.9, icc 12.0

See https://github.com/Normaliz/Normaliz/issues/26 for a more detailed discussion.

For compiling Normaliz the following libraries are needed:

* gmp with gmpxx
* boost (headers only)
* openmp enabled compiler (to use parallelization) For the support of OpenMP clang 3.7 or newer is needed.

On Ubuntu the following packages should be installed:

	sudo apt-get install g++ libgmp-dev libboost-dev cmake cmake-curses-gui

The last two are only needed if cmake is to be used for building Normaliz.

On Homebrew (Mac OS X):

        brew install gmp boost

For the openmp enabled compiler (LLVM 3.9 or newer), add:

        brew install llvm
        export PATH="`brew --prefix`/opt/llvm/bin/:$PATH"
        export LDFLAGS="-L`brew --prefix`/opt/llvm/lib"

On Fink (Mac OS X):

	fink install gmp5 boost1.58-nopython

We offer three ways of compilation, either use:

* standard autotools (./configure && make && make install)
* cmake -- cmake is also capable of generating compile instructions 
       for other systems, like MS VS projects, etc.
* plain old makefile (Makefile.classic)

For building Normaliz under Mac OS we recommend auttotools if you want to use Scip.

The basic steps are the same for all three systems:

* configuration
* compilation
* installation

The main difference is the way how the build system is configured.
 
 
*************************
*** Optional packages ***
*************************

For functional extension:

CoCoALib is necessary if you want to compute integrals or weighted Ehrhart series and, 
hence,  for symmetrization. If you want to compile Normaliz with CoCoALib, install  
CoCoALib first by running

        sudo ./install_nmz_cocoa.sh
        
in the Normaliz directory. This copies the files needed by Normaliz to nmz_opt_lib.

Without functional extension:

Flint: use

            sudo ./install_nmz_flint.sh
            
The remarks on CoCoA above apply here as well.

As discussed in the manual, Normaliz can use of SCIP. If you want to use it, SCIP
must be installed before the compilation of Normaliz, independently of
the method used for building Normaliz.
 
To build SCIP:

* download the scipoptsuite at http://scip.zib.de/ . 

   Notice that SCIP
   is not distributed under GPL, but the ZIB Academic License
   (http://scip.zib.de/academic.txt).
   
* Unpack it and then compile it with
 
   make ZLIB=false GMP=false READLINE=false scipoptlib
   
   (To compiling scip for 32bit systems, add also ARCH=x86 to the make.)
   
   If your C++ compiler is too old, you may need to add
   CXXFLAGS="-std=c++0x -fPIC"
   
* IMPORTANT: ** Don't try to build scipopt as a shared library!  It does not work
      because their build system is broken **

*******************
**** AUTOTOOLS ****
*******************

If you checked out normaliz from GitHub, first set up the autotools
system (./bootstrap.sh) -- in this case, the system needs to have
autoconf, automake, libtool installed.  This step is not necessary if
you started from a normaliz distribution.

We assune in the following that Boost and GMP are in standard locations. (It is
possible to customize the paths to them as well.)

We assume that you are in the directory in which source, doc etc. are subdirectories.

The first step is to configure the compilation. The simplest choice is

   ./configure
   
This is sufficient if you don't want any optional library. 

If CoCoALib is not in a standard location, to show configure the path to CoCoALib if you want
to compile with it use the option --with-cocoalib. For example:

   ./configure --with-cocoalib=$HOME/CoCoA/CoCoALib-0.99550
   
Simlarly, you can set the path for Flint

   ./configure --with-flint=...

Some more configure options:

* Static build (easier for debugging):

   ./configure --disable-shared
   
* Prefix (directory) for installation (default is /usr/local):

   ./configure --prefix=$HOME/normaliz
   
For more, see

   ./configure --help
   
After configuration we compile. Simply say

    make
    
This will compile normaliz, libnormaliz and maxsimplex, 
the example program in the manual.

and then (if you want)

    sudo make install
    
This will install normaliz, the libraries and header files in their chosen
location (usr/local by default).

Confuguration with Scip:

For example, on Fink (Mac OS X):

  ./configure CPPFLAGS="-I/sw/include -I/sw/opt/boost-1_58/include $CPPFLAGS" LDFLAGS="-L/sw/lib -L/sw/opt/boost-1_58/lib $LDFLAGS" 

To configure normaliz for scipoptsuite compiled as above use:

   ./configure --with-scipoptsuite-src=/path/to/scipoptsuite-source-dir


***************
**** CMAKE ****
***************

This has better capabilities to find libraries and allows to change settings with a nice interface. 
Furthermore it supports the compilation of the library as static and dynamic version, and the 
installation of the library.

We assume you start in the normaliz root dir (with subdirs source, examples, ...).

[1] Create a build directory where normaliz will be build and cd into it, e.g.

        mkdir BUILD; cd BUILD

[2] Initial configuration, have a look at the next sections for further config infos.
(can be skipped if step [3] is done, but it shows some information about what compiler, libraries, etc. it uses)

        cmake ../source

[3] (Optional) Check configuration and perhaps change some settings:

        ccmake ../source

In the ccmake interface you can use this workflow:

* c  (for configure)
* change entries if you like, then press c again
* g  (generate and exit)

[4] compile

        make
    
This make includes dependency checks and other nice features.
If you want to see what happens behind the scenes use

        make VERBOSE=1

[5] install it

        sudo make install

This will install the produced libnormaliz, the header files for it  and the normaliz executable. The path can be changed with ccmake (CMAKE_INSTALL_PREFIX).


**** ADDITIONAL CMAKE CONFIGURATION ****

If you want to override system defaults you can change values with ccmake or set enviroment variables.

IMPORTANT NOTE: Be aware that some of these only work with the first call of cmake. 
If you want to change it later clean your build directory first, or use another fresh build directory.

Some examples:

* Specifiy installation location:

        cmake -DCMAKE_INSTALL_PREFIX:PATH=$HOME/local ../source   (default is /usr/local)

* Different compiler:

        CC=gcc-4 CXX=g++-4  cmake  ../source/

* To specify search paths for GMP you can add before the cpmmand cmake

        GMP_DIR=/path/to/gmp     

It will look inside for subfolders with the headers and lib.
If this is not successfull you can specify the paths seperatly:

        GMP_INC_DIR=/path/to/include  (for headers)
        GMP_LIB_DIR=/path/to/lib     (for libs)

To use your own GMP version installed to the 'local' folder in the home directory use

        GMP_DIR=$HOME/local/   cmake   ../source/

For MacOS you can set CMAKE_OSX_ARCHITECTURES eigther with the cmake command-line option

        -DCMAKE_OSX_ARCHITECTURES=x86_64

or by setting it in ccmake to x86_64.

See also: http://stackoverflow.com/questions/5334095/cmake-multiarchitecture-compilation


Also the  Boost directories can be specified:

BOOST_ROOT                 - Preferred installation prefix
BOOST_INCLUDEDIR           - Preferred include directory e.g. <prefix>/include
BOOST_LIBRARYDIR           - Preferred library directory e.g. <prefix>/lib
Boost_NO_SYSTEM_PATHS      - Set to ON to disable searching in locations not
                             specified by these hint variables. Default is OFF.
Boost_ADDITIONAL_VERSIONS  - List of Boost versions not known to this module
                             (Boost install locations may contain the version)
	 
See http://www.cmake.org/cmake/help/git-master/module/FindBoost.html


**** CMAKE: Using Flint, SCIP and CoCoALib ****

Then configure Normaliz with, for example,

  SCIP_DIR=$HOME/SCIP/scipoptsuite-3.2.0/ cmake ../source

Currently our cmake module for SCIP only supports versions 3.2.1 and 3.2.0
on Linux 32 and 64 bit and MacOs X.

An example for finding CoCoALib:

  COCOA_DIR=$HOME/CoCoA/CoCoALib-0.99550 cmake ../source/
  
The directories for Flint and MPFR can be set via 

   FLINT_DIR
   MPFR_DIR
   
You need both of them.
  

********************
**** plain MAKE ****
********************

Under Linux one can still use our old simple plain Makefile. But the autotools and CMAKE configurations are much more powerful.

This Makefile is mainly used for deveopment and debuggung. It builds statically linked binaries
with -g (can be changed in Makefile.configutaion).

It is assumed that the optional libraries are in

   $/HOME)/nmz_opt_lib
   
So you should copy nmz_opt_lib from the Normaliz directory to your home directory.
(Intentionall we do not choose a standard location.)

1) Go to the source directory

2) Check the configuration in Makefile.configuration, especially the locations of
the optional packages and their versions.

3) Say 

        make -f Makefile.classic

It should work without change of Makefile.classic or Makefile.configuration on many systems
that have a system installation of the needed libraries. (We must use the name Makefile.claasic since Makefile is occupied by autotools.) 

Without further arguments, Makefile.classic will build Normaliz with OpenMP and CoCoALib, but without SCIP and Flint (see below how to change this behavior)

If everything is successful, then the executable file normaliz is
in the source directory. You may of course want to move them somewhere else.


Makefile.classic accepts optional arguments (also simultaneously):

        make -f Makefile.classic OPENMP=no  # deactivates OpenMP
        make -f Makefile.classic COCOA=no   # deactivates CoCoALib
        make -f Makefile.classic SCIP=yes   # compile with SCIP
        make -f Makefile.classic Flint=no   # compile with Flint

You must make sure that everything is compiled with the same set of options!
In doubt use make clean before.

Similarly

        make -f Makefile.classic maxsimplex

for the compilation of maxsimplex (in its directory, example for the use of libnormaliz
in the manial).

5) If you want to install Normaliz, Say 

        make -f Makefile.classic install

6) Makefile.classic includes a target "clean". It will remove the compiled files (but not uninstall them) by 

        make -f Makefile.classic clean

6) QNormaliz has its own Makefile.classic in Qsource. Apply the setps 2), 5) and 6) accordingly. QNormaliz will be installed in the same directories as Normaliz. This is possible since it has its own file names.

The whole point of QNormaliz is the use of a class library for field extensions of the rational numbers. Its use may require the adaptation of the Makefile.classic.
