cfitsTK
Modules

1. Compiling and linking modules with Autotools

Source code is organized in modules. Modules are compiled and linked using the libtool / autotools process, as shared libtool convenience libraries.

See : https://www.gnu.org/software/automake/manual/html_node/Libtool-Convenience-Libraries.html

The list of modules currently appears in multiple files associated with the build process. The build process uses autotools, which has the advantage of supporting many platforms.

Users adding modules are required to add the modules to 3 files, as described in sections 1.1, 1.2, and 1.3.

1.1. Adding modules to configure.ac

Modules are listed in file <srcdir>/configure.ac under the "AC_CONFIG_FILES"

see: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Configuration-Files.html

1.2. Adding module functions to the command line interface

Modules are listed in file <srcdir>/src/initmodules.c

The init_modules() function in this file is executed to register commands provided in each modules in the command line interface

1.3. Including modules in the recursive build and link process

Modules are listed in file <srcdir>/src/Makefile.am

This tells autotools' recursive build process to add the module directory in the list of subdirectories

This adds the library to the list of object files linked to the executable

2. Linking at runtile with dlopen()

Alternatively, users may create their own libraries and link them at runtime using the mload function of the comamnd line interface. At any time, a module can be loaded from the CLI using:

> mload <mymodulename>

See: http://www.linux-mag.com/id/1028/ for instructions to create shared libraries that can be loaded as modules.

The largely self-explanatory source code, extracted from src/CLIcore.c is:

1 static int_fast8_t load_module_shared(char *modulename)
2 {
3  char libname[200];
4  char modulenameLC[200];
5  char c;
6  int n;
7  int (*libinitfunc) ();
8  char *error;
9  char initfuncname[200];
10 
11 
12 
13  sprintf(modulenameLC, "%s", modulename);
14  for(n=0; n<strlen(modulenameLC); n++)
15  {
16  c = modulenameLC[n];
17  modulenameLC[n] = tolower(c);
18  }
19 
20  sprintf(libname, "src/%s/.libs/lib%s.so", modulename, modulenameLC);
21  printf("libname = %s\n", libname);
22 
23 
24  printf("[%5d] Loading object \"%s\"\n", DLib_index, libname);
25 
26 
27  DLib_handle[DLib_index] = dlopen(libname, RTLD_LAZY);
28  if (!DLib_handle[DLib_index]) {
29  fprintf(stderr, "%s\n", dlerror());
30  exit(EXIT_FAILURE);
31  }
32 
33  dlerror();
34 
35  sprintf(initfuncname, "initlib_%s", modulenameLC);
36  libinitfunc = dlsym(DLib_handle[DLib_index], initfuncname);
37  if ((error = dlerror()) != NULL) {
38  fputs(error, stderr);
39  exit(1);
40  }
41 
42  (*libinitfunc)();
43 
44  // increment number of libs dynamically loaded
45  DLib_index ++;
46 
47  return 0;
48 }

The library should include a function initlib_<modulename> to be executed when the module is loaded. This function should register functions to the command line interface, as done for all other modules that are part of the distribution.

3. Link to module pages

AO loop control

PIAACMC simulation