From 715d12f29a39bc15b85c7f37c2a0bf698656a1c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 4 Jan 2026 21:56:17 +0100 Subject: [PATCH] add makefile, improve gitignore, formatting --- .gitignore | 3 ++- CMakeLists.txt | 8 ++++---- Makefile | 25 +++++++++++++++++++++++++ src/main_simpletest.c | 2 ++ 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index dfcdc9f..9bab3b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /cmake-build-debug/ -.idea +/build/ +/.idea diff --git a/CMakeLists.txt b/CMakeLists.txt index 89450be..d719d16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,10 +9,10 @@ add_executable(modbus src/modbus.c src/main.c src/stcpsc.c - src/hexdump.c - src/hexdump.h - src/parsehex.c - src/parsehex.h) + src/hexdump.c + src/hexdump.h + src/parsehex.c + src/parsehex.h) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0e3d288 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +BUILD_DIR := build +EXECUTABLE := modbus + +.PHONY: all build run clean rebuild debug release help +all: build + +# Configure and build the project +build: + @mkdir -p $(BUILD_DIR) + @cd $(BUILD_DIR) && cmake .. + @cmake --build $(BUILD_DIR) + @echo "Build complete. Executable: $(BUILD_DIR)/$(EXECUTABLE)" + +# Run the built executable, build if needed +run: build + @echo "Running $(EXECUTABLE)..." + @./$(BUILD_DIR)/$(EXECUTABLE) + +# Clean build artifacts +clean: + @rm -rf $(BUILD_DIR) + @echo "Build directory cleaned" + +# Rebuild from scratch +rebuild: clean build diff --git a/src/main_simpletest.c b/src/main_simpletest.c index 053d9a7..840115a 100644 --- a/src/main_simpletest.c +++ b/src/main_simpletest.c @@ -1,3 +1,5 @@ +// This test shows how the library could be used to implement a Modbus RTU device + #include #include "modbus.h" #include "hexdump.h"