From 079921091f28212a774a212967c93fd89c80d963 Mon Sep 17 00:00:00 2001 From: anth64 Date: Wed, 8 Oct 2025 19:17:18 +0200 Subject: [PATCH] initial code + Makefile --- Makefile | 54 +++++++++++++++++++++++++++++++++++++++++++ include/stk.h | 9 ++++++++ include/stk_version.h | 16 +++++++++++++ src/stk.c | 14 +++++++++++ 4 files changed, 93 insertions(+) create mode 100644 Makefile create mode 100644 include/stk.h create mode 100644 include/stk_version.h create mode 100644 src/stk.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d6a6ceb --- /dev/null +++ b/Makefile @@ -0,0 +1,54 @@ +# Directories +SRC_DIR := src +INC_DIR := include +OBJ_DIR := obj +BIN_DIR := bin + +# Source files +SRCS := $(wildcard $(SRC_DIR)/*.c) +OBJS_DEBUG := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/debug/%.o,$(SRCS)) +OBJS_RELEASE := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/release/%.o,$(SRCS)) + +# Compiler and flags +CC := gcc +CFLAGS_DEBUG := -g -O0 -Wall -Wpedantic -I$(INC_DIR) -std=c89 -fPIC +CFLAGS_RELEASE := -O2 -Wall -Wpedantic -I$(INC_DIR) -std=c89 -fPIC + +# Library name +LIB_NAME := libstk.so + +# Default build +all: debug + +# Debug / Release builds +debug: $(BIN_DIR)/debug/$(LIB_NAME) +release: $(BIN_DIR)/release/$(LIB_NAME) + +# Build shared library +$(BIN_DIR)/debug/$(LIB_NAME): $(OBJS_DEBUG) + @mkdir -p $(BIN_DIR)/debug + $(CC) -shared -o $@ $^ + +$(BIN_DIR)/release/$(LIB_NAME): $(OBJS_RELEASE) + @mkdir -p $(BIN_DIR)/release + $(CC) -shared -o $@ $^ + +# Compile object files with header dependency tracking +$(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.c + @mkdir -p $(OBJ_DIR)/debug + $(CC) $(CFLAGS_DEBUG) -MMD -MP -c $< -o $@ + +$(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.c + @mkdir -p $(OBJ_DIR)/release + $(CC) $(CFLAGS_RELEASE) -MMD -MP -c $< -o $@ + +# Include generated dependency files +-include $(OBJS_DEBUG:.o=.d) +-include $(OBJS_RELEASE:.o=.d) + +# Clean +clean: + rm -rf $(OBJ_DIR) $(BIN_DIR) + +.PHONY: all debug release clean + diff --git a/include/stk.h b/include/stk.h new file mode 100644 index 0000000..77a6491 --- /dev/null +++ b/include/stk.h @@ -0,0 +1,9 @@ +#ifndef STK_H +#define STK_H + +#include "stk_version.h" + +int stk_init(void); +int stk_shutdown(void); + +#endif /* STK_H */ diff --git a/include/stk_version.h b/include/stk_version.h new file mode 100644 index 0000000..4b60445 --- /dev/null +++ b/include/stk_version.h @@ -0,0 +1,16 @@ +#ifndef STK_VERSION_H +#define STK_VERSION_H + +#define STK_VERSION_MAJOR 0 +#define STK_VERSION_MINOR 0 +#define STK_VERSION_PATCH 0 + +#define STK_STRINGIFY_HELPER(x) #x +#define STK_STRINGIFY(x) STK_STRINGIFY_HELPER(x) + +#define STK_VERSION_STRING \ + STK_STRINGIFY(STK_VERSION_MAJOR) \ + "." STK_STRINGIFY(STK_VERSION_MINOR) "." STK_STRINGIFY( \ + STK_VERSION_PATCH) + +#endif /* STK_VERSION_H */ diff --git a/src/stk.c b/src/stk.c new file mode 100644 index 0000000..3d08898 --- /dev/null +++ b/src/stk.c @@ -0,0 +1,14 @@ +#include "stk.h" +#include + +int stk_init(void) +{ + printf("stk initialized v%s\n", STK_VERSION_STRING); + return 0; +} + +int stk_shutdown(void) +{ + printf("stk shutdown\n"); + return 0; +}