Use ternary operator instead of 5 lines

For the oStrictHostKeyChecking we use the variable tmp, which is yes or
no, depending on the strict.

Signed-off-by: Aaron Karper <akarper@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Add cabal file generation to Makefile.am

This allows us to specify the exact version ranges of dependencies we
support, across all operating systems.

See issue #988.

This commit only adds the cabal file and declares the dependencies.
Enforcing them will be subject of a later commit.

So far, we have only given the names of dependency in most cases,
making sure that Ganeti builds with the dependency versions that are in
Debian.
This has caused problems for users that were not running Debian, or
when there were packages installed in the compiling user's ~/.ghc
directory, leading to compile-time type errors instead of pre-build
configuration errors; for an example, see:
  https://code.google.com/p/ganeti/issues/detail?id=979#c10

By explicitly listing our dependencies, we make clear which versions
are supported.

Modules and executables listed in the cabal file are automatically
generated from the Makefile; executables are symlinked in an apps/
directory to avoid repeated compilation as explained in:

  http://stackoverflow.com/a/6711739/263061
  http://stackoverflow.com/q/12305970/263061

For example, in apps/ there is:

  hluxid.hs -> ../src/hluxid.hs
  hluxid.hs.stamp
  [...]

Each executable symlink has a stamp file to track its modification time
because make follow symlinks and thus does not see symlink modification
times.

In addition to declaring our dependencies, this setup allows building
Ganeti's Haskell code with cabal to support editor integration and
cabal-based tooling, the Makefile remains the default way to build Ganeti.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Cabal: Allow json-0.8

Compilation was tested successfully.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Cabal: Allow attoparsec <= 0.12 and lens <= 4.3

Compilation was tested successfully.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Cabal: Allow network <= 2.6

Compilation was tested successfully with network-2.5.0.0 and network-2.6.0.2.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Cabal: Relax lower bounds

Compilation was tested successfully on our buildbot.

Indirect dependencies were removed, found by the `packdeps` tool.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Use Cabal to enforce dependency versions

This uses `cabal configure` to determine which exact dependency versions
we are compiling against, and ensures that these versions are used
by passing -package-id flags to GHC.

The `cabal configure` step makes the build fail before compiling / type
checking if the user tries to compile against a dependency version we don't
support; before, this case led to type errors which were not clearly
user errors. This fixes issue #988.

The output of `cabal configure` is also used to generate MIN_VERSION_*
macros.

MIN_VERSION_* macros are the standard way to build CPP dependency switches
in Haskell packages, and they replace our custom macros (like PARALLEL3
and NO_REGEX_PCRE) which had to be hand-built for each dependency.
We can now query the version of any Haskell dependency without having
to manually add a flag via autoconf.

All ghc and hlint invocations were adjusted to take these macros into
account.

This change introduces a Haskell-build-time dependency on cabal-install
(for `cabal configure`) and the Cabal API (for obtaining the configured
dependency versions and generating the macros).
Any cabal version since Debian Squeeze is supported.

Note that our use of Cabal does not imply any downloading of dependencies
at build time, hermetic builds are unaffected by this change.

For developers we now require hlint >= 1.8.60, to make use of its
--cpp-file option.
However, hlint >= 1.9.12 is recommended since for
hlint >= 1.8.58 && < 1.9.12 the --utf8 flag is non-functional
(see https://github.com/ndmitchell/hlint/issues/96); this can be worked
though by using the equivalent `--encoding=UTF-8` flag.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Remove check for PARALLEL3

This uses the new MIN_VERSION_* infrastructure now.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
NEWS: Mention Cabal version enforcement in build system

Also mention the added dependency on Cabal and cabal-install.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Remove check for HS_REGEX_PCRE

This uses the new MIN_VERSION_* infrastructure now.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
INSTALL: Remove unclear note

This is either outdated or a mistake; one cannot "enable symlinks"
in the cabal config, and if `symlink-bindir` was meant, that will
barely help against dependency installation failures.

Signed-off-by: Niklas Hambuechen <niklash@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>