-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMakefile
More file actions
586 lines (506 loc) · 22.5 KB
/
Makefile
File metadata and controls
586 lines (506 loc) · 22.5 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# GraphQLite Makefile
CC = gcc
BISON ?= bison
FLEX ?= flex
SQLITE ?= sqlite3
# Override with: make PYTHON=python3.12 test-python
PYTHON ?= python3
# Platform-specific paths for test builds (CUnit headers/libs)
# Auto-detect MacPorts (/opt/local) or Homebrew paths
# Can override with: make EXTRA_LIBS=-L/path/to/lib EXTRA_INCLUDES=-I/path/to/include
# Auto-detect CUnit from MacPorts
ifneq ($(wildcard /opt/local/include/CUnit/CUnit.h),)
MACPORTS_INCLUDES = -I/opt/local/include
MACPORTS_LIBS = -L/opt/local/lib
else
MACPORTS_INCLUDES =
MACPORTS_LIBS =
endif
# Auto-detect CUnit from Homebrew (common paths)
ifneq ($(wildcard /usr/local/include/CUnit/CUnit.h),)
HOMEBREW_INCLUDES = -I/usr/local/include
HOMEBREW_LIBS = -L/usr/local/lib
else ifneq ($(wildcard /opt/homebrew/include/CUnit/CUnit.h),)
HOMEBREW_INCLUDES = -I/opt/homebrew/include
HOMEBREW_LIBS = -L/opt/homebrew/lib
else
HOMEBREW_INCLUDES =
HOMEBREW_LIBS =
endif
# Combine detected paths (MacPorts takes priority, then Homebrew)
EXTRA_LIBS ?= $(MACPORTS_LIBS) $(HOMEBREW_LIBS)
EXTRA_INCLUDES ?= $(MACPORTS_INCLUDES) $(HOMEBREW_INCLUDES)
# Vendored SQLite headers for consistent extension builds
VENDOR_SQLITE_DIR = bindings/python/vendor/sqlite
# Base flags for extension builds (vendor headers only, no system includes)
EXTENSION_BASE_CFLAGS = -Wall -Wextra -I$(VENDOR_SQLITE_DIR) -I./src/include
# Build mode: debug (default) or release
# Use: make extension RELEASE=1
ifdef RELEASE
CFLAGS = -Wall -Wextra -O2 -I$(VENDOR_SQLITE_DIR) -I./src/include $(EXTRA_INCLUDES)
EXTENSION_CFLAGS_BASE = -Wall -Wextra -O2 -I$(VENDOR_SQLITE_DIR) -I./src/include
else
# Add -DGRAPHQLITE_PERF_TIMING for detailed query timing instrumentation
CFLAGS = -Wall -Wextra -g -I$(VENDOR_SQLITE_DIR) -I./src/include -DGRAPHQLITE_DEBUG $(EXTRA_INCLUDES)
EXTENSION_CFLAGS_BASE = -Wall -Wextra -g -I$(VENDOR_SQLITE_DIR) -I./src/include -DGRAPHQLITE_DEBUG
endif
LDFLAGS = $(EXTRA_LIBS) -lcunit -lsqlite3 -lm
# Extension-specific flags: enable sqlite3ext.h API pointer redirection
EXTENSION_CFLAGS = -DGRAPHQLITE_EXTENSION
# Coverage flags
COVERAGE_FLAGS = -fprofile-arcs -ftest-coverage
# Detect OS and set coverage libs accordingly
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
COVERAGE_LIBS = -lgcov
endif
ifeq ($(UNAME_S),Darwin)
# macOS with clang doesn't need -lgcov
COVERAGE_LIBS =
endif
# Source directories
SRC_DIR = src
BACKEND_DIR = $(SRC_DIR)/backend
PARSER_DIR = $(BACKEND_DIR)/parser
TEST_DIR = tests
# Build directories
BUILD_DIR = build
BUILD_PARSER_DIR = $(BUILD_DIR)/parser
BUILD_TRANSFORM_DIR = $(BUILD_DIR)/transform
BUILD_EXECUTOR_DIR = $(BUILD_DIR)/executor
BUILD_TEST_DIR = $(BUILD_DIR)/tests
COVERAGE_DIR = $(BUILD_DIR)/coverage
# Parser sources (C files)
PARSER_SRCS = \
$(PARSER_DIR)/cypher_keywords.c \
$(PARSER_DIR)/cypher_scanner_api.c \
$(PARSER_DIR)/cypher_ast.c \
$(PARSER_DIR)/cypher_parser.c
# Generated sources
SCANNER_SRC = $(BUILD_PARSER_DIR)/cypher_scanner.c
SCANNER_HDR = $(BUILD_PARSER_DIR)/cypher_flex.h
SCANNER_L = $(PARSER_DIR)/cypher_scanner.l
GRAMMAR_SRC = $(BUILD_PARSER_DIR)/cypher_gram.tab.c
GRAMMAR_HDR = $(BUILD_PARSER_DIR)/cypher_gram.tab.h
GRAMMAR_Y = $(PARSER_DIR)/cypher_gram.y
# All parser sources including generated
ALL_PARSER_SRCS = $(PARSER_SRCS) $(SCANNER_SRC) $(GRAMMAR_SRC)
PARSER_OBJS = $(PARSER_SRCS:$(PARSER_DIR)/%.c=$(BUILD_PARSER_DIR)/%.o) $(BUILD_PARSER_DIR)/cypher_scanner.o $(BUILD_PARSER_DIR)/cypher_gram.tab.o
PARSER_OBJS_COV = $(PARSER_SRCS:$(PARSER_DIR)/%.c=$(BUILD_PARSER_DIR)/%.cov.o) $(BUILD_PARSER_DIR)/cypher_scanner.cov.o $(BUILD_PARSER_DIR)/cypher_gram.tab.cov.o
PARSER_OBJS_PIC = $(PARSER_SRCS:$(PARSER_DIR)/%.c=$(BUILD_PARSER_DIR)/%.pic.o) $(BUILD_PARSER_DIR)/cypher_scanner.pic.o $(BUILD_PARSER_DIR)/cypher_gram.tab.pic.o
# Transform sources
TRANSFORM_DIR = $(SRC_DIR)/backend/transform
TRANSFORM_SRCS = \
$(TRANSFORM_DIR)/cypher_transform.c \
$(TRANSFORM_DIR)/transform_match.c \
$(TRANSFORM_DIR)/transform_create.c \
$(TRANSFORM_DIR)/transform_set.c \
$(TRANSFORM_DIR)/transform_delete.c \
$(TRANSFORM_DIR)/transform_remove.c \
$(TRANSFORM_DIR)/transform_foreach.c \
$(TRANSFORM_DIR)/transform_load_csv.c \
$(TRANSFORM_DIR)/transform_return.c \
$(TRANSFORM_DIR)/transform_func_string.c \
$(TRANSFORM_DIR)/transform_func_math.c \
$(TRANSFORM_DIR)/transform_func_entity.c \
$(TRANSFORM_DIR)/transform_func_path.c \
$(TRANSFORM_DIR)/transform_func_list.c \
$(TRANSFORM_DIR)/transform_func_graph.c \
$(TRANSFORM_DIR)/transform_func_aggregate.c \
$(TRANSFORM_DIR)/transform_func_dispatch.c \
$(TRANSFORM_DIR)/transform_helpers.c \
$(TRANSFORM_DIR)/transform_variables.c \
$(TRANSFORM_DIR)/transform_expr_predicate.c \
$(TRANSFORM_DIR)/transform_with.c \
$(TRANSFORM_DIR)/transform_unwind.c \
$(TRANSFORM_DIR)/transform_expr_ops.c \
$(TRANSFORM_DIR)/sql_builder.c
# Executor sources
EXECUTOR_DIR = $(SRC_DIR)/backend/executor
EXECUTOR_SRCS = \
$(EXECUTOR_DIR)/cypher_schema.c \
$(EXECUTOR_DIR)/cypher_executor.c \
$(EXECUTOR_DIR)/executor_variable_map.c \
$(EXECUTOR_DIR)/executor_foreach_ctx.c \
$(EXECUTOR_DIR)/executor_result.c \
$(EXECUTOR_DIR)/executor_helpers.c \
$(EXECUTOR_DIR)/executor_delete.c \
$(EXECUTOR_DIR)/executor_set.c \
$(EXECUTOR_DIR)/executor_remove.c \
$(EXECUTOR_DIR)/executor_create.c \
$(EXECUTOR_DIR)/executor_foreach.c \
$(EXECUTOR_DIR)/executor_merge.c \
$(EXECUTOR_DIR)/executor_match.c \
$(EXECUTOR_DIR)/query_dispatch.c \
$(EXECUTOR_DIR)/agtype.c \
$(EXECUTOR_DIR)/json_builder.c \
$(EXECUTOR_DIR)/graph_algorithms.c \
$(EXECUTOR_DIR)/graph_algo_pagerank.c \
$(EXECUTOR_DIR)/graph_algo_community.c \
$(EXECUTOR_DIR)/graph_algo_paths.c \
$(EXECUTOR_DIR)/graph_algo_centrality.c \
$(EXECUTOR_DIR)/graph_algo_components.c \
$(EXECUTOR_DIR)/graph_algo_betweenness.c \
$(EXECUTOR_DIR)/graph_algo_closeness.c \
$(EXECUTOR_DIR)/graph_algo_louvain.c \
$(EXECUTOR_DIR)/graph_algo_triangle.c \
$(EXECUTOR_DIR)/graph_algo_astar.c \
$(EXECUTOR_DIR)/graph_algo_traversal.c \
$(EXECUTOR_DIR)/graph_algo_similarity.c \
$(EXECUTOR_DIR)/graph_algo_knn.c \
$(EXECUTOR_DIR)/graph_algo_eigenvector.c \
$(EXECUTOR_DIR)/graph_algo_apsp.c
TRANSFORM_OBJS = $(TRANSFORM_SRCS:$(TRANSFORM_DIR)/%.c=$(BUILD_TRANSFORM_DIR)/%.o)
TRANSFORM_OBJS_COV = $(TRANSFORM_SRCS:$(TRANSFORM_DIR)/%.c=$(BUILD_TRANSFORM_DIR)/%.cov.o)
TRANSFORM_OBJS_PIC = $(TRANSFORM_SRCS:$(TRANSFORM_DIR)/%.c=$(BUILD_TRANSFORM_DIR)/%.pic.o)
EXECUTOR_OBJS = $(EXECUTOR_SRCS:$(EXECUTOR_DIR)/%.c=$(BUILD_EXECUTOR_DIR)/%.o)
EXECUTOR_OBJS_COV = $(EXECUTOR_SRCS:$(EXECUTOR_DIR)/%.c=$(BUILD_EXECUTOR_DIR)/%.cov.o)
EXECUTOR_OBJS_PIC = $(EXECUTOR_SRCS:$(EXECUTOR_DIR)/%.c=$(BUILD_EXECUTOR_DIR)/%.pic.o)
# Test sources
TEST_SRCS = \
$(TEST_DIR)/test_runner.c \
$(TEST_DIR)/test_parser_keywords.c \
$(TEST_DIR)/test_scanner.c \
$(TEST_DIR)/test_parser.c \
$(TEST_DIR)/test_transform_create.c \
$(TEST_DIR)/test_transform_set.c \
$(TEST_DIR)/test_transform_delete.c \
$(TEST_DIR)/test_transform_functions.c \
$(TEST_DIR)/test_transform_match.c \
$(TEST_DIR)/test_transform_return.c \
$(TEST_DIR)/test_agtype.c \
$(TEST_DIR)/test_schema.c \
$(TEST_DIR)/test_executor_basic.c \
$(TEST_DIR)/test_executor_relationships.c \
$(TEST_DIR)/test_executor_set.c \
$(TEST_DIR)/test_executor_delete.c \
$(TEST_DIR)/test_executor_varlen.c \
$(TEST_DIR)/test_executor_with.c \
$(TEST_DIR)/test_executor_unwind.c \
$(TEST_DIR)/test_executor_merge.c \
$(TEST_DIR)/test_executor_pagerank.c \
$(TEST_DIR)/test_executor_label_propagation.c \
$(TEST_DIR)/test_executor_dijkstra.c \
$(TEST_DIR)/test_executor_degree_centrality.c \
$(TEST_DIR)/test_executor_components.c \
$(TEST_DIR)/test_executor_betweenness.c \
$(TEST_DIR)/test_executor_closeness.c \
$(TEST_DIR)/test_executor_louvain.c \
$(TEST_DIR)/test_executor_triangle.c \
$(TEST_DIR)/test_executor_astar.c \
$(TEST_DIR)/test_executor_traversal.c \
$(TEST_DIR)/test_executor_similarity.c \
$(TEST_DIR)/test_executor_knn.c \
$(TEST_DIR)/test_executor_eigenvector.c \
$(TEST_DIR)/test_executor_apsp.c \
$(TEST_DIR)/test_executor_remove.c \
$(TEST_DIR)/test_executor_params.c \
$(TEST_DIR)/test_output_format.c \
$(TEST_DIR)/test_executor_expressions.c \
$(TEST_DIR)/test_executor_clauses.c \
$(TEST_DIR)/test_executor_patterns.c \
$(TEST_DIR)/test_executor_functions.c \
$(TEST_DIR)/test_executor_predicates.c \
$(TEST_DIR)/test_executor_multigraph.c \
$(TEST_DIR)/test_sql_builder.c \
$(TEST_DIR)/test_query_dispatch.c \
$(TEST_DIR)/test_cache.c
TEST_OBJS = $(TEST_SRCS:$(TEST_DIR)/%.c=$(BUILD_TEST_DIR)/%.o)
# Test executable
TEST_RUNNER = $(BUILD_DIR)/test_runner
# Main application executable
MAIN_APP = $(BUILD_DIR)/gqlite
MAIN_OBJ = $(BUILD_DIR)/main.o
# SQLite extension - use .dylib on macOS, .dll on Windows, .so on Linux
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_S),Darwin)
EXTENSION_LIB = $(BUILD_DIR)/graphqlite.dylib
else ifneq (,$(findstring MINGW,$(UNAME_S)))
EXTENSION_LIB = $(BUILD_DIR)/graphqlite.dll
else ifneq (,$(findstring MSYS,$(UNAME_S)))
EXTENSION_LIB = $(BUILD_DIR)/graphqlite.dll
else
EXTENSION_LIB = $(BUILD_DIR)/graphqlite.so
endif
EXTENSION_OBJ = $(BUILD_DIR)/extension.o
# Default target
all: dirs $(PARSER_OBJS)
# Build main application
graphqlite: $(MAIN_APP)
# Build SQLite extension
extension: $(EXTENSION_LIB)
# Copy extension to Rust bindings libs/ directory for bundled builds
# Note: macOS uses "arm64", Linux uses "aarch64" for ARM64
install-bundled: $(EXTENSION_LIB)
@mkdir -p $(RUST_BINDINGS_DIR)/libs
ifeq ($(UNAME_S),Darwin)
ifneq (,$(filter arm64 aarch64,$(UNAME_M)))
cp $(EXTENSION_LIB) $(RUST_BINDINGS_DIR)/libs/graphqlite-macos-aarch64.dylib
else
cp $(EXTENSION_LIB) $(RUST_BINDINGS_DIR)/libs/graphqlite-macos-x86_64.dylib
endif
else ifeq ($(UNAME_S),Linux)
ifneq (,$(filter arm64 aarch64,$(UNAME_M)))
cp $(EXTENSION_LIB) $(RUST_BINDINGS_DIR)/libs/graphqlite-linux-aarch64.so
else
cp $(EXTENSION_LIB) $(RUST_BINDINGS_DIR)/libs/graphqlite-linux-x86_64.so
endif
else
cp $(EXTENSION_LIB) $(RUST_BINDINGS_DIR)/libs/graphqlite-windows-x86_64.dll
endif
# Standard gqlite build (dynamic linking)
$(MAIN_APP): $(MAIN_OBJ) $(PARSER_OBJS) $(TRANSFORM_OBJS) $(EXECUTOR_OBJS) | dirs
$(CC) $(CFLAGS) $^ -o $@ -lsqlite3
# Portable gqlite build for releases (static linking where possible)
gqlite-portable: $(MAIN_OBJ) $(PARSER_OBJS) $(TRANSFORM_OBJS) $(EXECUTOR_OBJS) | dirs
ifeq ($(UNAME_S),Darwin)
$(CC) $(CFLAGS) $^ -o $(BUILD_DIR)/gqlite -lsqlite3
else ifneq (,$(findstring MINGW,$(UNAME_S)))
$(CC) $(CFLAGS) -static $^ -o $(BUILD_DIR)/gqlite.exe -lsqlite3 -lsystre -ltre -lintl -liconv
else ifneq (,$(findstring MSYS,$(UNAME_S)))
$(CC) $(CFLAGS) -static $^ -o $(BUILD_DIR)/gqlite.exe -lsqlite3 -lsystre -ltre -lintl -liconv
else
$(CC) $(CFLAGS) $^ -o $(BUILD_DIR)/gqlite -l:libsqlite3.a -lpthread -ldl -lm
endif
# SQLite extension shared library (with full parser, transform, and executor)
$(EXTENSION_LIB): $(EXTENSION_OBJ) $(PARSER_OBJS_PIC) $(TRANSFORM_OBJS_PIC) $(EXECUTOR_OBJS_PIC) | dirs $(GRAMMAR_HDR)
ifeq ($(UNAME_S),Darwin)
$(CC) -g -fPIC -dynamiclib $(EXTENSION_OBJ) $(PARSER_OBJS_PIC) $(TRANSFORM_OBJS_PIC) $(EXECUTOR_OBJS_PIC) -o $@ -undefined dynamic_lookup
else ifneq (,$(findstring MINGW,$(UNAME_S)))
$(CC) -shared -static $(EXTENSION_OBJ) $(PARSER_OBJS_PIC) $(TRANSFORM_OBJS_PIC) $(EXECUTOR_OBJS_PIC) -o $@ -lsqlite3 -lsystre -ltre -lintl -liconv
else ifneq (,$(findstring MSYS,$(UNAME_S)))
$(CC) -shared -static $(EXTENSION_OBJ) $(PARSER_OBJS_PIC) $(TRANSFORM_OBJS_PIC) $(EXECUTOR_OBJS_PIC) -o $@ -lsqlite3 -lsystre -ltre -lintl -liconv
else
$(CC) -shared -fPIC $(EXTENSION_OBJ) $(PARSER_OBJS_PIC) $(TRANSFORM_OBJS_PIC) $(EXECUTOR_OBJS_PIC) -o $@
endif
# Main application object
$(BUILD_DIR)/main.o: $(SRC_DIR)/main.c | dirs
$(CC) $(CFLAGS) -c $< -o $@
# Extension object (uses vendored SQLite headers for ABI consistency - no EXTRA_INCLUDES)
$(BUILD_DIR)/extension.o: $(SRC_DIR)/extension.c | dirs
$(CC) $(EXTENSION_CFLAGS_BASE) $(EXTENSION_CFLAGS) -fPIC -c $< -o $@
# Help target
help:
@echo "GraphQLite Makefile Commands:"
@echo " make - Build parser objects (default)"
@echo " make all - Same as 'make'"
@echo " make graphqlite - Build main interactive application"
@echo " make extension - Build SQLite extension (graphqlite.dylib on macOS, graphqlite.so on Linux)"
@echo " make test - Run all tests (unit + functional + bindings)"
@echo " make test unit - Run only CUnit tests"
@echo " make test rust - Run Rust binding tests"
@echo " make test python - Run Python binding tests"
@echo " make test bindings - Run all binding tests (Rust + Python)"
@echo " make test functional - Run functional SQL tests"
@echo " make test-constraints - Run constraint tests (expected to fail)"
@echo " make performance - Run all performance tests with summary table"
@echo " make coverage - Run tests and generate gcov coverage report"
@echo " make clean - Remove all build artifacts"
@echo " make help - Show this help message"
@echo ""
@echo "Build Directories:"
@echo " $(BUILD_DIR)/ - Main build directory"
@echo " $(BUILD_PARSER_DIR)/ - Parser objects"
@echo " $(BUILD_TEST_DIR)/ - Test objects"
@echo " $(COVERAGE_DIR)/ - Coverage reports"
# Create build directories
dirs:
@mkdir -p $(BUILD_DIR)
@mkdir -p $(BUILD_PARSER_DIR)
@mkdir -p $(BUILD_TRANSFORM_DIR)
@mkdir -p $(BUILD_EXECUTOR_DIR)
@mkdir -p $(BUILD_TEST_DIR)
@mkdir -p $(COVERAGE_DIR)
# Parser objects (regular build) - need build dir for generated headers
$(BUILD_PARSER_DIR)/%.o: $(PARSER_DIR)/%.c $(GRAMMAR_HDR) | dirs
$(CC) $(CFLAGS) -I$(BUILD_PARSER_DIR) -c $< -o $@
# Scanner API needs Flex-generated header (reentrant API declarations)
$(BUILD_PARSER_DIR)/cypher_scanner_api.o: $(SCANNER_HDR)
# Parser objects (coverage build) - need build dir for generated headers
$(BUILD_PARSER_DIR)/%.cov.o: $(PARSER_DIR)/%.c $(GRAMMAR_HDR) | dirs
$(CC) $(CFLAGS) $(COVERAGE_FLAGS) -I$(BUILD_PARSER_DIR) -c $< -o $@
$(BUILD_PARSER_DIR)/cypher_scanner_api.cov.o: $(SCANNER_HDR)
# Generate scanner from Flex specification (reentrant, with header for API)
$(SCANNER_SRC) $(SCANNER_HDR): $(SCANNER_L) | dirs
$(FLEX) -o $(SCANNER_SRC) --header=$(SCANNER_HDR) $<
# Generate parser from Bison grammar
$(GRAMMAR_SRC) $(GRAMMAR_HDR): $(GRAMMAR_Y) | dirs
$(BISON) -d -o $(GRAMMAR_SRC) $<
# Scanner objects (regular build)
$(BUILD_PARSER_DIR)/cypher_scanner.o: $(SCANNER_SRC) | dirs
$(CC) $(CFLAGS) -Wno-sign-compare -c $< -o $@
# Scanner objects (coverage build)
$(BUILD_PARSER_DIR)/cypher_scanner.cov.o: $(SCANNER_SRC) | dirs
$(CC) $(CFLAGS) $(COVERAGE_FLAGS) -Wno-sign-compare -c $< -o $@
# Grammar objects (regular build)
$(BUILD_PARSER_DIR)/cypher_gram.tab.o: $(GRAMMAR_SRC) $(GRAMMAR_HDR) | dirs
$(CC) $(CFLAGS) -Wno-unused-but-set-variable -I$(BUILD_PARSER_DIR) -c $< -o $@
# Grammar objects (coverage build)
$(BUILD_PARSER_DIR)/cypher_gram.tab.cov.o: $(GRAMMAR_SRC) $(GRAMMAR_HDR) | dirs
$(CC) $(CFLAGS) $(COVERAGE_FLAGS) -Wno-unused-but-set-variable -I$(BUILD_PARSER_DIR) -c $< -o $@
# Transform objects
$(BUILD_TRANSFORM_DIR)/%.o: $(TRANSFORM_DIR)/%.c | dirs
$(CC) $(CFLAGS) -c $< -o $@
# Transform objects (coverage build)
$(BUILD_TRANSFORM_DIR)/%.cov.o: $(TRANSFORM_DIR)/%.c | dirs
$(CC) $(CFLAGS) $(COVERAGE_FLAGS) -c $< -o $@
# Executor objects
$(BUILD_EXECUTOR_DIR)/%.o: $(EXECUTOR_DIR)/%.c | dirs
$(CC) $(CFLAGS) -c $< -o $@
# Executor objects (coverage build)
$(BUILD_EXECUTOR_DIR)/%.cov.o: $(EXECUTOR_DIR)/%.c | dirs
$(CC) $(CFLAGS) $(COVERAGE_FLAGS) -c $< -o $@
# PIC object builds for shared library (uses vendored SQLite headers only - no EXTRA_INCLUDES)
$(BUILD_PARSER_DIR)/%.pic.o: $(PARSER_DIR)/%.c $(GRAMMAR_HDR) | dirs
$(CC) $(EXTENSION_CFLAGS_BASE) $(EXTENSION_CFLAGS) -fPIC -I$(BUILD_PARSER_DIR) -c $< -o $@
$(BUILD_PARSER_DIR)/cypher_scanner_api.pic.o: $(SCANNER_HDR)
$(BUILD_PARSER_DIR)/cypher_scanner.pic.o: $(SCANNER_SRC) | dirs
$(CC) $(EXTENSION_CFLAGS_BASE) $(EXTENSION_CFLAGS) -fPIC -Wno-sign-compare -c $< -o $@
$(BUILD_PARSER_DIR)/cypher_gram.tab.pic.o: $(GRAMMAR_SRC) $(GRAMMAR_HDR) | dirs
$(CC) $(EXTENSION_CFLAGS_BASE) $(EXTENSION_CFLAGS) -fPIC -Wno-unused-but-set-variable -I$(BUILD_PARSER_DIR) -c $< -o $@
$(BUILD_TRANSFORM_DIR)/%.pic.o: $(TRANSFORM_DIR)/%.c | dirs
$(CC) $(EXTENSION_CFLAGS_BASE) $(EXTENSION_CFLAGS) -fPIC -c $< -o $@
$(BUILD_EXECUTOR_DIR)/%.pic.o: $(EXECUTOR_DIR)/%.c | dirs
$(CC) $(EXTENSION_CFLAGS_BASE) $(EXTENSION_CFLAGS) -fPIC -c $< -o $@
# Test objects
$(BUILD_TEST_DIR)/%.o: $(TEST_DIR)/%.c $(GRAMMAR_HDR) | dirs
$(CC) $(CFLAGS) -I$(BUILD_PARSER_DIR) -c $< -o $@
# Test runner executable
$(TEST_RUNNER): $(TEST_OBJS) $(PARSER_OBJS_COV) $(TRANSFORM_OBJS_COV) $(EXECUTOR_OBJS_COV) | dirs
$(CC) $(CFLAGS) $(COVERAGE_FLAGS) $^ -o $@ $(LDFLAGS) $(COVERAGE_LIBS)
# Run constraint tests (expected to fail with specific errors)
test-constraints: extension
@echo "Running constraint tests (expected to fail)..."
@for test_file in tests/functional/*constraint*.sql; do \
if [ -f "$$test_file" ]; then \
echo ""; \
echo "========================================"; \
echo "Running: $$(basename $$test_file)"; \
echo "========================================"; \
$(SQLITE) < "$$test_file" 2>&1 && echo "ERROR: Test should have failed!" || echo "Constraint correctly enforced"; \
fi; \
done
@echo ""
@echo "All functional tests completed successfully!"
# Generate coverage report
coverage: test-unit
@echo "Generating coverage report..."
@for obj in $(BUILD_PARSER_DIR)/*.cov.o; do \
gcov -o $(BUILD_PARSER_DIR) $$obj; \
done
@for obj in $(BUILD_TRANSFORM_DIR)/*.cov.o; do \
gcov -o $(BUILD_TRANSFORM_DIR) $$obj; \
done
@for obj in $(BUILD_EXECUTOR_DIR)/*.cov.o; do \
gcov -o $(BUILD_EXECUTOR_DIR) $$obj; \
done
@find . -name "*.gcov" -maxdepth 1 -exec mv {} $(COVERAGE_DIR)/ \;
@echo ""
@echo "========== CODE COVERAGE SUMMARY =========="
@for file in $(COVERAGE_DIR)/*.gcov; do \
if [ -f "$$file" ]; then \
filename=$$(basename $$file .gcov); \
coverage=$$(grep -E "^[[:space:]]*[0-9]+:" $$file | wc -l); \
total=$$(grep -E "^[[:space:]]*[0-9]+:|[[:space:]]*#####:" $$file | wc -l); \
if [ $$total -gt 0 ]; then \
percent=$$(echo "scale=2; $$coverage * 100 / $$total" | bc); \
printf "%-40s %6.2f%%\n" "$$filename:" "$$percent"; \
fi; \
fi; \
done
@echo "==========================================="
@echo ""
@echo "Detailed reports in: $(COVERAGE_DIR)/"
# Performance tests - unified script with modes: quick, standard, full
# Usage: make performance [MODE=quick|standard|full] [ITERATIONS=N]
performance: extension
@tests/performance/run_all_perf.sh $(or $(MODE),standard) 2>&1 | grep -v "^\[CYPHER_DEBUG\]"
# Quick performance check (~30s, 10K nodes only)
performance-quick: extension
@tests/performance/run_all_perf.sh quick 2>&1 | grep -v "^\[CYPHER_DEBUG\]"
# Full performance suite (~10min, up to 1M nodes)
performance-full: extension
@tests/performance/run_all_perf.sh full 2>&1 | grep -v "^\[CYPHER_DEBUG\]"
# Bindings directories
RUST_BINDINGS_DIR = bindings/rust
PYTHON_BINDINGS_DIR = bindings/python
# Nested test commands: make test [unit|rust|python|bindings|functional]
# Check what subcommand was passed
ifneq ($(filter unit,$(MAKECMDGOALS)),)
TEST_TARGET = unit
else ifneq ($(filter rust,$(MAKECMDGOALS)),)
TEST_TARGET = rust
else ifneq ($(filter python,$(MAKECMDGOALS)),)
TEST_TARGET = python
else ifneq ($(filter bindings,$(MAKECMDGOALS)),)
TEST_TARGET = bindings
else ifneq ($(filter functional,$(MAKECMDGOALS)),)
TEST_TARGET = functional
else
TEST_TARGET = all
endif
# Dummy targets for subcommands (prevents "No rule to make target" errors)
unit rust python bindings functional:
@true
# Individual test targets
test-unit: $(TEST_RUNNER)
@echo "Running unit tests..."
./$(TEST_RUNNER)
test-rust: extension install-bundled
@echo "Running Rust binding tests..."
cd $(RUST_BINDINGS_DIR) && cargo test -- --test-threads=1
test-python: extension
@echo "Running Python binding tests..."
@# Install in dev mode if not already installed, then run tests
@# Use $(PYTHON) -m pip to ensure pip matches the Python interpreter
@cd $(PYTHON_BINDINGS_DIR) && $(PYTHON) -m pip install -q -e . 2>/dev/null || true
cd $(PYTHON_BINDINGS_DIR) && $(PYTHON) -m pytest tests/ -v
test-bindings: test-rust test-python
test-functional: extension
@echo "Running functional tests..."
@for test_file in tests/functional/*.sql; do \
if [ -f "$$test_file" ] && [[ "$$test_file" != *"constraint"* ]] && [[ "$$test_file" != *"expected_failures"* ]]; then \
echo "Running: $$(basename $$test_file)"; \
$(SQLITE) -bail < "$$test_file" || exit 1; \
fi; \
done
test-cli:
@echo "Building gqlite in release mode for CLI tests..."
@$(MAKE) clean-app --no-print-directory 2>/dev/null || true
@$(MAKE) graphqlite RELEASE=1 --no-print-directory
@echo "Running CLI tests..."
@./tests/cli/run_cli_tests.sh $(BUILD_DIR)/gqlite
# Clean only the app-related object files (for switching between debug/release)
clean-app:
@rm -f $(BUILD_DIR)/main.o $(BUILD_DIR)/gqlite
test-all: test-unit test-functional test-cli test-bindings
# Main test target dispatches to appropriate sub-target
test: test-$(TEST_TARGET)
# Strict compilation check — catches C99/C11 compliance issues that CI will reject
# Run before pushing to catch label-after-declaration, implicit declarations, etc.
lint:
@echo "=== Strict C11 compilation check ==="
@echo "Catches: declarations after labels, implicit function declarations,"
@echo " missing prototypes, and other C99/C11 violations that break CI."
@FAIL=0; \
for f in src/backend/parser/cypher_ast.c src/backend/parser/cypher_parser.c src/backend/parser/cypher_scanner_api.c src/backend/parser/cypher_keywords.c \
src/backend/transform/*.c src/backend/executor/*.c src/extension.c; do \
/usr/bin/clang -std=c11 -Wall -Wextra -Werror -Wc23-extensions \
-Wno-unused-parameter -Wno-sign-compare -Wno-unused-variable \
-Wno-unused-but-set-variable -Wno-unused-function \
-Wno-newline-eof -Wno-gnu-zero-variadic-macro-arguments \
-Wno-incompatible-pointer-types-discards-qualifiers -Wno-format \
-I$(VENDOR_SQLITE_DIR) -I./src/include -DGRAPHQLITE_DEBUG \
-DGRAPHQLITE_EXTENSION -fPIC -I$(BUILD_DIR)/parser \
-fsyntax-only $$f 2>&1 || { echo " FAIL: $$f"; FAIL=1; }; \
done; \
if [ $$FAIL -eq 0 ]; then echo "=== All files pass strict C11 check ==="; \
else echo "=== STRICT CHECK FAILED — fix before pushing ==="; exit 1; fi
# Clean
clean:
rm -rf $(BUILD_DIR)
find . -name "*.gcda" -delete
find . -name "*.gcno" -delete
find . -name "*.gcov" -delete
.PHONY: all help dirs test test-unit test-rust test-python test-bindings test-functional test-cli test-all test-constraints test-perf test-perf-quick test-perf-scaled test-perf-pagerank performance coverage clean unit rust python bindings functional cli gqlite-portable