Files
hmmmm/Makefile
root 589bc8d620 feat: migrate config management from TOML to FlatBuffers
Config is now loaded at runtime via WebSocket (ConfigCtrlMessage)
instead of from hardcoded TOML files. The emulator starts with no
devices and waits for clients to send configuration.

- Define FlatBuffers schemas: EmulationConfig, ComposeDeviceConfig,
  BaseDeviceConfig with recursive DeviceConfig union
- Rename MemSegment.start → addr (flatcc builder/reader name collision)
- Add ConfigCtrlMessage handler: validates STILL state, walks the
  device tree depth-first, assigns numeric IDs, responds with
  DeviceIdMappingNotif or ConfigLoadError
- Add fb_build_config_device_id_mapping() and fb_build_config_error()
  FlatBuffer builders
- Remove hardcoded device loading from main.c; iterate dynamically
  loaded devices in the exec loop
- Fix double-free: freeConf() already frees the struct itself, remove
  redundant free() calls in config.c and base_device.c
- Fix heap-buffer-overflow in device parseSpecsFromConfig: malloc
  for segment name was missing +1 for the null terminator

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 14:02:41 +00:00

139 lines
4.2 KiB
Makefile

OPENSSL_INCLUDE ?= /usr/include/openssl/
BUILD_DIR=out
SRC_DIR=src
INC_DIR=inc
CC=gcc
OBJDUMP=objdump
LIBS=deps/tomlc99/libtoml.a deps/ptQueue/out/ptQueue.a deps/wsServer/libws.a deps/flatcc/lib/libflatccrt.a
LIBS_HEADERS=deps/ $(OPENSSL_INCLUDE)
# flatcc runtime and generated reader headers use const-dropping casts;
# include both as system headers so -Wcast-qual doesn't apply to them
SYSTEM_INCLUDES=-isystem deps/flatcc/include/ -isystem $(PROTO_INC_DIR)/
STATIC_LIBS=crypto
STANDART=c23
OPTIMIZE=-O3
TARGET=main
FLATCC = deps/flatcc/bin/flatcc
FLATC = deps/flatbuffers/build/flatc
FBS_DIR = flatbuffers
PROTO_INC_DIR = inc/flatbuf_autogen
PROTO_SRC_DIR = src/flatbuf_autogen
PROTO_STAMP = $(BUILD_DIR)/.proto_stamp
PY_PROTO_DIR = hmmmm_scripts/flatbuf_autogen
PY_PROTO_STAMP = $(BUILD_DIR)/.py_proto_stamp
FBS_SOURCES := $(shell find $(FBS_DIR) -name '*.fbs')
DEFINES=#-DOPCODE_WORDSIZE=2 -DMEM_CELL_WORDS=1 -DPC_WORDSIZE=2 -DGP_REG_CELL_WORDS=1 -DIO_REG_CELL_WORDS=1
C_SOURCES := $(shell find $(SRC_DIR) -type f -name '*.c')
C_INCLUDES=-I$(INC_DIR)/ $(addprefix -I,$(LIBS_HEADERS))
C_DEFS=-D_POSIX_C_SOURCE=199309L
DISABLE_FLAGS=-Wno-unused-variable -Wno-unused-parameter -Wno-write-strings -Wno-pointer-arith -Wno-analyzer-infinite-loop
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 -fdiagnostics-show-option -fdiagnostics-color=always
LSECTIONS=-ffunction-sections -fdata-sections -Wl,--gc-sections
CFLAGS=$(C_DEFS) -g $(C_INCLUDES) $(SYSTEM_INCLUDES) $(DEFINES) $(OPTIMIZE) --std=$(STANDART) $(PEDANTIC_FLAGS) $(ANALYZER_FLAGS) -MMD -MP # -fno-omit-frame-pointer -fno-inline -fno-lto
STATICLIBS_FLAGS=$(addprefix -l,$(STATIC_LIBS))
# LFLAGS=$(OPTIMIZE) -g $(PEDANTIC_FLAGS) $(DEFINES) $(STATICLIBS_FLAGS) $(LSECTIONS) -lm -fno-omit-frame-pointer -fno-inline -fno-lto
LFLAGS=$(OPTIMIZE) -g $(PEDANTIC_FLAGS) $(DEFINES) $(STATICLIBS_FLAGS) -flto -fuse-linker-plugin $(LSECTIONS) -lm -fno-omit-frame-pointer -fno-inline
OBJECTS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(C_SOURCES))
DEP = $(filter %.d, $(OBJECTS:.o=.d))
$(info $(DEP))
OBJECTS += $(LIBS)
vpath %.c $(sort $(dir $(C_SOURCES)))
all: build
build: date deps Dir proto target compile_commands
rebuild: clean | build
$(info $(DEP))
-include $(DEP)
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
@echo -e '\033[1;32mCC\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 proto $(BUILD_DIR)/$(TARGET).elf
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS)
@echo -e '\033[1;32mELF\t'$(OBJECTS)'\n\t\t\t->\t'$@'\033[0m'
@$(CC) $(LFLAGS) $(OBJECTS) $(LDLIBS) -o $(BUILD_DIR)/$(TARGET).elf
deps:
@make -C deps all
proto: $(PROTO_STAMP)
$(PROTO_STAMP): $(FBS_SOURCES) | ProtoDir BuildDir
@echo -e '\033[1;32mFLATCC\tGenerating FlatBuffers headers\033[0m'
@for fbs in $(FBS_SOURCES); do \
echo -e '\033[1;32mFLATCC\t'$$fbs'\033[0m'; \
$(FLATCC) -a -I $(FBS_DIR) -o $(PROTO_INC_DIR) $$fbs || exit 1; \
done
@touch $@
BuildDir:
@mkdir -p $(BUILD_DIR)
$(shell mkdir -p $(dir $(OBJECTS)))
SrcDir:
@mkdir -p $(SRC_DIR)
IncDir:
@mkdir -p $(INC_DIR)
ProtoDir:
@mkdir -p $(PROTO_INC_DIR)
@mkdir -p $(PROTO_SRC_DIR)
Dir: BuildDir SrcDir IncDir ProtoDir
python-proto: $(PY_PROTO_STAMP)
$(PY_PROTO_STAMP): $(FBS_SOURCES) $(FLATC) | $(PY_PROTO_DIR) BuildDir
@echo -e '\033[1;32mFLATC\tGenerating Python FlatBuffers bindings\033[0m'
@$(FLATC) --python --gen-all -I $(FBS_DIR) -o $(PY_PROTO_DIR) $(FBS_DIR)/proto.fbs
@touch $@
$(PY_PROTO_DIR):
@mkdir -p $@
$(FLATC):
@$(MAKE) -C deps flatbuffers/build/flatc
.PHONY: clean deps proto python-proto
clean:
@rm -rf $(BUILD_DIR)/* $(BUILD_DIR)/.* $(PROTO_INC_DIR)/* $(PROTO_SRC_DIR)/*
# @rm -f compile_commands.json
@echo -e '\033[0;31mCleaned\033[0m'
.NOTPARALLEL: date target rebuild deps proto
date:
@echo -e '\033[1;32m'"Starting build at " | tr -d '\n'
@date
@echo -e '\033[0m'
compile_commands:
# @bear -- ./.gen_compile_commands.sh $(TARGET) $(CC) "$(CFLAGS)" "$(LFLAGS)" "$(OBJECTS)"