Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
331 lines (276 sloc) 10.2 KB
-include nanonote_prefs.mk
-include ../nanonote_prefs.mk
# Compiler command and options
CC = STAGING_DIR=$(STAGING_DIR) "$(TOOLCHAIN_PREFIX)gcc"
CFLAGS = $(EXT_CC_OPTS) $(OPTS)
CDEBUG = -g
CCOUTPUTFLAG = -o
CXX =
CXXFLAGS =
CXXDEBUG =
# Linker command and options
LD = STAGING_DIR=$(STAGING_DIR) "$(TOOLCHAIN_PREFIX)gcc"
LDFLAGS = -lc -lm -lrt -lpthread -ldl
LDDEBUG = -g
LDOUTPUTFLAG = -o
# Archiver command and options
AR = STAGING_DIR=$(STAGING_DIR) "$(TOOLCHAIN_PREFIX)ar"
ARFLAGS = -r
# Binary file format converter command and options
OBJCOPY =
OBJCOPYFLAGS =
# Specify the output extension from compiler
OBJ_EXT = .o
# Specify extension from linker
PROGRAM_FILE_EXT = .out
# Specify extension for final product at end of build
EXE_FILE_EXT = $(PROGRAM_FILE_EXT)
#------------------------ Macros read by make_rtw ------------------------------
MAKECMD = |>MATLAB_BIN<|/|>ARCH<|/gmake
HOST = UNIX
BUILD = yes
SYS_TARGET_FILE = nanonote.tlc
COMPILER_TOOL_CHAIN = default
# Nanonote specific tokens
NANONOTE_DOWNLOAD = |>NANONOTE_DOWNLOAD<|
#---------------------- Tokens expanded by make_rtw ----------------------------
MODEL = |>MODEL_NAME<|
MODULES = |>MODEL_MODULES<|
MAKEFILE = |>MAKEFILE_NAME<|
MATLAB_ROOT = |>MATLAB_ROOT<|
ALT_MATLAB_ROOT = |>ALT_MATLAB_ROOT<|
MASTER_ANCHOR_DIR = |>MASTER_ANCHOR_DIR<|
START_DIR = |>START_DIR<|
S_FUNCTIONS = |>S_FUNCTIONS<|
S_FUNCTIONS_LIB = |>S_FUNCTIONS_LIB<|
NUMST = |>NUMST<|
NCSTATES = |>NCSTATES<|
COMPUTER = |>COMPUTER<|
BUILDARGS = |>BUILDARGS<|
MULTITASKING = |>MULTITASKING<|
INTEGER_CODE = |>INTEGER_CODE<|
MAT_FILE = |>MAT_FILE<|
ONESTEPFCN = |>COMBINE_OUTPUT_UPDATE_FCNS<|
TERMFCN = |>INCLUDE_MDL_TERMINATE_FCN<|
B_ERTSFCN = |>GENERATE_ERT_S_FUNCTION<|
MEXEXT = |>MEXEXT<|
EXT_MODE = |>EXT_MODE<|
TMW_EXTMODE_TESTING = |>TMW_EXTMODE_TESTING<|
EXTMODE_TRANSPORT = |>EXTMODE_TRANSPORT<|
EXTMODE_STATIC = |>EXTMODE_STATIC_ALLOC<|
EXTMODE_STATIC_SIZE = |>EXTMODE_STATIC_ALLOC_SIZE<|
MULTI_INSTANCE_CODE = |>MULTI_INSTANCE_CODE<|
TGT_FCN_LIB = |>TGT_FCN_LIB<|
MODELREFS = |>MODELREFS<|
SHARED_SRC = |>SHARED_SRC<|
SHARED_SRC_DIR = |>SHARED_SRC_DIR<|
SHARED_BIN_DIR = |>SHARED_BIN_DIR<|
SHARED_LIB = |>SHARED_LIB<|
GEN_SAMPLE_MAIN = |>GEN_SAMPLE_MAIN<|
TARGET_LANG_EXT = |>TARGET_LANG_EXT<|
PORTABLE_WORDSIZES = |>PORTABLE_WORDSIZES<|
SHRLIBTARGET = |>SHRLIBTARGET<|
OPTIMIZATION_FLAGS = |>OPTIMIZATION_FLAGS<|
ADDITIONAL_LDFLAGS = |>ADDITIONAL_LDFLAGS<|
MAKEFILEBUILDER_TGT = |>MAKEFILEBUILDER_TGT<|
STANDALONE_SUPPRESS_EXE = |>STANDALONE_SUPPRESS_EXE<|
#--------------------------- Model and reference models -----------------------
MODELLIB = |>MODELLIB<|
MODELREF_LINK_LIBS = |>MODELREF_LINK_LIBS<|
MODELREF_INC_PATH = |>START_MDLREFINC_EXPAND_INCLUDES<|-I|>MODELREF_INC_PATH<| |>END_MDLREFINC_EXPAND_INCLUDES<|
RELATIVE_PATH_TO_ANCHOR = |>RELATIVE_PATH_TO_ANCHOR<|
MODELREF_TARGET_TYPE = |>MODELREF_TARGET_TYPE<|
#-- In the case when directory name contains space ---
ifneq ($(MATLAB_ROOT),$(ALT_MATLAB_ROOT))
MATLAB_ROOT := $(ALT_MATLAB_ROOT)
endif
MATLAB_ROOT := $(subst \,/,$(MATLAB_ROOT))
#------------------------------ Includes -------------------------------------
# Place -I options here
MATLAB_INCLUDES = \
-I$(MATLAB_ROOT)/rtw/c/ert \
-I$(MATLAB_ROOT)/extern/include \
-I$(MATLAB_ROOT)/simulink/include \
-I$(MATLAB_ROOT)/rtw/c/src \
-I$(MATLAB_ROOT)/rtw/c/src/ext_mode/common
# Additional includes
ADD_INCLUDES = \
|>START_EXPAND_INCLUDES<| -I|>EXPAND_DIR_NAME<| \
|>END_EXPAND_INCLUDES<|
SHARED_INCLUDES =
ifneq ($(SHARED_SRC_DIR),)
SHARED_INCLUDES = -I$(SHARED_SRC_DIR)
endif
INCLUDES = -I. -I$(RELATIVE_PATH_TO_ANCHOR) $(MATLAB_INCLUDES) \
$(ADD_INCLUDES) $(MODELREF_INC_PATH) $(SHARED_INCLUDES) \
$(TARGET_BLOCK_INCS) $(TARGET_INCS)
CFLAGS += $(subst \,/,$(INCLUDES))
CXXFLAGS += $(subst \,/,$(INCLUDES))
ifeq ($(DEBUG_BUILD),1)
# Set flags for debugging
CFLAGS += $(CDEBUG)
CXXFLAGS += $(CXXDEBUG)
LDFLAGS += $(LDDEBUG)
endif
#----------------------------- External mode -----------------------------------
# Uncomment -DVERBOSE to have information printed to stdout
# To add a new transport layer, see the comments in
# <matlabroot>/toolbox/simulink/simulink/extmode_transports.m
ifeq ($(EXT_MODE),1)
EXT_CC_OPTS = -DEXT_MODE -D$(COMPUTER) #-DVERBOSE
EXT_LIB =
EXT_SRC =
LINT_EXT_COMMON_SRC =
LINT_EXT_TCPIP_SRC =
ifeq ($(EXTMODE_TRANSPORT),0) #tcpip
EXT_SRC = ext_svr.c updown.c ext_work.c rtiostream_interface.c rtiostream_tcpip.c
LINT_EXT_COMMON_SRC = ext_svr.c updown.c ext_work.c
LINT_EXT_TCPIP_SRC = rtiostream_interface.c rtiostream_tcpip.c
endif
ifeq ($(EXTMODE_TRANSPORT),1) #serial_win32
err:
@echo
@echo "### ERROR: External mode serial transport only available on win32"
@echo
endif
ifeq ($(TMW_EXTMODE_TESTING),1)
EXT_SRC += ext_test.c
EXT_CC_OPTS += -DTMW_EXTMODE_TESTING
endif
ifeq ($(EXTMODE_STATIC),1)
EXT_SRC += mem_mgr.c
LINT_EXT_COMMON_SRC += mem_mgr.c
EXT_CC_OPTS += -DEXTMODE_STATIC -DEXTMODE_STATIC_SIZE=$(EXTMODE_STATIC_SIZE)
endif
ifeq ($(COMPUTER),SOL64)
EXT_LIB = -lsocket -lnsl
endif
endif
#-------------------------------- Target application --------------------------------------
# Define the target file
ifeq ($(MODELREF_TARGET_TYPE), NONE)
ifeq ($(MAKEFILEBUILDER_TGT), 0)
ifeq ($(STANDALONE_SUPPRESS_EXE), 1)
# Build object code only for top level model (preliminary step for building
# PIL application)
BUILD_MODE=pil_prebuild
PRODUCT=ObjectModules
BUILD_PRODUCT_TYPE = object modules
else
# Building executable for real-time deployment
BUILD_MODE=real_time
PRODUCT = $(MODEL)$(EXE_FILE_EXT)
BUILD_PRODUCT_TYPE = executable
endif
else
# Building executable for deployment as PIL application (non-real-time
# simulation)
BUILD_MODE=pil_application
PRODUCT = $(MODEL)$(EXE_FILE_EXT)
BUILD_PRODUCT_TYPE = executable
endif
else
# Building a library for a referenced model
BUILD_MODE = model_reference
PRODUCT = $(MODELLIB)
BUILD_PRODUCT_TYPE = library
endif
#-------------- Source Files, Object Files and Dependency Files -----------
SRCS = $(ADD_SRCS) $(S_FUNCTIONS)
ifeq ($(BUILD_MODE), pil_prebuild)
SRCS += $(MODULES) $(MODEL).$(TARGET_LANG_EXT) $(EXT_SRC)
endif
ifeq ($(BUILD_MODE), pil_application)
SRCS += $(TARGET_SRCS) $(TARGET_BLOCK_SRCS)
PREBUILT_SRCS = $(subst \,/,$(MODULES))
PREBUILT_OBJS = $(addsuffix $(OBJ_EXT), $(basename $(PREBUILT_SRCS)))
endif
ifeq ($(BUILD_MODE), real_time)
ifeq ($(EXT_MODE),0)
SRCS += main_$(MODEL).c
else
#TODO could make it conditional (ert_main/rt_main) based on ML version.
#i can pass matlab version here from before make hook somehow (via nanonote_prefs.mk)
SRCS += rt_main.$(TARGET_LANG_EXT)
endif
SRCS += $(MODULES) $(MODEL).$(TARGET_LANG_EXT) $(EXT_SRC)
SRCS += $(TARGET_BLOCK_SRCS) $(TARGET_SRCS)
endif
ifeq ($(BUILD_MODE), model_reference)
SRCS += $(MODULES)
endif
OBJS = $(subst \,/,$(addsuffix $(OBJ_EXT), $(basename $(SRCS))))
LIBS = $(S_FUNCTIONS_LIB)
SHARED_SRC := $(subst \,/,$(SHARED_SRC))
SHARED_SRC := $(wildcard $(SHARED_SRC))
SHARED_OBJS = $(addsuffix $(OBJ_EXT), $(basename $(SHARED_SRC)))
SHARED_OBJS := $(subst \,/,$(SHARED_OBJS))
SHARED_LIB := $(subst \,/,$(SHARED_LIB))
# Define path to search for source files
VPATH = $(TARGET_BLOCK_DIR) $(TARGET_SRC_DIR)
#-------------- Default target -----------
TARGETS = $(PRODUCT)
all: $(TARGETS)
# Need a rule to generate the build success string if product was already up to date
.PHONY : all
all : $(PRODUCT)
@echo "### Created $(PRODUCT) successfully (or it was already up to date)"
#----------------------------- Dependencies ------------------------------------
$(OBJS) : $(MAKEFILE) rtw_proj.tmw
$(SHARED_LIB) : $(SHARED_OBJS)
@echo "### Creating $@ "
$(AR) $(ARFLAGS) $@ $(SHARED_OBJS)
@echo "### $@ Created "
##-------------------------- Support for building modules ----------------------
ifeq ($(BUILD_MODE), pil_prebuild)
$(PRODUCT) : $(OBJS)
@echo "### BUILD_MODE $(BUILD_MODE)"
@echo "### Created $(PRODUCT)"
endif
ifeq ($(BUILD_MODE), real_time)
$(MODEL)$(BINARY_FILE_EXT) : $(MODEL)$(PROGRAM_FILE_EXT)
@echo "### BUILD_MODE $(BUILD_MODE)"
$(OBJCOPY) $(OBJCOPYFLAGS) $< $@
@echo "### Generated $(PRODUCT)"
endif
ifeq ($(BUILD_MODE), pil_application)
$(MODEL)$(BINARY_FILE_EXT) : $(MODEL)$(PROGRAM_FILE_EXT)
@echo "### BUILD_MODE $(BUILD_MODE)"
$(OBJCOPY) $(OBJCOPYFLAGS) $< $@
@echo "### Generated $(PRODUCT)"
endif
ifeq ($(BUILD_MODE), model_reference)
$(PRODUCT) : $(OBJS) $(SHARED_LIB) $(LIBS)
@echo "### BUILD_MODE $(BUILD_MODE)"
@echo "### Linking ..."
$(AR) $(ARFLAGS) $@ $(OBJS)
@echo "### Generated $@"
endif
ifeq ($(BUILD_MODE), pil_application)
$(MODEL)$(PROGRAM_FILE_EXT): $(PREBUILT_OBJS) $(OBJS) $(MODELLIB) $(MODELREF_LINK_LIBS) $(SHARED_LIB) $(LIBS)
@echo "### BUILD_MODE $(BUILD_MODE)"
$(LD) $(LDFLAGS) $^ $(LDOUTPUTFLAG)$@
@echo "### Generated $@"
endif
ifeq ($(BUILD_MODE), real_time)
$(MODEL)$(PROGRAM_FILE_EXT): $(OBJS) $(MODELREF_LINK_LIBS) $(SHARED_LIB) $(LIBS)
@echo "### BUILD_MODE $(BUILD_MODE)"
$(LD) $(LDFLAGS) $^ $(LDOUTPUTFLAG)$@
@echo "### Generated $@"
endif
%$(OBJ_EXT) : $(subst \,/,$(RELATIVE_PATH_TO_ANCHOR))/%.c
$(CC) -c $(CFLAGS) $< $(CCOUTPUTFLAG) $@
%$(OBJ_EXT): $(subst \,/,$(RELATIVE_PATH_TO_ANCHOR))/%.cpp
$(CXX) -c $(CXXFLAGS) $< $(CCOUTPUTFLAG) $@
%$(OBJ_EXT): %.cpp
$(CXX) -c $(CXXFLAGS) $< $(CCOUTPUTFLAG)$@
%$(OBJ_EXT): %.c
$(CC) -c $(CFLAGS) $< $(CCOUTPUTFLAG)$@
%$(OBJ_EXT): $(MATLAB_ROOT)/rtw/c/src/rtiostream/rtiostreamtcpip/%.c
$(CC) -c $(CFLAGS) $< $(CCOUTPUTFLAG)$@
|>START_EXPAND_RULES<|%$(OBJ_EXT) : $(subst \,/,|>EXPAND_DIR_NAME<|)/%.cpp
$(CXX) -c $(CXXFLAGS) $<
|>END_EXPAND_RULES<|
|>START_EXPAND_RULES<|%$(OBJ_EXT) : $(subst \,/,|>EXPAND_DIR_NAME<|)/%.c
$(CC) -c $(CFLAGS) $<
|>END_EXPAND_RULES<|