# DeviceAtlas C API and Unix #
A how-to guide to compile and run the DeviceAtlas C API on Unix systems.
### Requirements ###
- A C compiler
- CMake 2.6 (or above)
- PCRE 6.x (or above). For best performance v8.21 (or above) is recommended or PCRE2 10.x (or above).
The following compilers have been tested and are able to compile all
components:
- GCC (3.4 or above (4.x versions, 5.x, 7.x and onwards are recommended, the 6.x versions could possibly impact
negatively the performances due to optimisations bugs)).
- Clang/LLVM (3.0 or above)
- Sun Pro family (12.x or above)
- Intel ICC Compiler Suite (16.0 minimum recommended)
- AMD CC Compiler Suite
- TinyCC
### Build ###
The API is compatible with ASLR with PIE enabled.
#### Ubuntu/Debian ####
```shell
% sudo apt-get install gcc (or clang) libpcre3-dev cmake
```
#### RedHat/CentOS ####
```shell
% sudo dnf install gcc (or clang) pcre-devel cmake
```
#### MacOS ####
```shell
% brew install gcc (or clang ; not necessary if clang from XCode is already installed) pcre cmake
```
#### FreeBSD ###
```shell
% sudo pkg install pcre cmake
(optional)
% sudo pkg install gcc (or llvm) if another compiler different from the base system is preferred
```
#### Compiling the API ####
```shell
% cd
% cmake .
% make
```
### CMake ###
By default CMake should find all necessary components if they are installed
with a package manager. This section describes setting cmake variables to
handle components installed in custom locations.
** PCRE/PCRE2 library and headers **
If the PCRE/PCRE2 library and headers are located in a custom location, the
following cmake environment variables may be set:
- REGEXLIBS=<path to the pcre/pcre2 library>
- REGEX_INCLUDE_DIR=<path to the pcre/pcre2 headers folder>
(For Red Hat based operating systems, the required packages are pcre-devel/pcre2-devel;
for Debian, the names are libpcre3-dev/libpcre2-dev (the 8 wide character support
at least needs to be present); otherwise, please check pcre/pcre2 and
zlib development packages with your package manager).
For example (pcre):
```shell
cmake -DREGEXLIBS=/home/test/pcre/lib/libpcre.so -DREGEX_INCLUDE_DIR=/home/test/pcre/include
```
For example (pcre2):
```shell
cmake -DREGEXLIBS=/home/test/pcre2/lib/libpcre2-8.so -DREGEX_INCLUDE_DIR=/home/test/pcre2/include -DREGEX_ENGINE=pcre2
```
Compatibility: For older PCRE versions it is possible to disable the PCRE Study
feature with cmake -DPCRE_STUDY=0. It is highly recommended to NOT disable
PCRE Study for better performance.
For PCRE, JIT support can be checked simply with the pcre2test utility
```shell
% pcretest -C jit
% 1
```
For PCRE2, JIT support can be checked simply with the pcre2test utility
```shell
% pcre2test -C jit
% 1
```
** Custom compiler location **
- CMAKE_C_COMPILER=<full path to the C compiler executable>
For example:
```shell
cmake -DCMAKE_C_COMPILER=/home/test/gcc-4.8.3/bin/gcc -DCMAKE_CXX_COMPILER=/home/test/gcc-4.8.3/bin/g++
```
NB: For a static API version used with another shared library it is possible to
use CFLAGS/CXXFLAGS with -fPIC/fpic compilation flag.
### Install the API (Optional) ###
```shell
% cd
% sudo make install
% sudo ldconfig
```
(Optional)
It is possible to build the API with shortened shlib values.
```shell
% cmake -DSHORT_VERSION=ON (OFF by default)
% make
```
It is possible to set the regex engine backend.
```
(pcre)
% cmake .
(or pcre2)
% cmake -DREGEX_ENGINE=pcre2
% make
```
### Sample applications ###
There are multiple examples in the /Examples folder to test the API.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_ Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved. _
https://deviceatlas.com