#

A Tour of NTL: Obtaining and Installing NTL for UNIX

This procedure should work on most Unix or Unix-like platorms (including MAC OSX, and Windows with Cygwin tools).

To obtain the source code and documentation for NTL, download `ntl-xxx.tar.gz`, placing it a directory, and then, working in this directory, do the following. Here, "`xxx`" denotes the current version number.

       % gunzip ntl-xxx.tar.gz
       % tar xf ntl-xxx.tar
       % cd ntl-xxx/src
       % ./configure PREFIX=$HOME/sw
       % make
       % make check
       % make install

This will build, test, and install NTL in `$HOME/sw`. Of course, change `$HOME/sw` to whatever you want (the default is `/usr/local`). You will find the NTL header files in `$HOME/sw/include/NTL` and the compiled binary in `$HOME/sw/lib/libntl.a`.

If you really are interested in high-performace, you will definitely want to build NTL using GMP (the GNU Multi-Precision package). If GMP has already been installed in a standard system library, like `/usr/local`, then invoke `configure` above as

       % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on

and if GMP is installed somewhere else, say `$HOME/sw`, then

       % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on GMP_PREFIX=$HOME/sw

does the job. This page provides more details.

Now suppose you want to compile a program that uses NTL. Suppose you are working in some directory and `foo.c` is your program. Assume that you have installed NTL in `$HOME/sw` as above. The following should work:

       % g++ -I$HOME/sw/include -L$HOME/sw/lib foo.c -o foo -lntl -lm

If you are using GMP, then:

       % g++ -I$HOME/sw/include -L$HOME/sw/lib foo.c -o foo -lntl -lgmp -lm

## More Details

What follows is a more detailed description of the installation process.

Step 1. Extract the source files by executing:

       % gunzip ntl-xxx.tar.gz
       % tar xvf ntl-xxx.tar

Note that this will unpack everything into a sub-directory `ntl-xxx`, creating this directory if necessary. Next:

       % cd ntl-xxx
       % ls

You should see a file "`README`", and directories "`include`", "`doc`", and "`src`". The directory "`doc`" contains all the documentation. The file "`doc/tour.html`" contains a copy of the on-line documentation. The directory "`include`" contains all the header files within a subdirectory "`include/NTL`". The directory "`src`" contains everything else. Go there now:

       % cd src

Step 2. Run the configuration script.

Execute the command

       % ./configure [ variable=value ]...

This configure script generates the file "`makefile`" and the file "`../include/NTL/config.h`", based upon the values assigned to the variables on the command line.

Here are the most important variables, and their default values.

       CC=gcc               # The C compiler
       CXX=g++              # The C++ compiler
       CFLAGS=-O2           # C complilation flags
       CXXFLAGS=$(CFLAGS)   # C++ compilation flags (by default, same as CFLAGS)

       PREFIX=/usr/local    # Directory in which to install NTL library components

       NTL_STD_CXX=on       # ISO Mode switch

       NTL_GMP_LIP=off      # Switch 'on' to enable the use of GMP as the primary
                            # long integer package

       GMP_PREFIX=none      # Directory in which GMP components have been installed

Examples.

- If you are happy with all the default values, run:

         % ./configure

  Actually, the initially installed `makefile` and `config.h` files already reflect the default values, and you do not have to even run the configure script.

- If your C/C++ compilers are called cc/CC, run:

         % ./configure CC=cc CXX=CC

- If you want to use, say, the options `-g` and `-O` for compiling `C` and `C++`, run:

         % ./configure "CFLAGS=-g -O"

  Note the use of quotes to keep the argument in one piece.

- If GMP (the GNU Multi-Precision package) is installed in a standard system directory, and you want to use it to obtain better performance for long integer arithemtic, run:

         % ./configure NTL_GMP_LIP=on

  If GMP was installed in `$HOME/sw`, run:

         % ./configure NTL_GMP_LIP=on GMP_PREFIX=$HOME/sw

  Go here for complete details.

- If you want to use traditional rather than ISO mode, run:

         % ./configure NTL_STD_CXX=off

- If you want to install NTL in the directory `$HOME/sw`, run:

         % ./configure PREFIX=$HOME/sw

There are a number of more esoteric configuration variables that can be set. See `config.txt` for a complete description.

