Simpatico  v1.10
4.3 Build system

4.2 Base Classes (Prev)         4.3 Factory Classes (Next)

Simpatico is built using a system of unix makefiles. Here, we discuss how to add a new class to the list of source files maintained by the build system, so that the new class will be compiled and linked along with the rest of the source code.

Every subdirectory of the simpatico src/ directory contains a file named sources.mk that defines a makefile variables that lists all of the *.cpp source files in that directory and its subdirectories that need to be be compiled. The name of the variable obtained by taking the path to the directory, relative to the src/ directory, and replacing directory separator slashes by underscores, and adding a trailing underscore. The name of the variable that expands to a list of all of the source files in the src/mcMd directory is thus mcMd_, while the name of the variable that contains a list of all of the source files in the src/mcMd/user directory is mcMd_user. The makefile variable associated with a directory that contains one or more subdirectories is constructed by first concatenating the values of the variables associated with all of the subdirectories that contain source files and then adding the names of any individual files in that directory. In order to add a user file to the simpatico build system, the user thus simply needs to add the name of the source file to the definition of the appropriate makefile variable.

User files that are defined within a particular simpatico namespace must be placed in either the user/ or modules/ directory of the corresponding namespace level directory, using the user/ subdirectory for individual classes and the modules/ subdirectory for modules. Thus for example, a class that provides a new feature for ddSim and that is defined in the DdMd namespace should be placed in ddMd/user directory.

After placing new C++ files in the appropriate user/ directory, the user must also modify a file named "sources.mk" in that directory. The "sources.mk" file in any subdirectory of src/ is a makefile fragment that contains a list of all of the source files in that directory. The source.mk file in user/ directory initially contains an empty list of such files. For example, the beginning of the file src/mcMd/user/ initially looks like this:

mcMd_user_=\
#$mcMd/user/Class1.cpp \
#mcMd/user/Class2.cpp

Here, mcMd_user_ is a makefile variable that lists all of the *.cpp source files in this directory. In any such file, the path of each file is expressed relative to the src/ directory. For the build system to work correctly, all source files must have a file extension *.cpp.

In the above example, the entries Class1.cpp and Class2.cpp are placeholders that are commented out by the '#' symbol at the beginning of each line. To add a new class to this initially empty list, uncomment the last of these lines, by removing the `#', and replace the placeholder "Class2.cpp" by the name of the new source file. The backslash at the end of each line is a line continuation symbol, which should appear at the end of every uncommented line of the definition of the _SRCS variable except the last line. The path to each source file must be given relative to the src/ directory. Only *.cpp files should be add to this list, and not header files.

To compile all of the *.cpp files in a user/ directory, without re-compiling any other files, simply type

> make all

from within that directory. This command may be used to compile a new class while it is being written and debugged.

After the new source file is added to the appropriate variable, it will automatically be compiled and linked into an executable when the relevant program or programs are compiled.


4.2 Base Classes (Prev)         4 Extending Simpatico (Up)         4.3 Factory Classes (Next)