2023-05-24 09:03:22 +02:00
|
|
|
# https://spin.atomicobject.com/2016/08/26/makefile-c-projects/ was a great
|
|
|
|
# base for this Makefile
|
2022-11-15 16:05:47 +01:00
|
|
|
|
2023-07-28 21:08:48 +02:00
|
|
|
-include config.mk
|
2023-05-29 14:48:50 +02:00
|
|
|
|
2023-07-28 21:08:48 +02:00
|
|
|
export CFLAGS
|
|
|
|
export LDFLAGS
|
2022-11-15 16:05:47 +01:00
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
BIN := $(BUILD_DIR)/$(BIN_FILENAME)
|
2022-11-15 16:05:47 +01:00
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
SRCS != find '$(SRC_DIR)' -iname '*.c'
|
|
|
|
SRCS_TEST != find '$(TEST_DIR)' -iname '*.c'
|
2023-05-24 12:05:09 +02:00
|
|
|
|
|
|
|
SRCS_H != find include -iname '*.h'
|
|
|
|
SRCS_H_INTERNAL != find $(SRC_DIR) -iname '*.h'
|
2022-11-15 16:05:47 +01:00
|
|
|
|
2023-12-07 11:02:20 +01:00
|
|
|
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
|
2023-05-24 09:03:22 +02:00
|
|
|
OBJS_TEST := $(SRCS_TEST:%=$(BUILD_DIR)/%.o)
|
2023-12-07 11:02:20 +01:00
|
|
|
DEPS := $(SRCS:%=$(BUILD_DIR)/%.d) $(SRCS_TEST:%=$(BUILD_DIR)/%.d)
|
2022-11-29 16:25:24 +01:00
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
BINS_TEST := $(OBJS_TEST:%.c.o=%)
|
|
|
|
TARGETS_TEST := $(BINS_TEST:%=test-%)
|
|
|
|
TARGETS_MEM_TEST := $(BINS_TEST:%=test-mem-%)
|
2022-11-15 16:05:47 +01:00
|
|
|
|
2023-07-28 21:08:48 +02:00
|
|
|
_CFLAGS := $(addprefix -I,$(INC_DIRS)) $(CFLAGS) -Wall -Wextra -DLANDER_VERSION=\"$(VERSION)\"
|
2023-07-28 18:48:44 +02:00
|
|
|
_LDFLAGS := $(addprefix -L,$(LIB_DIRS)) $(addprefix -l,$(LIBS)) $(LDFLAGS)
|
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
.PHONY: all
|
2023-07-28 21:08:48 +02:00
|
|
|
all: $(BIN)
|
2022-11-15 16:21:27 +01:00
|
|
|
|
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
# =====COMPILATION=====
|
|
|
|
# Utility used by the CI to lint
|
|
|
|
.PHONY: objs
|
|
|
|
objs: $(OBJS)
|
2022-11-15 16:05:47 +01:00
|
|
|
|
2023-10-25 10:57:45 +02:00
|
|
|
.PHONY: liblsm
|
|
|
|
liblsm:
|
|
|
|
$(MAKE) -C lsm
|
|
|
|
|
2023-12-02 20:22:05 +01:00
|
|
|
.PHONY: liblnm
|
|
|
|
liblnm:
|
|
|
|
$(MAKE) -C lnm
|
|
|
|
|
2023-12-17 17:29:20 +01:00
|
|
|
.PHONY: libltm
|
|
|
|
libltm:
|
|
|
|
$(MAKE) -C ltm
|
|
|
|
|
|
|
|
$(BIN): liblsm liblnm libltm $(OBJS)
|
2023-07-28 18:48:44 +02:00
|
|
|
$(CC) -o $@ $(OBJS) $(_LDFLAGS)
|
2022-12-07 13:29:21 +01:00
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
$(BUILD_DIR)/$(SRC_DIR)/%.c.o: $(SRC_DIR)/%.c
|
|
|
|
mkdir -p $(dir $@)
|
2023-07-28 18:48:44 +02:00
|
|
|
$(CC) $(_CFLAGS) -c $< -o $@
|
2022-11-29 15:08:07 +01:00
|
|
|
|
2023-11-14 10:49:12 +01:00
|
|
|
.PHONY: bin-docker
|
|
|
|
bin-docker:
|
|
|
|
docker build -t lander .
|
|
|
|
docker container create --name lander-temp lander
|
|
|
|
docker cp -q lander-temp:/bin/lander $(BUILD_DIR)/lander-docker
|
|
|
|
docker container rm lander-temp
|
2023-05-24 09:03:22 +02:00
|
|
|
|
|
|
|
# =====TESTING=====
|
2023-07-27 14:09:56 +02:00
|
|
|
.PHONY: run
|
2023-11-02 10:27:34 +01:00
|
|
|
run: $(BIN)
|
2023-07-27 14:09:56 +02:00
|
|
|
LANDER_API_KEY=test \
|
|
|
|
LANDER_DATA_DIR=data \
|
|
|
|
'$(BUILD_DIR)/$(BIN_FILENAME)'
|
|
|
|
|
2023-11-02 10:27:34 +01:00
|
|
|
.PHONY: valgrind
|
|
|
|
valgrind: $(BIN)
|
|
|
|
LANDER_API_KEY=test \
|
|
|
|
LANDER_DATA_DIR=data \
|
2024-03-09 21:01:14 +01:00
|
|
|
valgrind --track-origins=yes --leak-check=full '$(BUILD_DIR)/$(BIN_FILENAME)'
|
2023-11-02 10:27:34 +01:00
|
|
|
|
2022-11-29 16:25:24 +01:00
|
|
|
.PHONY: test
|
2023-05-24 09:03:22 +02:00
|
|
|
test: $(TARGETS_TEST)
|
2022-11-29 16:25:24 +01:00
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
.PHONY: test-mem
|
|
|
|
test-mem: $(TARGETS_MEM_TEST)
|
|
|
|
|
|
|
|
.PHONY: $(TARGETS_TEST)
|
|
|
|
$(TARGETS_TEST): test-%: %
|
|
|
|
./$^
|
2022-11-15 16:05:47 +01:00
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
.PHONY: $(TARGETS_MEM_TEST)
|
|
|
|
$(TARGETS_MEM_TEST): test-mem-%: %
|
|
|
|
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes --leak-check=full ./$^
|
|
|
|
|
|
|
|
.PHONY: build-test
|
|
|
|
build-test: $(BINS_TEST)
|
|
|
|
|
2023-05-29 18:40:36 +02:00
|
|
|
$(BINS_TEST): %: %.c.o
|
2023-05-24 09:03:22 +02:00
|
|
|
$(CC) \
|
|
|
|
$^ -o $@
|
|
|
|
|
|
|
|
# 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
|
|
|
|
# testing. This allows tests to access internal methods, which aren't publicly
|
|
|
|
# exposed.
|
|
|
|
$(BUILD_DIR)/$(TEST_DIR)/%.c.o: $(TEST_DIR)/%.c
|
|
|
|
mkdir -p $(dir $@)
|
2023-07-28 18:48:44 +02:00
|
|
|
$(CC) $(_CFLAGS) -I$(TEST_DIR) \
|
2023-05-24 09:03:22 +02:00
|
|
|
-I$(dir $(@:$(BUILD_DIR)/$(TEST_DIR)/%=$(SRC_DIR)/%)) \
|
|
|
|
-c $< -o $@
|
|
|
|
|
2023-07-28 21:08:48 +02:00
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
# =====MAINTENANCE=====
|
2022-11-15 16:05:47 +01:00
|
|
|
.PHONY: lint
|
|
|
|
lint:
|
2023-05-24 09:03:22 +02:00
|
|
|
clang-format -n --Werror $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL)
|
2023-11-18 21:36:08 +01:00
|
|
|
make -C lsm lint
|
|
|
|
make -C landerctl lint
|
2023-05-24 09:03:22 +02:00
|
|
|
|
|
|
|
.PHONY: fmt
|
|
|
|
fmt:
|
|
|
|
clang-format -i $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL)
|
2023-11-18 21:36:08 +01:00
|
|
|
make -C lsm fmt
|
|
|
|
make -C landerctl fmt
|
2023-05-24 09:03:22 +02:00
|
|
|
|
2023-11-14 10:49:12 +01:00
|
|
|
.PHONY: check
|
|
|
|
check:
|
|
|
|
mkdir -p $(BUILD_DIR)/cppcheck
|
|
|
|
cppcheck \
|
|
|
|
$(addprefix -I,$(INC_DIRS)) \
|
|
|
|
--cppcheck-build-dir=$(BUILD_DIR)/cppcheck \
|
|
|
|
--error-exitcode=1 \
|
|
|
|
--enable=warning,style \
|
2023-11-14 15:34:07 +01:00
|
|
|
--inline-suppr \
|
|
|
|
--check-level=exhaustive \
|
|
|
|
--quiet \
|
2023-11-18 21:36:08 +01:00
|
|
|
-j$(shell nproc) \
|
|
|
|
$(SRCS)
|
|
|
|
make -C lsm check
|
|
|
|
make -C landerctl check
|
2023-11-14 10:49:12 +01:00
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
rm -rf $(BUILD_DIR)
|
2023-10-25 10:57:45 +02:00
|
|
|
$(MAKE) -C lsm clean
|
2023-12-06 23:04:06 +01:00
|
|
|
$(MAKE) -C lnm clean
|
2023-11-18 21:36:08 +01:00
|
|
|
$(MAKE) -C landerctl clean
|
2023-05-24 09:03:22 +02:00
|
|
|
|
|
|
|
.PHONY: bear
|
|
|
|
bear: clean
|
|
|
|
bear -- make
|
|
|
|
bear --append -- make build-test
|
|
|
|
|
2022-11-15 16:05:47 +01:00
|
|
|
|
2023-05-24 09:03:22 +02:00
|
|
|
# Make make aware of the .d files
|
|
|
|
-include $(DEPS)
|