libvieter/Makefile

52 lines
1.1 KiB
Makefile
Raw Normal View History

2023-01-18 11:29:16 +01:00
LIB_FILENAME ?= libvieter.a
BUILD_DIR ?= build
SRC_DIR ?= src
INC_DIRS ?= include
SRCS != find '$(SRC_DIR)' -iname '*.c'
SRCS_H != find $(INC_DIRS) -iname '*.h'
2023-01-18 11:29:16 +01:00
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 $@
# =====MAINTENANCE=====
.PHONY: lint
lint:
clang-format -n --Werror $(SRCS) $(SRCS_H)
.PHONY: fmt
fmt:
clang-format -i $(SRCS) $(SRCS_H)
2023-01-18 11:29:16 +01:00
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
# Make make aware of the .d files
-include $(DEPS)