# Building of Munipack from source code.

Building Munipack from a source code

## Introduction

This page describes how to build Munipack from source codes. This is most portable way, but certain computer skills are required. A fine tune fitting is possible. A packaging system is unused. More convenient way to get Munipack offers the install page.

### The AppImage script

The script `dist/appimage.sh` described by AppImage makes a complete local installation. It can be considered as a guideline or be adjusted for a particular case.

## Summary

There is a short summary of installation steps which will install the latest stable release (replace X.Y by an appropriate number):

    $ mkdir ~/src/
    $ cd ~/src
    $ wget https://integral.physics.muni.cz/ftp/munipack/munipack-0.X.Y.tar.gz
    $ tar zxf munipack-0.X.Y.tar.gz
    $ cd munipack-0.X.Y
    $ ./configure
    $ make
    # [sudo] make install  # as root

More detailed description is below.

# Source building

The building takes phases:

- preparing helper tools
- getting sources
- initialisation
- configure
- compile

At the moment, Munipack can be compiled under GNU/Linux, g++, gfortran and wxWidgets ver. 3.0.0 (and above) only.

Munipack is designed to be pretty much portable and multi-platform, however, unusual combinations of compilers, operating systems, etc. should require some additional tuning.

## Download

Munipack's source is distributed as a tarball which contains the latest stable version.

Download: https://integral.physics.muni.cz/ftp/munipack/

To get source tree, download archive and unpack the tarball as:

    # cd $HOME/src
    # wget https://integral.physics.muni.cz/ftp/munipack/munipack-0.6.X.tar.gz
    # gzip -dc munipack-0.6.XXX.tar.gz | tar -xf -

The preferred path for placing sources is `$HOME/src` for the per-user installation If you have root privileges, use `/usr/src` and replace all references by `$HOME/src` in this text.

## Prerequisites

Following tools are required for compiling of Munipack:

- Any Unix-like system (GNU/Linux, *BSD, etc.)
- Fortran 2008+ and C++ compilers
- Autoconf and automake (optional)
- cfitsio library
- Oakleaf library
- minpack library
- PLplot library including Cairo driver
- wxWidgets library (ver. >= 3.0.0)

All libraries must be available in the development version. Common package systems contains development libraries as -dev (-devel) packages.

The requirement for 3+ version of wxWidgets is the support of the event handling system, which is necessary for command-line applications. The instructions for wxWidgets installation can be found on wiki: http://wiki.wxwidgets.org/Prerequisites.

The necessary tools can be, under GNU/Debian, Ubuntu and derivatives, installed by

        apt install libcfitsio-dev libwxgtk3.2-dev minpack-dev liboakleaf-dev \
                    pkg-config libplplot-dev

PLPlot is necessary for plotting. Cairo is the default driver; it provides high quality graphs, supports of the anti-aliasing and the alpha transparency. If the driver is unsuitable, user is prompted; an alternative driver can be selected in `xmunipack/plplot.cpp`.

Autoconfig is required for bootstrap (the `configure` script generation), and left unused if the code is build unmodified.

## Initialisation

Required only if the sources are taken directly from the Mercurial repository. The repository is not public available, robots losing respect to humans.

Initialisation requires:

- Working installation of Autotools (automake, autoconf).

Munipack building is on base of Autotools which is most widely portable way working under common computer systems. The initialisation of building framework is required.

The building is controlled by configure.ac (top) and set of Makefile.am-s (all building directories).

This phase creates `configure.ac` and other auxiliary files:

    $ ./bootstrap --dev

Next step is to activate Autotools, and to make Makefiles by processing of the control files:

    $ autoreconf -i

## Configure and install

The initialised source is ready for compilation. This can be done quite easy on Linux based distributions, same as other Unix's systems. The configuration, compilation and installation is provided by the standard GNU way. Simply, run the following sequence of commands:

    $ ./configure
    $ make
    $ make install

Munipack will check available tools and will be installed by default under tree `/usr/local`.

The phase will work under any supported system. C++ and Fortran compilers and appropriate development libraries needs to be installed, of course.

There is possibility to fit the installation according to your needs. Running of the command

    ./configure --help

will display possible switches to fine tuning of building.

The recommended setup is:

    ./configure FCFLAGS="-O2 -ffpe-summary=invalid,zero,overflow" \
                CFLAGS="-O2 -DNDEBUG" CXXFLAGS="-O2 -DNDEBUG"

Certain setting of the environment variables affects of the compilation process. For example, more progressive optimisation of the output code for 32-bit machines (64-bit machines are optimised on the level by default) and GNU compilers (g++, gfortran) is provided by `FCFLAGS` and `CFLAGS` variables

      $ ./configure CXXFLAGS="-march=i686 -O2" FCFLAGS="-march=i686 -O2"

If the default installation `/usr/local` is not enough, place it into another directory:

        ./configure [..] --prefix=$HOME/opt

and modify your search path like `PATH=$PATH:$HOME/opt/bin`.

The installation under FreeBSD would work with parameters:

    csh:> ./configure LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include

The installation under Fedora/RHEL will require

    ./configure CXXFLAGS=-I/usr/include/cfitsio

On finish, the configure command will print the summary:

    Configured Munipack:

                          Virtual Observatory support enabled: yes
                               Command line interface enabled: yes
                             Graphical User Interface enabled: yes

If the configure script had found wxWidgets library, both the first and the second options are set to `yes`. The command line and the graphical interfaces requires wxWidgets; without them, only processing engines are compiled. They has no user interfaces and any communication is released only via the standard input and output (which can be useful for daemons, web interfaces, etc.).

## Options for the configure

There are some alternative ways to fit uncommon requirements:

- To suppress build of GUI (xmunipack command) suitable for non-iterative analysis (scripts) without support of graphical devices, use:

      ./configure --disable-gui

- To suppress build of the command-line interface (muninpack command) for direct use of modules:

      ./configure --disable-cli

- Virtual Observatory support is disabled by:

      ./configure --disable-vo

Use of all the options (`--disable-[gui|cli|vo]`) together eliminates completely dependency on both wxWidgets and PLPlot. cFITSIO, Oakleaf and Minpack libraries are still necessary.

## Un-Installation

Use commands

    # cd $HOME/src/munipack-0.6.X
    # make uninstall

in the installation directory to uninstall Munipack.

This implying that it is not a good idea to remove the source directory immediately after installation (the reason to use `/usr/src` or an equivalent path).