Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
245 lines (168 loc) · 6.7 KB
/
Copy pathMakefile
File metadata and controls
245 lines (168 loc) · 6.7 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# Actual Binary Name
BIN=pankti
# Build Directory of CMake
CMAKE_BUILD_DIR=build
# CMake built binary
CMAKE_OUTPUT=$(CMAKE_BUILD_DIR)/$(BIN)
# CC
CC:=cc
# TCC Path (currently external kb_text_shaping doesn't support tcc)
TCC=/usr/bin/tcc
# Performance Test Compiler
PERFCC=clang
# Release Mode Compiler
RELEASE_CC=clang
# File to Run on `run` step
FILE=./a.pn
# File to Run for benchmark
PERFFILE=./benchmarks/samples/fib.pn
# The Native Frontend Test Binary
FRONTEND_TEST_BIN=pankti_tests
# Frontend Test Binary Output path for CMake build
FRONTEND_TEST_OUTPUT=$(CMAKE_BUILD_DIR)/$(FRONTEND_TEST_BIN)
# The Native Runtime Test Binary
RUNTIME_TEST_BIN=pankti_runtime_tests
# Runtime Test Binary Output path for CMake build
RUNTIME_TEST_OUTPUT=$(CMAKE_BUILD_DIR)/$(RUNTIME_TEST_BIN)
SAMPLES_DIR=tests/runtime/samples
# Arguments to pass to the testing binary
FRONTEND_TEST_ARGS=
RUNTIME_TEST_ARGS=
KWLOOKUP_OUTPUT:=src/gen/kwlookup.h
CPPCHECK_BUILD_DIR=$(CMAKE_BUILD_DIR)/cppcheck
HEADERS := $(shell find src/ \( -path 'src/gen' -o -path 'src/external' -o -path 'src/tmpl' \) -prune -o -name '*.h' -print)
SOURCES := $(shell find src/ \( -path 'src/gen' -o -path 'src/external' -o -path 'src/tmpl' \) -prune -o -name '*.c' -print)
# =============================================================================
# CORE : Primary Actions
# =============================================================================
# Build and Run the Test file
.PHONY: all
all: run
# Build the project with default configuration
.PHONY: build
build:
cmake --build build --target $(BIN) --parallel
# Run the interpreter with the Test file
.PHONY: run
run: build
./$(CMAKE_OUTPUT) $(FILE)
# Run code formatter
.PHONY: fmt
fmt:
@clang-format -i -style=file --verbose $(SOURCES) $(HEADERS)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# =============================================================================
# TEST(s) : Run Tests
# =============================================================================
.PHONY: _test
_test:
@cmake --build build --target $(FRONTEND_TEST_BIN) --parallel
@cmake --build build --target $(RUNTIME_TEST_BIN) --parallel
@echo "==== Running Frontend Tests ===="
@./$(FRONTEND_TEST_OUTPUT) $(FRONTEND_TEST_ARGS)
@echo "==== Finished Frontend Tests ===="
@echo "==== Running Runtime Tests ===="
@PANKTI_BIN=$(CMAKE_OUTPUT) SAMPLES_DIR=$(SAMPLES_DIR) ./$(RUNTIME_TEST_OUTPUT)
@echo "==== Finished Runtime Tests ===="
.PHONY: test
test: build_release _test
.PHONY: retest
retest: _test
.PHONY: test_runtime
test_runtime:
@cmake --build build --target $(RUNTIME_TEST_BIN)
@echo "==== Running Runtime Tests ===="
@PANKTI_BIN=$(CMAKE_OUTPUT) SAMPLES_DIR=$(SAMPLES_DIR) ./$(RUNTIME_TEST_OUTPUT)
@echo "==== Finished Runtime Tests ===="
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# =============================================================================
# CONFIGURE(s) : Setup Build Tools
# =============================================================================
.PHONY: configure
configure:
cmake -S . -B build -DCMAKE_C_COMPILER=$(CC)
.PHONY: configure_tcc
configure_tcc:
cmake -S . -B build -DCMAKE_C_COMPILER=$(TCC)
.PHONY: configure_clang
configure_clang:
cmake -S . -B build -DCMAKE_C_COMPILER=clang
.PHONY: configure_ninja
configure_ninja:
cmake -S . -B build -DCMAKE_C_COMPILER=clang -G "Ninja"
.PHONY: configure_gcc
configure_gcc:
cmake -S . -B build -DCMAKE_C_COMPILER=gcc
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# =============================================================================
# BUILD(s) : Build The Project
# =============================================================================
.PHONY: build_debug
build_debug:
rm -rf build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build --target $(BIN) --parallel
.PHONY: build_release_ninja
build_release_ninja:
rm -rf build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=$(RELEASE_CC) -G "Ninja"
cmake --build build --target $(BIN) --parallel
.PHONY: build_release
build_release:
rm -rf build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=$(RELEASE_CC)
cmake --build build --target $(BIN) --parallel
.PHONY: build_profile
build_profile:
rm -rf build
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_COMPILER=$(RELEASE_CC)
cmake --build build --target $(BIN) --parallel
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# =============================================================================
# TOOL(s) : Run External Tools
# =============================================================================
.PHONY: run_valgrind
run_valgrind: build
valgrind --leak-check=full --show-leak-kinds=all -s $(CMAKE_OUTPUT) $(FILE)
.PHONY: run_perf
run_perf: build_profile
perf record -g --call-graph dwarf -F 999 ./$(CMAKE_OUTPUT) $(PERFFILE)
perf script -F +pid > pankti.perf
.PHONY: run_callgrind
run_callgrind: build_profile
valgrind --tool=callgrind --callgrind-out-file="$(BIN).%p.callgrind.out" --dump-instr=yes --simulate-cache=yes $(CMAKE_OUTPUT) $(PERFFILE)
.PHONY: run_clangtidy
run_clangtidy:
clang-tidy --config-file=.clang-tidy $(SOURCES) $(HEADERS)
.PHONY: run_infer
run_infer: cmake_clean
infer run --compilation-database build/compile_commands.json
.PHONY: run_cppcheck
run_cppcheck:
mkdir -p $(CPPCHECK_BUILD_DIR)
cppcheck --project=pankti.cppcheck
.PHONY: bench
bench: build_release
bash scripts/run_benchmarks.sh $(CMAKE_OUTPUT)
pandoc -f markdown -t html -o benchmarks/results/benchmarks.html benchmarks/results/benchmark_results.md
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# =============================================================================
# Generator(s) : Generate Stuff
# =============================================================================
.PHONY: gen_kwlookup
gen_kwlookup:
./scripts/kwgperfgen.py src/keywords.h $(KWLOOKUP_OUTPUT)
.PHONY: gen_diagon
gen_diagon:
./scripts/diagongen.py
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# =============================================================================
# Cleaning : Clean Artifcats and Stuff
# =============================================================================
.PHONY: clean_artifacts
clean_artifacts:
cmake --build build --target clean
.PHONY: clean
clean: clean_artifacts
rm -rf .cache
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~