Creating a DOLFIN kernel library

From The FEniCS project

Directories and source code

Go to the DOLFIN root directory and create a new subdirectory of src/kernel. DOLFIN places the .h files in a separate subdir called "dolfin" so create that as well. For example to create a library named mylib:

 mkdir src/kernel/mylib
 mkdir src/kernel/mylib/dolfin

Now create some source code:

 vim src/kernel/mylib/dolfin/MyClass.h
 vim src/kernel/mylib/dolfin/MyOtherClass.h
 vim src/kernel/mylib/MyClass.cpp
 vim src/kernel/mylib/MyOtherClass.cpp

And create a include file:

 vim src/kernel/mylib/dolfin_mylib.h

With the following content:

#ifndef __DOLFIN_MYLIB_H
#define __DOLFIN_MYLIB_H

// DOLFIN mylib

#include <dolfin/MyClass.h>
#include <dolfin/MyOtherClass.h>

#endif

Configuration files

Add the new directory to "List of DOLFIN kernel libraries" in the configure file of the DOLFIN root directory:

 vim configure

Look for a line similar to this and add the new library to the list:

 DOLFIN_KERNEL="common fem form function graph io la main math mesh mf nls ode pde quadrature parameter log"

Then find the paragraph starting with:

 # List output to be generated: Makefiles and pkgconfig configuration
 ac_config_files="$ac_config_files Makefile src/Makefile . . . .

And add:

 src/kernel/mylib/Makefile src/kernel/mylib/dolfin/Makefile

Add directory to list of kernel subdirs:

 vim src/kernel/Makefile.am

Look for a line similar to this and add the new directory to the list:

 SUBDIRS = common fem form function graph io log la math main mesh mf nls ode parameter pde quadrature

Add your include file to dolfin.h:

 vim src/kernel/main/dolfin.h

Add the following line

 #include <dolfin/dolfin_mylib.h>
 

DOLFIN uses automake which is a tool for automatically generating `Makefile.in' files compliant with the GNU Coding Standards:

To install automake on Ubuntu use:

 sudo apt-get install automake1.9

Update configure.ac file to include the new library. Look for a line similar to this and add the new directory to the list:

 DOLFIN_KERNEL="common fem form function io la main math mesh mf nls ode pde quadrature parameter log"

Then find the paragraph starting with

 AC_OUTPUT( Makefile \
 src/Makefile \
 src/kernel/Makefile \
 .
 .

And add two new lines:

 src/kernel/mylib/Makefile \
 src/kernel/mylib/dolfin/Makefile \

Create automake file for the library:

 vim src/kernel/mylib/Makefile.am

Add the following lines (replace with your library name) to the file:

 SUBDIRS                   = dolfin
 nobase_include_HEADERS    = dolfin/dolfin_mylib.h \
                             dolfin/MyClass.h \
                             dolfin/MyOtherClass.h
 INCLUDES                  = @KERNEL_CFLAGS@
 lib_LTLIBRARIES           = libdolfin-mylib.la
 libdolfin_mylib_la_SOURCES = MyClass.cpp \
                             MyOtherClass.cpp
 libdolfin_mylib_la_LDFLAGS = -static

Create automake file for the dolfin subdir:

 vim src/kernel/mylib/dolfin/Makefile.am

Add the following lines (replace with actual filenames) to the file:

 EXTRA_DIST = dolfin_mylib.h \
              MyClass.h \
              MyOtherClass.h

Generate new configuration

Run preconfigure script (script runs aclocal, autoconf and automake):

 scripts/preconfigure

Generate makefiles by running configure. E.g. configure with debug and mpi:

 sudo ./configure --enable-debug --enable-mpi

To compile and install the new library:

 make -C src/kernel/mylib
 make -C src/kernel/mylib/ install && make -C src/lib/ install

Make your library available in pydolfin:

 touch src/pydolfin/dolfin.i
 make -C src/pydolfin
 make -C src/pydolfin/ install && make -C src/lib/ install
Personal tools