Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop   

Supporting Shared Utility Directories in the Build Process

The shared utility directories (slprj/target/_sharedutils) typically store generated utility code that is common to a top model and the models it references. You can also force the build process to use a shared utilities directory for a standalone model. See Setting Up Runtime Logging to MAT-Files for details.

If you want your target to support compilation of code generated in the shared utilities directory, several updates to your template makefile (TMF) are required. Support for the shared utilities directory is a necessary, but not sufficient, condition for supporting model reference builds. See Supporting Optional Features to learn about additional updates that are needed for supporting model reference builds.

The exact syntax of the changes can vary due to differences in the make utility and compiler/archive tools used by your target. The examples below are based on the Free Software Foundation's GNU® make utility. You can find the following updated TMF examples for GNU and Microsoft® Visual C++® make utilities in the GRT and ERT target directories:

Use the GRT or ERT examples as a guide to the location, within the TMF, of the changes and additions described below.

Modifying Template Makefiles to Support Shared Utilities

Make the following changes to your TMF to support the shared utilities directory:

  1. Add the following make variables and tokens to be expanded when the makefile is generated:

    SHARED_SRC      = |>SHARED_SRC<|
    SHARED_SRC_DIR  = |>SHARED_SRC_DIR<|
    SHARED_BIN_DIR  = |>SHARED_BIN_DIR<|
    SHARED_LIB      = |>SHARED_LIB<|
    

    SHARED_SRC specifies the shared utilities directory location and the source files in it. A typical expansion in a makefile is

    SHARED_SRC      = ../slprj/ert/_sharedutils/*.c
    

    SHARED_LIB specifies the library file built from the shared source files, as in the following expansion.

    SHARED_LIB      = ../slprj/ert/_sharedutils/rtwshared.lib
    

    SHARED_SRC_DIR and SHARED_BIN_DIR allow specification of separate directories for shared source files and the library compiled from the source files. In the current release, all TMFs use the same path, as in the following expansions.

    SHARED_SRC_DIR  = ../slprj/ert/_sharedutils
    SHARED_BIN_DIR  = ../slprj/ert/_sharedutils
    
  2. Set the SHARED_INCLUDES variable according to whether shared utilities are in use. Then append it to the overall INCLUDES variable.

    SHARED_INCLUDES =
    ifneq ($(SHARED_SRC_DIR),)
    SHARED_INCLUDES = -I$(SHARED_SRC_DIR) 
    endif
    
    INCLUDES = -I. $(MATLAB_INCLUDES) $(ADD_INCLUDES) \
               $(USER_INCLUDES) $(SHARED_INCLUDES)
    
  3. Update the SHARED_SRC variable to list all shared files explicitly.

    SHARED_SRC := $(wildcard $(SHARED_SRC))
    
  4. Create a SHARED_OBJS variable based on SHARED_SRC.

    SHARED_OBJS = $(addsuffix .o, $(basename $(SHARED_SRC)))
    
  5. Create an OPTS (options) variable for compilation of shared utilities.

    SHARED_OUTPUT_OPTS = -o $@
    
  6. Provide a rule to compile the shared utility source files.

    $(SHARED_OBJS) : $(SHARED_BIN_DIR)/%.o : $(SHARED_SRC_DIR)/%.c
    	$(CC) -c $(CFLAGS) $(SHARED_OUTPUT_OPTS) $<
    
  7. Provide a rule to create a library of the shared utilities. The following example is based on The Open Group UNIX platforms.

    $(SHARED_LIB) : $(SHARED_OBJS)
       @echo "### Creating $@ "
       ar r $@ $(SHARED_OBJS)
       @echo "### Created  $@ "
    
  8. Add SHARED_LIB to the rule that creates the final executable.

    $(PROGRAM) : $(OBJS) $(LIBS) $(SHARED_LIB)
    $(LD) $(LDFLAGS) -o $@ $(LINK_OBJS) $(LIBS) $(SHARED_LIB)\
        $(SYSLIBS) 
    @echo "### Created executable: $(MODEL)"
  9. Remove any explicit reference to rt_nonfinite.c or rt_nonfinite.cpp from your TMF. For example, change

    ADD_SRCS = $(RTWLOG) rt_nonfinite.c
    

    to

    ADD_SRCS = $(RTWLOG)
    

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS