From 0e39ce3618f2fe0bf39b09652de45a45e7440165 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 30 Mar 2024 11:46:49 +0100 Subject: [PATCH] chore: refactor repository for cleaner development --- Makefile | 45 +++++++++------------- config.mk | 3 +- {include => src/_include}/picohttpparser.h | 0 src/{ => lnm}/http/lnm_http_consts.c | 0 src/{ => lnm}/http/lnm_http_loop.c | 0 src/{ => lnm}/http/lnm_http_loop_ctx.c | 0 src/{ => lnm}/http/lnm_http_loop_process.c | 0 src/{ => lnm}/http/lnm_http_loop_steps.c | 0 src/{ => lnm}/http/lnm_http_req.c | 0 src/{ => lnm}/http/lnm_http_res.c | 0 src/{ => lnm}/http/lnm_http_route.c | 0 src/{ => lnm}/http/lnm_http_router.c | 0 src/{ => lnm}/lnm_log.c | 0 src/{ => lnm}/lnm_utils.c | 0 src/{ => lnm}/loop/lnm_loop.c | 0 src/{ => lnm}/loop/lnm_loop_conn.c | 0 src/{ => lnm}/loop/lnm_loop_io.c | 0 src/{ => lnm}/loop/lnm_loop_worker.c | 0 18 files changed, 19 insertions(+), 29 deletions(-) rename {include => src/_include}/picohttpparser.h (100%) rename src/{ => lnm}/http/lnm_http_consts.c (100%) rename src/{ => lnm}/http/lnm_http_loop.c (100%) rename src/{ => lnm}/http/lnm_http_loop_ctx.c (100%) rename src/{ => lnm}/http/lnm_http_loop_process.c (100%) rename src/{ => lnm}/http/lnm_http_loop_steps.c (100%) rename src/{ => lnm}/http/lnm_http_req.c (100%) rename src/{ => lnm}/http/lnm_http_res.c (100%) rename src/{ => lnm}/http/lnm_http_route.c (100%) rename src/{ => lnm}/http/lnm_http_router.c (100%) rename src/{ => lnm}/lnm_log.c (100%) rename src/{ => lnm}/lnm_utils.c (100%) rename src/{ => lnm}/loop/lnm_loop.c (100%) rename src/{ => lnm}/loop/lnm_loop_conn.c (100%) rename src/{ => lnm}/loop/lnm_loop_io.c (100%) rename src/{ => lnm}/loop/lnm_loop_worker.c (100%) diff --git a/Makefile b/Makefile index 9041b06..914c089 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ -include config.mk -LIB := $(BUILD_DIR)/$(LIB_FILENAME) +LIB_ARCHIVE := $(BUILD_DIR)/lib$(LIB).a SRCS != find '$(SRC_DIR)' -iname '*.c' SRCS_H != find include -iname '*.h' @@ -20,26 +20,17 @@ DEPS := $(SRCS:%=$(BUILD_DIR)/%.d) $(SRCS_TEST:%=$(BUILD_DIR)/%.d) BIN_TEST := $(BUILD_DIR)/$(TEST_DIR)/runner BINS_EXAMPLE := $(OBJS_EXAMPLE:%.c.o=%) -TARGETS_TEST := $(BINS_TEST:%=test-%) -TARGETS_MEM_TEST := $(BINS_TEST:%=test-mem-%) -TARGETS_EXAMPLE := $(BINS_EXAMPLE:%=example-%) - _CFLAGS := $(addprefix -I,$(INC_DIRS)) $(CFLAGS) -Wall -Wextra -.PHONY: all -all: lib - - # =====COMPILATION===== # Utility used by the CI to lint +.PHONY: lib +$(LIB_ARCHIVE): $(OBJS) + ar -rcs $@ $^ + .PHONY: objs objs: $(OBJS) -.PHONY: lib -lib: $(LIB) -$(LIB): $(OBJS) - ar -rcs $@ $(OBJS) - $(BUILD_DIR)/$(SRC_DIR)/%.c.o: $(SRC_DIR)/%.c mkdir -p $(dir $@) $(CC) -c $(_CFLAGS) $< -o $@ @@ -56,7 +47,7 @@ test-mem: $(BIN_TEST) .PHONY: build-test build-test: $(BIN_TEST) -$(BIN_TEST): $(OBJS_TEST) $(LIB) +$(BIN_TEST): $(OBJS_TEST) $(LIB_ARCHIVE) $(CC) -o $@ $^ $(_LDFLAGS) # Along with the include directory, each test includes $(TEST_DIR) (which @@ -73,7 +64,7 @@ $(BUILD_DIR)/$(TEST_DIR)/%.c.o: $(TEST_DIR)/%.c .PHONY: build-example build-example: $(BINS_EXAMPLE) -$(BINS_EXAMPLE): %: %.c.o $(LIB) +$(BINS_EXAMPLE): %: %.c.o $(LIB_ARCHIVE) $(CC) $(LDFLAGS) \ $^ -o $@ @@ -85,22 +76,22 @@ $(BUILD_DIR)/$(EXAMPLE_DIR)/%.c.o: $(EXAMPLE_DIR)/%.c # =====MAINTENANCE===== .PHONY: lint lint: - clang-format -n --Werror \ - $(filter-out $(THIRDPARTY),$(SRCS)) \ - $(filter-out $(THIRDPARTY),$(SRCS_H)) \ - $(filter-out $(THIRDPARTY),$(SRCS_H_INTERNAL)) + @ clang-format -n --Werror \ + $(shell find '$(SRC_DIR)/$(LIB)' -iname '*.c') \ + $(shell find '$(SRC_DIR)/_include/$(LIB)' -iname '*.h') \ + $(shell find 'include/$(LIB)' -iname '*.h') .PHONY: fmt fmt: - clang-format -i \ - $(filter-out $(THIRDPARTY),$(SRCS)) \ - $(filter-out $(THIRDPARTY),$(SRCS_H)) \ - $(filter-out $(THIRDPARTY),$(SRCS_H_INTERNAL)) + @ clang-format -i \ + $(shell find '$(SRC_DIR)/$(LIB)' -iname '*.c') \ + $(shell find '$(SRC_DIR)/_include/$(LIB)' -iname '*.h') \ + $(shell find 'include/$(LIB)' -iname '*.h') .PHONY: check check: - mkdir -p $(BUILD_DIR)/cppcheck - cppcheck \ + @ mkdir -p $(BUILD_DIR)/cppcheck + @ cppcheck \ $(addprefix -I,$(INC_DIRS)) \ --cppcheck-build-dir=$(BUILD_DIR)/cppcheck \ --error-exitcode=1 \ @@ -109,7 +100,7 @@ check: --check-level=exhaustive \ --quiet \ -j$(shell nproc) \ - $(filter-out $(THIRDPARTY),$(SRCS)) + $(shell find '$(SRC_DIR)/$(LIB)' -iname '*.c') .PHONY: clean clean: diff --git a/config.mk b/config.mk index 4345382..96d73b9 100644 --- a/config.mk +++ b/config.mk @@ -1,10 +1,9 @@ -LIB_FILENAME = liblnm.a +LIB = lnm BUILD_DIR = build SRC_DIR = src TEST_DIR = test EXAMPLE_DIR = example -THIRDPARTY = src/picohttpparser.c include/picohttpparser.h PUB_INC_DIR = include INC_DIRS = $(PUB_INC_DIR) src/_include diff --git a/include/picohttpparser.h b/src/_include/picohttpparser.h similarity index 100% rename from include/picohttpparser.h rename to src/_include/picohttpparser.h diff --git a/src/http/lnm_http_consts.c b/src/lnm/http/lnm_http_consts.c similarity index 100% rename from src/http/lnm_http_consts.c rename to src/lnm/http/lnm_http_consts.c diff --git a/src/http/lnm_http_loop.c b/src/lnm/http/lnm_http_loop.c similarity index 100% rename from src/http/lnm_http_loop.c rename to src/lnm/http/lnm_http_loop.c diff --git a/src/http/lnm_http_loop_ctx.c b/src/lnm/http/lnm_http_loop_ctx.c similarity index 100% rename from src/http/lnm_http_loop_ctx.c rename to src/lnm/http/lnm_http_loop_ctx.c diff --git a/src/http/lnm_http_loop_process.c b/src/lnm/http/lnm_http_loop_process.c similarity index 100% rename from src/http/lnm_http_loop_process.c rename to src/lnm/http/lnm_http_loop_process.c diff --git a/src/http/lnm_http_loop_steps.c b/src/lnm/http/lnm_http_loop_steps.c similarity index 100% rename from src/http/lnm_http_loop_steps.c rename to src/lnm/http/lnm_http_loop_steps.c diff --git a/src/http/lnm_http_req.c b/src/lnm/http/lnm_http_req.c similarity index 100% rename from src/http/lnm_http_req.c rename to src/lnm/http/lnm_http_req.c diff --git a/src/http/lnm_http_res.c b/src/lnm/http/lnm_http_res.c similarity index 100% rename from src/http/lnm_http_res.c rename to src/lnm/http/lnm_http_res.c diff --git a/src/http/lnm_http_route.c b/src/lnm/http/lnm_http_route.c similarity index 100% rename from src/http/lnm_http_route.c rename to src/lnm/http/lnm_http_route.c diff --git a/src/http/lnm_http_router.c b/src/lnm/http/lnm_http_router.c similarity index 100% rename from src/http/lnm_http_router.c rename to src/lnm/http/lnm_http_router.c diff --git a/src/lnm_log.c b/src/lnm/lnm_log.c similarity index 100% rename from src/lnm_log.c rename to src/lnm/lnm_log.c diff --git a/src/lnm_utils.c b/src/lnm/lnm_utils.c similarity index 100% rename from src/lnm_utils.c rename to src/lnm/lnm_utils.c diff --git a/src/loop/lnm_loop.c b/src/lnm/loop/lnm_loop.c similarity index 100% rename from src/loop/lnm_loop.c rename to src/lnm/loop/lnm_loop.c diff --git a/src/loop/lnm_loop_conn.c b/src/lnm/loop/lnm_loop_conn.c similarity index 100% rename from src/loop/lnm_loop_conn.c rename to src/lnm/loop/lnm_loop_conn.c diff --git a/src/loop/lnm_loop_io.c b/src/lnm/loop/lnm_loop_io.c similarity index 100% rename from src/loop/lnm_loop_io.c rename to src/lnm/loop/lnm_loop_io.c diff --git a/src/loop/lnm_loop_worker.c b/src/lnm/loop/lnm_loop_worker.c similarity index 100% rename from src/loop/lnm_loop_worker.c rename to src/lnm/loop/lnm_loop_worker.c