cd******************************************************************************
* Copyright (c) 2000-2020 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*  Contributors:
*   Balasko, Jeno
*   Baranyi, Botond
*   Lelik, Elemer
*   Pilisi, Gergely
*   Szabados, Kristof
*   Fekete, Tamas
******************************************************************************

Build and install Titan on Linux

1.Install required libraries: 
(Examples are given for Ubuntu 12.04/14.04/16.04/18.04; for other Linuxes, pls. use the relevant library installation method)

UBUNTU :
sudo apt-get update -y
sudo apt-get install g++ expect libssl-dev libxml2-dev libncurses5-dev flex bison libedit2 libedit-dev

NOTE: If You run into an error "E: Unable to locate package libedit-dev
" then enabling Universe repository mey be needed:
sudo add-apt-repository universe

SLES 11.4: sudo zypper in libopenssl-devel libedit0 libedit-devel (g++ flex bison, expect, libncurses5 already installed)
SLED 14.0: sudo zypper in libopenssl-devel libedit0 libedit-devel ( g++, flex, bison libncurses5 already installed)
RHEL8: sudo yum libedit; g++, flex, bison already installed

xutils-dev is needed by makedepend:
sudo apt-get install xutils-dev
(SLED 14.0: - )

Install optional packages required some tests:

The following packages may be needed for titan_eclipse/automatic_build:
Ubuntu: sudo apt-get install ant xsltproc ant-junit
(SLED 12.4: sudo zypper install ant-junit ; libxslt-tools already installed)
(RHEL: sudo yum install ant ant-junit# xsltproc already installed)
(SUSE 15.1: -)

The regression test requires xmllint. The package containing it: libxml2-utils
ubuntu: sudo apt install libxml2-utils
suse: sudo zypper install libxml2-tools or libxml2
rhel: sudo yum install libxml2-devel


Performance test requires pcap
ubuntu: sudo apt-get install libpcap0.8-dev
suse: sudo zypper install libpcap-devel libpcap1

2.Clone or update the titan directory from git into /home/<user_id>/titan.core

cd /home/<user_id>/
git clone https://github.com/eclipse/titan.core.git  titan.core

or

Update the already existing local repository:
cd /home/<user_id>/titan.core
git pull https://github.com/eclipse/titan.core.git

3. Configure the build 

cd titan.core

For open source users: check that MakefileFOSS.cfg is present and has the following content:
cat MakefileFOSS.cfg

# Configurations for the Free Open Source Software version
LICENSING := no
USAGE_STATS := no

If you want to use your build within the Ericsson domain: delete MakefileFOSS.cfg
This will enable Ericsson internal-only licensing and statistics.

#This paragraph is obsolete 
#GEN_PDF set to yes will convert Word documents to PDF using a web service available within Ericsson only.
#Alternatively, one can install libreoffice and convert the documentation files as below:
#cd titan.core/userguide
#libreoffice -convert-to pdf *.doc *.docx

GEN_PDF set to yes will convert .adoc documents to pdf using asciidoctor-pdf

Several other build options are possible; for details on options please read through the Makefile.cfg.
Options can be overridden by the content of  a file named Makefile.personal which can be used to 
adapt to local installation directories, change config options etc.
Below, a small number of typical scenarios are presented.

Note: For each scenario below on Raspberry Pi "-fsigned-char" needs to be added to compiler flags in Makefile.personal:

COMPILERFLAGS := -Wall -fsigned-char


a) JNI  disabled, gcc compiler (default)

The JNI interface is used by the Eclipse Titan Executor or by the Java Executor API.
If you don't need them, Titan can be compiled without JNI. 

Create ~/titan.core/Makefile.personal to override settings in Makefile.cfg with the following content:
(replace paths with values relevant to your installation)

