Compare commits
2 Commits
195eb9eb48
...
0e39ce3618
Author | SHA1 | Date |
---|---|---|
Jef Roosens | 0e39ce3618 | |
Jef Roosens | 5ff788c108 |
66
Makefile
66
Makefile
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
-include config.mk
|
-include config.mk
|
||||||
|
|
||||||
LIB := $(BUILD_DIR)/$(LIB_FILENAME)
|
LIB_ARCHIVE := $(BUILD_DIR)/lib$(LIB).a
|
||||||
|
|
||||||
SRCS != find '$(SRC_DIR)' -iname '*.c'
|
SRCS != find '$(SRC_DIR)' -iname '*.c'
|
||||||
SRCS_H != find include -iname '*.h'
|
SRCS_H != find include -iname '*.h'
|
||||||
|
@ -17,54 +17,38 @@ OBJS_EXAMPLE := $(SRCS_EXAMPLE:%=$(BUILD_DIR)/%.o)
|
||||||
|
|
||||||
DEPS := $(SRCS:%=$(BUILD_DIR)/%.d) $(SRCS_TEST:%=$(BUILD_DIR)/%.d)
|
DEPS := $(SRCS:%=$(BUILD_DIR)/%.d) $(SRCS_TEST:%=$(BUILD_DIR)/%.d)
|
||||||
|
|
||||||
BINS_TEST := $(OBJS_TEST:%.c.o=%)
|
BIN_TEST := $(BUILD_DIR)/$(TEST_DIR)/runner
|
||||||
BINS_EXAMPLE := $(OBJS_EXAMPLE:%.c.o=%)
|
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
|
_CFLAGS := $(addprefix -I,$(INC_DIRS)) $(CFLAGS) -Wall -Wextra
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
all: lib
|
|
||||||
|
|
||||||
|
|
||||||
# =====COMPILATION=====
|
# =====COMPILATION=====
|
||||||
# Utility used by the CI to lint
|
# Utility used by the CI to lint
|
||||||
|
.PHONY: lib
|
||||||
|
$(LIB_ARCHIVE): $(OBJS)
|
||||||
|
ar -rcs $@ $^
|
||||||
|
|
||||||
.PHONY: objs
|
.PHONY: objs
|
||||||
objs: $(OBJS)
|
objs: $(OBJS)
|
||||||
|
|
||||||
.PHONY: lib
|
|
||||||
lib: $(LIB)
|
|
||||||
$(LIB): $(OBJS)
|
|
||||||
ar -rcs $@ $(OBJS)
|
|
||||||
|
|
||||||
$(BUILD_DIR)/$(SRC_DIR)/%.c.o: $(SRC_DIR)/%.c
|
$(BUILD_DIR)/$(SRC_DIR)/%.c.o: $(SRC_DIR)/%.c
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
$(CC) -c $(_CFLAGS) $< -o $@
|
$(CC) -c $(_CFLAGS) $< -o $@
|
||||||
|
|
||||||
# =====TESTING=====
|
# =====TESTING=====
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: $(TARGETS_TEST)
|
test: $(BIN_TEST)
|
||||||
|
'./$^'
|
||||||
|
|
||||||
.PHONY: test-mem
|
.PHONY: test-mem
|
||||||
test-mem: $(TARGETS_MEM_TEST)
|
test-mem: $(BIN_TEST)
|
||||||
|
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes --leak-check=full './$^'
|
||||||
.PHONY: $(TARGETS_TEST)
|
|
||||||
$(TARGETS_TEST): test-%: %
|
|
||||||
./$^
|
|
||||||
|
|
||||||
.PHONY: $(TARGETS_MEM_TEST)
|
|
||||||
$(TARGETS_MEM_TEST): test-mem-%: %
|
|
||||||
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes --leak-check=full ./$^
|
|
||||||
|
|
||||||
.PHONY: build-test
|
.PHONY: build-test
|
||||||
build-test: $(BINS_TEST)
|
build-test: $(BIN_TEST)
|
||||||
|
|
||||||
$(BINS_TEST): %: %.c.o $(LIB)
|
$(BIN_TEST): $(OBJS_TEST) $(LIB_ARCHIVE)
|
||||||
$(CC) \
|
$(CC) -o $@ $^ $(_LDFLAGS)
|
||||||
$^ -o $@
|
|
||||||
|
|
||||||
# Along with the include directory, each test includes $(TEST_DIR) (which
|
# Along with the include directory, each test includes $(TEST_DIR) (which
|
||||||
# contains the acutest.h header file), and the src directory of the module it's
|
# contains the acutest.h header file), and the src directory of the module it's
|
||||||
|
@ -80,7 +64,7 @@ $(BUILD_DIR)/$(TEST_DIR)/%.c.o: $(TEST_DIR)/%.c
|
||||||
.PHONY: build-example
|
.PHONY: build-example
|
||||||
build-example: $(BINS_EXAMPLE)
|
build-example: $(BINS_EXAMPLE)
|
||||||
|
|
||||||
$(BINS_EXAMPLE): %: %.c.o $(LIB)
|
$(BINS_EXAMPLE): %: %.c.o $(LIB_ARCHIVE)
|
||||||
$(CC) $(LDFLAGS) \
|
$(CC) $(LDFLAGS) \
|
||||||
$^ -o $@
|
$^ -o $@
|
||||||
|
|
||||||
|
@ -92,22 +76,22 @@ $(BUILD_DIR)/$(EXAMPLE_DIR)/%.c.o: $(EXAMPLE_DIR)/%.c
|
||||||
# =====MAINTENANCE=====
|
# =====MAINTENANCE=====
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint:
|
lint:
|
||||||
clang-format -n --Werror \
|
@ clang-format -n --Werror \
|
||||||
$(filter-out $(THIRDPARTY),$(SRCS)) \
|
$(shell find '$(SRC_DIR)/$(LIB)' -iname '*.c') \
|
||||||
$(filter-out $(THIRDPARTY),$(SRCS_H)) \
|
$(shell find '$(SRC_DIR)/_include/$(LIB)' -iname '*.h') \
|
||||||
$(filter-out $(THIRDPARTY),$(SRCS_H_INTERNAL))
|
$(shell find 'include/$(LIB)' -iname '*.h')
|
||||||
|
|
||||||
.PHONY: fmt
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
clang-format -i \
|
@ clang-format -i \
|
||||||
$(filter-out $(THIRDPARTY),$(SRCS)) \
|
$(shell find '$(SRC_DIR)/$(LIB)' -iname '*.c') \
|
||||||
$(filter-out $(THIRDPARTY),$(SRCS_H)) \
|
$(shell find '$(SRC_DIR)/_include/$(LIB)' -iname '*.h') \
|
||||||
$(filter-out $(THIRDPARTY),$(SRCS_H_INTERNAL))
|
$(shell find 'include/$(LIB)' -iname '*.h')
|
||||||
|
|
||||||
.PHONY: check
|
.PHONY: check
|
||||||
check:
|
check:
|
||||||
mkdir -p $(BUILD_DIR)/cppcheck
|
@ mkdir -p $(BUILD_DIR)/cppcheck
|
||||||
cppcheck \
|
@ cppcheck \
|
||||||
$(addprefix -I,$(INC_DIRS)) \
|
$(addprefix -I,$(INC_DIRS)) \
|
||||||
--cppcheck-build-dir=$(BUILD_DIR)/cppcheck \
|
--cppcheck-build-dir=$(BUILD_DIR)/cppcheck \
|
||||||
--error-exitcode=1 \
|
--error-exitcode=1 \
|
||||||
|
@ -116,7 +100,7 @@ check:
|
||||||
--check-level=exhaustive \
|
--check-level=exhaustive \
|
||||||
--quiet \
|
--quiet \
|
||||||
-j$(shell nproc) \
|
-j$(shell nproc) \
|
||||||
$(filter-out $(THIRDPARTY),$(SRCS))
|
$(shell find '$(SRC_DIR)/$(LIB)' -iname '*.c')
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
LIB_FILENAME = liblnm.a
|
LIB = lnm
|
||||||
|
|
||||||
BUILD_DIR = build
|
BUILD_DIR = build
|
||||||
SRC_DIR = src
|
SRC_DIR = src
|
||||||
TEST_DIR = test
|
TEST_DIR = test
|
||||||
EXAMPLE_DIR = example
|
EXAMPLE_DIR = example
|
||||||
THIRDPARTY = src/picohttpparser.c include/picohttpparser.h
|
|
||||||
|
|
||||||
PUB_INC_DIR = include
|
PUB_INC_DIR = include
|
||||||
INC_DIRS = $(PUB_INC_DIR) src/_include
|
INC_DIRS = $(PUB_INC_DIR) src/_include
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,9 @@
|
||||||
|
#define TEST_NO_MAIN
|
||||||
|
#include "acutest.h"
|
||||||
|
#include "tests.h"
|
||||||
|
|
||||||
#include "lnm/common.h"
|
#include "lnm/common.h"
|
||||||
#include "lnm/http/route.h"
|
#include "lnm/http/route.h"
|
||||||
#include "test.h"
|
|
||||||
|
|
||||||
#include "lnm/http/loop.h"
|
|
||||||
|
|
||||||
void test_routing_simple() {
|
void test_routing_simple() {
|
||||||
lnm_http_router *router;
|
lnm_http_router *router;
|
||||||
|
@ -101,11 +102,3 @@ void test_routing_nest() {
|
||||||
|
|
||||||
lnm_http_router_free(r2);
|
lnm_http_router_free(r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_LIST = {
|
|
||||||
{ "routing simple", test_routing_simple },
|
|
||||||
{ "routing star", test_routing_star },
|
|
||||||
{ "routing merge", test_routing_merge },
|
|
||||||
{ "routing nest", test_routing_nest },
|
|
||||||
{ NULL, NULL }
|
|
||||||
};
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include "acutest.h"
|
||||||
|
#include "tests.h"
|
||||||
|
|
||||||
|
TEST_LIST = {
|
||||||
|
{ "routing simple", test_routing_simple },
|
||||||
|
{ "routing star", test_routing_star },
|
||||||
|
{ "routing merge", test_routing_merge },
|
||||||
|
{ "routing nest", test_routing_nest },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef TEST_TESTS
|
||||||
|
#define TEST_TESTS
|
||||||
|
|
||||||
|
void test_routing_simple();
|
||||||
|
void test_routing_star();
|
||||||
|
void test_routing_merge();
|
||||||
|
void test_routing_nest();
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue