-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
60 lines (42 loc) · 1.08 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
# author : Prajwal Chapagain ([email protected])
# created at : Tuesday Jul 20, 2021 13:00:19 NPT
# license : MIT
DEBUG=0
STD=-std=c99
WARN=-Wall -Wextra -Wpedantic \
-Wformat=2 -Wshadow \
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition \
-Wredundant-decls -Wnested-externs -Wmissing-include-dirs
OPTIMIZE=-O2
DEBUG_FLAGS=-g
CC=clang
CFLAGS=$(STD) -MMD
# GCC warnings that Clang doesn't provide:
ifeq ($(CC),gcc)
WARN += -Wjump-misses-init -Wlogical-op
endif
ifeq ($(DEBUG), 1)
CFLAGS += $(DEBUG_FLAGS) $(WARN) -DDEBUG
else
CFLAGS += $(OPTIMIZE) -DNDEBUG
endif
BIN_DIR=./bin
BUILD_DIR=./build
INCLUDE_DIR=./include
SRC_DIR=./src
ifneq (,$(wildcard $(INCLUDE_DIR)))
CFLAGS += -I$(INCLUDE_DIR)
endif
SRCS=$(wildcard $(SRC_DIR)/*.c)
OBJS=$(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS))
DEPS=$(patsubst %.o, %.d, $(OBJS))
TARGET=server
LIBS=-lm
$(BIN_DIR)/$(TARGET): $(OBJS)
$(CC) -o $@ $^ $(LIBS)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
-include ($(DEPS))
.PHONY: clean
clean:
$(RM) $(BIN_DIR)/* $(BUILD_DIR)/*