12 Commits
Author SHA1 Message Date
anth64 270808e602 docs: update current version in readme to 1.0.0 2026-09-30 18:56:07 +02:00
anth64 053f8a14c8 docs: add changelog entry for 1.0.0 2026-09-29 23:51:55 +02:00
anth64 6429e29084 feat: add module template 2026-09-29 23:17:45 +02:00
anth64 5509c18b17 docs: update version in readme and add entry in changelog for 1.0.0-pre.12 2026-03-29 08:09:42 +02:00
anth64 cc39200917 build: change static library extension on Windows from .lib to .a for MinGW 2026-03-29 08:03:05 +02:00
anth64 95d7191fdd fix: use RTLD_GLOBAL when loading modules to expose host symbols 2026-03-19 07:38:49 +01:00
anth64 eb4b4c1f80 fix(build): default PREFIX to /usr in gmake.mk 2026-03-15 18:01:46 +01:00
anth64 7b7916911c chore: bump to pre.10 2026-03-14 17:31:06 +01:00
anth64 e46ec52c72 build(windows): use ar instead of lib for static library on MinGW 2026-03-14 13:22:31 +01:00
anth64 09528d60fd build(freebsd): fix path nesting 2026-03-13 08:03:14 +01:00
anth64 d1004d8840 chore(docs): update installation instructions and bump to pre.9 2026-03-12 22:44:44 +01:00
anth64 6fbd03f863 chore(build): add static library output and privilege-safe install
- debug and release targets now produce both shared and static libs
- obj dirs split into shared/ and static/ to keep fPIC objects isolated
- install no longer depends on release, guards with existence check instead
- build.sh handles privilege escalation for install/uninstall via doas or
  sudo, falling back gracefully if already root
