Prerequisites
=============

Maude requires following the tools:

GNU gcc		http://gcc.gnu.org/
GNU bison	http://www.gnu.org/software/bison/
flex		https://github.com/westes/flex

It is recommended that you use the latest versions of bison and flex
since Maude is known to tickle bugs in certain older versions. You
should use gcc 5.2 or later as there are code generation issues with
earlier versions.

Maude requires the following packages:

GNU gmp		  https://gmplib.org/
GNU libsigsegv	  https://www.gnu.org/software/libsigsegv/
Tecla		  http://www.astro.caltech.edu/~mcs/tecla/
BuDDY		  http://sourceforge.net/projects/buddy
CVC4 (optional)	  https://cvc4.github.io/
Yices2 (optional) https://github.com/SRI-CSL/yices2


Configuring the 3rd party packages
==================================
It is recommended that GNU gmp, BuDDy and CVC4 be
compiled with the same compiler you will use for Maude.


GMP
---
GNU gmp	must be configured with --enable-cxx to generate the C++
bindings. I also recommend --enable-fat to allow the code to
run on CPUs older than the one you build on.
In order to build Yices you will need both static and dynamic
GMP libraries - you can discard the dynamic ones once Yices is
built. I use the following configure arguments for Linux64 and
Darwin64:

../configure \
CFLAGS="-O3 -pedantic -fno-stack-protector" \
CXXFLAGS="-O3 -pedantic -fno-stack-protector" \
--prefix=/home/Linux64 \
--enable-cxx \
--enable-fat

../configure \
--prefix="/Users/Darwin64" \
--enable-cxx \
--enable-fat


libsigsegv
----------
Your Linux distribution may come with a suitable libsigsegv.
On Mac I configure it with:

../configure \
--prefix=/Users/Darwin64 \
CFLAGS="-Wall -O3 -fno-stack-protector -fstrict-aliasing"


Tecla
-----
Tecla does not support separate build directories. I use
the following configure arguments for Linux64 and Darwin64:

./configure \
CFLAGS="-g -fno-stack-protector -O3" \
-host=x86-linux-gnu \
--prefix=/home/Linux64

./configure \
CFLAGS="-g -fno-stack-protector -O3" \
--prefix=/Users/Darwin64


BuDDy
-----
As of 2.4 BuDDy has moved to autoconf. The option --disable-shared is
recommended to avoid linking issues on various platforms. I use
the following configure arguments for Linux64 and Darwin64:

../configure LDFLAGS=-lm \
CFLAGS="-g -fno-stack-protector -O3" \
CXXFLAGS="-g -fno-stack-protector -O3" \
--prefix=/home/Linux64 \
--disable-shared

../configure LDFLAGS=-lm \
CFLAGS="-g -fno-stack-protector -O3" \
CXXFLAGS="-g -fno-stack-protector -O3" \
--prefix=/Users/Darwin64 \
--disable-shared


Yices
-----
Yices2 must be built from source, and does not support separate
build directories. It is very finicky about GMP. I use
the following configure arguments for Linux64 and Darwin64:

./configure \
--prefix=/home/Linux64 \
--with-static-gmp=/home/Linux64/lib/libgmp.a \
--with-static-gmp-include-dir=/home/Linux64/include \
CFLAGS="-fno-stack-protector -O3" \
LDFLAGS="-L/home/Linux64/lib" \
CPPFLAGS="-I/home/Linux64/include"

./configure \
--prefix=/Users/Darwin64 \
--with-static-gmp=/Users/Darwin64/lib/libgmp.a \
--with-static-gmp-include-dir=/Users/Darwin64/include \
CFLAGS="-fno-stack-protector -O3" \
LDFLAGS="-L/Users/Darwin64/lib" \
CPPFLAGS="-I/Users/Darwin64/include"


Building Maude
==============
Only one of CVC4 and Yices2 should be linked to provide an SMT backend.
By default, Maude is configured to use Yices2, which is significantly
easier to build. I use the following configure arguments for Linux64
and Darwin64:

../configure \
--with-yices2=yes \
--with-cvc4=no \
--enable-compiler \
-host=x86-linux-gnu \
CFLAGS="-Wall -O3 -fno-crossjumping -fno-stack-protector -finline-limit=10000" \
CXXFLAGS="-Wall -O3 -fno-crossjumping -fno-stack-protector -finline-limit=10000" \
CPPFLAGS="-I/home/Linux64/include" \
LDFLAGS="-L/home/Linux64/lib" \
GMP_LIBS="/home/Linux64/lib/libgmpxx.a /home/Linux64/lib/libgmp.a"

../configure \
--with-yices2=yes \
--with-cvc4=no \
FLEX=/Users/Darwin64/bin/flex \
BISON=/Users/Darwin64/bin/bison \
CFLAGS="-Wall -O3 -fno-stack-protector -fstrict-aliasing" \
CXXFLAGS="-Wall -O3 -fno-stack-protector -fstrict-aliasing -std=c++11" \
CPPFLAGS="-I/Users/Darwin64/include" \
LDFLAGS="-L/Users/Darwin64/lib" \
GMP_LIBS="/Users/Darwin64/lib/libgmpxx.a /Users/Darwin64/lib/libgmp.a"

Passing --with-yices2=no --with-cvc4=yes to configure will use CVC4
instead of Yices2. Passing both options as no will build Maude without
SMT support.

A very basic test suite can be run using the command:

make check

The maude binary is installed in $(bindir) and the .maude files are
installed in $(datadir). In order for the Maude binary to find the
.maude files you should set the environment variable MAUDE_LIB to
point to $(datadir). Alternatively you could move the .maude files to
$(bindir).

Note that if your CVC4 library is built using CLN then you must
also link this library (-lcln).


Note for Mac users
==================

As of Mavericks, Apple no longer supports gcc so Maude must be compiled
with clang, which you can get by installing Apple's Xcode. Note that
Xcode comes with ancient versions of flex and bison so you should
install the latest versions from source or a package manager such
as Mac Ports or Homebrew.
