forked from ThakeeNathees/pocketlang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
64 lines (45 loc) · 1.4 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
## Copyright (c) 2020-2021 Thakee Nathees
## Distributed Under The MIT License
CC = gcc
CFLAGS = -fPIC
DEBUG_CFLAGS = -D DEBUG -g3 -Og
RELEASE_CFLAGS = -g -O3
LDFLAGS = -lm -ldl
TARGET_EXEC = pocket
BUILD_DIR = ./build/
SRC_DIRS = ./cli/ ./src/core/ ./src/libs/
INC_DIRS = ./src/include/
BIN_DIR = bin/
OBJ_DIR = obj/
SRCS := $(foreach DIR,$(SRC_DIRS),$(wildcard $(DIR)*.c))
OBJS := $(SRCS:.c=.o)
DEPS := $(OBJS:.o=.d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
DEP_FLAGS = -MMD -MP
CC_FLAGS = $(INC_FLAGS) $(DEP_FLAGS) $(CFLAGS)
DEBUG_DIR = $(BUILD_DIR)Debug/
DEBUG_TARGET = $(DEBUG_DIR)$(BIN_DIR)$(TARGET_EXEC)
DEBUG_OBJS := $(addprefix $(DEBUG_DIR)$(OBJ_DIR), $(OBJS))
RELEASE_DIR = $(BUILD_DIR)Release/
RELEASE_TARGET = $(RELEASE_DIR)$(BIN_DIR)$(TARGET_EXEC)
RELEASE_OBJS := $(addprefix $(RELEASE_DIR)$(OBJ_DIR), $(OBJS))
.PHONY: debug release all clean
# default; target if run as `make`
debug: $(DEBUG_TARGET)
$(DEBUG_TARGET): $(DEBUG_OBJS)
@mkdir -p $(dir $@)
$(CC) $^ -o $@ $(LDFLAGS)
$(DEBUG_DIR)$(OBJ_DIR)%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CC_FLAGS) $(DEBUG_CFLAGS) -c $< -o $@
release: $(RELEASE_TARGET)
$(RELEASE_TARGET): $(RELEASE_OBJS)
@mkdir -p $(dir $@)
$(CC) $^ -o $@ $(LDFLAGS)
$(RELEASE_DIR)$(OBJ_DIR)%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CC_FLAGS) $(RELEASE_CFLAGS) -c $< -o $@
all: debug release
clean:
rm -rf $(BUILD_DIR)
-include $(DEPS)