Documentation

Customize Build to Use Shared Utility Code

The shared utility folders (e.g.codeGenFolder/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 folder for a standalone model. SeeSpecify Generated Code Interfacesfor details.

If you want your target to support compilation of code generated in the shared utilities folder, you must modify your template makefile (TMF). The shared utilities folder is required to support model reference builds. SeeSupport Model Referencingto learn about additional updates for supporting model reference builds.

The exact syntax of the changes can vary due to differences in themakeutility 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 andMicrosoft®Visual C++®make utilities in the GRT and ERT target folders:

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

Note

The ERT-based TMFs contain extra code to handle generation of ERT S-functions and model reference simulation targets. Your target does not need to handle these cases.

Modify Template Makefiles to Support Shared Utilities

让你的TMF支持以下更改金宝appthe shared utilities folder:

  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_SRCspecifies the shared utilities folder location and the source files in it. A typical expansion in a makefile is

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

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

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

    SHARED_SRC_DIRandSHARED_BIN_DIRallow specification of separate folders for shared source files and the library compiled from the source files. In the current release, TMFs use the same path, as in the following expansions.

    SHARED_SRC_DIR = ../slprj/ert/_sharedutils SHARED_BIN_DIR = ../slprj/ert/_sharedutils
  2. Set theSHARED_INCLUDESvariable according to whether shared utilities are in use. Then append it to the overallINCLUDESvariable.

    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 theSHARED_SRCvariable to list shared files explicitly.

    SHARED_SRC := $(wildcard $(SHARED_SRC))
  4. 创建一个SHARED_OBJSvariable based onSHARED_SRC.

    SHARED_OBJS = $(addsuffix .o, $(basename $(SHARED_SRC)))
  5. 创建一个n选择(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. AddSHARED_LIBto 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 explicit reference tort_nonfinite.corrt_nonfinite.cppfrom your TMF. For example, change

    ADD_SRCS = $(RTWLOG) rt_nonfinite.c

    to

    ADD_SRCS = $(RTWLOG)

Related Topics

Was this topic helpful?