@node Building ECL
@section Building ECL

Due to its portable nature, ECL works on every (at least) 32-bit
architecture which provides a proper C99 compliant compiler.

Operating systems on which ECL is reported to work: Linux, Darwin (Mac
OS X), Solaris, FreeBSD, NetBSD, OpenBSD, DragonFly BSD, Windows and
Android. On each of them ECL supports native threads.

In the past Juanjo José García-Ripoll maintained a test farm which
performed ECL tests for each release on number of platforms and
architectures. Due to lack of the resources we can't afford such doing,
however each release is tested by volunteers with an excellent package
@uref{https://common-lisp.net/project/cl-test-grid,cl-test-grid} created
and maintained by Anton Vodonosov.

@subsection Autoconf based configuration

ECL, like many other FOSS programs, can be built and installed with a
GNU tool called Autoconf. This is a set of automatically generated
scripts that detect the features of your machine, such as the compiler
type, existing libraries, desired installation path, and configures ECL
accordingly. The following procedure describes how to build ECL using
this procedure and it applies to all platforms except for the Windows
ports using Microsoft Visual Studio compilers (however you may build ECL
with cygwin or mingw using the autoconf as described here).

To build @ecl{} you need to

@enumerate
@item
Extract the source code and enter it's directory

@example
$ tar -xf ecl-xx.x.x.tgz
$ cd ecl-xx.x.x
@end example

@item
Run the configuration file, build the program and install it

@example
$ ./configure --prefix=/usr/local
$ make                          # -jX if you have X cores
$ make install
@end example

@item
Make sure the program is installed and ready to run:

@example
$ /usr/local/bin/ecl

ECL (Embeddable Common-Lisp) 16.0.0
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
Copyright (C) 2015 Daniel Kochmanski
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.
Top level in: #<process TOP-LEVEL>.
> 
@end example
@end enumerate

@subsection Platform specific instructions

@c @node BSD systems
@c @subsubsection BSD systems

@subsubsection Android

Cross compiling ECL for Android requires first configuring the cross
compilation toolchain. This requires the Android NDK version 22 or
higher.

@example
@verbatim
export NDK_PATH=/opt/android-ndk
export ANDROID_API=23
export TOOLCHAIN_PATH=${NDK_PATH}/toolchains/llvm/prebuilt/linux-x86_64 # use darwin instead of linux if compiling on Mac OS host
export TARGET=armv7a-linux-androideabi
@end verbatim
@end example

Here, @code{ANDROID_API} is the minimum Android API version ECL will
run on. Moreover, an existing installation ECL is required. This installation
has to be the same version as the one you are attempting to build.
Assuming you have installed in "/usr/local":

@example
@verbatim
export ECL_TO_RUN=/usr/local/bin/ecl
@end verbatim
@end example

Finally, we can build and install the target ECL:

@example
@verbatim
export CC="${TOOLCHAIN_PATH}/bin/clang --target=${TARGET}${ANDROID_API}"
export LD=${TOOLCHAIN_PATH}/bin/ld
export AR=${TOOLCHAIN_PATH}/bin/llvm-ar
export RANLIB=${TOOLCHAIN_PATH}/bin/llvm-ranlib
export ECL_TO_RUN=/usr/local/bin/ecl
./configure --host=${TARGET} \
            --prefix=`pwd`/ecl-android \
            --disable-c99complex \
            --with-cross-config=`pwd`/src/util/android-arm.cross_config
make -j9
make install
@end verbatim
@end example

Library and assets are installed in the "ecl-android" directory
and are ready to run on the Android system.

@subsubsection iOS

The cross-compilation steps for iOS are similar to those for Android.

@example
@verbatim
export ECL_TO_RUN=/usr/local/bin/ecl
@end verbatim
@end example

Configure the toolchain:
@example
@verbatim
export IOS_VERSION_MIN="8.0"
export IOS_SDK_DIR="`xcode-select --print-path`/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/"

export CC="clang"
export CXX="clang++"

export CFLAGS="-arch arm64 -miphoneos-version-min=${IOS_VERSION_MIN} -isysroot ${IOS_SDK_DIR}"
export CFLAGS="$CFLAGS -pipe -Wno-trigraphs -Wreturn-type -Wunused-variable"
export CFLAGS="$CFLAGS -fpascal-strings -fasm-blocks -fmessage-length=0 -fvisibility=hidden"
export CFLAGS="$CFLAGS -O2 -DNO_ASM"

export LD="ld"
export LDFLAGS="-arch arm64 -pipe -std=c99 -gdwarf-2 -isysroot ${IOS_SDK_DIR}"
export LIBS="-framework Foundation"
@end verbatim
@end example

Build and install the target library:
@example
@verbatim
export CFLAGS="$CFLAGS -DGC_DISABLE_INCREMENTAL -DECL_RWLOCK"
export CXXFLAGS="$CFLAGS"
./configure --host=aarch64-apple-darwin \
            --prefix=`pwd`/ecl-iOS \
            --disable-c99complex \
            --disable-shared \
            --with-cross-config=`pwd`/src/util/iOS-arm64.cross_config
make -j9
make install
@end verbatim
@end example

Library and assets in the "ecl-iOS" directory are ready to run on the iOS system.
