From 4d72e6051505da84dba686403381df6a6de4c3e5 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Wed, 18 Jan 2023 11:29:16 +0100 Subject: [PATCH] chore: added makefile --- .gitignore | 2 + Makefile | 41 +++++++++++++++++++ .../expression.h => include/vieter_cron.h | 0 src/cron/expression.c | 2 +- src/cron/parse.c | 2 +- 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile rename src/cron/expression.h => include/vieter_cron.h (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6654b8d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +compile_commands.json diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4783d2e --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +LIB_FILENAME ?= libvieter.a + +BUILD_DIR ?= build +SRC_DIR ?= src +INC_DIRS ?= include + +SRCS != find '$(SRC_DIR)' -iname '*.c' +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) +DEPS := $(SRCS:%=$(BUILD_DIR)/%.d) + +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) + +# -MMD: generate a .d file for every source file. This file can be imported by +# make and makes make aware that a header file has been changed, ensuring an +# object file is also recompiled if only a header is changed. +# -MP: generate a dummy target for every header file (according to the docs it +# prevents some errors when removing header files) +CFLAGS ?= $(INC_FLAGS) -O3 -MMD -MP -Wall -Werror -Wextra + +.PHONY: all +all: vieter + + +# =====COMPILATION===== +.PHONY: vieter +vieter: $(BUILD_DIR)/$(LIB_FILENAME) +$(BUILD_DIR)/$(LIB_FILENAME): $(OBJS) + ar -rcs $@ $(OBJS) + +$(BUILD_DIR)/%.c.o: %.c + mkdir -p $(dir $@) + $(CC) $(CFLAGS) -c $< -o $@ + + +.PHONY: clean +clean: + rm -rf $(BUILD_DIR) + + +# Make make aware of the .d files +-include $(DEPS) diff --git a/src/cron/expression.h b/include/vieter_cron.h similarity index 100% rename from src/cron/expression.h rename to include/vieter_cron.h diff --git a/src/cron/expression.c b/src/cron/expression.c index 7d27be6..f7660d5 100644 --- a/src/cron/expression.c +++ b/src/cron/expression.c @@ -1,4 +1,4 @@ -#include "expression.h" +#include "vieter_cron.h" #include const uint8_t month_days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; diff --git a/src/cron/parse.c b/src/cron/parse.c index 6a8bdc1..da5bcfe 100644 --- a/src/cron/parse.c +++ b/src/cron/parse.c @@ -1,4 +1,4 @@ -#include "expression.h" +#include "vieter_cron.h" // This prefix is needed to properly compile const uint8_t parse_month_days[] = {31, 28, 31, 30, 31, 30,