From 0de0b2fa60f05d05eb0f4a0ee51d10a5e1225f4d Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 21 Aug 2025 16:45:54 +0000 Subject: [PATCH] makefile only --- CMakeLists.txt | 35 -------------- cmake/FindDPP.cmake | 7 --- cmake/main.cpp | 0 cmake/main.h | 0 main.cpp => discord-bot.cpp | 0 makefile | 92 +++++++++++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 42 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100644 cmake/FindDPP.cmake delete mode 100644 cmake/main.cpp delete mode 100644 cmake/main.h rename main.cpp => discord-bot.cpp (100%) create mode 100644 makefile diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index d901687..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# Minimum CMake version required -cmake_minimum_required(VERSION 3.22) - -# Project name, version, and description -project(discord-bot VERSION 1.0 DESCRIPTION "A discord bot" LANGUAGES CXX) # Specify CXX language - -# Temporarily removed to rule out interference from custom CMake modules. -# If you have custom CMake modules here that you need, we can re-add this later. -# list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) - -# Create an executable -add_executable(${PROJECT_NAME} - main.cpp -) - -# Include directories for your headers and D++ headers -# This tells the compiler where to find #include and #include -target_include_directories(${PROJECT_NAME} PRIVATE - # Ensure this path is correct if your D++ headers are NOT directly in ${CMAKE_CURRENT_SOURCE_DIR}/include/dpp - # If dpp/dpp.h is found in ${CMAKE_CURRENT_SOURCE_DIR}/include/dpp, then the line below is correct. - ${CMAKE_CURRENT_SOURCE_DIR} -) - -# --- NEW: Direct Linker Injection using Generator Expression --- -# This method tells CMake to ONLY pass the full path to the linker, -# explicitly preventing it from being treated as a build target. -target_link_libraries(${PROJECT_NAME} PRIVATE - "$" -) - -# Set C++ version -set_target_properties(${PROJECT_NAME} PROPERTIES - CXX_STANDARD 20 - CXX_STANDARD_REQUIRED ON -) diff --git a/cmake/FindDPP.cmake b/cmake/FindDPP.cmake deleted file mode 100644 index 3df29d3..0000000 --- a/cmake/FindDPP.cmake +++ /dev/null @@ -1,7 +0,0 @@ -find_path(DPP_INCLUDE_DIR NAMES dpp/dpp.h HINTS ${DPP_ROOT_DIR}) - -find_library(DPP_LIBRARIES NAMES dpp "libdpp.a" HINTS ${DPP_ROOT_DIR}) - -include(FindPackageHandleStandardArgs) - -find_package_handle_standard_args(DPP DEFAULT_MSG DPP_LIBRARIES DPP_INCLUDE_DIR) diff --git a/cmake/main.cpp b/cmake/main.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/cmake/main.h b/cmake/main.h deleted file mode 100644 index e69de29..0000000 diff --git a/main.cpp b/discord-bot.cpp similarity index 100% rename from main.cpp rename to discord-bot.cpp diff --git a/makefile b/makefile new file mode 100644 index 0000000..3bdbf89 --- /dev/null +++ b/makefile @@ -0,0 +1,92 @@ + +# Project configuration +EXECUTABLE_NAME = discord-bot +PLATFORM = $(shell uname) +BUILD_TYPE ?= release# Default to release build if not specified + +# Version configuration (can be overridden) +DPP_VERSION ?= $(shell find ../DPP/build/library -name "libdpp.so.*.*.*" -type f | head -1 | sed 's/.*libdpp\.so\.//') +# Conditional assignment for DPP_PATH based on whether DPP_VERSION was found or is empty +# This logic assumes that if DPP_VERSION is found (not empty), it's a custom build (../DPP). +# If DPP_VERSION is empty (meaning libdpp.so.*.*.* was not found in the custom build path), +# we default to 'lib', assuming a system-wide or standard install location. +ifeq ($(strip $(DPP_VERSION)),) # Check if DPP_VERSION is empty (no version found) + DPP_PATH = ./lib # use .so file provided instead of the dpp source files + # Define include directories for headers + # -I tells the compiler where to look for #include or #include + # We assume: + # - Your own headers (like ImageProcessor.h) are in 'include/' + # - STB headers are in 'include/stb/' + # - D++ headers are in 'include/dpp/' (so dpp.h is found via include/dpp/dpp.h) + INC_DIRS = -Iinclude -Idpp/ + LIB_PATHS = $(DPP_PATH) +else + # If DPP_VERSION has a value (a version was found), assume custom build path + DPP_PATH = ../DPP + DPP_BUILD_DIR = $(DPP_PATH)/build/library + LIB_PATHS = $(DPP_BUILD_DIR) + INC_DIRS = -Iinclude -I../dpp/ +endif + +DPP_VERSION := $(or $(DPP_VERSION),10.1.4)# Fallback version if auto-detection fails + +# Common paths +OBJ_DIR = obj/$(PLATFORM)/$(BUILD_TYPE) +BIN_DIR = bin/$(PLATFORM)/$(BUILD_TYPE) +OUTPUT_FILE = $(BIN_DIR)/$(EXECUTABLE_NAME) + + + +# Build type specific flags +ifeq ($(BUILD_TYPE), debug) + CPP_DEFINES = -D_DEBUG -DDL_USE_SHARED + COMMON_FLAGS = $(ARCH_FLAGS) -fvisibility=hidden -g -O0 $(INCLUDE_PATHS) +else + CPP_DEFINES = -DNDEBUG=1 -DDL_USE_SHARED + COMMON_FLAGS = $(ARCH_FLAGS) -fvisibility=hidden -O3 $(INCLUDE_PATHS) +endif + +# Language-specific flags +C_FLAGS = $(COMMON_FLAGS) -std=c17 +CXX_FLAGS = $(COMMON_FLAGS) -std=c++17 -Wall -g $(INC_DIRS) + +# Linker directive flags (L for library search path, l for library) +# Need to link against the D++ library and pthread (common for C++ applications with threading) +#LDFLAGS = -L$(LIB_PATHS) -ldpp -lpthread -Wl,-rpath=../../../$(LIB_PATHS) +LDFLAGS = -L$(LIB_PATHS) -ldpp -lpthread -Wl,-rpath=../../../$(LIB_PATHS) + +# List of object files for your executable +# We've changed this back to use discord-bot.o as the source of the executable +OBJECTS = $(OBJ_DIR)/discord-bot.o + +# --- Main Target --- +# 'all' is the default target that builds your executable +all: $(OUTPUT_FILE) + @echo "DPP_PATH: "$(DPP_PATH) + @echo "Build complete." + +# Rule to link the executable: +# It depends on the object files and uses CXX to link them with specified libraries. +$(OUTPUT_FILE): $(OBJECTS) + @echo "Linking $(OUTPUT_FILE)..." + @echo "LDFLAGS: $(LDFLAGS)" + @mkdir -p $(@D) # Ensure the output binary directory exists (e.g., bin/Linux/release/) + $(CXX) -o $@ $(OBJECTS) $(LDFLAGS) + cp token.txt $(@D) + +# Rule to compile the object file: +# This takes your .cpp source file and compiles it into an object file (.o). +$(OBJ_DIR)/$(EXECUTABLE_NAME).o: $(EXECUTABLE_NAME).cpp + @echo "Compiling $< to $@" + @mkdir -p $(@D) # Ensure the object directory exists (e.g., obj/Linux/release/) + $(CXX) -c -o $@ $< $(CXX_FLAGS) $(CPP_DEFINES) + + # --- Clean Target --- +# Removes all generated build files and directories +clean: + @echo "Cleaning build directory..." + $(RM) -r $(BIN_DIR) + $(RM) -r $(OBJ_DIR) + +# .PHONY specifies targets that are not actual files to prevent conflicts with file names +.PHONY: all clean \ No newline at end of file