Customize Build to Use Shared Utility Code
The shared utility folders (e.g.codeGenFolder
/slprj/
) 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.target
/_sharedutils
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 themake
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 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:
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 folder location and the source files in it. A typical expansion in a makefile isSHARED_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
andSHARED_BIN_DIR
allow 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
Set the
SHARED_INCLUDES
variable according to whether shared utilities are in use. Then append it to the overallINCLUDES
variable.SHARED_INCLUDES = ifneq ($(SHARED_SRC_DIR),) SHARED_INCLUDES = -I$(SHARED_SRC_DIR) endif INCLUDES = -I. $(MATLAB_INCLUDES) $(ADD_INCLUDES) \ $(USER_INCLUDES) $(SHARED_INCLUDES)
Update the
SHARED_SRC
variable to list shared files explicitly.SHARED_SRC := $(wildcard $(SHARED_SRC))
创建一个
SHARED_OBJS
variable based onSHARED_SRC
.SHARED_OBJS = $(addsuffix .o, $(basename $(SHARED_SRC)))
创建一个n
选择
(options) variable for compilation of shared utilities.SHARED_OUTPUT_OPTS = -o $@
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) $<
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 $@ "
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)"
Remove explicit reference to
rt_nonfinite.c
orrt_nonfinite.cpp
from your TMF. For example, changeADD_SRCS = $(RTWLOG) rt_nonfinite.c
to
ADD_SRCS = $(RTWLOG)