From 7dcb67c8482aa1511d896159acca7b54d7cf636f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 31 Oct 2025 12:31:29 +0000 Subject: [PATCH 1/7] Initial plan From 2a1e3e4d733d4c103975bd23c5fb4006651cb05e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 31 Oct 2025 12:52:58 +0000 Subject: [PATCH 2/7] Add create_executable_makefile function and Makefile-exe.in template Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com> --- examples/system/dmod_loader/CMakeLists.txt | 2 + examples/system/dmod_loader/Makefile | 67 ++++---- scripts/CMakeLists.txt | 175 ++++++++++++++++++++- scripts/Makefile-exe.in | 79 ++++++++++ 4 files changed, 289 insertions(+), 34 deletions(-) create mode 100644 scripts/Makefile-exe.in diff --git a/examples/system/dmod_loader/CMakeLists.txt b/examples/system/dmod_loader/CMakeLists.txt index aa1412cc..5a9d9059 100644 --- a/examples/system/dmod_loader/CMakeLists.txt +++ b/examples/system/dmod_loader/CMakeLists.txt @@ -18,3 +18,5 @@ target_link_libraries(${PROJECT_NAME} dmod) target_link_options(${PROJECT_NAME} PRIVATE -L ${DMOD_DIR}/scripts) target_link_options(${PROJECT_NAME} PRIVATE -T ${CMAKE_CURRENT_SOURCE_DIR}/main.ld) + +create_executable_makefile(${PROJECT_NAME}) diff --git a/examples/system/dmod_loader/Makefile b/examples/system/dmod_loader/Makefile index d74e7272..92ed9288 100644 --- a/examples/system/dmod_loader/Makefile +++ b/examples/system/dmod_loader/Makefile @@ -1,43 +1,52 @@ +# ############################################################################## +# Makefile for the dmod_loader executable # -# This is a makefile for the dmod loader example. -# It is used to build the dmod loader example. +# This Makefile is used to build the dmod_loader executable # +# DONT EDIT THIS FILE - it is automatically generated. +# Edit the scripts/Makefile-exe.in file instead. +# +# ############################################################################## +ifeq ($(DMOD_DIR),) + DMOD_DIR = ../../../ +endif -# ----------------------------------------------------------------------------- -# Paths configuration -# ----------------------------------------------------------------------------- -DMOD_DIR=../.. -MAIN_LD=main.ld -THIS_DIR=$(shell pwd) -DMOD_CFG=$(THIS_DIR)/dmod-cfg.mk +# +# Name of the executable +# +PROJECT_NAME=dmod_loader +DMOD_SOURCES=main.c +DMOD_INC_DIRS = $(DMOD_DIR)/inc\ + $(DMOD_BUILD_DIR)\ + $(DMOD_DIR)/examples/system/dmod_loader +DMOD_LIBS = dmod_common\ + dmod_fastlz\ + dmod_system\ + pthread +DEFINITIONS = # ----------------------------------------------------------------------------- # Initialization of paths # ----------------------------------------------------------------------------- include $(DMOD_DIR)/paths.mk -include $(DMOD_TOOLS) # ----------------------------------------------------------------------------- # Project's definitions # ----------------------------------------------------------------------------- -PROJECT_NAME = dmod_loader -OUTPUT_DIR = $(DMOD_BUILD_DIR)/examples/system -DMOD_SOURCES = main.c -DMOD_INC_DIRS = $(DMOD_INC_DIR) \ - $(DMOD_BUILD_DIR) -DMOD_LIBS = dmod_system\ - dmod_common\ - pthread -DEFINITIONS = +OUTPUT_DIR = ../../../build/examples/system/dmod_loader +MAIN_LD = $(DMOD_SCRIPTS_DIR)/main.ld +DMOD_EXE_SRC_PATH = $(DMOD_DIR)/examples/system/dmod_loader +OBJ_OUTPUT_DIR = $(DMOD_OBJS_DIR)/$(PROJECT_NAME) -ifeq ($(DMOD_USE_FASTLZ),ON) - DMOD_LIBS += dmod_fastlz -endif +# ----------------------------------------------------------------------------- +# Initialization of tools configuration +# ----------------------------------------------------------------------------- +include $(DMOD_TOOLS) # ----------------------------------------------------------------------------- # List of objects # ----------------------------------------------------------------------------- -DMOD_OBJECTS = $(addprefix $(OUTPUT_DIR)/, $(DMOD_SOURCES:.c=.o)) +DMOD_OBJECTS = $(addprefix $(OBJ_OUTPUT_DIR)/, $(DMOD_SOURCES:.c=.o)) # ----------------------------------------------------------------------------- # Preparation of C flags @@ -57,17 +66,19 @@ dmod: @echo "Skipping dmod build" else dmod: - $(MAKE) -C $(DMOD_DIR) DMOD_CFG="$(DMOD_CFG)" + $(MAKE) -C $(DMOD_DIR) endif + $(PROJECT_NAME): $(DMOD_OBJECTS) + @$(MKDIR) -p $(OUTPUT_DIR) $(CC) $(CFLAGS) -L $(DMOD_SCRIPTS_DIR) -T $(MAIN_LD) -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(DMOD_OBJECTS) $(CFLAGS_LIB) $(CFLAGS_DEF) -$(OUTPUT_DIR)/%.o: %.c - @$(MKDIR) -p $(OUTPUT_DIR) +$(OBJ_OUTPUT_DIR)/%.o: $(DMOD_EXE_SRC_PATH)/%.c + @$(MKDIR) -p $(dir $@) $(CC) $(CFLAGS) -c $< -o $@ clean: - @$(RM) -rf $(OUTPUT_DIR) @$(RM) -rf $(OUTPUT_DIR)/$(PROJECT_NAME) + @$(RM) -rf $(OBJ_OUTPUT_DIR) -.PHONY: all clean \ No newline at end of file +.PHONY: all clean dmod diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 94cbdd1e..16e72f8f 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -47,12 +47,15 @@ function( create_library_makefile targetName ) foreach(LIB ${DMOD_LINKED_LIBRARIES}) message(STATUS "LIB: ${LIB}") - get_target_property(LIB_INC_DIRS ${LIB} INTERFACE_INCLUDE_DIRECTORIES) - if(LIB_INC_DIRS) - foreach(LIB_INC_DIR ${LIB_INC_DIRS}) - message(STATUS "LIB_INC_DIR: ${LIB_INC_DIR}") - list(APPEND DMOD_INC_DIRS ${LIB_INC_DIR}) - endforeach() + # Check if LIB is a target + if(TARGET ${LIB}) + get_target_property(LIB_INC_DIRS ${LIB} INTERFACE_INCLUDE_DIRECTORIES) + if(LIB_INC_DIRS) + foreach(LIB_INC_DIR ${LIB_INC_DIRS}) + message(STATUS "LIB_INC_DIR: ${LIB_INC_DIR}") + list(APPEND DMOD_INC_DIRS ${LIB_INC_DIR}) + endforeach() + endif() endif() endforeach() @@ -89,6 +92,166 @@ function( create_library_makefile targetName ) configure_file(${DMOD_DIR}/scripts/Makefile-lib.in ${CMAKE_CURRENT_SOURCE_DIR}/Makefile) endfunction() +# +# Creates makefile for the given executable. +# +function( create_executable_makefile targetName ) + # Check if DMOD_DIR is defined + if(NOT DEFINED DMOD_DIR) + message(FATAL_ERROR "DMOD_DIR is not defined. Please set DMOD_DIR variable before calling create_executable_makefile function.") + endif() + + # Configure the Makefile + if(DMOD_MODE STREQUAL "DMOD_SYSTEM") + set(DMOD_SYSTEM ON) + set(DMOD_MODULE OFF) + elseif(DMOD_MODE STREQUAL "DMOD_MODULE") + set(DMOD_SYSTEM OFF) + set(DMOD_MODULE ON) + else() + set(DMOD_SYSTEM OFF) + set(DMOD_MODULE OFF) + endif() + file(RELATIVE_PATH DMOD_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" "${DMOD_DIR}") + string(REPLACE "${DMOD_DIR}" "$(DMOD_DIR)" DMOD_PROJECT_DIR "${DMOD_PROJECT_DIR}") + + set(DMOD_EXE_NAME ${targetName}) + file(RELATIVE_PATH DMOD_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") + set(DMOD_OUTPUT_DIR ${DMOD_OUTPUT_DIR}) + + set(DMOD_EXE_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + string(REPLACE "${DMOD_DIR}" "$(DMOD_DIR)" DMOD_EXE_SRC_PATH "${DMOD_EXE_SRC_PATH}") + + set(DMOD_LIBS_DIR ${CMAKE_BINARY_DIR}/libs) + string(REPLACE "${DMOD_BUILD_DIR}" "$(DMOD_BUILD_DIR)" DMOD_LIBS_DIR "${DMOD_LIBS_DIR}") + + get_target_property(DMOD_SOURCES ${targetName} SOURCES) + get_target_property(DMOD_INC_DIRS ${targetName} INCLUDE_DIRECTORIES) + get_target_property(DMOD_LINKED_LIBRARIES ${targetName} LINK_LIBRARIES) + get_target_property(DMOD_COMPILE_DEFINITIONS ${targetName} COMPILE_DEFINITIONS) + + # Initialize lists for collecting all libraries and include directories + set(ALL_LIBS "") + set(ALL_INC_DIRS "") + + # Check if the executable has any linked libraries + if(NOT DMOD_LINKED_LIBRARIES) + set(DMOD_LINKED_LIBRARIES "") + endif() + + # Recursively collect libraries and include directories + set(LIBS_TO_PROCESS ${DMOD_LINKED_LIBRARIES}) + set(PROCESSED_LIBS "") + + while(LIBS_TO_PROCESS) + list(POP_FRONT LIBS_TO_PROCESS CURRENT_LIB) + + # Skip if already processed + if(CURRENT_LIB IN_LIST PROCESSED_LIBS) + continue() + endif() + list(APPEND PROCESSED_LIBS ${CURRENT_LIB}) + + # Special case: if LIB is "dmod" and it's not a target yet, expand it manually + if(CURRENT_LIB STREQUAL "dmod" AND NOT TARGET ${CURRENT_LIB}) + # Add the standard include directories + list(APPEND ALL_INC_DIRS "${DMOD_DIR}/inc") + list(APPEND ALL_INC_DIRS "${DMOD_BUILD_DIR}") + + # Add the constituent libraries that dmod links to + list(APPEND ALL_LIBS "dmod_common") + if(DMOD_USE_FASTLZ) + list(APPEND ALL_LIBS "dmod_fastlz") + endif() + if(DMOD_SYSTEM) + list(APPEND ALL_LIBS "dmod_system") + elseif(DMOD_MODULE) + list(APPEND ALL_LIBS "dmod_module") + endif() + list(APPEND ALL_LIBS "pthread") + continue() + endif() + + # Check if CURRENT_LIB is a target + if(NOT TARGET ${CURRENT_LIB}) + # Not a target, add to libs as-is (e.g., system libraries like pthread) + list(APPEND ALL_LIBS ${CURRENT_LIB}) + continue() + endif() + + get_target_property(LIB_TYPE ${CURRENT_LIB} TYPE) + if(LIB_TYPE) + + # Get include directories + get_target_property(LIB_INC_DIRS ${CURRENT_LIB} INTERFACE_INCLUDE_DIRECTORIES) + if(LIB_INC_DIRS) + foreach(LIB_INC_DIR ${LIB_INC_DIRS}) + if(NOT LIB_INC_DIR IN_LIST ALL_INC_DIRS) + list(APPEND ALL_INC_DIRS ${LIB_INC_DIR}) + endif() + endforeach() + endif() + + # For INTERFACE libraries, recursively get their linked libraries + if(LIB_TYPE STREQUAL "INTERFACE_LIBRARY") + # Try both INTERFACE_LINK_LIBRARIES and LINK_LIBRARIES + get_target_property(INTERFACE_LINK_LIBS ${CURRENT_LIB} INTERFACE_LINK_LIBRARIES) + if(NOT INTERFACE_LINK_LIBS OR INTERFACE_LINK_LIBS STREQUAL "INTERFACE_LINK_LIBRARIES-NOTFOUND") + get_target_property(INTERFACE_LINK_LIBS ${CURRENT_LIB} LINK_LIBRARIES) + endif() + if(INTERFACE_LINK_LIBS AND NOT INTERFACE_LINK_LIBS STREQUAL "INTERFACE_LINK_LIBRARIES-NOTFOUND" AND NOT INTERFACE_LINK_LIBS STREQUAL "LINK_LIBRARIES-NOTFOUND") + foreach(INTERFACE_LIB ${INTERFACE_LINK_LIBS}) + if(NOT INTERFACE_LIB IN_LIST PROCESSED_LIBS) + list(APPEND LIBS_TO_PROCESS ${INTERFACE_LIB}) + endif() + endforeach() + endif() + else() + # For non-interface libraries, add to the list + list(APPEND ALL_LIBS ${CURRENT_LIB}) + endif() + else() + # Could not get type, add to libs as-is + list(APPEND ALL_LIBS ${CURRENT_LIB}) + endif() + endwhile() + + # Combine with target's own include directories + if(DMOD_INC_DIRS) + list(APPEND ALL_INC_DIRS ${DMOD_INC_DIRS}) + endif() + + set(DMOD_DEFINITIONS "") + if(DMOD_COMPILE_DEFINITIONS) + foreach(DEFINITION ${DMOD_COMPILE_DEFINITIONS}) + list(APPEND DMOD_DEFINITIONS ${DEFINITION}) + endforeach() + endif() + + set(DMOD_RELATIVE_HEADER_PATHS "") + foreach(HEADER_PATH ${ALL_INC_DIRS}) + # Check if path is absolute + if(IS_ABSOLUTE "${HEADER_PATH}") + # First try to replace with dmod variables + string(REPLACE "${DMOD_BUILD_DIR}" "$(DMOD_BUILD_DIR)" HEADER_PATH "${HEADER_PATH}") + string(REPLACE "${DMOD_DIR}" "$(DMOD_DIR)" HEADER_PATH "${HEADER_PATH}") + + # If still absolute, convert to relative path relative to CMAKE_CURRENT_SOURCE_DIR + if(IS_ABSOLUTE "${HEADER_PATH}") + file(RELATIVE_PATH RELATIVE_HEADER_PATH "${CMAKE_CURRENT_SOURCE_DIR}" "${HEADER_PATH}") + set(HEADER_PATH "${RELATIVE_HEADER_PATH}") + endif() + endif() + + list(APPEND DMOD_RELATIVE_HEADER_PATHS "${HEADER_PATH}") + endforeach() + string(REPLACE ";" "\\\n\t\t" DMOD_SOURCES "${DMOD_SOURCES}") + string(REPLACE ";" "\\\n\t\t" DMOD_INC_DIRS "${DMOD_RELATIVE_HEADER_PATHS}") + string(REPLACE ";" "\\\n\t\t" DMOD_LIBS "${ALL_LIBS}") + string(REPLACE "Threads::Threads" "pthread" DMOD_LIBS "${DMOD_LIBS}") + configure_file(${DMOD_DIR}/scripts/Makefile-exe.in ${CMAKE_CURRENT_SOURCE_DIR}/Makefile) +endfunction() + function(to_snake_case INPUT_STRING OUTPUT_VARIABLE) # Replace hyphens with underscores diff --git a/scripts/Makefile-exe.in b/scripts/Makefile-exe.in new file mode 100644 index 00000000..5f0a13a1 --- /dev/null +++ b/scripts/Makefile-exe.in @@ -0,0 +1,79 @@ +# ############################################################################## +# Makefile for the @DMOD_EXE_NAME@ executable +# +# This Makefile is used to build the @DMOD_EXE_NAME@ executable +# +# DONT EDIT THIS FILE - it is automatically generated. +# Edit the scripts/Makefile-exe.in file instead. +# +# ############################################################################## +ifeq ($(DMOD_DIR),) + DMOD_DIR = @DMOD_PROJECT_DIR@ +endif + +# +# Name of the executable +# +PROJECT_NAME=@DMOD_EXE_NAME@ +DMOD_SOURCES=@DMOD_SOURCES@ +DMOD_INC_DIRS = @DMOD_INC_DIRS@ +DMOD_LIBS = @DMOD_LIBS@ +DEFINITIONS = @DMOD_DEFINITIONS@ + +# ----------------------------------------------------------------------------- +# Initialization of paths +# ----------------------------------------------------------------------------- +include $(DMOD_DIR)/paths.mk + +# ----------------------------------------------------------------------------- +# Project's definitions +# ----------------------------------------------------------------------------- +OUTPUT_DIR = @DMOD_OUTPUT_DIR@ +MAIN_LD = $(DMOD_SCRIPTS_DIR)/main.ld +DMOD_EXE_SRC_PATH = @DMOD_EXE_SRC_PATH@ +OBJ_OUTPUT_DIR = $(DMOD_OBJS_DIR)/$(PROJECT_NAME) + +# ----------------------------------------------------------------------------- +# Initialization of tools configuration +# ----------------------------------------------------------------------------- +include $(DMOD_TOOLS) + +# ----------------------------------------------------------------------------- +# List of objects +# ----------------------------------------------------------------------------- +DMOD_OBJECTS = $(addprefix $(OBJ_OUTPUT_DIR)/, $(DMOD_SOURCES:.c=.o)) + +# ----------------------------------------------------------------------------- +# Preparation of C flags +# ----------------------------------------------------------------------------- +CFLAGS_INC = $(addprefix -I,$(DMOD_INC_DIRS)) +CFLAGS_LIB = $(addprefix -l,$(DMOD_LIBS)) -L $(DMOD_LIBS_DIR) +CFLAGS_DEF = $(addprefix -D,$(DEFINITIONS)) +CFLAGS += $(CFLAGS_INC) $(CFLAGS_LIB) $(CFLAGS_DEF) + +# ----------------------------------------------------------------------------- +# Build rules +# ----------------------------------------------------------------------------- +all: dmod $(PROJECT_NAME) + +ifeq ($(DMOD_BUILD_EXAMPLES),ON) +dmod: + @echo "Skipping dmod build" +else +dmod: + $(MAKE) -C $(DMOD_DIR) +endif + +$(PROJECT_NAME): $(DMOD_OBJECTS) + @$(MKDIR) -p $(OUTPUT_DIR) + $(CC) $(CFLAGS) -L $(DMOD_SCRIPTS_DIR) -T $(MAIN_LD) -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(DMOD_OBJECTS) $(CFLAGS_LIB) $(CFLAGS_DEF) + +$(OBJ_OUTPUT_DIR)/%.o: $(DMOD_EXE_SRC_PATH)/%.c + @$(MKDIR) -p $(dir $@) + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + @$(RM) -rf $(OUTPUT_DIR)/$(PROJECT_NAME) + @$(RM) -rf $(OBJ_OUTPUT_DIR) + +.PHONY: all clean dmod From de5f9bc66e97c8fc8caa813b28af9e3ea8954d1f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 31 Oct 2025 12:55:55 +0000 Subject: [PATCH 3/7] Address code review comments - fix typo and clarify comment Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com> --- examples/system/dmod_loader/Makefile | 2 +- scripts/CMakeLists.txt | 3 ++- scripts/Makefile-exe.in | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/system/dmod_loader/Makefile b/examples/system/dmod_loader/Makefile index 92ed9288..a1e45772 100644 --- a/examples/system/dmod_loader/Makefile +++ b/examples/system/dmod_loader/Makefile @@ -3,7 +3,7 @@ # # This Makefile is used to build the dmod_loader executable # -# DONT EDIT THIS FILE - it is automatically generated. +# DON'T EDIT THIS FILE - it is automatically generated. # Edit the scripts/Makefile-exe.in file instead. # # ############################################################################## diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 16e72f8f..63af1649 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -152,7 +152,8 @@ function( create_executable_makefile targetName ) endif() list(APPEND PROCESSED_LIBS ${CURRENT_LIB}) - # Special case: if LIB is "dmod" and it's not a target yet, expand it manually + # Special case: if the library is "dmod" INTERFACE library and it's not a target yet + # (due to forward reference), expand it manually to its constituent libraries if(CURRENT_LIB STREQUAL "dmod" AND NOT TARGET ${CURRENT_LIB}) # Add the standard include directories list(APPEND ALL_INC_DIRS "${DMOD_DIR}/inc") diff --git a/scripts/Makefile-exe.in b/scripts/Makefile-exe.in index 5f0a13a1..dd2f21e8 100644 --- a/scripts/Makefile-exe.in +++ b/scripts/Makefile-exe.in @@ -3,7 +3,7 @@ # # This Makefile is used to build the @DMOD_EXE_NAME@ executable # -# DONT EDIT THIS FILE - it is automatically generated. +# DON'T EDIT THIS FILE - it is automatically generated. # Edit the scripts/Makefile-exe.in file instead. # # ############################################################################## From b9e437f4a742ad70b80ade8b15b0ee403239d53d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 31 Oct 2025 12:57:29 +0000 Subject: [PATCH 4/7] Add detailed documentation for create_executable_makefile function Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com> --- scripts/CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 63af1649..6399b0ff 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -94,6 +94,18 @@ endfunction() # # Creates makefile for the given executable. +# +# This function generates a Makefile for an executable target using the Makefile-exe.in template. +# It extracts build information from the CMake target including sources, include directories, +# linked libraries, and compile definitions. +# +# Parameters: +# targetName - Name of the executable target (created with add_executable) +# +# Example usage: +# add_executable(my_app main.c) +# target_link_libraries(my_app dmod) +# create_executable_makefile(my_app) # function( create_executable_makefile targetName ) # Check if DMOD_DIR is defined From ca5bd8eef6dae7fcb42e2fc7ac1480331b7a8336 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 31 Oct 2025 18:36:55 +0000 Subject: [PATCH 5/7] Fix OUTPUT_DIR to use DMOD_BUILD_DIR variable instead of hardcoded relative path Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com> --- examples/system/dmod_loader/Makefile | 2 +- scripts/CMakeLists.txt | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/system/dmod_loader/Makefile b/examples/system/dmod_loader/Makefile index a1e45772..4c094195 100644 --- a/examples/system/dmod_loader/Makefile +++ b/examples/system/dmod_loader/Makefile @@ -33,7 +33,7 @@ include $(DMOD_DIR)/paths.mk # ----------------------------------------------------------------------------- # Project's definitions # ----------------------------------------------------------------------------- -OUTPUT_DIR = ../../../build/examples/system/dmod_loader +OUTPUT_DIR = $(DMOD_BUILD_DIR)/examples/system/dmod_loader MAIN_LD = $(DMOD_SCRIPTS_DIR)/main.ld DMOD_EXE_SRC_PATH = $(DMOD_DIR)/examples/system/dmod_loader OBJ_OUTPUT_DIR = $(DMOD_OBJS_DIR)/$(PROJECT_NAME) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 6399b0ff..0b425f32 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -128,8 +128,10 @@ function( create_executable_makefile targetName ) string(REPLACE "${DMOD_DIR}" "$(DMOD_DIR)" DMOD_PROJECT_DIR "${DMOD_PROJECT_DIR}") set(DMOD_EXE_NAME ${targetName}) - file(RELATIVE_PATH DMOD_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") - set(DMOD_OUTPUT_DIR ${DMOD_OUTPUT_DIR}) + # Use DMOD_BUILD_DIR variable instead of relative path + set(DMOD_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}") + string(REPLACE "${DMOD_BUILD_DIR}" "$(DMOD_BUILD_DIR)" DMOD_OUTPUT_DIR "${DMOD_OUTPUT_DIR}") + string(REPLACE "${DMOD_DIR}" "$(DMOD_DIR)" DMOD_OUTPUT_DIR "${DMOD_OUTPUT_DIR}") set(DMOD_EXE_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}) string(REPLACE "${DMOD_DIR}" "$(DMOD_DIR)" DMOD_EXE_SRC_PATH "${DMOD_EXE_SRC_PATH}") From 39b9212480d8d96dac2d72fdf2907e3fa7e2a9ae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 18 Nov 2025 06:52:19 +0000 Subject: [PATCH 6/7] Revert dmod_loader Makefile to original state and add Makefile generation to dmod_add_tool function Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com> --- examples/system/dmod_loader/CMakeLists.txt | 2 - examples/system/dmod_loader/Makefile | 67 +++++++---------- scripts/CMakeLists.txt | 6 ++ tools/system/todmfc/Makefile | 85 ++++++++++++++++++---- tools/system/todmp/Makefile | 85 ++++++++++++++++++---- 5 files changed, 178 insertions(+), 67 deletions(-) diff --git a/examples/system/dmod_loader/CMakeLists.txt b/examples/system/dmod_loader/CMakeLists.txt index 5a9d9059..aa1412cc 100644 --- a/examples/system/dmod_loader/CMakeLists.txt +++ b/examples/system/dmod_loader/CMakeLists.txt @@ -18,5 +18,3 @@ target_link_libraries(${PROJECT_NAME} dmod) target_link_options(${PROJECT_NAME} PRIVATE -L ${DMOD_DIR}/scripts) target_link_options(${PROJECT_NAME} PRIVATE -T ${CMAKE_CURRENT_SOURCE_DIR}/main.ld) - -create_executable_makefile(${PROJECT_NAME}) diff --git a/examples/system/dmod_loader/Makefile b/examples/system/dmod_loader/Makefile index 4c094195..d74e7272 100644 --- a/examples/system/dmod_loader/Makefile +++ b/examples/system/dmod_loader/Makefile @@ -1,52 +1,43 @@ -# ############################################################################## -# Makefile for the dmod_loader executable # -# This Makefile is used to build the dmod_loader executable +# This is a makefile for the dmod loader example. +# It is used to build the dmod loader example. # -# DON'T EDIT THIS FILE - it is automatically generated. -# Edit the scripts/Makefile-exe.in file instead. -# -# ############################################################################## -ifeq ($(DMOD_DIR),) - DMOD_DIR = ../../../ -endif -# -# Name of the executable -# -PROJECT_NAME=dmod_loader -DMOD_SOURCES=main.c -DMOD_INC_DIRS = $(DMOD_DIR)/inc\ - $(DMOD_BUILD_DIR)\ - $(DMOD_DIR)/examples/system/dmod_loader -DMOD_LIBS = dmod_common\ - dmod_fastlz\ - dmod_system\ - pthread -DEFINITIONS = +# ----------------------------------------------------------------------------- +# Paths configuration +# ----------------------------------------------------------------------------- +DMOD_DIR=../.. +MAIN_LD=main.ld +THIS_DIR=$(shell pwd) +DMOD_CFG=$(THIS_DIR)/dmod-cfg.mk # ----------------------------------------------------------------------------- # Initialization of paths # ----------------------------------------------------------------------------- include $(DMOD_DIR)/paths.mk +include $(DMOD_TOOLS) # ----------------------------------------------------------------------------- # Project's definitions # ----------------------------------------------------------------------------- -OUTPUT_DIR = $(DMOD_BUILD_DIR)/examples/system/dmod_loader -MAIN_LD = $(DMOD_SCRIPTS_DIR)/main.ld -DMOD_EXE_SRC_PATH = $(DMOD_DIR)/examples/system/dmod_loader -OBJ_OUTPUT_DIR = $(DMOD_OBJS_DIR)/$(PROJECT_NAME) +PROJECT_NAME = dmod_loader +OUTPUT_DIR = $(DMOD_BUILD_DIR)/examples/system +DMOD_SOURCES = main.c +DMOD_INC_DIRS = $(DMOD_INC_DIR) \ + $(DMOD_BUILD_DIR) +DMOD_LIBS = dmod_system\ + dmod_common\ + pthread +DEFINITIONS = -# ----------------------------------------------------------------------------- -# Initialization of tools configuration -# ----------------------------------------------------------------------------- -include $(DMOD_TOOLS) +ifeq ($(DMOD_USE_FASTLZ),ON) + DMOD_LIBS += dmod_fastlz +endif # ----------------------------------------------------------------------------- # List of objects # ----------------------------------------------------------------------------- -DMOD_OBJECTS = $(addprefix $(OBJ_OUTPUT_DIR)/, $(DMOD_SOURCES:.c=.o)) +DMOD_OBJECTS = $(addprefix $(OUTPUT_DIR)/, $(DMOD_SOURCES:.c=.o)) # ----------------------------------------------------------------------------- # Preparation of C flags @@ -66,19 +57,17 @@ dmod: @echo "Skipping dmod build" else dmod: - $(MAKE) -C $(DMOD_DIR) + $(MAKE) -C $(DMOD_DIR) DMOD_CFG="$(DMOD_CFG)" endif - $(PROJECT_NAME): $(DMOD_OBJECTS) - @$(MKDIR) -p $(OUTPUT_DIR) $(CC) $(CFLAGS) -L $(DMOD_SCRIPTS_DIR) -T $(MAIN_LD) -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(DMOD_OBJECTS) $(CFLAGS_LIB) $(CFLAGS_DEF) -$(OBJ_OUTPUT_DIR)/%.o: $(DMOD_EXE_SRC_PATH)/%.c - @$(MKDIR) -p $(dir $@) +$(OUTPUT_DIR)/%.o: %.c + @$(MKDIR) -p $(OUTPUT_DIR) $(CC) $(CFLAGS) -c $< -o $@ clean: + @$(RM) -rf $(OUTPUT_DIR) @$(RM) -rf $(OUTPUT_DIR)/$(PROJECT_NAME) - @$(RM) -rf $(OBJ_OUTPUT_DIR) -.PHONY: all clean dmod +.PHONY: all clean \ No newline at end of file diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 0b425f32..19d398d2 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -452,4 +452,10 @@ function(dmod_add_tool toolName) COMMAND ${CMAKE_COMMAND} -E copy $ ${DMOD_TOOLS_BIN_DIR}/${toolName} COMMENT "Copying the binary to the tools directory" ) + + # Generate Makefile for the tool (only for tools in the tools/ directory) + string(FIND "${CMAKE_CURRENT_SOURCE_DIR}" "/tools/" TOOLS_DIR_POS) + if(TOOLS_DIR_POS GREATER -1) + create_executable_makefile(${toolName}) + endif() endfunction() \ No newline at end of file diff --git a/tools/system/todmfc/Makefile b/tools/system/todmfc/Makefile index f71c788f..a88acb31 100644 --- a/tools/system/todmfc/Makefile +++ b/tools/system/todmfc/Makefile @@ -1,25 +1,84 @@ +# ############################################################################## +# Makefile for the todmfc executable # -# This is a makefile for the system tools +# This Makefile is used to build the todmfc executable # +# DON'T EDIT THIS FILE - it is automatically generated. +# Edit the scripts/Makefile-exe.in file instead. +# +# ############################################################################## +ifeq ($(DMOD_DIR),) + DMOD_DIR = ../../../ +endif + +# +# Name of the executable +# +PROJECT_NAME=todmfc +DMOD_SOURCES=main.c +DMOD_INC_DIRS = $(DMOD_DIR)/inc\ + $(DMOD_BUILD_DIR)\ + $(DMOD_DIR)/tools/system/todmfc +DMOD_LIBS = dmod_common\ + dmod_fastlz\ + dmod_system\ + pthread +DEFINITIONS = # ----------------------------------------------------------------------------- -# Paths configuration +# Initialization of paths # ----------------------------------------------------------------------------- -DMOD_DIR=../../.. -THIS_DIR=$(shell pwd) -TOOL_SRC_DIR=$(THIS_DIR) +include $(DMOD_DIR)/paths.mk # ----------------------------------------------------------------------------- # Project's definitions # ----------------------------------------------------------------------------- -PROJECT_NAME = todmfc -DMOD_SOURCES = main.c -DMOD_INC_DIRS = -DMOD_LIBS = -DEFINITIONS = +OUTPUT_DIR = $(DMOD_BUILD_DIR)/tools/system/todmfc +MAIN_LD = $(DMOD_SCRIPTS_DIR)/main.ld +DMOD_EXE_SRC_PATH = $(DMOD_DIR)/tools/system/todmfc +OBJ_OUTPUT_DIR = $(DMOD_OBJS_DIR)/$(PROJECT_NAME) # ----------------------------------------------------------------------------- -# Initialization of paths +# Initialization of tools configuration # ----------------------------------------------------------------------------- -include $(DMOD_DIR)/paths.mk -include $(DMOD_SYSTEM_TOOL_MK_FILE_PATH) +include $(DMOD_TOOLS) + +# ----------------------------------------------------------------------------- +# List of objects +# ----------------------------------------------------------------------------- +DMOD_OBJECTS = $(addprefix $(OBJ_OUTPUT_DIR)/, $(DMOD_SOURCES:.c=.o)) + +# ----------------------------------------------------------------------------- +# Preparation of C flags +# ----------------------------------------------------------------------------- +CFLAGS_INC = $(addprefix -I,$(DMOD_INC_DIRS)) +CFLAGS_LIB = $(addprefix -l,$(DMOD_LIBS)) -L $(DMOD_LIBS_DIR) +CFLAGS_DEF = $(addprefix -D,$(DEFINITIONS)) +CFLAGS += $(CFLAGS_INC) $(CFLAGS_LIB) $(CFLAGS_DEF) + +# ----------------------------------------------------------------------------- +# Build rules +# ----------------------------------------------------------------------------- +all: dmod $(PROJECT_NAME) + +ifeq ($(DMOD_BUILD_EXAMPLES),ON) +dmod: + @echo "Skipping dmod build" +else +dmod: + $(MAKE) -C $(DMOD_DIR) +endif + +$(PROJECT_NAME): $(DMOD_OBJECTS) + @$(MKDIR) -p $(OUTPUT_DIR) + $(CC) $(CFLAGS) -L $(DMOD_SCRIPTS_DIR) -T $(MAIN_LD) -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(DMOD_OBJECTS) $(CFLAGS_LIB) $(CFLAGS_DEF) + +$(OBJ_OUTPUT_DIR)/%.o: $(DMOD_EXE_SRC_PATH)/%.c + @$(MKDIR) -p $(dir $@) + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + @$(RM) -rf $(OUTPUT_DIR)/$(PROJECT_NAME) + @$(RM) -rf $(OBJ_OUTPUT_DIR) + +.PHONY: all clean dmod diff --git a/tools/system/todmp/Makefile b/tools/system/todmp/Makefile index 859f1a5d..31d5e183 100644 --- a/tools/system/todmp/Makefile +++ b/tools/system/todmp/Makefile @@ -1,25 +1,84 @@ +# ############################################################################## +# Makefile for the todmp executable # -# This is a makefile for the system tools +# This Makefile is used to build the todmp executable # +# DON'T EDIT THIS FILE - it is automatically generated. +# Edit the scripts/Makefile-exe.in file instead. +# +# ############################################################################## +ifeq ($(DMOD_DIR),) + DMOD_DIR = ../../../ +endif + +# +# Name of the executable +# +PROJECT_NAME=todmp +DMOD_SOURCES=main.c +DMOD_INC_DIRS = $(DMOD_DIR)/inc\ + $(DMOD_BUILD_DIR)\ + $(DMOD_DIR)/tools/system/todmp +DMOD_LIBS = dmod_common\ + dmod_fastlz\ + dmod_system\ + pthread +DEFINITIONS = # ----------------------------------------------------------------------------- -# Paths configuration +# Initialization of paths # ----------------------------------------------------------------------------- -DMOD_DIR=../../.. -THIS_DIR=$(shell pwd) -TOOL_SRC_DIR=$(THIS_DIR) +include $(DMOD_DIR)/paths.mk # ----------------------------------------------------------------------------- # Project's definitions # ----------------------------------------------------------------------------- -PROJECT_NAME = todmp -DMOD_SOURCES = main.c -DMOD_INC_DIRS = -DMOD_LIBS = -DEFINITIONS = +OUTPUT_DIR = $(DMOD_BUILD_DIR)/tools/system/todmp +MAIN_LD = $(DMOD_SCRIPTS_DIR)/main.ld +DMOD_EXE_SRC_PATH = $(DMOD_DIR)/tools/system/todmp +OBJ_OUTPUT_DIR = $(DMOD_OBJS_DIR)/$(PROJECT_NAME) # ----------------------------------------------------------------------------- -# Initialization of paths +# Initialization of tools configuration # ----------------------------------------------------------------------------- -include $(DMOD_DIR)/paths.mk -include $(DMOD_SYSTEM_TOOL_MK_FILE_PATH) +include $(DMOD_TOOLS) + +# ----------------------------------------------------------------------------- +# List of objects +# ----------------------------------------------------------------------------- +DMOD_OBJECTS = $(addprefix $(OBJ_OUTPUT_DIR)/, $(DMOD_SOURCES:.c=.o)) + +# ----------------------------------------------------------------------------- +# Preparation of C flags +# ----------------------------------------------------------------------------- +CFLAGS_INC = $(addprefix -I,$(DMOD_INC_DIRS)) +CFLAGS_LIB = $(addprefix -l,$(DMOD_LIBS)) -L $(DMOD_LIBS_DIR) +CFLAGS_DEF = $(addprefix -D,$(DEFINITIONS)) +CFLAGS += $(CFLAGS_INC) $(CFLAGS_LIB) $(CFLAGS_DEF) + +# ----------------------------------------------------------------------------- +# Build rules +# ----------------------------------------------------------------------------- +all: dmod $(PROJECT_NAME) + +ifeq ($(DMOD_BUILD_EXAMPLES),ON) +dmod: + @echo "Skipping dmod build" +else +dmod: + $(MAKE) -C $(DMOD_DIR) +endif + +$(PROJECT_NAME): $(DMOD_OBJECTS) + @$(MKDIR) -p $(OUTPUT_DIR) + $(CC) $(CFLAGS) -L $(DMOD_SCRIPTS_DIR) -T $(MAIN_LD) -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(DMOD_OBJECTS) $(CFLAGS_LIB) $(CFLAGS_DEF) + +$(OBJ_OUTPUT_DIR)/%.o: $(DMOD_EXE_SRC_PATH)/%.c + @$(MKDIR) -p $(dir $@) + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + @$(RM) -rf $(OUTPUT_DIR)/$(PROJECT_NAME) + @$(RM) -rf $(OBJ_OUTPUT_DIR) + +.PHONY: all clean dmod From 2fa8590c987c33e6aef146b18604313afecc8216 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 18 Nov 2025 22:22:27 +0000 Subject: [PATCH 7/7] Fix Makefile template to follow convention - include system-tool.mk instead of defining targets manually Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com> --- scripts/CMakeLists.txt | 11 ----- scripts/Makefile-exe.in | 72 ++++++-------------------------- tools/system/todmfc/Makefile | 80 ++++++++---------------------------- tools/system/todmp/Makefile | 80 ++++++++---------------------------- 4 files changed, 44 insertions(+), 199 deletions(-) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 19d398d2..ba76aa21 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -125,19 +125,8 @@ function( create_executable_makefile targetName ) set(DMOD_MODULE OFF) endif() file(RELATIVE_PATH DMOD_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" "${DMOD_DIR}") - string(REPLACE "${DMOD_DIR}" "$(DMOD_DIR)" DMOD_PROJECT_DIR "${DMOD_PROJECT_DIR}") set(DMOD_EXE_NAME ${targetName}) - # Use DMOD_BUILD_DIR variable instead of relative path - set(DMOD_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}") - string(REPLACE "${DMOD_BUILD_DIR}" "$(DMOD_BUILD_DIR)" DMOD_OUTPUT_DIR "${DMOD_OUTPUT_DIR}") - string(REPLACE "${DMOD_DIR}" "$(DMOD_DIR)" DMOD_OUTPUT_DIR "${DMOD_OUTPUT_DIR}") - - set(DMOD_EXE_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - string(REPLACE "${DMOD_DIR}" "$(DMOD_DIR)" DMOD_EXE_SRC_PATH "${DMOD_EXE_SRC_PATH}") - - set(DMOD_LIBS_DIR ${CMAKE_BINARY_DIR}/libs) - string(REPLACE "${DMOD_BUILD_DIR}" "$(DMOD_BUILD_DIR)" DMOD_LIBS_DIR "${DMOD_LIBS_DIR}") get_target_property(DMOD_SOURCES ${targetName} SOURCES) get_target_property(DMOD_INC_DIRS ${targetName} INCLUDE_DIRECTORIES) diff --git a/scripts/Makefile-exe.in b/scripts/Makefile-exe.in index dd2f21e8..2494bb9c 100644 --- a/scripts/Makefile-exe.in +++ b/scripts/Makefile-exe.in @@ -7,73 +7,25 @@ # Edit the scripts/Makefile-exe.in file instead. # # ############################################################################## -ifeq ($(DMOD_DIR),) - DMOD_DIR = @DMOD_PROJECT_DIR@ -endif - -# -# Name of the executable -# -PROJECT_NAME=@DMOD_EXE_NAME@ -DMOD_SOURCES=@DMOD_SOURCES@ -DMOD_INC_DIRS = @DMOD_INC_DIRS@ -DMOD_LIBS = @DMOD_LIBS@ -DEFINITIONS = @DMOD_DEFINITIONS@ # ----------------------------------------------------------------------------- -# Initialization of paths +# Paths configuration # ----------------------------------------------------------------------------- -include $(DMOD_DIR)/paths.mk +DMOD_DIR=@DMOD_PROJECT_DIR@ +THIS_DIR=$(shell pwd) +TOOL_SRC_DIR=$(THIS_DIR) # ----------------------------------------------------------------------------- # Project's definitions # ----------------------------------------------------------------------------- -OUTPUT_DIR = @DMOD_OUTPUT_DIR@ -MAIN_LD = $(DMOD_SCRIPTS_DIR)/main.ld -DMOD_EXE_SRC_PATH = @DMOD_EXE_SRC_PATH@ -OBJ_OUTPUT_DIR = $(DMOD_OBJS_DIR)/$(PROJECT_NAME) - -# ----------------------------------------------------------------------------- -# Initialization of tools configuration -# ----------------------------------------------------------------------------- -include $(DMOD_TOOLS) - -# ----------------------------------------------------------------------------- -# List of objects -# ----------------------------------------------------------------------------- -DMOD_OBJECTS = $(addprefix $(OBJ_OUTPUT_DIR)/, $(DMOD_SOURCES:.c=.o)) +PROJECT_NAME = @DMOD_EXE_NAME@ +DMOD_SOURCES = @DMOD_SOURCES@ +DMOD_INC_DIRS = @DMOD_INC_DIRS@ +DMOD_LIBS = @DMOD_LIBS@ +DEFINITIONS = @DMOD_DEFINITIONS@ # ----------------------------------------------------------------------------- -# Preparation of C flags -# ----------------------------------------------------------------------------- -CFLAGS_INC = $(addprefix -I,$(DMOD_INC_DIRS)) -CFLAGS_LIB = $(addprefix -l,$(DMOD_LIBS)) -L $(DMOD_LIBS_DIR) -CFLAGS_DEF = $(addprefix -D,$(DEFINITIONS)) -CFLAGS += $(CFLAGS_INC) $(CFLAGS_LIB) $(CFLAGS_DEF) - -# ----------------------------------------------------------------------------- -# Build rules +# Initialization of paths # ----------------------------------------------------------------------------- -all: dmod $(PROJECT_NAME) - -ifeq ($(DMOD_BUILD_EXAMPLES),ON) -dmod: - @echo "Skipping dmod build" -else -dmod: - $(MAKE) -C $(DMOD_DIR) -endif - -$(PROJECT_NAME): $(DMOD_OBJECTS) - @$(MKDIR) -p $(OUTPUT_DIR) - $(CC) $(CFLAGS) -L $(DMOD_SCRIPTS_DIR) -T $(MAIN_LD) -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(DMOD_OBJECTS) $(CFLAGS_LIB) $(CFLAGS_DEF) - -$(OBJ_OUTPUT_DIR)/%.o: $(DMOD_EXE_SRC_PATH)/%.c - @$(MKDIR) -p $(dir $@) - $(CC) $(CFLAGS) -c $< -o $@ - -clean: - @$(RM) -rf $(OUTPUT_DIR)/$(PROJECT_NAME) - @$(RM) -rf $(OBJ_OUTPUT_DIR) - -.PHONY: all clean dmod +include $(DMOD_DIR)/paths.mk +include $(DMOD_SYSTEM_TOOL_MK_FILE_PATH) diff --git a/tools/system/todmfc/Makefile b/tools/system/todmfc/Makefile index a88acb31..f5c04b39 100644 --- a/tools/system/todmfc/Makefile +++ b/tools/system/todmfc/Makefile @@ -7,78 +7,30 @@ # Edit the scripts/Makefile-exe.in file instead. # # ############################################################################## -ifeq ($(DMOD_DIR),) - DMOD_DIR = ../../../ -endif -# -# Name of the executable -# -PROJECT_NAME=todmfc -DMOD_SOURCES=main.c -DMOD_INC_DIRS = $(DMOD_DIR)/inc\ +# ----------------------------------------------------------------------------- +# Paths configuration +# ----------------------------------------------------------------------------- +DMOD_DIR=../../../ +THIS_DIR=$(shell pwd) +TOOL_SRC_DIR=$(THIS_DIR) + +# ----------------------------------------------------------------------------- +# Project's definitions +# ----------------------------------------------------------------------------- +PROJECT_NAME = todmfc +DMOD_SOURCES = main.c +DMOD_INC_DIRS = $(DMOD_DIR)/inc\ $(DMOD_BUILD_DIR)\ $(DMOD_DIR)/tools/system/todmfc -DMOD_LIBS = dmod_common\ +DMOD_LIBS = dmod_common\ dmod_fastlz\ dmod_system\ pthread -DEFINITIONS = +DEFINITIONS = # ----------------------------------------------------------------------------- # Initialization of paths # ----------------------------------------------------------------------------- include $(DMOD_DIR)/paths.mk - -# ----------------------------------------------------------------------------- -# Project's definitions -# ----------------------------------------------------------------------------- -OUTPUT_DIR = $(DMOD_BUILD_DIR)/tools/system/todmfc -MAIN_LD = $(DMOD_SCRIPTS_DIR)/main.ld -DMOD_EXE_SRC_PATH = $(DMOD_DIR)/tools/system/todmfc -OBJ_OUTPUT_DIR = $(DMOD_OBJS_DIR)/$(PROJECT_NAME) - -# ----------------------------------------------------------------------------- -# Initialization of tools configuration -# ----------------------------------------------------------------------------- -include $(DMOD_TOOLS) - -# ----------------------------------------------------------------------------- -# List of objects -# ----------------------------------------------------------------------------- -DMOD_OBJECTS = $(addprefix $(OBJ_OUTPUT_DIR)/, $(DMOD_SOURCES:.c=.o)) - -# ----------------------------------------------------------------------------- -# Preparation of C flags -# ----------------------------------------------------------------------------- -CFLAGS_INC = $(addprefix -I,$(DMOD_INC_DIRS)) -CFLAGS_LIB = $(addprefix -l,$(DMOD_LIBS)) -L $(DMOD_LIBS_DIR) -CFLAGS_DEF = $(addprefix -D,$(DEFINITIONS)) -CFLAGS += $(CFLAGS_INC) $(CFLAGS_LIB) $(CFLAGS_DEF) - -# ----------------------------------------------------------------------------- -# Build rules -# ----------------------------------------------------------------------------- -all: dmod $(PROJECT_NAME) - -ifeq ($(DMOD_BUILD_EXAMPLES),ON) -dmod: - @echo "Skipping dmod build" -else -dmod: - $(MAKE) -C $(DMOD_DIR) -endif - -$(PROJECT_NAME): $(DMOD_OBJECTS) - @$(MKDIR) -p $(OUTPUT_DIR) - $(CC) $(CFLAGS) -L $(DMOD_SCRIPTS_DIR) -T $(MAIN_LD) -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(DMOD_OBJECTS) $(CFLAGS_LIB) $(CFLAGS_DEF) - -$(OBJ_OUTPUT_DIR)/%.o: $(DMOD_EXE_SRC_PATH)/%.c - @$(MKDIR) -p $(dir $@) - $(CC) $(CFLAGS) -c $< -o $@ - -clean: - @$(RM) -rf $(OUTPUT_DIR)/$(PROJECT_NAME) - @$(RM) -rf $(OBJ_OUTPUT_DIR) - -.PHONY: all clean dmod +include $(DMOD_SYSTEM_TOOL_MK_FILE_PATH) diff --git a/tools/system/todmp/Makefile b/tools/system/todmp/Makefile index 31d5e183..69f2cb3b 100644 --- a/tools/system/todmp/Makefile +++ b/tools/system/todmp/Makefile @@ -7,78 +7,30 @@ # Edit the scripts/Makefile-exe.in file instead. # # ############################################################################## -ifeq ($(DMOD_DIR),) - DMOD_DIR = ../../../ -endif -# -# Name of the executable -# -PROJECT_NAME=todmp -DMOD_SOURCES=main.c -DMOD_INC_DIRS = $(DMOD_DIR)/inc\ +# ----------------------------------------------------------------------------- +# Paths configuration +# ----------------------------------------------------------------------------- +DMOD_DIR=../../../ +THIS_DIR=$(shell pwd) +TOOL_SRC_DIR=$(THIS_DIR) + +# ----------------------------------------------------------------------------- +# Project's definitions +# ----------------------------------------------------------------------------- +PROJECT_NAME = todmp +DMOD_SOURCES = main.c +DMOD_INC_DIRS = $(DMOD_DIR)/inc\ $(DMOD_BUILD_DIR)\ $(DMOD_DIR)/tools/system/todmp -DMOD_LIBS = dmod_common\ +DMOD_LIBS = dmod_common\ dmod_fastlz\ dmod_system\ pthread -DEFINITIONS = +DEFINITIONS = # ----------------------------------------------------------------------------- # Initialization of paths # ----------------------------------------------------------------------------- include $(DMOD_DIR)/paths.mk - -# ----------------------------------------------------------------------------- -# Project's definitions -# ----------------------------------------------------------------------------- -OUTPUT_DIR = $(DMOD_BUILD_DIR)/tools/system/todmp -MAIN_LD = $(DMOD_SCRIPTS_DIR)/main.ld -DMOD_EXE_SRC_PATH = $(DMOD_DIR)/tools/system/todmp -OBJ_OUTPUT_DIR = $(DMOD_OBJS_DIR)/$(PROJECT_NAME) - -# ----------------------------------------------------------------------------- -# Initialization of tools configuration -# ----------------------------------------------------------------------------- -include $(DMOD_TOOLS) - -# ----------------------------------------------------------------------------- -# List of objects -# ----------------------------------------------------------------------------- -DMOD_OBJECTS = $(addprefix $(OBJ_OUTPUT_DIR)/, $(DMOD_SOURCES:.c=.o)) - -# ----------------------------------------------------------------------------- -# Preparation of C flags -# ----------------------------------------------------------------------------- -CFLAGS_INC = $(addprefix -I,$(DMOD_INC_DIRS)) -CFLAGS_LIB = $(addprefix -l,$(DMOD_LIBS)) -L $(DMOD_LIBS_DIR) -CFLAGS_DEF = $(addprefix -D,$(DEFINITIONS)) -CFLAGS += $(CFLAGS_INC) $(CFLAGS_LIB) $(CFLAGS_DEF) - -# ----------------------------------------------------------------------------- -# Build rules -# ----------------------------------------------------------------------------- -all: dmod $(PROJECT_NAME) - -ifeq ($(DMOD_BUILD_EXAMPLES),ON) -dmod: - @echo "Skipping dmod build" -else -dmod: - $(MAKE) -C $(DMOD_DIR) -endif - -$(PROJECT_NAME): $(DMOD_OBJECTS) - @$(MKDIR) -p $(OUTPUT_DIR) - $(CC) $(CFLAGS) -L $(DMOD_SCRIPTS_DIR) -T $(MAIN_LD) -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(DMOD_OBJECTS) $(CFLAGS_LIB) $(CFLAGS_DEF) - -$(OBJ_OUTPUT_DIR)/%.o: $(DMOD_EXE_SRC_PATH)/%.c - @$(MKDIR) -p $(dir $@) - $(CC) $(CFLAGS) -c $< -o $@ - -clean: - @$(RM) -rf $(OUTPUT_DIR)/$(PROJECT_NAME) - @$(RM) -rf $(OBJ_OUTPUT_DIR) - -.PHONY: all clean dmod +include $(DMOD_SYSTEM_TOOL_MK_FILE_PATH)