Revision 2 as of 2015-03-06 20:27:35

Clear message

Source Code Structure

SAFplus source code is located under the "src" directory, examples are located under "examples". Every SAFplus library and component is located under the "src" directory. Special directories are as follows:

Component source code structure

Inside a component directory code is structured as follows:

 [component]
  [files to build the client library (if any)]
  server
    [files to build the server side of the component (if it has a server)]
  test
    [unit tests for this component]

Makefile System

Makefiles are structured so that a user can build in any subdirectory simply by typing "make". At the top, every Makefile includes the file "src/mk/preface.mk" which defines make variables that should be used in the rest of the makefile. At the bottom, every makefile includes "src/mk/safplus_targets.mk" which defines how other SAFplus targets (libraries, programs, tests) can be made.

Makefile Variables

These make variables are only set to values if they are not already set. They can be overridden via environment variables, make command line parameters, or via parent makefiles.

Source code Locations

These variables define where source code is located:

Useful Inside Makefiles

Output Locations

By default all output files are stored in the directory ".../src/target/$(TARGET_OS)/$(TARGET_PLATFORM). This allows cross compiles to be output into a new directory so they do not interfere with eachother or the native compilation. The directory structure is as follows:

.../src/target/$(TARGET_OS)/$(TARGET_PLATFORM)
  lib       : SAFplus libraries
  bin       : SAFplus executables
  obj       : .o files not part of libmw.so
  mwobj     : .o files that are part of libmw.so
  test      : unit tests
  install   : install "prefix" for all 3rdparty code.  Everything in here becomes part of the final package (unless the packager deliberately omits dev directories like "include").
    bin
    include
    lib
    share
    [...and more...]

These variables define output target directories described above.

Makefile Detailed Structure

The following is an example Makefile:

SAFPLUS_LOG_LIB:=1
include ../mk/preface.mk

CLIENT_H := $(wildcard *.hxx) $(wildcard $(SAFPLUS_INC_DIR)/*.hpp) $(wildcard $(SAFPLUS_INC_DIR)/*.hxx)
CLIENT_SRC := $(wildcard *.cxx)
CLIENT_OBJ := $(subst .cxx,.o,$(CLIENT_SRC))
CLIENT_OBJ := $(addprefix $(MWOBJ_DIR)/,$(subst .cxx,.o,$(CLIENT_SRC)))

# Specify the required libraries
SAFPLUS_LIBS := clOsal clUtils
# Then use these in the make rule
SAFPLUS_DEP_LIBS     := $(addsuffix .so,$(addprefix $(LIB_DIR)/lib,$(SAFPLUS_LIBS)))
SAFPLUS_LINK_LIBS := -L$(LIB_DIR) $(addprefix -l,$(SAFPLUS_LIBS))


Release all: $(LIB_DIR)/libclLog.so

$(SAFPLUS_TARGET)/lib/libclLog.so: $(CLIENT_OBJ) $(SAFPLUS_DEP_LIBS)
        $(LINK_SO) $@ $(CLIENT_OBJ) $(SAFPLUS_LINK_LIBS) $(LINK_SO_LIBS)

$(MWOBJ_DIR)/%.o: %.cxx Makefile $(SERVER_H)
        $(COMPILE_CPP)  $@ $<

clean:
        rm -f $(SAFPLUS_TARGET)/lib/clLog.o $(CLIENT_OBJ)

include $(SAFPLUS_MAKE_DIR)/safplus_targets.mk