Initial commit

This commit is contained in:
2025-01-19 14:31:35 +03:00
commit 216db38825
10 changed files with 947 additions and 0 deletions

79
Makefile Normal file
View File

@@ -0,0 +1,79 @@
INCLUDES=-Iinc -I.
# BUILD_DIR=out
ifeq ($(BUILD_DIR),)
BUILD_DIR := out
endif
SRC_DIR=src
INC_DIR=inc
CC=gcc
OBJDUMP=objdump
LIBS=
STANDART=c23
OPTIMIZE=-Og
TARGET=device
DEFINES=-DOPCODE_WORDSIZE=2 -DMEM_CELL_WORDS=1 -DPC_WORDSIZE=3 -DGP_REG_CELL_WORDS=1 -DIO_REG_CELL_WORDS=1 -DARCH=$(ARCH)
C_SOURCES=$(wildcard $(SRC_DIR)/*.c)
C_HEADERS=$(wildcard $(INC_DIR)/*.h)
C_INCLUDES=-I$(INC_DIR)/
DISABLE_FLAGS=-Wno-unused-variable -Wno-unused-parameter -Wno-write-strings -Wno-pointer-arith -Wno-analyzer-use-of-uninitialized-value
PEDANTIC_FLAGS=-pedantic -pedantic-errors $(DISABLE_FLAGS) -Wall -Wcast-align -Wcast-qual -Wconversion -Wduplicated-branches -Wduplicated-cond -Werror -Wextra -Wfloat-equal -Wlogical-op -Wpedantic -Wredundant-decls -Wsign-conversion
ANALYZER_FLAGS=-fanalyzer
LSECTIONS=-ffunction-sections -fdata-sections -Wl,--gc-sections
CFLAGS=$(C_DEFS) -g $(C_INCLUDES) $(DEFINES) $(OPTIMIZE) --std=$(STANDART) $(PEDANTIC_FLAGS) $(ANALYZER_FLAGS) -fPIC
LFLAGS=$(OPTIMIZE) -g $(PEDANTIC_FLAGS) $(DEFINES) -flto -fuse-linker-plugin $(LSECTIONS) -lm $(LIBS) -fPIC -shared
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
vpath %.h $(sort $(dir $(C_HEADERS)))
rebuild: clean | build
all:
build: date Dir $(C_HEADERS) target
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
@echo -e '\033[1;32mCC ('$(ARCH)')\t'$<'\t->\t'$@'\033[0m'
@$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
@$(OBJDUMP) -d -S $@ > $(BUILD_DIR)/$(notdir $(<:.c=.casm))
target: date $(BUILD_DIR)/$(TARGET).so
$(BUILD_DIR)/$(TARGET).so: $(OBJECTS)
@echo -e '\033[1;32mELF ('$(ARCH)')\t'$(OBJECTS)'\n\t\t\t->\t'$@'\033[0m'
@$(CC) $(LFLAGS) $(OBJECTS) -o $(BUILD_DIR)/$(TARGET).so
BuildDir:
@mkdir -p $(BUILD_DIR)
SrcDir:
@mkdir -p $(SRC_DIR)
IncDir:
@mkdir -p $(INC_DIR)
Dir: BuildDir SrcDir IncDir
.PHONY: clean
clean:
@rm -rf $(BUILD_DIR)/*
@echo -e '\033[0;31mCleaned\033[0m'
.NOTPARALLEL: date target rebuild
date:
@echo -e '\033[1;32m'"Starting build at " | tr -d '\n'
@date
@echo -e '\033[0m'