xFOCE Autotools HOWTO

### 
# Setting up a project to use autotools
### 

### 

###
# Adding a new source file
###

- use templates in xfoce/doc/examples/
- fill in title, author, creation date
- for header files, create enclosing #ifdef HEADER_NAME (also closing endif comment)

- update /path/to/src/Makefile.am
bin_PROGRAMS = hello xfoce
hello_SOURCES = hello.c
xfoce_SOURCES = main.c

- If adding a new source directory
  - add new Makefile.am to new directory
  - update xfoce/configure.ac
AC_CONFIG_FILES([Makefile
                 src/gateway/core/Makefile path/to/new/Makefile])
  - add directory to xfoce/Makefile.am

- configure 
- make

include paths 
- In the new source file, include headers defined elsewhere in the tree:
#include "xfoce.h" (not #include <xfoce.h>)

- add appropriate header include paths and linkages to Makefile.am
bin_PROGRAMS = testHello
testHello_SOURCES = testHello.c
testHello_CPPFLAGS = -I$(top_builddir)/src/gateway/core
testHello_LDADD = $(top_builddir)/src/gateway/core/main.o

- autoreconf
- ./configure (?)
- make

### 

###
# Make debug version
###
./configure CPPFLAGS=-DDEBUG
make clean
make
### 

###
# Using autoreconf
###
autoreconf
./configure [options...]
make clean
make
### 

###
# Using pkg-config
###
Many modern libraries use pkg-config to manage library metadata.
The pkg-config utility can provide things like version information, linker/compiler flags, etc. for libraries installed using pkg-config.
### 

### 
# Linking to third-party and system libraries
### 
Libraries (e.g. zeromq, pthreads, timer) are in different directories 
on the build host than on the target. 
If you hard code the path, configure/make will work on one or the other but not both.

The linker needs to know which libraries to link against, and where they are.

The paths and libraries may be set via environment passed to configure.
The LIBS variable specifies which libraries should be linked against (-llibsomething).
The LDFLAGS variable specifies the library path (-L/path/to/libsomething).

These may be specified on the configure command line.

These environment variables are added to the DEPS_LIBS and DEPS_CFLAGS variables. The targets specified in Makefile.am reference DEPS_LIBS and DEPS_CFLAGS to know which libraries to link and where to find them.

The type of target (library or program) set different parameters to reference them (e.g. prefix_LIBADD vs prefix_LDADD), but DEP_LIBS and DEP_CFLAGS are used for both. 

On Ubuntu VM:
./configure LDFLAGS='-L/usr/lib/i386-linux-gnu -L/usr/local/lib' LIBS='-lpthread -lrt -lzmq -lm -lmodbus' CPPFLAGS='-I/usr/local/include/modbus'

On BBone:
./configure LDFLAGS="-L/usr/lib -L/usr/local/lib" LIBS="-lpthread -lrt -lzmq -lm" CPPFLAGS='-I/usr/local/include/modbus'

export LD_LIBRARY_PATH=/usr/local/lib[...]

Makefile.am
applications link like this:

testgw_SOURCES = test-gateway.c 
testgw_LDADD = $(DEPS_LIBS) $(top_builddir)/src/gateway/core/libgateway.a
testgw_CFLAGS = $(DEPS_CFLAGS) -lgateway -L$(top_builddir)/src/gateway/core

libraries link like this:
libgateway_a_SOURCES = gateway.c sampler.c timer.c task.c $(top_builddir)/src/common/xf-utils.c
libgateway_a_LIBADD = $(DEPS_LIBS)
libgateway_a_CFLAGS = $(DEPS_CFLAGS)

###
# At top level Makefile.am, this will ensure  that non-build data
# is included in distribution in its own subdirectory  when the package is
# installed (in $datadir, e.g. /usr/share/arch)
###

archdir=$(datadir)/arch

dist_arch_DATA = \
arch/README