42 lines
978 B
Makefile
42 lines
978 B
Makefile
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)
|