-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
145 lines (122 loc) · 3.39 KB
/
Makefile
File metadata and controls
145 lines (122 loc) · 3.39 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#-------------------------------------------------
# Makefile Usage
# > make # release build + unit-tests
# > make build # release build qc
# > make build MODE=debug # debug build qc
# > make test # qk tests
# > make test-c # unit-tests
# > make release # release build qc + unit-tests
# > make debug # debug build qc + unit-tests
# > make clean # remove build/files
#-------------------------------------------------
# ========= Tools =========
CC := gcc
QC := qc
EXE :=
# ========= Platform detection =========
ifeq ($(OS),Windows_NT)
PLATFORM := windows
EXE := .exe
CC := $(CC)$(EXE)
QC := $(QC)$(EXE)
MKDIR = if not exist "$(1)" mkdir "$(1)"
RM_RF = if exist "$(1)" rmdir /S /Q "$(1)"
RM_F = if exist "$(1)" del /Q "$(1)"
COPY = copy /Y
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
PLATFORM := macos
else
PLATFORM := linux
endif
MKDIR = mkdir -p "$(1)"
RM_RF = rm -rf "$(1)"
RM_F = rm -f "$(1)"
COPY = cp
endif
# ========= Flags =========
CFLAGS := -Isrc/include -Isrc -Wall -Wno-missing-braces -Wno-char-subscripts
LDFLAGS :=
# ========= Directories =========
BUILD_DIR := build
TEST_BUILD := $(BUILD_DIR)/tests
UT_BUILD := $(BUILD_DIR)/unit_tests
# ========= Mode normalize =========
MODE ?= release
MODE_L := $(shell echo $(MODE) | tr A-Z a-z)
# ========= Sources =========
MAIN_C := src/main.c
SRCS := \
$(wildcard src/*/*.c) \
$(wildcard src/*/*/*.c) \
$(wildcard src/*/*/*/*.c)
TEST_QK := $(wildcard tests/*.qk)
UT_SRCS := \
$(wildcard unit-tests/*.c) \
$(wildcard unit-tests/*/*.c) \
$(wildcard unit-tests/*/*/*.c) \
$(wildcard unit-tests/*/*/*/*.c) \
# ========= Output =========
OUT := ./${QC}
.PHONY: all build test test-c release debug clean
.DEFAULT_GOAL := all
# ========= Directories =========
dirs:
@$(call MKDIR,$(BUILD_DIR))
@$(call MKDIR,$(TEST_BUILD))
@$(call MKDIR,$(UT_BUILD))
# ========= Build qc =========
build: dirs
ifeq ($(MODE_L),debug)
@echo ------ Debug build qc ------
$(CC) $(CFLAGS) $(MAIN_C) $(SRCS) $(LDFLAGS) -g -ggdb -DEBUG -o $(BUILD_DIR)/$(QC)
else
@echo ------ Release build qc ------
$(CC) $(CFLAGS) $(MAIN_C) $(SRCS) $(LDFLAGS) -O2 -o $(BUILD_DIR)/$(QC)
endif
@$(COPY) $(BUILD_DIR)/$(QC) $(OUT)
# ========= Default =========
all: build test-c
# ========= qk tests =========
test:
@echo ------ qk tests ------
@$(call MKDIR,$(TEST_BUILD))
ifeq ($(PLATFORM),windows)
@if not "$(TEST_QK)"=="" ( \
for %%f in ($(TEST_QK)) do ( \
$(OUT) %%f -o $(TEST_BUILD)\%%~nf.c -l "$(CURDIR)" && \
$(CC) $(CFLAGS) -g $(TEST_BUILD)\%%~nf.c -o $(TEST_BUILD)\%%~nf$(EXE) \
) \
) else ( \
echo No .qk tests found \
)
else
@set -e; \
if [ -n "$(TEST_QK)" ]; then \
for f in $(TEST_QK); do \
base=$$(basename $$f .qk); \
$(OUT) "$$f" -o "$(TEST_BUILD)/$$base.c" -l "$(CURDIR)"; \
$(CC) $(CFLAGS) -g "$(TEST_BUILD)/$$base.c" -o "$(TEST_BUILD)/$$base$(EXE)"; \
done; \
else \
echo "No .qk tests found"; \
fi
endif
# ========= unit-tests =========
build-test-c: dirs
$(CC) $(CFLAGS) -g $(UT_SRCS) $(SRCS) $(LDFLAGS) -o $(UT_BUILD)/unit-tests$(EXE)
test-c: build-test-c
@echo ------ unit-tests ------
@$(UT_BUILD)/unit-tests$(EXE)
# ========= Presets =========
release:
$(MAKE) build MODE=release
$(MAKE) test-c
debug:
$(MAKE) build MODE=debug
$(MAKE) test-c
# ========= Clean =========
clean:
@$(call RM_RF,$(BUILD_DIR))
@$(call RM_F,$(OUT))