From 6f587de022739ab2df32547409fda2d9baad837c Mon Sep 17 00:00:00 2001 From: omicron Date: Sat, 18 Oct 2025 23:52:08 +0200 Subject: [PATCH] Initial Commit, project structure and build system. --- .clang-format | 6 ++++++ .gitignore | 1 + LICENSE | 19 +++++++++++++++++++ Makefile | 17 +++++++++++++++++ make/include/defaults.mk | 21 +++++++++++++++++++++ make/include/shared.mk | 9 +++++++++ make/loader.mk | 19 +++++++++++++++++++ make/runtime.mk | 9 +++++++++ make/test.mk | 20 ++++++++++++++++++++ 9 files changed, 121 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 make/include/defaults.mk create mode 100644 make/include/shared.mk create mode 100644 make/loader.mk create mode 100644 make/runtime.mk create mode 100644 make/test.mk diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..9e34f21 --- /dev/null +++ b/.clang-format @@ -0,0 +1,6 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +ColumnLimit: 90 +Cpp11BracedListStyle: true +AlignArrayOfStructures: Left +AllowShortFunctionsOnASingleLine: Empty diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c0d882d --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2025 omicron + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..453c0d6 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +.PHONY: all loader runtime test clean + +include make/include/defaults.mk + +all: loader runtime + +loader: + $(MAKE) -rRf make/loader.mk + +runtime: + $(MAKE) -rRf make/runtime.mk + +test: + $(MAKE) -rRf make/test.mk test + +clean: + rm -rf $(BUILD_DIR) diff --git a/make/include/defaults.mk b/make/include/defaults.mk new file mode 100644 index 0000000..b3ae922 --- /dev/null +++ b/make/include/defaults.mk @@ -0,0 +1,21 @@ +CC ?= i686-w64-mingw32-gcc +CFLAGS = -Wall -Wextra -pedantic -Werror -std=c23 + +SRC_DIR = src +SRC_DIR_COMMON = $(SRC_DIR)/common +SRC_DIR_RUNTIME = $(SRC_DIR)/runtime +SRC_DIR_LOADER = $(SRC_DIR)/loader + +SOURCES_COMMON := $(shell find $(SRC_DIR_COMMON) -name '*.c') +SOURCES_RUNTIME := $(shell find $(SRC_DIR_RUNTIME) -name '*.c') +SOURCES_LOADER := $(shell find $(SRC_DIR_LOADER) -name '*.c') + +BUILD_DIR ?= build + +OBJECTS_COMMON = $(SOURCES_COMMON:%.c=$(BUILD_DIR)/%.o) +OBJECTS_RUNTIME = $(SOURCES_RUNTIME:%.c=$(BUILD_DIR)/%.o) +OBJECTS_LOADER = $(SOURCES_LOADER:%.c=$(BUILD_DIR)/%.o) + +DEPS_COMMON = $(SOURCES_COMMON:%.c=$(BUILD_DIR)/%.d) +DEPS_RUNTIME = $(SOURCES_RUNTIME:%.c=$(BUILD_DIR)/%.d) +DEPS_LOADER = $(SOURCES_LOADER:%.c=$(BUILD_DIR)/%.d) diff --git a/make/include/shared.mk b/make/include/shared.mk new file mode 100644 index 0000000..f89383d --- /dev/null +++ b/make/include/shared.mk @@ -0,0 +1,9 @@ +$(TARGET): $(OBJECTS) + @mkdir -p $(dir $@) + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ + +$(BUILD_DIR)/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -MMD -MP -c $< -o $@ + +-include $(DEPS) diff --git a/make/loader.mk b/make/loader.mk new file mode 100644 index 0000000..e7afdda --- /dev/null +++ b/make/loader.mk @@ -0,0 +1,19 @@ +.PHONY: all + +include make/include/defaults.mk + +CFLAGS += -I$(BUILD_DIR)/stub +LDFLAGS += +TARGET = $(BUILD_DIR)/loader.exe +OBJECTS = $(OBJECTS_COMMON) $(OBJECTS_LOADER) +DEPS = $(DEPS_COMMON) $(DEPS_LOADER) +STUB = $(BUILD_DIR)/stub/stub.bin + +all: $(STUB) $(TARGET) + +$(STUB): $(SRC_DIR)/stub/stub.asm + @mkdir -p $(dir $@) + nasm -f bin $< -o $@ + +include make/include/shared.mk +$(OBJECTS_LOADER): $(STUB) diff --git a/make/runtime.mk b/make/runtime.mk new file mode 100644 index 0000000..cc8eac2 --- /dev/null +++ b/make/runtime.mk @@ -0,0 +1,9 @@ +include make/include/defaults.mk + +CFLAGS += +LDFLAGS += -shared +TARGET = $(BUILD_DIR)/runtime.dll +OBJECTS = $(OBJECTS_COMMON) $(OBJECTS_RUNTIME) +DEPS = $(DEPS_COMMON) $(DEPS_RUNTIME) + +include make/include/shared.mk diff --git a/make/test.mk b/make/test.mk new file mode 100644 index 0000000..273dd9d --- /dev/null +++ b/make/test.mk @@ -0,0 +1,20 @@ +.PHONY: all test + +include make/include/defaults.mk + +SOURCES_TEST := $(shell find tests/ -name '*.c') +OBJECTS_TEST = $(SOURCES_TEST:%.c=$(BUILD_DIR)/%.o) +DEPS_TEST = $(SOURCES_TEST:%.c=$(BUILD_DIR)/%.d) + +CFLAGS += -Isrc -D__STDC_NO_ATOMICS__ -DMUNIT_TEST_NAME_LEN=45 +LDFLAGS += +TARGET = $(BUILD_DIR)/binprobe-tests.exe +OBJECTS = $(OBJECTS_COMMON) $(OBJECTS_TEST) +DEPS = $(DEPS_COMMON) $(DEPS_TEST) + +all: $(TARGET) + +test: $(TARGET) + WINEDEBUG=-all wine $(TARGET) + +include make/include/shared.mk