Note that all of these configuration options can also be set by editing the two files `makefile` and `../include/NTL/def_config.h` by hand. These files are fairly simple and well documented, and so this is not too hard to do.

Note that the file "`../include/NTL/def_config.h`" contains a backup copy of the original `config.h` file, and that the file "`def_makefile`" contains a backup copy of the original `makefile` file.

This command is intended only as a convenience and -- more importantly -- to allow the configuration process to be script driven. This script does not perform any "magic", like finding out what the local C compiler is called, etc. If the defaults are not correct for your platform, you have to set an appropriate variable.

Step 3. Execute `make`.

Just type:

       % make

The build process after this point is fully automatic. But here is a description of what happens.

1. The makefile builds the file "`../include/NTL/mach_desc.h`", which defines some machine characteristics such as word size and machine precision. This is done by compiling and running a `C` program called `MakeDesc` that figures out these characteristics on its own, and prints some diagnostics to the terminal.

2. A script is run that "automagically" determines the best way to write a timing function on your platform. It tries different routines in the files `GetTime1.c`, `GetTime2.c`, etc., and when it finds a good one, it copies the file into `GetTime.c`.

3. The files "`lip_gmp_aux_impl.h`" and "`../include/NTL/gmp_aux.h`" are generated for use with GMP. If not using GMP, these files are still created, but they are empty.

4. The configuration wizard script is run. This script works in a sub-directory, compiling several programs, and performing a number of timing experiments, in order to determine the optimal setting for a number of flags in the file `../include/NTL/config.h`. When the script finishes (it may take several minutes), you will be told what the wizard thinks are the best settings, and your `config.h` file will be automatically updated. Note that any flags you set in Step 2 will be in effect while the wizard runs, and will be retained in the updated `config.h` file, with the exception of the flags

          NTL_LONG_LONG NTL_AVOID_FLOAT NTL_TBL_REM NTL_AVOID_BRANCHING
          NTL_SPMM_UL NTL_SPMM_ULL NTL_SPMM_ASM NTL_GF2X_NOINLINE NTL_GF2X_ALTCODE

   which are set by the wizard. Also note that if you do not want the wizard to run, you should pass `WIZARD=off` to the configure script; however, this is not recommended.

5. The makefile will compile all the source files, and then creates the library "`ntl.a`" in the current directory.

Note that for finer control you can optionally break up this process into the five component steps:

       % make setup1
       % make setup2
       % make setup3
       % make setup4
       % make ntl.a

After NTL is built.

Executing `make check` runs a series of timing and test programs. It is a good idea to run this to see if everything really went well.

Executing `make install` copies a number of files to a directory `<prefix>` that you specify by passing `PREFIX=<prefix>` as an argument to `configure` at configuration time, or as an argument to `make install` at installation time. The default is `/usr/local`, so either you need root permissions, or you choose a `<prefix>` for which you have write permission. The files `../include/NTL/*` are copied into `<prefix>/include/NTL`. The file `ntl.a` is copied to `<prefix>/lib/libntl.a`. The files `../doc/*` are copied into `<prefix>/doc/NTL`.

You can also "fine tune" the installation procedure further. See the configure documentation for details.

Executing `make uninstall` undoes `make install`.

Executing `make clobber` essentially undoes `make`. Make sure you do this if you re-build NTL for a different architecture!

Executing `make clean` will remove object files, but not `ntl.a`. To rebuild after executing `make clean`, execute `make ntl.a`.

Assuming you have installed NTL as above, to compile a program `foo.c` that uses NTL, execute

       g++ -I<prefix>/include -L<prefix>/lib foo.c -o foo -lntl -lm

This compiles `foo.c` as a `C++` program and creates the binary `foo`.

If you built NTL using GMP, execute:

       g++ -I<prefix>/include -L<prefix>/lib -L<gmp_prefix>/lib  foo.c -lntl -lgmp -lm

Of course, if `<prefix>` and `<gmp_prefix>` are the same, you do not need to duplicate the `-L` flags, and if either are standard directories, like `/usr/local`, you can leave out the corresponding `-I` and `-L` flags altogether.

This works even if you are not working in the directory in which you built NTL. If you are working in that directory, you can just execute

       make foo