Make.mm tips

From DANSE

Make.mm files are really just Makefiles, so they enjoy all the tricks and pitfalls. Makefiles are old hat to most *nix programmers, but it's a whole new world to MS programmers. Here are a few tips for working with them as we usually structure them in the DANSE project.

Make.mm syntax notes

The PROJ_SRCS variable is usually written with one file per line. In addition, we usually keep these in alphabetical order: this makes it fast & easy to read. Example:

PROJ_SRCS = \
    hello.cc          \
    my_foo.cc         \
    some_fools_foo.cc 

Those are spaces before (and after) each file name, and yes, you do need to have the backslash to tell make to read to the next line. The number of space is arbitrary, but we prefer four. The real retentives among us, the kind who go out and write tutorials, also like the backslashes to line up.

make quits reading the line as soon as it sees a comment symbol (#), in the following example only hello.cc will compile.:

PROJ_SRCS = \
    hello.cc          \
    #my_foo.cc        \
    some_fools_foo.cc 

To temporarily remove one file from the compile list, cut it and paste it below:

PROJ_SRCS = \
    hello.cc          \
    some_fools_foo.cc 

    #my_foo.cc         \

Building with debug information

To compile your project with debugging on, set the environment variable TARGET=debug before running mm. With gcc/g++ it helps to add -gstabs+ switch which includes more detailed debugging information. To add -gstabs+ or other compiler options in Make.mm, put them to the DEV_CXX_FLAGS variable:

DEV_CXX_FLAGS = -gstabs+

Static linking of C-code into python module

By default, the build system links C or Fortran sources from the libpackage/ directory into a shared library object libpackage.so. The python interface is built as another shared library, packagemodule.so, which dynamically loads libpackage.so and thus it requires that libpackage.so is available somewhere in $LD_LIBRARY_PATH.

Sometimes it is preferable to do a static link of C-sources into python interface. This would produce a single packagemodule.so file that immediately works if it is placed inside $PYTHONPATH - without any need to worry about libpackage.so. To setup the static linking of C-sources, edit the libpackage/Make.mm file and insert

PROJ_CXX_LIB = $(BLD_LIBDIR)/$(PACKAGE).a
PROJ_CLEAN += $(PROJ_CXX_LIB)

below the definition of the PACKAGE variable. After that just change the default "all" target and all should be ready to go:

## link C code into shared library, this needs to be exported
# all: $(PROJ_SAR) export
## static link of C code into python interface, no need for export
all: $(PROJ_CXX_LIB)

You may revert back to the default, shared library build by reversing comments of the "all:" targets.

Personal tools
Document Uploads/Links