- uninstall cleans up static lib alongside shared
2026-03-12 22:35:03 +01:00
17 changed files with 347 additions and 48 deletions
+36 -1
View File
@@ -7,6 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [1.0.0] - 2026-09-29
### Added
- `module_template/`: copyable starting point for a native stk module, builds cross-platform out of the box
## [1.0.0-pre.12] - 2026-03-29
### Fixed
- `gmake.mk`: changed static library extension on Windows from `.lib` to `.a` for MinGW compatibility
- `module_loader`: use `RTLD_GLOBAL` when loading modules to correctly expose host symbols to dynamic libraries
## [1.0.0-pre.11] - 2026-03-15
### Fixed
- `gmake.mk`: `PREFIX` now defaults to `/usr` on Linux instead of `/usr/local`
## [1.0.0-pre.10] - 2026-03-14
### Fixed
- `bmake.mk`: all target and object paths now anchored with `${.CURDIR}` to fix incorrect path nesting when building from outside the project root; substitution delimiters switched to `|` to avoid conflicts with path separators; compile rules now emit `-MT`/`-MF` for correct dependency file targeting; removed stale `.-include` directives for `.d` files; release lib rules now use `${.TARGET}` consistently
- `gmake.mk`: removed `AR`/`ARFLAGS_STATIC` variables and the `ifeq`-guarded static lib rules; both debug and release static lib rules now use `ar rcs` directly, as MinGW ships `ar` and `lib.exe` was incorrect
## [1.0.0-pre.9] - 2026-03-12
### Changed
- `debug` and `release` targets now produce both a shared and static library alongside each other
- obj directories split into `shared/` and `static/` subdirs to keep `-fPIC` objects isolated
- `install` no longer depends on `release`; guards with an existence check and exits with a clear message if artifacts are missing
- `uninstall` removes static lib alongside shared lib
- `build.sh`: `install` and `uninstall` now handle privilege escalation automatically via `doas` or `sudo`; skips escalation if already root
## [1.0.0-pre.8] - 2026-03-08 ## [1.0.0-pre.8] - 2026-03-08
### Fixed ### Fixed
@@ -192,7 +223,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Dependency management and versioning not yet implemented - Dependency management and versioning not yet implemented
- API is unstable and subject to change in future releases - API is unstable and subject to change in future releases
[Unreleased]: https://github.com/anth64/stk/compare/v1.0.0-pre.8...HEAD [Unreleased]: https://github.com/anth64/stk/compare/v1.0.0-pre.12...HEAD
[1.0.0-pre.12]: https://github.com/anth64/stk/compare/v1.0.0-pre.11...v1.0.0-pre.12
[1.0.0-pre.11]: https://github.com/anth64/stk/compare/v1.0.0-pre.10...v1.0.0-pre.11
[1.0.0-pre.10]: https://github.com/anth64/stk/compare/v1.0.0-pre.9...v1.0.0-pre.10
[1.0.0-pre.9]: https://github.com/anth64/stk/compare/v1.0.0-pre.8...v1.0.0-pre.9
[1.0.0-pre.8]: https://github.com/anth64/stk/compare/v1.0.0-pre.7...v1.0.0-pre.8 [1.0.0-pre.8]: https://github.com/anth64/stk/compare/v1.0.0-pre.7...v1.0.0-pre.8
[1.0.0-pre.7]: https://github.com/anth64/stk/compare/v1.0.0-pre.6...v1.0.0-pre.7 [1.0.0-pre.7]: https://github.com/anth64/stk/compare/v1.0.0-pre.6...v1.0.0-pre.7
[1.0.0-pre.6]: https://github.com/anth64/stk/compare/v1.0.0-pre.5...v1.0.0-pre.6 [1.0.0-pre.6]: https://github.com/anth64/stk/compare/v1.0.0-pre.5...v1.0.0-pre.6
+7 -5
View File
@@ -43,19 +43,19 @@ build.bat debug release
#### Unix (Linux/BSD/macOS) #### Unix (Linux/BSD/macOS)
```bash ```bash
sudo ./build.sh install ./build.sh install
``` ```
Installs to `/usr/local` by default. Use `PREFIX` to customize: Installs to `/usr` on Linux, `/usr/local` on BSD/macOS by default. Use `PREFIX` to customize:
```bash ```bash
sudo ./build.sh PREFIX=$HOME/.local install ./build.sh PREFIX=$HOME/.local install
``` ```
#### Windows #### Windows
``` ```
build.bat release build.bat release
``` ```
* Once finished building, copy the headers from `include/` to `your_project/include/stk/` and `bin/release/stk.dll` to your project's lib directory. * Once finished building, copy the headers from `include/` to `your_project/include/stk/` and copy `bin/release/stk.dll` or `bin/release/stk.lib` to your project's `lib` directory, depending on whether you are linking dynamically or statically.
--- ---
@@ -131,6 +131,8 @@ cc -shared -o my_module.dll my_module.c
Place the compiled module in the `mods/` directory (default), and `stk` will automatically load it and watch for changes. Place the compiled module in the `mods/` directory (default), and `stk` will automatically load it and watch for changes.
Copy `module_template/` as a starting point, it builds cross-platform out of the box.
### Module Metadata ### Module Metadata
Modules can optionally export metadata functions: Modules can optionally export metadata functions:
@@ -234,7 +236,7 @@ stk_init();
## Project Status ## Project Status
**Current Version:** 1.0.0-pre.8 **Current Version:** 1.0.0
### What Works ### What Works
- Cross-platform module loading and hot-reloading - Cross-platform module loading and hot-reloading
+36 -18
View File
@@ -12,44 +12,59 @@ FULL_LIB = lib${LIB_NAME}.dylib
FULL_LIB = lib${LIB_NAME}.so FULL_LIB = lib${LIB_NAME}.so
.endif .endif
STATIC_LIB = lib${LIB_NAME}.a
LDFLAGS_PLAT = -ldl LDFLAGS_PLAT = -ldl
CFLAGS_PLAT = -fPIC CFLAGS_PLAT = -fPIC
CFLAGS_BASE = -Wall -Wpedantic -I${.CURDIR}/${INC_DIR} -std=c89 ${CFLAGS_PLAT} CFLAGS_BASE = -Wall -Wpedantic -I${.CURDIR}/${INC_DIR} -std=c89 ${CFLAGS_PLAT}
CFLAGS_STATIC =
.PHONY: all debug release clean test install uninstall .PHONY: all debug release clean test install uninstall
all: debug all: debug
OBJS_DEBUG = ${SRCS:S/^src\//obj\/debug\//:S/.c$/.o/} OBJS_DEBUG_SHARED = ${SRCS:S|^src/|${.CURDIR}/obj/debug/shared/|:S/.c$/.o/}
OBJS_RELEASE = ${SRCS:S/^src\//obj\/release\//:S/.c$/.o/} OBJS_DEBUG_STATIC = ${SRCS:S|^src/|${.CURDIR}/obj/debug/static/|:S/.c$/.o/}
OBJS_RELEASE_SHARED = ${SRCS:S|^src/|${.CURDIR}/obj/release/shared/|:S/.c$/.o/}
OBJS_RELEASE_STATIC = ${SRCS:S|^src/|${.CURDIR}/obj/release/static/|:S/.c$/.o/}
debug: ${BIN_DIR}/debug/${FULL_LIB} debug: ${.CURDIR}/${BIN_DIR}/debug/${FULL_LIB} ${.CURDIR}/${BIN_DIR}/debug/${STATIC_LIB}
release: ${BIN_DIR}/release/${FULL_LIB} release: ${.CURDIR}/${BIN_DIR}/release/${FULL_LIB} ${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB}
${BIN_DIR}/debug/${FULL_LIB}: ${OBJS_DEBUG} ${.CURDIR}/${BIN_DIR}/debug/${FULL_LIB}: ${OBJS_DEBUG_SHARED}
@mkdir -p ${.TARGET:H} @mkdir -p ${.TARGET:H}
${CC} -shared -o ${.TARGET} ${.ALLSRC} ${LDFLAGS_PLAT} ${CC} -shared -o ${.TARGET} ${.ALLSRC} ${LDFLAGS_PLAT}
${BIN_DIR}/release/${FULL_LIB}: ${OBJS_RELEASE} ${.CURDIR}/${BIN_DIR}/debug/${STATIC_LIB}: ${OBJS_DEBUG_STATIC}
@mkdir -p ${.CURDIR}/${BIN_DIR}/release @mkdir -p ${.TARGET:H}
${CC} -shared -s -o ${.CURDIR}/${BIN_DIR}/release/${FULL_LIB} ${.ALLSRC} ${LDFLAGS_PLAT} ar rcs ${.TARGET} ${.ALLSRC}
${.CURDIR}/${BIN_DIR}/release/${FULL_LIB}: ${OBJS_RELEASE_SHARED}
@mkdir -p ${.TARGET:H}
${CC} -shared -s -o ${.TARGET} ${.ALLSRC} ${LDFLAGS_PLAT}
${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB}: ${OBJS_RELEASE_STATIC}
@mkdir -p ${.TARGET:H}
ar rcs ${.TARGET} ${.ALLSRC}
.for _src in ${SRCS} .for _src in ${SRCS}
_obj_base = ${_src:S/^src\///:S/.c$/.o/} ${.CURDIR}/obj/debug/shared/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
obj/debug/${_obj_base}: ${_src}
@mkdir -p ${.TARGET:H} @mkdir -p ${.TARGET:H}
${CC} ${CFLAGS_BASE} -g -O0 -MMD -MP -c ${.ALLSRC} -o ${.TARGET} ${CC} ${CFLAGS_BASE} -g -O0 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
obj/release/${_obj_base}: ${_src} ${.CURDIR}/obj/debug/static/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
@mkdir -p ${.TARGET:H} @mkdir -p ${.TARGET:H}
${CC} ${CFLAGS_BASE} -O2 -MMD -MP -c ${.ALLSRC} -o ${.TARGET} ${CC} ${CFLAGS_BASE} ${CFLAGS_STATIC} -g -O0 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
${.CURDIR}/obj/release/shared/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
@mkdir -p ${.TARGET:H}
${CC} ${CFLAGS_BASE} -O2 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
${.CURDIR}/obj/release/static/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
@mkdir -p ${.TARGET:H}
${CC} ${CFLAGS_BASE} ${CFLAGS_STATIC} -O2 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
.endfor .endfor
.-include "obj/debug/*.d"
.-include "obj/release/*.d"
clean: clean:
rm -rf ${.CURDIR}/${OBJ_DIR} ${.CURDIR}/${BIN_DIR} rm -rf ${.CURDIR}/${OBJ_DIR} ${.CURDIR}/${BIN_DIR}
@@ -57,13 +72,16 @@ test: debug
@echo "=== Building and running stk tests ===" @echo "=== Building and running stk tests ==="
cd ${.CURDIR}/test && ${MAKE} -f bmake.mk cd ${.CURDIR}/test && ${MAKE} -f bmake.mk
install: release install:
@test -f ${.CURDIR}/${BIN_DIR}/release/${FULL_LIB} || { echo "Run 'make -f bmake.mk release' before installing."; exit 1; }
install -d ${LIBDIR} ${INCDIR}/stk install -d ${LIBDIR} ${INCDIR}/stk
install -m 755 ${.CURDIR}/${BIN_DIR}/release/${FULL_LIB} ${LIBDIR}/ install -m 755 ${.CURDIR}/${BIN_DIR}/release/${FULL_LIB} ${LIBDIR}/
install -m 644 ${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB} ${LIBDIR}/
install -m 644 ${.CURDIR}/${INC_DIR}/stk.h ${INCDIR}/stk/ install -m 644 ${.CURDIR}/${INC_DIR}/stk.h ${INCDIR}/stk/
install -m 644 ${.CURDIR}/${INC_DIR}/stk_version.h ${INCDIR}/stk/ install -m 644 ${.CURDIR}/${INC_DIR}/stk_version.h ${INCDIR}/stk/
install -m 644 ${.CURDIR}/${INC_DIR}/stk_log.h ${INCDIR}/stk/ install -m 644 ${.CURDIR}/${INC_DIR}/stk_log.h ${INCDIR}/stk/
uninstall: uninstall:
rm -f ${LIBDIR}/${FULL_LIB} rm -f ${LIBDIR}/${FULL_LIB}
rm -f ${LIBDIR}/${STATIC_LIB}
rm -rf ${INCDIR}/stk rm -rf ${INCDIR}/stk
+29 -1
View File
@@ -8,4 +8,32 @@ else
MK_FILE="bmake.mk" MK_FILE="bmake.mk"
fi fi
make -f "$MK_FILE" "$@" HAS_INSTALL=0
HAS_UNINSTALL=0
for arg in "$@"; do
case "$arg" in
install) HAS_INSTALL=1 ;;
uninstall) HAS_UNINSTALL=1 ;;
esac
done
if [ "$HAS_INSTALL" = "1" ] || [ "$HAS_UNINSTALL" = "1" ]; then
if [ "$HAS_INSTALL" = "1" ]; then
make -f "$MK_FILE" release
fi
if [ "$(id -u)" = "0" ]; then
PRIV=""
elif command -v doas > /dev/null 2>&1; then
PRIV="doas"
elif command -v sudo > /dev/null 2>&1; then
PRIV="sudo"
else
echo "error: install requires root. neither doas nor sudo found." >&2
exit 1
fi
$PRIV make -f "$MK_FILE" "$@"
else
make -f "$MK_FILE" "$@"
fi
+1
View File
@@ -4,6 +4,7 @@ OBJ_DIR = obj
BIN_DIR = bin BIN_DIR = bin
LIB_NAME = stk LIB_NAME = stk
STATIC_LIB = lib$(LIB_NAME).a
SRCS = src/module.c \ SRCS = src/module.c \
src/platform.c \ src/platform.c \
+47 -22
View File
@@ -2,15 +2,19 @@ include config.mk
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
SHELL := cmd.exe SHELL := cmd.exe
FULL_LIB := $(LIB_NAME).dll FULL_LIB := $(LIB_NAME).dll
LDFLAGS_PLAT := STATIC_LIB := lib$(LIB_NAME).a
CFLAGS_PLAT := LDFLAGS_PLAT :=
CFLAGS_PLAT :=
CFLAGS_STATIC :=
MKDIR = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1)) MKDIR = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
RMDIR = if exist $(subst /,\,$(1)) rd /s /q $(subst /,\,$(1)) RMDIR = if exist $(subst /,\,$(1)) rd /s /q $(subst /,\,$(1))
else else
FULL_LIB := lib$(LIB_NAME).so FULL_LIB := lib$(LIB_NAME).so
LDFLAGS_PLAT := -ldl STATIC_LIB := lib$(LIB_NAME).a
CFLAGS_PLAT := -fPIC LDFLAGS_PLAT := -ldl
CFLAGS_PLAT := -fPIC
CFLAGS_STATIC :=
MKDIR = mkdir -p $(1) MKDIR = mkdir -p $(1)
RMDIR = rm -rf $(1) RMDIR = rm -rf $(1)
endif endif
@@ -18,37 +22,55 @@ endif
RELEASE_LDFLAGS := -s RELEASE_LDFLAGS := -s
CFLAGS_BASE := -Wall -Wpedantic -I$(INC_DIR) -std=c89 $(CFLAGS_PLAT) CFLAGS_BASE := -Wall -Wpedantic -I$(INC_DIR) -std=c89 $(CFLAGS_PLAT)
PREFIX ?= /usr/local PREFIX ?= /usr
LIBDIR ?= $(PREFIX)/lib LIBDIR ?= $(PREFIX)/lib
INCDIR ?= $(PREFIX)/include INCDIR ?= $(PREFIX)/include
.PHONY: all debug release clean test install uninstall .PHONY: all debug release clean test install uninstall
all: debug all: debug
debug: $(BIN_DIR)/debug/$(FULL_LIB) debug: $(BIN_DIR)/debug/$(FULL_LIB) $(BIN_DIR)/debug/$(STATIC_LIB)
release: $(BIN_DIR)/release/$(FULL_LIB) release: $(BIN_DIR)/release/$(FULL_LIB) $(BIN_DIR)/release/$(STATIC_LIB)
# Debug Rules # Debug Rules
$(BIN_DIR)/debug/$(FULL_LIB): $(SRCS:src/%.c=obj/debug/%.o) $(BIN_DIR)/debug/$(FULL_LIB): $(SRCS:src/%.c=obj/debug/shared/%.o)
@$(call MKDIR,$(@D)) @$(call MKDIR,$(@D))
$(CC) -shared -o $@ $^ $(LDFLAGS_PLAT) $(CC) -shared -o $@ $^ $(LDFLAGS_PLAT)
obj/debug/%.o: src/%.c $(BIN_DIR)/debug/$(STATIC_LIB): $(SRCS:src/%.c=obj/debug/static/%.o)
@$(call MKDIR,$(@D)) @$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) -g -O0 -MMD -MP -c $< -o $@ ar rcs $@ $^
obj/debug/shared/%.o: src/%.c
@$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) -g -O0 -MMD -MP -c $< -o $@
obj/debug/static/%.o: src/%.c
@$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) $(CFLAGS_STATIC) -g -O0 -MMD -MP -c $< -o $@
# Release Rules # Release Rules
$(BIN_DIR)/release/$(FULL_LIB): $(SRCS:src/%.c=obj/release/%.o) $(BIN_DIR)/release/$(FULL_LIB): $(SRCS:src/%.c=obj/release/shared/%.o)
@$(call MKDIR,$(@D)) @$(call MKDIR,$(@D))
$(CC) -shared $(RELEASE_LDFLAGS) -o $@ $^ $(LDFLAGS_PLAT) $(CC) -shared $(RELEASE_LDFLAGS) -o $@ $^ $(LDFLAGS_PLAT)
obj/release/%.o: src/%.c $(BIN_DIR)/release/$(STATIC_LIB): $(SRCS:src/%.c=obj/release/static/%.o)
@$(call MKDIR,$(@D)) @$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) -O2 -MMD -MP -c $< -o $@ ar rcs $@ $^
-include $(wildcard obj/debug/*.d) obj/release/shared/%.o: src/%.c
-include $(wildcard obj/release/*.d) @$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) -O2 -MMD -MP -c $< -o $@
obj/release/static/%.o: src/%.c
@$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) $(CFLAGS_STATIC) -O2 -MMD -MP -c $< -o $@
-include $(wildcard obj/debug/shared/*.d)
-include $(wildcard obj/debug/static/*.d)
-include $(wildcard obj/release/shared/*.d)
-include $(wildcard obj/release/static/*.d)
clean: clean:
@$(call RMDIR,$(OBJ_DIR)) @$(call RMDIR,$(OBJ_DIR))
@@ -58,23 +80,26 @@ test: debug
@echo "=== Building and running stk tests ===" @echo "=== Building and running stk tests ==="
@$(MAKE) -C test -f gmake.mk @$(MAKE) -C test -f gmake.mk
# Installation (Unix only)
ifneq ($(OS),Windows_NT) ifneq ($(OS),Windows_NT)
install: release install:
@test -f $(BIN_DIR)/release/$(FULL_LIB) || { echo "Run 'make -f gmake.mk release' before installing."; exit 1; }
install -d $(LIBDIR) $(INCDIR)/stk install -d $(LIBDIR) $(INCDIR)/stk
install -m 755 $(BIN_DIR)/release/$(FULL_LIB) $(LIBDIR)/ install -m 755 $(BIN_DIR)/release/$(FULL_LIB) $(LIBDIR)/
install -m 644 $(BIN_DIR)/release/$(STATIC_LIB) $(LIBDIR)/
install -m 644 $(INC_DIR)/stk.h $(INCDIR)/stk/ install -m 644 $(INC_DIR)/stk.h $(INCDIR)/stk/
install -m 644 $(INC_DIR)/stk_version.h $(INCDIR)/stk/ install -m 644 $(INC_DIR)/stk_version.h $(INCDIR)/stk/
install -m 644 $(INC_DIR)/stk_log.h $(INCDIR)/stk/ install -m 644 $(INC_DIR)/stk_log.h $(INCDIR)/stk/
uninstall: uninstall:
rm -f $(LIBDIR)/$(FULL_LIB) rm -f $(LIBDIR)/$(FULL_LIB)
rm -f $(LIBDIR)/$(STATIC_LIB)
rm -rf $(INCDIR)/stk rm -rf $(INCDIR)/stk
else else
install: install:
@echo "make install is not supported on Windows." @echo "make install is not supported on Windows."
@echo "Copy include/ directory contents to your_project/include/stk/" @echo "Copy include/ directory contents to your_project/include/stk/"
@echo "Copy bin/release/stk.dll to your project's lib directory." @echo "Copy bin/release/stk.dll to your project's lib directory."
@echo "Copy bin/release/stk.lib to your project's lib directory."
uninstall: uninstall:
@echo "make uninstall is not supported on Windows." @echo "make uninstall is not supported on Windows."
+3
View File
@@ -0,0 +1,3 @@
# Build directories
obj/
bin/
+20
View File
@@ -0,0 +1,20 @@
# my_module
TODO: one-line description.
An stk module.
## Build
```bash
./build.sh debug release # Linux/BSD/macOS
build.bat debug release # Windows
```
## Install
Copy `bin/release/my_module.so`/`.dylib`/`.dll` into the game's `mods/` directory.
## Dependencies
TODO: list any, or delete this section.
+43
View File
@@ -0,0 +1,43 @@
.include "config.mk"
UNAME_S != uname -s
.if ${UNAME_S} == "Darwin"
MODULE_EXT = .dylib
.else
MODULE_EXT = .so
.endif
CC ?= cc
CFLAGS_BASE = -Wall -Wpedantic -I${.CURDIR}/${INC_DIR} -fPIC
.PHONY: all debug release clean
all: debug
OBJS_DEBUG = ${SRCS:S|^src/|${.CURDIR}/obj/debug/|:S/.c$/.o/}
OBJS_RELEASE = ${SRCS:S|^src/|${.CURDIR}/obj/release/|:S/.c$/.o/}
debug: ${.CURDIR}/${BIN_DIR}/debug/${MODULE_NAME}${MODULE_EXT}
release: ${.CURDIR}/${BIN_DIR}/release/${MODULE_NAME}${MODULE_EXT}
${.CURDIR}/${BIN_DIR}/debug/${MODULE_NAME}${MODULE_EXT}: ${OBJS_DEBUG}
@mkdir -p ${.TARGET:H}
${CC} -shared -o ${.TARGET} ${.ALLSRC}
${.CURDIR}/${BIN_DIR}/release/${MODULE_NAME}${MODULE_EXT}: ${OBJS_RELEASE}
@mkdir -p ${.TARGET:H}
${CC} -shared -s -o ${.TARGET} ${.ALLSRC}
.for _src in ${SRCS}
${.CURDIR}/obj/debug/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
@mkdir -p ${.TARGET:H}
${CC} ${CFLAGS_BASE} -g -O0 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
${.CURDIR}/obj/release/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
@mkdir -p ${.TARGET:H}
${CC} ${CFLAGS_BASE} -O2 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
.endfor
clean:
rm -rf ${.CURDIR}/${OBJ_DIR} ${.CURDIR}/${BIN_DIR}
+2
View File
@@ -0,0 +1,2 @@
@echo off
make -f gmake.mk %*
+11
View File
@@ -0,0 +1,11 @@
#!/bin/sh
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
if [ "$OS" = "linux" ]; then
MK_FILE="gmake.mk"
else
MK_FILE="bmake.mk"
fi
make -f "$MK_FILE" "$@"
+4
View File
@@ -0,0 +1,4 @@
-xc
-Wall
-Wpedantic
-Iinclude
+8
View File
@@ -0,0 +1,8 @@
SRC_DIR = src
INC_DIR = include
OBJ_DIR = obj
BIN_DIR = bin
MODULE_NAME = my_module
SRCS = src/module.c
+45
View File
@@ -0,0 +1,45 @@
include config.mk
ifeq ($(OS),Windows_NT)
SHELL := cmd.exe
MODULE_EXT = .dll
MKDIR = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
RMDIR = if exist $(subst /,\,$(1)) rd /s /q $(subst /,\,$(1))
else
MODULE_EXT = .so
MKDIR = mkdir -p $(1)
RMDIR = rm -rf $(1)
endif
CC = cc
CFLAGS_BASE = -Wall -Wpedantic -I$(INC_DIR) -fPIC
.PHONY: all debug release clean
all: debug
debug: $(BIN_DIR)/debug/$(MODULE_NAME)$(MODULE_EXT)
release: $(BIN_DIR)/release/$(MODULE_NAME)$(MODULE_EXT)
$(BIN_DIR)/debug/$(MODULE_NAME)$(MODULE_EXT): $(SRCS:src/%.c=obj/debug/%.o)
@$(call MKDIR,$(@D))
$(CC) -shared -o $@ $^
obj/debug/%.o: src/%.c
@$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) -g -O0 -MMD -MP -c $< -o $@
$(BIN_DIR)/release/$(MODULE_NAME)$(MODULE_EXT): $(SRCS:src/%.c=obj/release/%.o)
@$(call MKDIR,$(@D))
$(CC) -shared -s -o $@ $^
obj/release/%.o: src/%.c
@$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) -O2 -MMD -MP -c $< -o $@
-include $(wildcard obj/debug/*.d)
-include $(wildcard obj/release/*.d)
clean:
@$(call RMDIR,$(OBJ_DIR))
@$(call RMDIR,$(BIN_DIR))
+16
View File
@@ -0,0 +1,16 @@
#ifndef MODULE_VERSION_H
#define MODULE_VERSION_H
#define MY_MODULE_VERSION_MAJOR 0
#define MY_MODULE_VERSION_MINOR 1
#define MY_MODULE_VERSION_PATCH 0
#define MY_MODULE_STRINGIFY_HELPER(x) #x
#define MY_MODULE_STRINGIFY(x) MY_MODULE_STRINGIFY_HELPER(x)
#define MY_MODULE_VERSION_STRING \
MY_MODULE_STRINGIFY(MY_MODULE_VERSION_MAJOR) \
"." MY_MODULE_STRINGIFY(MY_MODULE_VERSION_MINOR) "." MY_MODULE_STRINGIFY( \
MY_MODULE_VERSION_PATCH)
#endif /* MODULE_VERSION_H */
+38
View File
@@ -0,0 +1,38 @@
#include "module_version.h"
#include <stdio.h>
/* on load */
int stk_mod_init(void)
{
printf("my_module initialized!\n");
return 0;
}
/* on unload/reload */
void stk_mod_shutdown(void) { printf("my_module shut down.\n"); }
const char *stk_mod_name(void) { return "my_module"; }
const char *stk_mod_version(void) { return MY_MODULE_VERSION_STRING; }
const char *stk_mod_description(void) { return "TODO: describe this module"; }
/*
* declares which other modules must be loaded first.
* id = dependency's filename, minus extension.
* layout must match stk_dep_t: id[64], version[32].
* sentinel ("","") required, always last.
*
* =1.0.0 exact
* >=1.0.0 minimum (default)
* ^1.0.0 same major
*/
/*
typedef struct {
char id[64];
char version[32];
} dep_t;
dep_t stk_mod_deps[] = {
{ "physics", ">=2.0.0" },
{ "", "" }
};
*/
+1 -1
View File
@@ -278,7 +278,7 @@ void *platform_load_library(const char *path)
#ifdef _WIN32 #ifdef _WIN32
return (void *)LoadLibraryA(path); return (void *)LoadLibraryA(path);
#else #else
return dlopen(path, RTLD_NOW); return dlopen(path, RTLD_NOW | RTLD_GLOBAL);
#endif #endif
} }