147 lines
6.1 KiB
Makefile
147 lines
6.1 KiB
Makefile
OPENSSL_INCLUDE ?= /usr/include/openssl/
|
|
BUILD_DIR=out
|
|
SRC_DIR=src
|
|
INC_DIR=inc
|
|
CC=gcc
|
|
OBJDUMP=objdump
|
|
LIBS=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=-Og #3 -march=native
|
|
OPTIMIZE=-O3 -march=native
|
|
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 -Wno-unused-function -Wno-unused-but-set-variable
|
|
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 -pthread $(C_INCLUDES) $(SYSTEM_INCLUDES) $(DEFINES) $(OPTIMIZE) --std=$(STANDART) $(PEDANTIC_FLAGS) $(ANALYZER_FLAGS) -MMD -MP -fprofile-use # -fprofile-generate -fprofile-arcs -ftest-coverage # -fno-omit-frame-pointer -fno-inline -fno-lto # -fprofile-use # -fprofile-generate -fprofile-arcs -ftest-coverage # -fno-omit-frame-pointer -fno-inline -fno-lto # -fprofile-use # -fprofile-generate -fprofile-arcs -ftest-coverage # -fno-omit-frame-pointer -fno-inline # -fno-omit-frame-pointer -fno-inline -fno-lto
|
|
CFLAGS=$(C_DEFS) -g -pthread $(C_INCLUDES) $(SYSTEM_INCLUDES) $(DEFINES) $(OPTIMIZE) --std=$(STANDART) $(PEDANTIC_FLAGS) $(ANALYZER_FLAGS) -MMD -MP # -fprofile-generate -fprofile-arcs -ftest-coverage # -fno-omit-frame-pointer -fno-inline -fno-lto # -fprofile-use # -fprofile-generate -fprofile-arcs -ftest-coverage # -fno-omit-frame-pointer -fno-inline -fno-lto # -fprofile-use # -fprofile-generate -fprofile-arcs -ftest-coverage # -fno-omit-frame-pointer -fno-inline # -fno-omit-frame-pointer -fno-inline -fno-lto
|
|
STATICLIBS_FLAGS=$(addprefix -l,$(STATIC_LIBS))
|
|
# LFLAGS=$(OPTIMIZE) -g -pthread $(PEDANTIC_FLAGS) $(DEFINES) $(STATICLIBS_FLAGS) $(LSECTIONS) -lm -fno-omit-frame-pointer -fno-inline -fno-lto
|
|
# LFLAGS=$(OPTIMIZE) -g -pthread $(PEDANTIC_FLAGS) $(DEFINES) $(STATICLIBS_FLAGS) -fuse-linker-plugin $(LSECTIONS) -lm -fprofile-use # -fprofile-generate -fprofile-arcs -ftest-coverage # -fno-omit-frame-pointer -fno-inline -fno-lto # -fprofile-use # -fprofile-generate -fprofile-arcs -ftest-coverage # -fno-omit-frame-pointer -fno-inline -fno-lto # -fno-omit-frame-pointer -fno-inline -flto -lgcov # -fno-omit-frame-pointer -fno-inline # #-fprofile-generate # -flto
|
|
LFLAGS=$(OPTIMIZE) -g -pthread $(PEDANTIC_FLAGS) $(DEFINES) $(STATICLIBS_FLAGS) -fuse-linker-plugin $(LSECTIONS) -lm # -fprofile-generate -fprofile-arcs -ftest-coverage # -fno-omit-frame-pointer -fno-inline -fno-lto # -fprofile-use # -fprofile-generate -fprofile-arcs -ftest-coverage # -fno-omit-frame-pointer -fno-inline -fno-lto # -fno-omit-frame-pointer -fno-inline -flto -lgcov # -fno-omit-frame-pointer -fno-inline # #-fprofile-generate # -flto
|
|
|
|
|
|
|
|
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)))
|
|
|
|
# asan: CFLAGS := $(filter-out -fanalyzer,$(CFLAGS)) -fsanitize=address,undefined
|
|
# asan: LFLAGS := $(filter-out -flto -fuse-linker-plugin,$(LFLAGS)) -fsanitize=address,undefined
|
|
# asan: build
|
|
|
|
# tsan: CFLAGS := $(filter-out -fanalyzer,$(CFLAGS)) -fsanitize=thread
|
|
# tsan: LFLAGS := $(filter-out -flto -fuse-linker-plugin,$(LFLAGS)) -fsanitize=thread
|
|
# tsan: build
|
|
|
|
|
|
all: build
|
|
|
|
build: date deps Dir proto python-proto target
|
|
|
|
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 asan tsan clean
|
|
|
|
clean:
|
|
@rm -rf $(BUILD_DIR)/* $(BUILD_DIR)/.* $(PROTO_INC_DIR)/* $(PROTO_SRC_DIR)/*
|
|
@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'
|
|
|