                    Building and Installing HTSlib
                    ==============================

Requirements
============

Building HTSlib requires a few programs and libraries to be present.
At least the following are required:

    GNU make
    C compiler (e.g. gcc or clang)

In addition, building the configure script requires:

    autoheader
    autoconf

Running the configure script uses awk, along with a number of
standard UNIX tools (cat, cp, grep, mv, rm, sed, among others).  Almost
all installations will have these already.  

Running the test harness (make test) uses:

    bash
    perl

HTSlib uses the following external libraries.  Building requires both the
library itself, and include files needed to compile code that uses functions
from the library.  Note that some Linux distributions put include files in
a development ('-dev' or '-devel') package separate from the main library.

    libz       (required)
    libbz2     (required, unless configured with --disable-bz2)
    liblzma    (required, unless configured with --disable-lzma)
    libcurl    (optional, but strongly recommended)
    libcrypto  (optional for Amazon S3 support; not needed on MacOS)

Disabling libbzip2 and liblzma will make some CRAM files unreadable, so
is not recommended.

Using libcurl provides HTSlib with better network protocol support, for
example it enables the use of https:// URLs.  It is also required if
direct access to Amazon S3 or Google Cloud Storage is enabled.

Amazon S3 support requires an HMAC function to calculate a message
authentication code.  On MacOS, the CCHmac function from the standard
library is used.  Systems that do not have CChmac will get this from
libcrypto.  libcrypto is part of OpenSSL or one of its derivatives (LibreSSL
or BoringSSL).

Building Configure
==================

This step is only needed if configure.ac has been changed, or if configure
does not exist (for example, when building from a git clone).  The
configure script and config.h.in can be built by running:

    autoheader
    autoconf

If you have a full GNU autotools install, you can alternatively run:

    autoreconf

Basic Installation
==================

To build and install HTSlib, 'cd' to the htslib-1.x directory containing
the package's source and type the following commands:

    ./configure
    make
    make install

The './configure' command checks your build environment and allows various
optional functionality to be enabled (see Configuration below).  If you
don't want to select any optional functionality, you may wish to omit
configure and just type 'make; make install' as for previous versions
of HTSlib.  However if the build fails you should run './configure' as
it can diagnose the common reasons for build failures.

The 'make' command builds the HTSlib library and and various useful
utilities: bgzip, htsfile, and tabix.  If compilation fails you should
run './configure' as it can diagnose problems with your build environment
that cause build failures.

The 'make install' command installs the libraries, library header files,
utilities, several manual pages, and a pkgconfig file to /usr/local.
The installation location can be changed by configuring with --prefix=DIR
or via 'make prefix=DIR install' (see Installation Locations below).


Configuration
=============

By default, './configure' examines your build environment, checking for
requirements such as the zlib development files, and arranges for a plain
HTSlib build.  The following configure options can be used to enable
various features and specify further optional external requirements:

--enable-plugins
    Use plugins to implement exotic file access protocols and other
    specialised facilities.  This enables such facilities to be developed
    and packaged outwith HTSlib, and somewhat isolates HTSlib-using programs
    from their library dependencies.  By default (or with --disable-plugins),
    any enabled pluggable facilities (such as libcurl file access) are built
    directly within HTSlib.

    The <https://github.com/samtools/htslib-plugins> repository contains
    several additional plugins, including the iRODS (<http://irods.org/>)
    file access plugin previously distributed with HTSlib.

--with-plugin-dir=DIR
    Specifies the directory into which plugins built while building HTSlib
    should be installed; by default, LIBEXECDIR/htslib.

--with-plugin-path=DIR:DIR:DIR...
    Specifies the list of directories that HTSlib will search for plugins.
    By default, only the directory specified via --with-plugin-dir will be
    searched; you can use --with-plugin-path='DIR:$(plugindir):DIR' and so
    on to cause additional directories to be searched.

--enable-libcurl
    Use libcurl (<http://curl.haxx.se/>) to implement network access to
    remote files via FTP, HTTP, HTTPS, etc.  By default, HTSlib uses its
    own simple networking code to provide access via FTP and HTTP only.

--enable-gcs
    Implement network access to Google Cloud Storage.  By default or with
    --enable-gcs=check, this is enabled when libcurl is enabled.

--enable-s3
    Implement network access to Amazon AWS S3.  By default or with
    --enable-s3=check, this is enabled when libcurl is enabled.

--disable-bz2
    Bzip2 is an optional compression codec format for CRAM, included
    in HTSlib by default.  It can be disabled with --disable-bz2, but
    be aware that not all CRAM files may be possible to decode.

--disable-lzma
    LZMA is an optional compression codec for CRAM, included in HTSlib
    by default.  It can be disabled with --disable-lzma, but be aware
    that not all CRAM files may be possible to decode.

The configure script also accepts the usual options and environment variables
for tuning installation locations and compilers: type './configure --help'
for details.  For example,

    ./configure CC=icc --prefix=/opt/icc-compiled

would specify that HTSlib is to be built with icc and installed into bin,
lib, etc subdirectories under /opt/icc-compiled.


Installation Locations
======================

By default, 'make install' installs HTSlib libraries under /usr/local/lib,
HTSlib header files under /usr/local/include, utility programs under
/usr/local/bin, etc.  (To be precise, the header files are installed within
a fixed 'htslib' subdirectory under the specified .../include location.)

You can specify a different location to install HTSlib by configuring
with --prefix=DIR or specify locations for particular parts of HTSlib by
configuring with --libdir=DIR and so on.  Type './configure --help' for
the full list of such install directory options.

Alternatively you can specify different locations at install time by
typing 'make prefix=DIR install' or 'make libdir=DIR install' and so on.
Consult the list of prefix/exec_prefix/etc variables near the top of the
Makefile for the full list of such variables that can be overridden.

You can also specify a staging area by typing 'make DESTDIR=DIR install',
possibly in conjunction with other --prefix or prefix=DIR settings.
For example,

    make DESTDIR=/tmp/staging prefix=/opt

would install into bin, lib, etc subdirectories under /tmp/staging/opt.
