-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
95 lines (70 loc) · 1.67 KB
/
Makefile
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
.POSIX:
BUILD_DIR := .build
OUT := hello
CC := gcc
CFLAGS := -pedantic
CFLAGS += -pipe
CFLAGS += -O2 -march=native -mtune=native
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -Wall
CFLAGS += -Wcast-qual
CFLAGS += -Wconversion
CFLAGS += -Werror=return-type
CFLAGS += -Werror=vla-larger-than=0
CFLAGS += -Wextra
CFLAGS += -Wmissing-prototypes
CFLAGS += -Wshadow
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wwrite-strings
CFLAGS += -iquote src
LDFLAGS := -fwhole-program -flto
LDFLAGS += -Wl,--gc-sections
LDLIBS += -lc
VPATH += src
SRC := main.c
vpath %.c $(VPATH)
OBJ := $(SRC:%.c=$(BUILD_DIR)/release/%.o)
.PHONY: all
all: $(OUT)
$(OUT): $(OBJ)
@ mkdir -p $(dir $@)
$Q $(CC) -o $@ $(OBJ) $(CFLAGS) $(LDLIBS) $(LDFLAGS)
@ $(LOG_TIME) "LD $(C_GREEN) $@ $(C_RESET)"
$(BUILD_DIR)/release/%.o: %.c
@ mkdir -p $(dir $@)
$Q $(CC) $(CFLAGS) -o $@ -c $< || exit 1
@ $(LOG_TIME) "CC $(C_PURPLE) $(notdir $@) $(C_RESET)"
.PHONY: clean
clean:
$(RM) $(OBJ)
@ $(LOG_TIME) $@
.PHONY: fclean
fclean: clean
$(RM) -r $(BUILD_DIR) $(OUT)
@ $(LOG_TIME) $@
.PHONY: re
.NOTPARALLEL: re
re: fclean all
ifneq ($(shell command -v tput),)
ifneq ($(shell tput colors),0)
C_RESET := \033[00m
C_BOLD := \e[1m
C_RED := \e[31m
C_GREEN := \e[32m
C_YELLOW := \e[33m
C_BLUE := \e[34m
C_PURPLE := \e[35m
C_CYAN := \e[36m
C_BEGIN := \033[A
endif
endif
NOW = $(shell date +%s%3N)
STIME := $(call NOW)
TIME_NS = $(shell expr $(call NOW) - $(STIME))
TIME_MS = $(shell expr $(call TIME_NS))
BOXIFY = "[$(C_BLUE)$(1)$(C_RESET)] $(2)"
ifneq ($(shell command -v printf),)
LOG_TIME = printf $(call BOXIFY, %6s , %b\n) "$(call TIME_MS)"
else
LOG_TIME = echo -e $(call BOXIFY, $(call TIME_MS) ,)
endif