Files
klibc/Makefile
2025-07-25 12:02:28 +02:00

50 lines
1.2 KiB
Makefile

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 \
$(DIR_BLD)/perror.o \
$(DIR_BLD)/file.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 *.txt
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