-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (46 loc) · 3.29 KB
/
Makefile
File metadata and controls
70 lines (46 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# **************************************************************************** #
# #
# Makefile – libpnglode #
# #
# PNG encoder / decoder library #
# #
# **************************************************************************** #
NAME := libpnglode.a
# ── Directories ──────────────────────────────────────────────────────────── #
BUILD_DIR := build
OBJ_DIR := $(BUILD_DIR)/obj
DEP_DIR := $(BUILD_DIR)/deps
LIB_DIR := $(BUILD_DIR)/lib
# ── Toolchain ────────────────────────────────────────────────────────────── #
CC := cc
AR := gcc-ar
ARFLAGS := rcs
CFLAGS := -std=c99 -O3 -march=native -fno-math-errno -flto \
-DNDEBUG -pipe \
-D_POSIX_C_SOURCE=200809L \
-Wall -Wextra -Werror
INCLUDES := -I .
# ── Sources ──────────────────────────────────────────────────────────────── #
SRCS := $(wildcard ./*.c)
OBJS := $(SRCS:./%.c=$(OBJ_DIR)/%.o)
DEPS := $(OBJS:$(OBJ_DIR)/%.o=$(DEP_DIR)/%.d)
# ── Phony targets ────────────────────────────────────────────────────────── #
.PHONY: all clean fclean re
all: $(LIB_DIR)/$(NAME)
# ── Directory creation ───────────────────────────────────────────────────── #
$(OBJ_DIR) $(DEP_DIR) $(LIB_DIR):
@mkdir -p $@
# ── Compile ──────────────────────────────────────────────────────────────── #
$(OBJ_DIR)/%.o: ./%.c | $(OBJ_DIR) $(DEP_DIR)
@$(CC) $(CFLAGS) $(INCLUDES) -MMD -MP -MF $(DEP_DIR)/$*.d -c $< -o $@
# ── Archive ──────────────────────────────────────────────────────────────── #
$(LIB_DIR)/$(NAME): $(OBJS) | $(LIB_DIR)
@printf "\033[35m[png_writer]\033[0m libpnglode.a\n"
@$(AR) $(ARFLAGS) $@ $?
# ── House-keeping ────────────────────────────────────────────────────────── #
clean:
@rm -rf $(BUILD_DIR)
fclean: clean
re: fclean all
# ── Auto-dependency inclusion ────────────────────────────────────────────── #
-include $(wildcard $(DEP_DIR)/*.d)