| 1 |
\chapter{Building NoTA-based software}\label{chap:building}\index{building} |
| 2 |
\section{Introduction} |
| 3 |
Here, we discuss building software with NoTA. We assume that your using |
| 4 |
GNU/Linux or another UNIX-like platform, a C-compiler and the related |
| 5 |
development tools (such as {\tt make}\index{make} and {\tt |
| 6 |
pkg-config}\index{\tt pkg-config}) installed. Of course, you'll also need |
| 7 |
the NoTA-libraries; for their installation, please refer to |
| 8 |
appendix~\ref{chap:installation}. |
| 9 |
|
| 10 |
\section{Building and {\tt pkg-config}} |
| 11 |
After you've written your NoTA-based software, you naturally would like to |
| 12 |
compile it. Let's assume that we have written an application node in an |
| 13 |
implementation file called {\tt an.c}, and the corresponding service node in |
| 14 |
{\tt sn.c}. Both live in the same directory. |
| 15 |
|
| 16 |
The easiest way to compile these is to use something like: |
| 17 |
\begin{verbatim} |
| 18 |
$ cc -o an an.c `pkg-config --cflags --libs nota-h_in-3.0` |
| 19 |
$ cc -o sn sn.c `pkg-config --cflags --libs nota-h_in-3.0` |
| 20 |
\end{verbatim} |
| 21 |
|
| 22 |
After you finished compiling\index{compilation} this (and fixed the almost |
| 23 |
unavoidable typing errors in your code), this will generate an executable {\tt |
| 24 |
an}, your application node. Instead of the {\tt nota-h\_in-3.0} above, you |
| 25 |
could instead use {\tt nota-h\_in-sp-3.0}, which gives you the {\em single |
| 26 |
process} version. |
| 27 |
|
| 28 |
If you get any errors (from {\tt pkg-config} about not able to find the |
| 29 |
libraries, make sure they are listed in the {\tt PKG\_CONFIG\_PATH}. If you |
| 30 |
compiled yourself, by default the libraries will go under {\tt /usr/local}. To |
| 31 |
use them, you could add {\tt export |
| 32 |
PKG\_CONFIG\_PATH="/usr/local/lib/pkgconfig"} to your shell configuration |
| 33 |
files. If you install the libraries elsewhere, e.g., under {\tt /opt}, you |
| 34 |
will need to update your {\tt PKG\_CONFIG\_PATH}. |
| 35 |
|
| 36 |
{\tt Important note}: to prevent using the wrong libraries (or wrong library |
| 37 |
versions), it's good to run: |
| 38 |
\begin{verbatim} |
| 39 |
$ pkg-config --cflags --libs nota-h_in-3.0 nota-l_in-3.0 |
| 40 |
\end{verbatim} |
| 41 |
The output of that command should tell you where {\tt pkg-config} (and |
| 42 |
therefore, the compilation) thinks that your libraries live. It's a common |
| 43 |
mistake to use some older version of a library that is still installed. |
| 44 |
|
| 45 |
\textbf{Note:} instead of using \texttt{nota-h\_in-3.0}, you can also use |
| 46 |
\texttt{nota-h\_in-sp-3.0}. If you use the latter, your software will be build |
| 47 |
with \emph{single-process}\index{single-process}-capabilities, i.e., without |
| 48 |
the need for the NoTA-daemon \texttt{nota-ind}. FIXME |
| 49 |
|
| 50 |
\section{Other build options} |
| 51 |
How you pass build options to your compilation depends on the details of your |
| 52 |
build environment. In general, it should work by putting the compiler flags in |
| 53 |
the {\tt CFLAGS} environment variable. |
| 54 |
|
| 55 |
Of course, you can also add other compiler flags; for example, when using the |
| 56 |
{\tt gcc}\index{gcc}-compiler, you could set {\tt CFLAGS=''-g -00''} to get a build |
| 57 |
with debugging symbols include, and no optimizations. This would be |
| 58 |
appropriate for a debug build. |
| 59 |
|
| 60 |
You could also use {\tt CFLAGS=''-g -O2''} to get an optimized build, which is |
| 61 |
also a bit harder to debug in a debugger (such as {\tt gdb}), but also |
| 62 |
faster. Note that will still include debugging symbols, which makes the |
| 63 |
libraries somewhat bigger, but incurs no runtime costs. |
| 64 |
|
| 65 |
\section{Using a Makefile} |
| 66 |
Instead of running these compilations 'by hand' all the time, it's a bit more |
| 67 |
convenient to use a {\tt Makefile}\index{Makefile}. Again, books have |
| 68 |
been written about the wonderful world of {\tt Makefile}s; we do not want to |
| 69 |
repeat them here. However, we give a small example, based on the one mentioned |
| 70 |
before. Note that lines 4, 7 and 10 should start with a TAB-character. |
| 71 |
\begin{lstlisting}[language=make,numbers=none] |
| 72 |
all: an sn |
| 73 |
|
| 74 |
an: |
| 75 |
cc -o an an.c `pkg-config --cflags --libs nota-h_in-3.0` |
| 76 |
|
| 77 |
sn: |
| 78 |
cc -o sn sn.c `pkg-config --cflags --libs nota-h_in-3.0` |
| 79 |
|
| 80 |
clean: |
| 81 |
rm -f an sn *~ |
| 82 |
\end{lstlisting} |
| 83 |
|
| 84 |
\section{Using autotools, {\tt cmake}, {\tt scons}, {\tt qmake}, ...} |
| 85 |
For bigger software project, you probably don't want to use plain Makefiles as |
| 86 |
above but instead use a kind of build system. NoTA itself uses {\tt |
| 87 |
autotools}, but many other systems exist. We do not go into the details of all |
| 88 |
of those, but hope that the instructions in this appendix suffice to make the |
| 89 |
build system of your choice, work. |