-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
44 lines (35 loc) · 1022 Bytes
/
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
CC := gcc
# Removed -g from CFLAGS
CFLAGS := -Iincludes -Wall -Wextra -Werror -Wpedantic
LDFLAGS := -lpthread -lsqlite3
SRC_DIR := src
BIN_DIR := bin
OBJS_DIR := $(BIN_DIR)/objs
VIEWS_DIR := views
SRC_FILES := $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(OBJS_DIR)/%.o,$(SRC_FILES))
TARGET := $(BIN_DIR)/server
# Default debug flags are empty
DEBUG_FLAGS :=
RELEASE_FLAGS :=
# This target is for release builds
all: DEBUG_FLAGS :=
all: RELEASE_FLAGS := -Ofast
all: $(TARGET) copy_views
# This target is for debug builds
debug: DEBUG_FLAGS := -g -O0
debug: RELEASE_FLAGS :=
debug: $(TARGET) copy_views
$(TARGET): $(OBJ_FILES)
$(CC) $(DEBUG_FLAGS) $^ -o $@ $(LDFLAGS)
$(OBJS_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJS_DIR)
$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(RELEASE_FLAGS) -c $< -o $@
$(BIN_DIR) $(OBJS_DIR):
mkdir -p $@
copy_views: | $(BIN_DIR)
cp -r $(VIEWS_DIR) $(BIN_DIR)
mkdir -p $(BIN_DIR)/sessions
mkdir -p $(BIN_DIR)/database
clean:
rm -rf $(BIN_DIR)
.PHONY: all clean copy_views debug