TTCN3_DIR := /home/<user id>/titan.core/Install
OPENSSL_DIR := /usr
#JDKDIR := /usr/lib/jvm/java-7-openjdk-amd64
XMLDIR := /usr
JNI := no
GEN_PDF := no
OLD_LIBEDIT := yes # if the first line of /usr/include/editline/readline.h
                   # contains v1.34 or older i.e version of editline is 0:53:0 or older.

b) JNI  disabled, clang compiler ver. 3.8

Create ~/titan.core/Makefile.personal to override settings in Makefile.cfg with the following content:
(replace paths with values relevant to your installation). 

TTCN3_DIR := /home/<user id>/titan.core/Install
OPENSSL_DIR := /usr
#JDKDIR := /usr/lib/jvm/java-7-openjdk-amd64
XMLDIR := /usr
JNI := no
GEN_PDF := no
CXX := clang++-3.8
CC := clang-3.8 
OLD_LIBEDIT = yes  # if the first line of /usr/include/editline/readline.h
                   # contains v1.34 or older i.e version of editline is 0:53:0 or older.

c) JNI  enabled, gcc compiler (default)

install JDK   into /home/<user id>/jdk

Create ~/titan.core/Makefile.personal to override settings in Makefile.cfg with the following content:
(replace paths with values relevant to your installation).

TTCN3_DIR := /home/<user id>/titan.core/Install
OPENSSL_DIR := /usr
JDKDIR := /home/<user id>/jdk
XMLDIR := /usr
JNI := yes
GEN_PDF := no
COMPILERFLAGS += -Wall -Wlogical-op -I/home/<user id>/jdk/include -I/usr/include
OLD_LIBEDIT = yes  # if the first line of /usr/include/editline/readline.h
                   # contains v1.34 or older i.e version of editline is 0:53:0 or older.
                   
d) For Alpine Linux, an appropriate flag has to be set:

:
ALPINE_LINUX := yes
:


4. Run make

make

5. Set environment variables

setenv TTCN3_DIR /home/<user id>/titan.core/Install
setenv PATH /home/<userid>/titan.core/Install/bin:${PATH}
setenv LD_LIBRARY_PATH /home/<userid>/titan.core/Install/lib:${LD_LIBRARY_PATH}

for csh

or 

export TTCN3_DIR=/home/<user id>/titan.core/Install
export PATH=/home/<userid>/titan.core/Install/bin:${PATH}
export LD_LIBRARY_PATH=/home/<userid>/titan.core/Install/lib:${LD_LIBRARY_PATH}

for bash

6. Run make install

make install

This will install Titan into  /home/<user id>/titan.core/Install


7. Optionally , run function/regression tests

cd /home/<user id>/titan.core/function_test

in the following Makefiles 

BER_EncDec/Makefile
XER_EncDec/Makefile
Text_EncDec/Makefile
RAW_EncDec/Makefile

edit the value of XMLDIR to match your installation values 

run the tests

make

( or make |& tee outputfile if you want to save the output for verification)

cd /home/<user id>/titan.core/regression_test
make run

( or make run |& tee outputfile if you want to save the output for verification)

These tests might run for half an hour (regr.tests)  to two hours (func.tests)

8. Optionally, copy Titan into its final directory.
From here on, you can continue with the Titan installation guide, see /Install/docs, to set/change environment variables etc.
and then, optionally, the Eclipse installation guide.


9. Important Note:  In later Debian and derived (Ubuntu etc.)  distributions Titan is avalable directly from repositories 
and can be installed with:

apt-get install eclipse-titan

However, environment variables and your Makefile will still have to be configured manually:

export TTCN3_DIR=/usr
export PATH=$TTCN3_DIR/bin:${PATH}
export LD_LIBRARY_PATH=$TTCN3_DIR/lib:${LD_LIBRARY_PATH}

Add to your Makefile the appropriate flags:

# Flags for the C++ preprocessor (and makedepend as well):
CPPFLAGS = ..... -I/usr/include/titan

and 

# Flags for the linker:
LDFLAGS = -L/usr/lib/titan 



