edouard@3937: # Builds standalone C/C++ Beremiz runtime edouard@3937: edouard@3937: # This Makefile is based on fragments of eRPC Makefiles edouard@3937: edouard@3937: APP_NAME = beremiz_runtime edouard@3937: edouard@3937: RUNTIME_ROOT = $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) edouard@3937: ERPC_ROOT ?= $(abspath $(RUNTIME_ROOT)/../../erpc) edouard@3937: ERPC_C_ROOT = $(ERPC_ROOT)/erpc_c edouard@3940: BEREMIZ_ROOT = $(abspath $(RUNTIME_ROOT)/..) edouard@3940: MATIEC_ROOT ?= $(abspath $(RUNTIME_ROOT)/../../matiec) edouard@3937: edouard@3937: INCLUDES += $(ERPC_C_ROOT)/infra \ edouard@3937: $(ERPC_C_ROOT)/port \ edouard@3937: $(ERPC_C_ROOT)/setup \ edouard@3937: $(ERPC_C_ROOT)/transports \ edouard@3937: $(ERPC_ROOT)/test/common/config \ edouard@3940: $(ERPC_ROOT)/erpcgen/src \ edouard@3940: $(BEREMIZ_ROOT)/targets \ edouard@4058: $(RUNTIME_ROOT)/service \ edouard@3940: $(MATIEC_ROOT)/lib/C edouard@3937: edouard@3937: INCLUDES := $(foreach includes, $(INCLUDES), -I $(includes)) edouard@3937: edouard@3937: ERPC_SOURCES += $(ERPC_ROOT)/erpcgen/src/format_string.cpp \ edouard@3937: $(ERPC_ROOT)/erpcgen/src/Logging.cpp \ edouard@3937: $(ERPC_ROOT)/erpcgen/src/options.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_arbitrated_client_manager.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_basic_codec.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_client_manager.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_crc16.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_server.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_simple_server.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_framed_transport.cpp \ edouard@4044: $(ERPC_C_ROOT)/infra/erpc_nocrc_framed_transport.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_message_buffer.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_message_loggers.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_transport_arbitrator.cpp \ edouard@3937: $(ERPC_C_ROOT)/infra/erpc_utils.cpp \ edouard@3937: $(ERPC_C_ROOT)/port/erpc_port_stdlib.cpp \ edouard@3937: $(ERPC_C_ROOT)/port/erpc_threading_pthreads.cpp \ edouard@3937: $(ERPC_C_ROOT)/port/erpc_serial.cpp \ edouard@3937: $(ERPC_C_ROOT)/transports/erpc_serial_transport.cpp \ edouard@3937: $(ERPC_C_ROOT)/transports/erpc_tcp_transport.cpp edouard@3937: edouard@4058: SOURCES += $(RUNTIME_ROOT)/service/erpc_PLCObject_client.cpp \ edouard@4058: $(RUNTIME_ROOT)/service/erpc_PLCObject_interface.cpp \ edouard@4058: $(RUNTIME_ROOT)/service/erpc_PLCObject_server.cpp \ edouard@3940: $(RUNTIME_ROOT)/md5.cpp \ edouard@3940: $(RUNTIME_ROOT)/blob.cpp \ edouard@3937: $(RUNTIME_ROOT)/posix_main.cpp \ edouard@3937: $(RUNTIME_ROOT)/PLCObject.cpp edouard@3937: edouard@3937: edouard@3937: # get version from version.py edouard@3937: BEREMIZ_VERSION := $(shell python3 $(RUNTIME_ROOT)/../version.py) edouard@3937: edouard@3937: CXXFLAGS += -std=gnu++17 -Wunused-variable -Wno-deprecated-register -Wno-narrowing -Werror -DBEREMIZ_VERSION=$(BEREMIZ_VERSION) edouard@3937: # CFLAGS += -Os -DNDEBUG edouard@3937: CXXFLAGS += -g3 -O0 -DDEBUG edouard@3937: edouard@3937: LIBRARIES += -lpthread -lrt -lc -lm edouard@3937: LD = $(CXX) edouard@3937: edouard@3937: OBJS_ROOT = $(RUNTIME_ROOT)/build edouard@3937: SOURCES_ABS := $(foreach s,$(SOURCES),$(abspath $(s))) edouard@3937: SOURCES_REL := $(subst $(RUNTIME_ROOT)/,,$(SOURCES_ABS)) edouard@3937: SOURCE_DIRS_ABS := $(sort $(foreach f,$(SOURCES_ABS),$(dir $(f)))) edouard@3937: SOURCE_DIRS_REL := $(subst $(RUNTIME_ROOT)/,,$(SOURCE_DIRS_ABS)) edouard@3937: CXX_SOURCES = $(filter %.cpp,$(SOURCES_REL)) edouard@3937: OBJECTS_CXX := $(addprefix $(OBJS_ROOT)/,$(CXX_SOURCES:.cpp=.o)) edouard@3937: edouard@3937: $(OBJS_ROOT)/%.o: $(RUNTIME_ROOT)/%.cpp edouard@3937: @echo Compiling $(subst $(RUNTIME_ROOT)/,,$<) edouard@3937: $(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MF $(basename $@).d -MP -o $@ -c $< edouard@3937: edouard@3937: ERPC_OBJS_ROOT = $(RUNTIME_ROOT)/erpcbuild edouard@3937: ERPC_SOURCES_ABS := $(foreach s,$(ERPC_SOURCES),$(abspath $(s))) edouard@3937: ERPC_SOURCES_REL := $(subst $(ERPC_ROOT)/,,$(ERPC_SOURCES_ABS)) edouard@3937: ERPC_SOURCE_DIRS_ABS := $(sort $(foreach f,$(ERPC_SOURCES_ABS),$(dir $(f)))) edouard@3937: ERPC_SOURCE_DIRS_REL := $(subst $(ERPC_ROOT)/,,$(ERPC_SOURCE_DIRS_ABS)) edouard@3937: ERPC_CXX_SOURCES = $(filter %.cpp,$(ERPC_SOURCES_REL)) edouard@3937: ERPC_OBJECTS_CXX := $(addprefix $(ERPC_OBJS_ROOT)/,$(ERPC_CXX_SOURCES:.cpp=.o)) edouard@3937: edouard@3937: $(ERPC_OBJS_ROOT)/%.o: $(ERPC_ROOT)/%.cpp edouard@3937: @echo Compiling, $(subst $(ERPC_ROOT)/,,$<) edouard@3937: $(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -MF $(basename $@).d -MP -o $@ -c $< edouard@3937: edouard@3937: OBJECTS_ALL := $(sort $(ERPC_OBJECTS_CXX) $(OBJECTS_CXX)) edouard@3937: OBJECTS_DIRS := $(OBJS_ROOT) $(addprefix $(OBJS_ROOT)/,$(SOURCE_DIRS_REL)) $(ERPC_OBJS_ROOT) $(addprefix $(ERPC_OBJS_ROOT)/,$(ERPC_SOURCE_DIRS_REL)) edouard@3937: edouard@3937: .PHONY: all $(APP_NAME) edouard@3937: all: $(APP_NAME) $(OBJECTS_DIRS) edouard@3937: edouard@3937: $(OBJECTS_DIRS) : edouard@3937: mkdir -p $@ edouard@3937: edouard@3937: $(OBJECTS_ALL): | $(OBJECTS_DIRS) edouard@3937: edouard@3937: $(APP_NAME): $(OBJECTS_ALL) edouard@3937: @echo Linking, $(APP_NAME) edouard@3937: $(LD) $(LDFLAGS) \ edouard@3937: $(OBJECTS_ALL) \ edouard@3937: -o $@ \ edouard@3937: $(LIBRARIES) edouard@3937: @echo "Output binary:" ; echo " $(APP_NAME)" edouard@3937: edouard@3937: .PHONY: clean edouard@3937: clean:: edouard@3937: @echo "Cleaning $(APP_NAME)" edouard@3937: rm -rf $(OBJECTS_ALL) $(OBJECTS_DIRS) $(APP_NAME) edouard@3937: edouard@3937: -include $(OBJECTS_ALL:.o=.d)