From e12b8f036519e37bfa8ec27b287dcfd6e049334f Mon Sep 17 00:00:00 2001 From: Kwarde Date: Sat, 5 Jul 2025 01:11:30 +0200 Subject: [PATCH] Add Makefile, gitignore and (empty-ish) source files --- .gitignore | 3 +++ Makefile | 47 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- src/console.asm | 1 + src/constants.asm | 1 + src/convert.asm | 1 + src/core.asm | 1 + src/string.asm | 1 + src/tests.asm | 1 + 9 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 src/console.asm create mode 100644 src/constants.asm create mode 100644 src/convert.asm create mode 100644 src/core.asm create mode 100644 src/string.asm create mode 100644 src/tests.asm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50e842d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build +tests +*.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..71ec0aa --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +DIR_SRC := src +DIR_BLD := build +DIR_BIN := $(DIR_BLD)/bin + +OBJS := $(DIR_BLD)/tests.o \ + $(DIR_BLD)/constants.o \ + $(DIR_BLD)/core.o \ + $(DIR_BLD)/console.o \ + $(DIR_BLD)/string.o \ + $(DIR_BLD)/convert.o +OBJS_LST := false +SRCS := $(patsubst $(DIR_BLD)/%.o,$(SRC_DIR)/%.asm,$(OBJS)) + +COMPILER := nasm +COMPILER_FLAGS := -f elf64 +COMPILER_FLAGS_D := -f elf64 -g -F dwarf +LINKER := ld +LINKER_FLAGS := -no-pie -z noexecstack -Ox + +.PHONY: all clean debug + +all: $(DIR_BIN)/tests + +$(DIR_BIN)/tests: $(OBJS) + @mkdir -p $(DIR_BIN) + $(LINKER) $^ -o $@ $(LINKER_FLAGS) + ln -sf $@ tests +$(DIR_BLD)/%.o: $(DIR_SRC)/%.asm + @mkdir -p $(DIR_BLD) + @LST=$(basename $@).lst; \ + if [ "$(OBJS_LST)" = "true" ]; then \ + $(COMPILER) $< $(COMPILER_FLAGS) -l $$LST -o $@; \ + echo $(COMPILER) $< $(COMPILER_FLAGS) -l $$LST -o $@; \ + else \ + $(COMPILER) $< $(COMPILER_FLAGS) -o $@; \ + echo $(COMPILER) $< $(COMPILER_FLAGS) -o $@; \ + fi + +clean: + rm -rf $(DIR_BLD) tests + +debug: COMPILER_FLAGS = $(COMPILER_FLAGS_D) +debug: OBJS_LST := true +debug: clean $(OBJS) + @mkdir -p $(DIR_BIN) + $(LINKER) $(OBJS) -o $(DIR_BIN)/tests $(LINKER_FLAGS) + ln -sf $(DIR_BIN)/tests tests diff --git a/README.md b/README.md index 6c9ec92..7539cd6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -Minimal C-like library written in x64 assembly (Intel 64) - let's call it C-. +Minimal C-like library written in x64 assembly (Intel 64) - let's call it C- and/or klibc. NOT usable for production - written for study purposes only. diff --git a/src/console.asm b/src/console.asm new file mode 100644 index 0000000..2e069bf --- /dev/null +++ b/src/console.asm @@ -0,0 +1 @@ +%include "src/constants.asm" diff --git a/src/constants.asm b/src/constants.asm new file mode 100644 index 0000000..b0a1a47 --- /dev/null +++ b/src/constants.asm @@ -0,0 +1 @@ +section .rodata diff --git a/src/convert.asm b/src/convert.asm new file mode 100644 index 0000000..2e069bf --- /dev/null +++ b/src/convert.asm @@ -0,0 +1 @@ +%include "src/constants.asm" diff --git a/src/core.asm b/src/core.asm new file mode 100644 index 0000000..2e069bf --- /dev/null +++ b/src/core.asm @@ -0,0 +1 @@ +%include "src/constants.asm" diff --git a/src/string.asm b/src/string.asm new file mode 100644 index 0000000..2e069bf --- /dev/null +++ b/src/string.asm @@ -0,0 +1 @@ +%include "src/constants.asm" diff --git a/src/tests.asm b/src/tests.asm new file mode 100644 index 0000000..2e069bf --- /dev/null +++ b/src/tests.asm @@ -0,0 +1 @@ +%include "src/constants.asm"