#!/usr/bin/env bash
set -e

# After installing CentOS 6.5 as "Minimal Desktop"

if command -v yum &> /dev/null
then
    # Redhat

    yum install \
        make gcc gcc-c++ \
        flex bison \
        patch \
        zlib-devel $(: for astrometry.net) \
        ncurses-devel readline-devel \
        libX11-devel libXt-devel \
        openssl-devel bzip2-devel $(: for python) \
        cairo-devel $(: for matplotlib) \
        wget curl git

elif command -v apt-get &> /dev/null
then
    # Debian

    apt-get install gcc g++ make flex bison patch wget curl git \
        zlib1g-dev libncurses5-dev \
        libreadline-dev libx11-dev libxt-dev \
        libssl-dev libbz2-dev libcairo2-dev
elif command -v zypper &> /dev/null
then
    # SUSE

    zypper install \
        make gcc gcc-c++ \
        flex bison \
        patch \
        zlib-devel $(: for astrometry.net) \
        ncurses-devel readline-devel \
        xorg-x11-libX11-devel xorg-x11-libXt-devel \
        libopenssl-devel libbz2-devel $(: for python) \
        cairo-devel $(: for matplotlib) \
        wget curl git
else
    echo "Cannot automatically install what are needed." 1>&2
    exit 1
fi

: << EOF
for FreeBSD
    pkg install gmake gcc5 flex bison patch ncurses openssl bzip2 cairo wget curl git bash pkgconf python unzip

    AND you must export the following environment variables:
    (FreeBSD only)
    export CC=gcc5
    export CXX=g++5
    export EUPS_FLAVOR=Linux64
    # It is important to forswear the OS because many build scripts
    # don't consider FreeBSD

    AND you must override make with gmake
    ln -s /usr/local/bin/gmake /usr/local/bin/make

    # You must further add to config.rc:
    systemPath=/usr/local/bin:/usr/bin:/bin
EOF
