-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·972 lines (820 loc) · 36.8 KB
/
Copy pathconfigure
File metadata and controls
executable file
·972 lines (820 loc) · 36.8 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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
#!/bin/bash
# Configuration script for sourceminder
# Default values - all languages disabled by default
ENABLE_C=0
ENABLE_GO=0
ENABLE_PERL=0
ENABLE_PHP=0
ENABLE_PYTHON=0
ENABLE_RUST=0
ENABLE_TS=0
PORTABLE=0
CC="${CC:-gcc}"
# Detect OS for platform-specific commands
UNAME_S=$(uname -s)
IS_MSYS=0
# Check for MSYS2/MinGW environment
case "$UNAME_S" in
MINGW*|MSYS*)
IS_MSYS=1
SED_INPLACE="sed -i"
;;
Darwin)
# macOS requires empty string after -i
SED_INPLACE="sed -i ''"
;;
*)
# Linux uses -i directly
SED_INPLACE="sed -i"
;;
esac
# Parse command line arguments
show_help() {
cat << EOF
Usage: ./configure [OPTIONS]
Language Options (all disabled by default):
--enable-all Enable all languages
--enable-c Enable C indexer
--enable-go Enable Go indexer
--enable-perl Enable Perl indexer
--enable-php Enable PHP indexer
--enable-python Enable Python indexer
--enable-rust Enable Rust indexer
--enable-typescript Enable TypeScript indexer
--disable-c Disable C indexer
--disable-go Disable Go indexer
--disable-perl Disable Perl indexer
--disable-php Disable PHP indexer
--disable-python Disable Python indexer
--disable-rust Disable Rust indexer
--disable-typescript Disable TypeScript indexer
Other Options:
--portable Build for any CPU of the target architecture
(omits -march=native -mtune=native; use for
distributable/release binaries)
--help Show this help message
CC=compiler Specify C compiler (default: gcc)
Examples:
./configure --enable-c # C-only build
./configure --enable-c --enable-typescript # C + TypeScript
./configure --enable-all # All languages
./configure --enable-all --disable-go # All except Go
CC=clang ./configure --enable-c # C-only with clang
EOF
exit 0
}
while [ $# -gt 0 ]; do
case "$1" in
--enable-all)
ENABLE_C=1
ENABLE_GO=1
ENABLE_PERL=1
ENABLE_PHP=1
ENABLE_PYTHON=1
ENABLE_RUST=1
ENABLE_TS=1
;;
--enable-c)
ENABLE_C=1
;;
--disable-c)
ENABLE_C=0
;;
--enable-go)
ENABLE_GO=1
;;
--disable-go)
ENABLE_GO=0
;;
--enable-perl)
ENABLE_PERL=1
;;
--disable-perl)
ENABLE_PERL=0
;;
--enable-php)
ENABLE_PHP=1
;;
--disable-php)
ENABLE_PHP=0
;;
--enable-python)
ENABLE_PYTHON=1
;;
--disable-python)
ENABLE_PYTHON=0
;;
--enable-rust)
ENABLE_RUST=1
;;
--disable-rust)
ENABLE_RUST=0
;;
--enable-typescript)
ENABLE_TS=1
;;
--disable-typescript)
ENABLE_TS=0
;;
--portable)
PORTABLE=1
;;
--help)
show_help
;;
CC=*)
CC="${1#CC=}"
;;
*)
echo "Unknown option: $1"
echo "Run './configure --help' for usage information"
exit 1
;;
esac
shift
done
echo "Configuring sourceminder..."
echo ""
# Check for required tools
if ! command -v "$CC" >/dev/null 2>&1; then
echo "Error: C compiler '$CC' not found"
exit 1
fi
echo " C compiler: $CC"
# Check for tree-sitter
#if echo '#include <tree_sitter/api.h>' | $CC -E - >/dev/null 2>&1 || \
# echo '#include <tree-sitter/api.h>' | $CC -E - >/dev/null 2>&1; then
# echo " tree-sitter: found"
#else
# echo "Error: tree-sitter development library not found"
# echo "Install: sudo apt-get install libtree-sitter-dev"
# exit 1
#fi
# Check for SQLite
#if echo '#include <sqlite3.h>' | $CC -E - >/dev/null 2>&1; then
# echo " SQLite: found"
#else
# echo "Error: SQLite development library not found"
# echo "Install: sudo apt-get install libsqlite3-dev"
# exit 1
#fi
# Function to extract version from package.json using grep and sed (cross-platform)
extract_version() {
local package_json="$1"
if [ -f "$package_json" ]; then
# Extract version line, remove quotes, commas, and whitespace
grep '"version"' "$package_json" | head -1 | sed 's/.*"version"[^"]*"\([^"]*\)".*/\1/'
else
echo "unknown"
fi
}
# Generate grammar_version.h files for enabled languages
echo ""
echo "Generating grammar version headers..."
if [ $ENABLE_C -eq 1 ]; then
C_VERSION=$(extract_version "tree-sitter-c/package.json")
echo " C grammar: $C_VERSION"
cat > c/grammar_version.h << EOF
/* Generated by ./configure - DO NOT EDIT */
#ifndef C_GRAMMAR_VERSION_H
#define C_GRAMMAR_VERSION_H
#define GRAMMAR_NAME "c"
#define GRAMMAR_VERSION "$C_VERSION"
#endif
EOF
fi
if [ $ENABLE_GO -eq 1 ]; then
GO_VERSION=$(extract_version "tree-sitter-go/package.json")
echo " Go grammar: $GO_VERSION"
cat > go/grammar_version.h << EOF
/* Generated by ./configure - DO NOT EDIT */
#ifndef GO_GRAMMAR_VERSION_H
#define GO_GRAMMAR_VERSION_H
#define GRAMMAR_NAME "go"
#define GRAMMAR_VERSION "$GO_VERSION"
#endif
EOF
fi
if [ $ENABLE_PERL -eq 1 ]; then
PERL_VERSION=$(extract_version "tree-sitter-perl/package.json")
echo " Perl grammar: $PERL_VERSION"
cat > perl/grammar_version.h << EOF
/* Generated by ./configure - DO NOT EDIT */
#ifndef PERL_GRAMMAR_VERSION_H
#define PERL_GRAMMAR_VERSION_H
#define GRAMMAR_NAME "perl"
#define GRAMMAR_VERSION "$PERL_VERSION"
#endif
EOF
fi
if [ $ENABLE_PHP -eq 1 ]; then
PHP_VERSION=$(extract_version "tree-sitter-php/package.json")
echo " PHP grammar: $PHP_VERSION"
cat > php/grammar_version.h << EOF
/* Generated by ./configure - DO NOT EDIT */
#ifndef PHP_GRAMMAR_VERSION_H
#define PHP_GRAMMAR_VERSION_H
#define GRAMMAR_NAME "php"
#define GRAMMAR_VERSION "$PHP_VERSION"
#endif
EOF
fi
if [ $ENABLE_PYTHON -eq 1 ]; then
PYTHON_VERSION=$(extract_version "tree-sitter-python/package.json")
echo " Python grammar: $PYTHON_VERSION"
cat > python/grammar_version.h << EOF
/* Generated by ./configure - DO NOT EDIT */
#ifndef PYTHON_GRAMMAR_VERSION_H
#define PYTHON_GRAMMAR_VERSION_H
#define GRAMMAR_NAME "python"
#define GRAMMAR_VERSION "$PYTHON_VERSION"
#endif
EOF
fi
if [ $ENABLE_RUST -eq 1 ]; then
RUST_VERSION=$(extract_version "tree-sitter-rust/package.json")
echo " Rust grammar: $RUST_VERSION"
cat > rust/grammar_version.h << EOF
/* Generated by ./configure - DO NOT EDIT */
#ifndef RUST_GRAMMAR_VERSION_H
#define RUST_GRAMMAR_VERSION_H
#define GRAMMAR_NAME "rust"
#define GRAMMAR_VERSION "$RUST_VERSION"
#endif
EOF
fi
if [ $ENABLE_TS -eq 1 ]; then
TS_VERSION=$(extract_version "tree-sitter-typescript/package.json")
echo " TypeScript grammar: $TS_VERSION"
cat > typescript/grammar_version.h << EOF
/* Generated by ./configure - DO NOT EDIT */
#ifndef TS_GRAMMAR_VERSION_H
#define TS_GRAMMAR_VERSION_H
#define GRAMMAR_NAME "typescript"
#define GRAMMAR_VERSION "$TS_VERSION"
#endif
EOF
fi
# Generate config.h
echo ""
echo "Generating config.h..."
cat > config.h << EOF
/* Generated by ./configure - DO NOT EDIT */
#ifndef CONFIG_H
#define CONFIG_H
/* Language support */
#define ENABLE_C $ENABLE_C
#define ENABLE_GO $ENABLE_GO
#define ENABLE_PERL $ENABLE_PERL
#define ENABLE_PHP $ENABLE_PHP
#define ENABLE_PYTHON $ENABLE_PYTHON
#define ENABLE_RUST $ENABLE_RUST
#define ENABLE_TYPESCRIPT $ENABLE_TS
/* Convenience macro for checking if a language is enabled */
#define ENABLED(lang) (ENABLE_##lang)
#endif /* CONFIG_H */
EOF
# Prepare language-specific build targets
ALL_TARGETS=""
SYMLINK_TARGETS=""
# STATIC_TARGETS mirrors ALL_TARGETS for the Linux-only `make static` target,
# which links fully self-contained build/<tool>-static binaries (for use inside
# SWE-bench Docker containers) from the same objects as the normal build.
STATIC_TARGETS=""
if [ $ENABLE_C -eq 1 ]; then
ALL_TARGETS="$ALL_TARGETS \$(BUILD_DIR)/index-c"
SYMLINK_TARGETS="$SYMLINK_TARGETS ./index-c"
STATIC_TARGETS="$STATIC_TARGETS \$(BUILD_DIR)/index-c-static"
fi
if [ $ENABLE_GO -eq 1 ]; then
ALL_TARGETS="$ALL_TARGETS \$(BUILD_DIR)/index-go"
SYMLINK_TARGETS="$SYMLINK_TARGETS ./index-go"
STATIC_TARGETS="$STATIC_TARGETS \$(BUILD_DIR)/index-go-static"
fi
if [ $ENABLE_PERL -eq 1 ]; then
ALL_TARGETS="$ALL_TARGETS \$(BUILD_DIR)/index-perl"
SYMLINK_TARGETS="$SYMLINK_TARGETS ./index-perl"
STATIC_TARGETS="$STATIC_TARGETS \$(BUILD_DIR)/index-perl-static"
fi
if [ $ENABLE_PHP -eq 1 ]; then
ALL_TARGETS="$ALL_TARGETS \$(BUILD_DIR)/index-php"
SYMLINK_TARGETS="$SYMLINK_TARGETS ./index-php"
STATIC_TARGETS="$STATIC_TARGETS \$(BUILD_DIR)/index-php-static"
fi
if [ $ENABLE_PYTHON -eq 1 ]; then
ALL_TARGETS="$ALL_TARGETS \$(BUILD_DIR)/index-python"
SYMLINK_TARGETS="$SYMLINK_TARGETS ./index-python"
STATIC_TARGETS="$STATIC_TARGETS \$(BUILD_DIR)/index-python-static"
fi
if [ $ENABLE_RUST -eq 1 ]; then
ALL_TARGETS="$ALL_TARGETS \$(BUILD_DIR)/index-rust"
SYMLINK_TARGETS="$SYMLINK_TARGETS ./index-rust"
STATIC_TARGETS="$STATIC_TARGETS \$(BUILD_DIR)/index-rust-static"
fi
if [ $ENABLE_TS -eq 1 ]; then
ALL_TARGETS="$ALL_TARGETS \$(BUILD_DIR)/index-ts"
SYMLINK_TARGETS="$SYMLINK_TARGETS ./index-ts"
STATIC_TARGETS="$STATIC_TARGETS \$(BUILD_DIR)/index-ts-static"
fi
# Always include qi
ALL_TARGETS="$ALL_TARGETS \$(BUILD_DIR)/qi"
SYMLINK_TARGETS="$SYMLINK_TARGETS ./qi"
STATIC_TARGETS="$STATIC_TARGETS \$(BUILD_DIR)/qi-static"
# Generate Makefile
echo "Generating Makefile..."
cat > Makefile << 'EOF_MAKEFILE'
CC = @CC@
# Detect OS
UNAME_S := $(shell uname -s)
# Tree-sitter grammar directories (reference external repos)
C_GRAMMAR_DIR = tree-sitter-c
GO_GRAMMAR_DIR = tree-sitter-go
PERL_GRAMMAR_DIR = tree-sitter-perl
PHP_GRAMMAR_DIR = tree-sitter-php/php
PYTHON_GRAMMAR_DIR = tree-sitter-python
RUST_GRAMMAR_DIR = tree-sitter-rust
TS_GRAMMAR_DIR = tree-sitter-typescript/typescript
# Detect MSYS2/MinGW environment
IS_MSYS := $(findstring MINGW,$(UNAME_S))$(findstring MSYS,$(UNAME_S))
ifneq ($(IS_MSYS),)
# MSYS2/MinGW paths (Windows)
# Detect MSYS2 prefix (UCRT64 vs MINGW64)
MSYS2_PREFIX := $(shell test -d /ucrt64 && echo /ucrt64 || echo /mingw64)
# Include tree-sitter/lib/include for api.h (clone tree-sitter repo if needed)
# Also include tree-sitter/lib/src for internal headers needed by lib.c
INCLUDE_PATHS = -I$(MSYS2_PREFIX)/include -Itree-sitter/lib/include -Itree-sitter/lib/src -I. -I$(C_GRAMMAR_DIR)/src -I$(GO_GRAMMAR_DIR)/src -I$(PERL_GRAMMAR_DIR)/src -I$(PHP_GRAMMAR_DIR)/src -I$(PYTHON_GRAMMAR_DIR)/src -I$(RUST_GRAMMAR_DIR)/src -I$(TS_GRAMMAR_DIR)/src
LIB_PATHS = -L$(MSYS2_PREFIX)/lib
# Executable extension for Windows
EXE_EXT = .exe
# Build tree-sitter from source (MSYS2 package doesn't include the library)
TREE_SITTER_SRC = tree-sitter/lib/src/lib.c
TREE_SITTER_OBJ = tree-sitter/lib/src/lib.o
else ifeq ($(UNAME_S),Darwin)
# macOS (Homebrew) paths
# Try to detect Homebrew prefix (Apple Silicon vs Intel)
HOMEBREW_PREFIX := $(shell test -d /opt/homebrew && echo /opt/homebrew || echo /usr/local)
SQLITE_PREFIX := $(HOMEBREW_PREFIX)/opt/sqlite
INCLUDE_PATHS = -I$(HOMEBREW_PREFIX)/include -I$(SQLITE_PREFIX)/include -I. -I$(C_GRAMMAR_DIR)/src -I$(GO_GRAMMAR_DIR)/src -I$(PERL_GRAMMAR_DIR)/src -I$(PHP_GRAMMAR_DIR)/src -I$(PYTHON_GRAMMAR_DIR)/src -I$(RUST_GRAMMAR_DIR)/src -I$(TS_GRAMMAR_DIR)/src
LIB_PATHS = -L$(HOMEBREW_PREFIX)/lib -L$(SQLITE_PREFIX)/lib
EXE_EXT =
else
# Linux paths
INCLUDE_PATHS = -I/usr/local/include -I/usr/include -I. -I$(C_GRAMMAR_DIR)/src -I$(GO_GRAMMAR_DIR)/src -I$(PERL_GRAMMAR_DIR)/src -I$(PHP_GRAMMAR_DIR)/src -I$(PYTHON_GRAMMAR_DIR)/src -I$(RUST_GRAMMAR_DIR)/src -I$(TS_GRAMMAR_DIR)/src
LIB_PATHS = -L/usr/local/lib -Wl,-rpath,/usr/local/lib
EXE_EXT =
endif
# Base flags for release and debug. ARCH_CFLAGS is empty for --portable
# builds (distributable binaries must run on any CPU of the architecture).
BASE_CFLAGS_RELEASE = -O3@ARCH_CFLAGS@ -funroll-loops -std=c11 -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE $(INCLUDE_PATHS)
BASE_CFLAGS_DEBUG = -g -O0 -std=c11 -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE $(INCLUDE_PATHS)
# Default to release build
BASE_CFLAGS = $(BASE_CFLAGS_RELEASE)
# Linker flags - platform specific
ifneq ($(IS_MSYS),)
# Windows: tree-sitter built from source, libsystre provides POSIX regex
LDFLAGS = $(LIB_PATHS) -lsqlite3 -lsystre
LDFLAGS_DEBUG = $(LIB_PATHS) -lsqlite3 -lsystre
else
LDFLAGS = $(LIB_PATHS) -lsqlite3 -ltree-sitter
LDFLAGS_DEBUG = $(LIB_PATHS) -lsqlite3 -ltree-sitter -rdynamic
endif
# Static-link flags for `make static` (Linux only). Produces fully self-contained
# binaries (no shared-library deps) for use inside SWE-bench Docker containers.
# Requires libsqlite3.a (apt-get install libsqlite3-dev) and a static
# libtree-sitter.a built from source in /usr/local/lib. uname -m keeps the
# multiarch path correct on both x86_64 and aarch64.
ifeq ($(UNAME_S),Linux)
SQLITE_STATIC = /usr/lib/$(shell uname -m)-linux-gnu/libsqlite3.a
TREE_SITTER_STATIC = /usr/local/lib/libtree-sitter.a
STATIC_LDFLAGS = $(SQLITE_STATIC) $(TREE_SITTER_STATIC) -lm -lpthread -ldl -static
endif
# Compiler-specific warning flags for our code (strict)
GCC_WARNINGS = -Wall -Wextra -fprefetch-loop-arrays
CLANG_WARNINGS = -Wall -Wextra -Wpedantic -Wconversion -Wshadow -Wcast-qual -Wno-gnu-zero-variadic-macro-arguments
# Relaxed flags for third-party tree-sitter code (suppress common third-party warnings)
THIRD_PARTY_WARNINGS = -Wno-sign-conversion -Wno-strict-prototypes -Wno-padded -Wno-documentation -Wno-covered-switch-default -Wno-missing-prototypes
# Detect compiler by parsing version string
COMPILER_VERSION := $(shell $(CC) --version 2>/dev/null)
ifneq '' '$(findstring clang,$(COMPILER_VERSION))'
CFLAGS = $(BASE_CFLAGS) $(CLANG_WARNINGS)
THIRD_PARTY_CFLAGS = $(BASE_CFLAGS) $(THIRD_PARTY_WARNINGS)
else ifneq '' '$(findstring g++,$(COMPILER_VERSION))'
CFLAGS = $(BASE_CFLAGS) $(GCC_WARNINGS)
THIRD_PARTY_CFLAGS = $(BASE_CFLAGS) $(THIRD_PARTY_WARNINGS)
else ifneq '' '$(findstring gcc,$(COMPILER_VERSION))'
CFLAGS = $(BASE_CFLAGS) $(GCC_WARNINGS)
THIRD_PARTY_CFLAGS = $(BASE_CFLAGS) $(THIRD_PARTY_WARNINGS)
else
$(warning Unknown compiler: $(CC))
CFLAGS = $(BASE_CFLAGS) -Wall
THIRD_PARTY_CFLAGS = $(BASE_CFLAGS)
endif
# Shared source files
SHARED_SRC = shared/database.c shared/filter.c shared/file_walker.c shared/file_watcher.c shared/validation.c shared/comment_utils.c shared/string_utils.c shared/file_opener.c shared/indexer_main.c shared/extensions.c shared/parse_result.c shared/file_utils.c shared/paths.c shared/toc.c shared/debug.c shared/version.c shared/sql_builder.c shared/preflight_report.c shared/embedded_config.c
SHARED_OBJ = $(SHARED_SRC:.c=.o)
# On MSYS2, we need to build tree-sitter from source (package only has CLI, no library)
ifneq ($(IS_MSYS),)
TREE_SITTER_LIB_OBJ = tree-sitter/lib/src/lib.o
else
TREE_SITTER_LIB_OBJ =
endif
# C language files
C_TREE_SITTER_SRC = $(C_GRAMMAR_DIR)/src/parser.c
C_TREE_SITTER_OBJ = $(C_TREE_SITTER_SRC:.c=.o)
C_LANGUAGE_SRC = c/c_language.c
C_LANGUAGE_OBJ = $(C_LANGUAGE_SRC:.c=.o)
C_MAIN_SRC = c/index-c.c
C_MAIN_OBJ = $(C_MAIN_SRC:.c=.o)
# Go language files
GO_TREE_SITTER_SRC = $(GO_GRAMMAR_DIR)/src/parser.c
GO_TREE_SITTER_OBJ = $(GO_TREE_SITTER_SRC:.c=.o)
GO_LANGUAGE_SRC = go/go_language.c
GO_LANGUAGE_OBJ = $(GO_LANGUAGE_SRC:.c=.o)
GO_MAIN_SRC = go/index-go.c
GO_MAIN_OBJ = $(GO_MAIN_SRC:.c=.o)
# Perl language files
PERL_TREE_SITTER_SRC = $(PERL_GRAMMAR_DIR)/src/parser.c $(PERL_GRAMMAR_DIR)/src/scanner.c
PERL_TREE_SITTER_OBJ = $(PERL_TREE_SITTER_SRC:.c=.o)
PERL_LANGUAGE_SRC = perl/perl_language.c
PERL_LANGUAGE_OBJ = $(PERL_LANGUAGE_SRC:.c=.o)
PERL_MAIN_SRC = perl/index-perl.c
PERL_MAIN_OBJ = $(PERL_MAIN_SRC:.c=.o)
# PHP language files
PHP_TREE_SITTER_SRC = $(PHP_GRAMMAR_DIR)/src/parser.c $(PHP_GRAMMAR_DIR)/src/scanner.c
PHP_TREE_SITTER_OBJ = $(PHP_TREE_SITTER_SRC:.c=.o)
PHP_LANGUAGE_SRC = php/php_language.c
PHP_LANGUAGE_OBJ = $(PHP_LANGUAGE_SRC:.c=.o)
PHP_MAIN_SRC = php/index-php.c
PHP_MAIN_OBJ = $(PHP_MAIN_SRC:.c=.o)
# Python language files
PYTHON_TREE_SITTER_SRC = $(PYTHON_GRAMMAR_DIR)/src/parser.c $(PYTHON_GRAMMAR_DIR)/src/scanner.c
PYTHON_TREE_SITTER_OBJ = $(PYTHON_TREE_SITTER_SRC:.c=.o)
PYTHON_LANGUAGE_SRC = python/python_language.c
PYTHON_LANGUAGE_OBJ = $(PYTHON_LANGUAGE_SRC:.c=.o)
PYTHON_MAIN_SRC = python/index-python.c
PYTHON_MAIN_OBJ = $(PYTHON_MAIN_SRC:.c=.o)
# Rust language files
RUST_TREE_SITTER_SRC = $(RUST_GRAMMAR_DIR)/src/parser.c $(RUST_GRAMMAR_DIR)/src/scanner.c
RUST_TREE_SITTER_OBJ = $(RUST_TREE_SITTER_SRC:.c=.o)
RUST_LANGUAGE_SRC = rust/rust_language.c
RUST_LANGUAGE_OBJ = $(RUST_LANGUAGE_SRC:.c=.o)
RUST_MAIN_SRC = rust/index-rust.c
RUST_MAIN_OBJ = $(RUST_MAIN_SRC:.c=.o)
# TypeScript language files
TS_TREE_SITTER_SRC = $(TS_GRAMMAR_DIR)/src/parser.c $(TS_GRAMMAR_DIR)/src/scanner.c
TS_TREE_SITTER_OBJ = $(TS_TREE_SITTER_SRC:.c=.o)
TS_LANGUAGE_SRC = typescript/ts_language.c
TS_LANGUAGE_OBJ = $(TS_LANGUAGE_SRC:.c=.o)
TS_MAIN_SRC = typescript/index-ts.c
TS_MAIN_OBJ = $(TS_MAIN_SRC:.c=.o)
# Query index
QUERY_SRC = query-index.c
QUERY_OBJ = $(QUERY_SRC:.c=.o)
# Web/WASM query slice
WEB_SRC = query-index-web.c
WEB_ENTRY_SRC = qi-web-entry.c
WEB_DIR = $(BUILD_DIR)/web
WASM_DIR = wasm
WEB_SHARED_SRC = shared/sql_builder.c shared/database.c shared/string_utils.c shared-web/toc-web.c shared-web/source-render-web.c
# Build directory
BUILD_DIR = build
# Targets - configured by ./configure script
all: $(BUILD_DIR)@ALL_TARGETS@@SYMLINK_TARGETS@
# Create build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Embedded default config data: generated from the config/*.txt files so
# installed binaries work without /usr/share/sourceminder. Files on disk
# always override the built-in defaults (see resolve_data_file in paths.c).
EMBED_CONFIG_TOOL = $(BUILD_DIR)/embed-config
EMBEDDED_CONFIG_SRC = shared/embedded_config.c
EMBEDDED_CONFIG_INPUTS = $(wildcard shared/config/*.txt) $(wildcard c/config/*.txt) $(wildcard go/config/*.txt) $(wildcard perl/config/*.txt) $(wildcard php/config/*.txt) $(wildcard python/config/*.txt) $(wildcard rust/config/*.txt) $(wildcard typescript/config/*.txt)
$(EMBED_CONFIG_TOOL): tools/embed-config.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -o $@ tools/embed-config.c
$(EMBEDDED_CONFIG_SRC): $(EMBED_CONFIG_TOOL) $(EMBEDDED_CONFIG_INPUTS)
$(EMBED_CONFIG_TOOL) $@ $(EMBEDDED_CONFIG_INPUTS)
# C indexer
$(BUILD_DIR)/index-c: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(C_TREE_SITTER_OBJ) $(C_LANGUAGE_OBJ) $(C_MAIN_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# Go indexer
$(BUILD_DIR)/index-go: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(GO_TREE_SITTER_OBJ) $(GO_LANGUAGE_OBJ) $(GO_MAIN_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# Perl indexer
$(BUILD_DIR)/index-perl: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(PERL_TREE_SITTER_OBJ) $(PERL_LANGUAGE_OBJ) $(PERL_MAIN_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# PHP indexer
$(BUILD_DIR)/index-php: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(PHP_TREE_SITTER_OBJ) $(PHP_LANGUAGE_OBJ) $(PHP_MAIN_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# Python indexer
$(BUILD_DIR)/index-python: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(PYTHON_TREE_SITTER_OBJ) $(PYTHON_LANGUAGE_OBJ) $(PYTHON_MAIN_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# Rust indexer
$(BUILD_DIR)/index-rust: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(RUST_TREE_SITTER_OBJ) $(RUST_LANGUAGE_OBJ) $(RUST_MAIN_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# TypeScript indexer
$(BUILD_DIR)/index-ts: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(TS_TREE_SITTER_OBJ) $(TS_LANGUAGE_OBJ) $(TS_MAIN_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# Query tool
$(BUILD_DIR)/qi: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(QUERY_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# ── Static binaries (Linux only): `make static` ───────────────────────────────
# Links fully self-contained build/<tool>-static binaries for use inside
# SWE-bench Docker containers and release tarballs (release.sh), reusing the
# same objects as the normal build.
# Canned recipe: enforce Linux, static-link $^ into $@, then verify no dyn
# deps. On a static binary, glibc ldd says "not a dynamic executable"; musl
# ldd (Alpine release builds) says "Not a valid dynamic program".
define static_link
@test "$(UNAME_S)" = "Linux" || { echo "ERROR: 'make static' is supported on Linux only (got $(UNAME_S))"; exit 1; }
$(CC) $(CFLAGS) -o $@ $^ $(STATIC_LDFLAGS)
@ldd $@ 2>&1 | grep -qiE "not a dynamic executable|not a valid dynamic program" && echo "OK: $@ is fully static ($$(du -h $@ | cut -f1))" || { echo "ERROR: $@ has dynamic dependencies:"; ldd $@; exit 1; }
endef
$(BUILD_DIR)/index-c-static: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(C_TREE_SITTER_OBJ) $(C_LANGUAGE_OBJ) $(C_MAIN_OBJ) | $(BUILD_DIR)
$(static_link)
$(BUILD_DIR)/index-go-static: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(GO_TREE_SITTER_OBJ) $(GO_LANGUAGE_OBJ) $(GO_MAIN_OBJ) | $(BUILD_DIR)
$(static_link)
$(BUILD_DIR)/index-perl-static: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(PERL_TREE_SITTER_OBJ) $(PERL_LANGUAGE_OBJ) $(PERL_MAIN_OBJ) | $(BUILD_DIR)
$(static_link)
$(BUILD_DIR)/index-php-static: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(PHP_TREE_SITTER_OBJ) $(PHP_LANGUAGE_OBJ) $(PHP_MAIN_OBJ) | $(BUILD_DIR)
$(static_link)
$(BUILD_DIR)/index-python-static: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(PYTHON_TREE_SITTER_OBJ) $(PYTHON_LANGUAGE_OBJ) $(PYTHON_MAIN_OBJ) | $(BUILD_DIR)
$(static_link)
$(BUILD_DIR)/index-rust-static: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(RUST_TREE_SITTER_OBJ) $(RUST_LANGUAGE_OBJ) $(RUST_MAIN_OBJ) | $(BUILD_DIR)
$(static_link)
$(BUILD_DIR)/index-ts-static: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(TS_TREE_SITTER_OBJ) $(TS_LANGUAGE_OBJ) $(TS_MAIN_OBJ) | $(BUILD_DIR)
$(static_link)
$(BUILD_DIR)/qi-static: $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(QUERY_OBJ) | $(BUILD_DIR)
$(static_link)
# Aggregate: build static binaries for the enabled languages (+ qi).
static: $(BUILD_DIR)@STATIC_TARGETS@
@echo "Static binaries built in $(BUILD_DIR)/ (Linux, fully static)."
# All selected binaries. Used as an order-only prerequisite (after the '|') on
# every symlink so that under a parallel build (make -j) no 'ln -sf' runs until
# the entire build is finished. This keeps output grouped (all compiles, then
# all symlinks) instead of interleaving a slow link (e.g. rust) among symlinks.
ALL_BINARIES =@ALL_TARGETS@
# Convenience symlinks in root
./index-c: $(BUILD_DIR)/index-c | $(ALL_BINARIES)
ln -sf $(BUILD_DIR)/index-c index-c
./index-go: $(BUILD_DIR)/index-go | $(ALL_BINARIES)
ln -sf $(BUILD_DIR)/index-go index-go
./index-perl: $(BUILD_DIR)/index-perl | $(ALL_BINARIES)
ln -sf $(BUILD_DIR)/index-perl index-perl
./index-php: $(BUILD_DIR)/index-php | $(ALL_BINARIES)
ln -sf $(BUILD_DIR)/index-php index-php
./index-python: $(BUILD_DIR)/index-python | $(ALL_BINARIES)
ln -sf $(BUILD_DIR)/index-python index-python
./index-rust: $(BUILD_DIR)/index-rust | $(ALL_BINARIES)
ln -sf $(BUILD_DIR)/index-rust index-rust
./index-ts: $(BUILD_DIR)/index-ts | $(ALL_BINARIES)
ln -sf $(BUILD_DIR)/index-ts index-ts
./qi: $(BUILD_DIR)/qi | $(ALL_BINARIES)
ln -sf $(BUILD_DIR)/qi qi
# Build tree-sitter library from source (MSYS2 only - package doesn't include library)
ifneq ($(IS_MSYS),)
tree-sitter/lib/src/lib.o: tree-sitter/lib/src/lib.c
$(CC) $(THIRD_PARTY_CFLAGS) -c $< -o $@
endif
# Pattern rules for object files
# Third-party tree-sitter parser code (relaxed warnings)
$(C_GRAMMAR_DIR)/src/%.o: $(C_GRAMMAR_DIR)/src/%.c
$(CC) $(THIRD_PARTY_CFLAGS) -c $< -o $@
$(GO_GRAMMAR_DIR)/src/%.o: $(GO_GRAMMAR_DIR)/src/%.c
$(CC) $(THIRD_PARTY_CFLAGS) -c $< -o $@
$(PERL_GRAMMAR_DIR)/src/%.o: $(PERL_GRAMMAR_DIR)/src/%.c
$(CC) $(THIRD_PARTY_CFLAGS) -c $< -o $@
$(PHP_GRAMMAR_DIR)/src/%.o: $(PHP_GRAMMAR_DIR)/src/%.c
$(CC) $(THIRD_PARTY_CFLAGS) -c $< -o $@
$(PYTHON_GRAMMAR_DIR)/src/%.o: $(PYTHON_GRAMMAR_DIR)/src/%.c
$(CC) $(THIRD_PARTY_CFLAGS) -c $< -o $@
$(RUST_GRAMMAR_DIR)/src/%.o: $(RUST_GRAMMAR_DIR)/src/%.c
$(CC) $(THIRD_PARTY_CFLAGS) -c $< -o $@
$(TS_GRAMMAR_DIR)/src/%.o: $(TS_GRAMMAR_DIR)/src/%.c
$(CC) $(THIRD_PARTY_CFLAGS) -c $< -o $@
# Our code (strict warnings)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(SHARED_OBJ) $(TREE_SITTER_LIB_OBJ) $(C_TREE_SITTER_OBJ) $(C_LANGUAGE_OBJ) $(C_MAIN_OBJ) $(GO_TREE_SITTER_OBJ) $(GO_LANGUAGE_OBJ) $(GO_MAIN_OBJ) $(PERL_TREE_SITTER_OBJ) $(PERL_LANGUAGE_OBJ) $(PERL_MAIN_OBJ) $(PHP_TREE_SITTER_OBJ) $(PHP_LANGUAGE_OBJ) $(PHP_MAIN_OBJ) $(PYTHON_TREE_SITTER_OBJ) $(PYTHON_LANGUAGE_OBJ) $(PYTHON_MAIN_OBJ) $(RUST_TREE_SITTER_OBJ) $(RUST_LANGUAGE_OBJ) $(RUST_MAIN_OBJ) $(TS_TREE_SITTER_OBJ) $(TS_LANGUAGE_OBJ) $(TS_MAIN_OBJ) $(QUERY_OBJ)
rm -rf $(BUILD_DIR)
rm -f $(EMBEDDED_CONFIG_SRC)
rm -f index-c index-go index-perl index-php index-python index-rust index-ts qi
install: all install-data
@mkdir -p /usr/local/bin
cp $(BUILD_DIR)/qi /usr/local/bin/qi
@INSTALL_TARGETS@
# IMPORTANT: blank line above is required to prevent sed from appending next line to last cp command
@echo ""
@echo "Binaries installed to /usr/local/bin/"
@echo "Data files installed to:"
ifeq ($(UNAME_S),Darwin)
@echo " /usr/local/share/sourceminder/"
else
@echo " /usr/share/sourceminder/"
endif
# Install config files to system location
install-data:
ifeq ($(UNAME_S),Darwin)
@echo "Installing config files to /usr/local/share/sourceminder/..."
mkdir -p /usr/local/share/sourceminder/shared/config
cp shared/config/*.txt /usr/local/share/sourceminder/shared/config/
@INSTALL_DATA_MAC_TARGETS@
# IMPORTANT: blank line above is required to prevent sed from appending 'else' to last cp command
else
@echo "Installing config files to /usr/share/sourceminder/..."
mkdir -p /usr/share/sourceminder/shared/config
cp shared/config/*.txt /usr/share/sourceminder/shared/config/
@INSTALL_DATA_LINUX_TARGETS@
# IMPORTANT: blank line above is required to prevent sed from appending 'endif' to last cp command
endif
# Uninstall binaries and data files
uninstall:
rm -f /usr/local/bin/qi
@UNINSTALL_TARGETS@
# IMPORTANT: blank line above is required to prevent sed from appending 'ifeq' to last rm command
ifeq ($(UNAME_S),Darwin)
rm -rf /usr/local/share/sourceminder
@echo "Uninstalled from /usr/local/bin/ and /usr/local/share/sourceminder/"
else
rm -rf /usr/share/sourceminder
@echo "Uninstalled from /usr/local/bin/ and /usr/share/sourceminder/"
endif
lint:
@echo "Running clang-tidy..."
@clang-tidy shared/*.c typescript/*.c typescript/src/*.c query-index.c \
-- $(CFLAGS) -I. -Ishared || true
@echo ""
# Debug build - rebuild everything with debug symbols
debug:
@echo "Building with debug symbols (-g -O0 -rdynamic)..."
$(MAKE) clean
$(MAKE) all BASE_CFLAGS="$(BASE_CFLAGS_DEBUG)" LDFLAGS="$(LDFLAGS_DEBUG)"
# Test target - compile and run regression tests ('tests' is an alias)
test tests: tests/run-tests
@echo "Running regression tests..."
@./tests/run-tests
tests/run-tests: tests/run-tests.c
@echo "Compiling test runner..."
@$(CC) -std=c11 -Wall -Wextra -o tests/run-tests tests/run-tests.c
# Web/WASM slice compile-only smoke test
web-smoke: $(WEB_DIR)
emcc -I. -Ishared -Ishared-web -std=c11 -c -DENABLE_TYPESCRIPT=1 $(WEB_SRC) -o $(WEB_DIR)/query-index-web.o
# Linked web/WASM module: qi SQL builder + output formatter (no sqlite3)
web: $(WEB_DIR)
emcc -I$(WASM_DIR) -I. -Ishared -Ishared-web -std=c11 -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE -DENABLE_TYPESCRIPT=1 \
-O2 \
-sMODULARIZE=1 \
-sEXPORT_ES6=1 \
-sEXPORT_NAME='QiWebModule' \
-sEXPORTED_FUNCTIONS='["_qi_web_build","_qi_web_format","_qi_web_format_breakdown","_qi_web_format_files","_qi_web_format_no_results","_qi_web_free_result","_qi_web_toc_format","_qi_web_help","_qi_web_list_types","_qi_web_version","_malloc","_free"]' \
-sEXPORTED_RUNTIME_METHODS='["ccall","cwrap","UTF8ToString","lengthBytesUTF8","stringToUTF8"]' \
-sALLOW_MEMORY_GROWTH=1 \
-sINITIAL_MEMORY=32MB \
-o $(WEB_DIR)/qi-web.js \
$(WEB_SRC) $(WEB_ENTRY_SRC) $(WEB_SHARED_SRC)
@mkdir -p html/assets
cp $(WEB_DIR)/qi-web.js $(WEB_DIR)/qi-web.wasm html/assets/
@# Content-hash the wasm and mint hashed copies + asset-manifest.json so the
@# browser worker (which resolves asset names via asset-manifest.json) can
@# never serve a stale cached binary. The wasm glue+binary live under
@# html/assets/ (the CDN origin in prod); the manifest stays same-origin at
@# html/ (the worker fetches it there). The plain html/assets/qi-web.{js,wasm}
@# above stay as the no-manifest fallback; the glob below only clears prior
@# HASHED copies (qi-web.<hash>.*), not the two-dotless plain names. Both js
@# and wasm share the wasm-derived hash (the .js embeds no wasm name -- the
@# worker's locateFile rewrites it). shasum is the macOS fallback.
@rm -f html/assets/qi-web.*.js html/assets/qi-web.*.wasm
@H=$$( { sha256sum html/assets/qi-web.wasm 2>/dev/null || shasum -a 256 html/assets/qi-web.wasm; } | cut -c1-12 ); \
cp html/assets/qi-web.js html/assets/qi-web.$$H.js; \
cp html/assets/qi-web.wasm html/assets/qi-web.$$H.wasm; \
printf '{"qiWebJs":"qi-web.%s.js","qiWebWasm":"qi-web.%s.wasm"}\n' $$H $$H > html/asset-manifest.json; \
echo "web: asset-manifest.json -> qi-web.$$H.{js,wasm}"
# Headless end-to-end test of the web bridge: loads the built qi-web.wasm under
# Node and runs canned qi queries through the shared pipeline (no browser).
# Run after `make web`. See test/web-harness/README.md.
web-test:
node test/web-harness/run.mjs
# Side-by-side parity: diff native `qi` output against the web bridge for the
# same commands and data. Run after `make web`. See test/web-harness/README.md.
web-parity:
node test/web-harness/parity.mjs --batch
# Working-tree index for the web test harness (test/web-harness/projects.test.json):
# index this repo with the local C indexer into build/test/, then snapshot a
# browser-safe (non-WAL) copy via VACUUM INTO. --exclude-dir html keeps demo
# source copies under html/ out of the index.
test-web-db: ./index-c
@mkdir -p build/test
@rm -f build/test/code-index.db build/test/code-index.browser.db
./index-c . --once --silent --db-file build/test/code-index.db --exclude-dir html
sqlite3 build/test/code-index.db "VACUUM INTO 'build/test/code-index.browser.db'"
@echo "wrote build/test/code-index.db + build/test/code-index.browser.db"
$(WEB_DIR):
mkdir -p $(WEB_DIR)
.PHONY: all static clean install install-data uninstall lint debug test tests web web-smoke web-test web-parity test-web-db
EOF_MAKEFILE
# Substitute variables in Makefile
if [ $PORTABLE -eq 1 ]; then
ARCH_CFLAGS=""
else
ARCH_CFLAGS=" -march=native -mtune=native"
fi
if [ "$UNAME_S" = "Darwin" ]; then
sed -i '' "s|@CC@|$CC|g" Makefile
sed -i '' "s|@ARCH_CFLAGS@|$ARCH_CFLAGS|g" Makefile
sed -i '' "s|@ALL_TARGETS@|$ALL_TARGETS|g" Makefile
sed -i '' "s|@SYMLINK_TARGETS@|$SYMLINK_TARGETS|g" Makefile
sed -i '' "s|@STATIC_TARGETS@|$STATIC_TARGETS|g" Makefile
else
sed -i "s|@CC@|$CC|g" Makefile
sed -i "s|@ARCH_CFLAGS@|$ARCH_CFLAGS|g" Makefile
sed -i "s|@ALL_TARGETS@|$ALL_TARGETS|g" Makefile
sed -i "s|@SYMLINK_TARGETS@|$SYMLINK_TARGETS|g" Makefile
sed -i "s|@STATIC_TARGETS@|$STATIC_TARGETS|g" Makefile
fi
# Build install/uninstall targets based on enabled languages
INSTALL_TARGETS=""
UNINSTALL_TARGETS=""
INSTALL_DATA_MAC=""
INSTALL_DATA_LINUX=""
if [ $ENABLE_C -eq 1 ]; then
INSTALL_TARGETS="$INSTALL_TARGETS\n\tcp \$(BUILD_DIR)/index-c /usr/local/bin/index-c"
UNINSTALL_TARGETS="$UNINSTALL_TARGETS\n\trm -f /usr/local/bin/index-c"
INSTALL_DATA_MAC="$INSTALL_DATA_MAC\n\tmkdir -p /usr/local/share/sourceminder/c/config\n\tcp c/config/*.txt /usr/local/share/sourceminder/c/config/"
INSTALL_DATA_LINUX="$INSTALL_DATA_LINUX\n\tmkdir -p /usr/share/sourceminder/c/config\n\tcp c/config/*.txt /usr/share/sourceminder/c/config/"
fi
if [ $ENABLE_GO -eq 1 ]; then
INSTALL_TARGETS="$INSTALL_TARGETS\n\tcp \$(BUILD_DIR)/index-go /usr/local/bin/index-go"
UNINSTALL_TARGETS="$UNINSTALL_TARGETS\n\trm -f /usr/local/bin/index-go"
INSTALL_DATA_MAC="$INSTALL_DATA_MAC\n\tmkdir -p /usr/local/share/sourceminder/go/config\n\tcp go/config/*.txt /usr/local/share/sourceminder/go/config/"
INSTALL_DATA_LINUX="$INSTALL_DATA_LINUX\n\tmkdir -p /usr/share/sourceminder/go/config\n\tcp go/config/*.txt /usr/share/sourceminder/go/config/"
fi
if [ $ENABLE_PERL -eq 1 ]; then
INSTALL_TARGETS="$INSTALL_TARGETS\n\tcp \$(BUILD_DIR)/index-perl /usr/local/bin/index-perl"
UNINSTALL_TARGETS="$UNINSTALL_TARGETS\n\trm -f /usr/local/bin/index-perl"
INSTALL_DATA_MAC="$INSTALL_DATA_MAC\n\tmkdir -p /usr/local/share/sourceminder/perl/config\n\tcp perl/config/*.txt /usr/local/share/sourceminder/perl/config/"
INSTALL_DATA_LINUX="$INSTALL_DATA_LINUX\n\tmkdir -p /usr/share/sourceminder/perl/config\n\tcp perl/config/*.txt /usr/share/sourceminder/perl/config/"
fi
if [ $ENABLE_PHP -eq 1 ]; then
INSTALL_TARGETS="$INSTALL_TARGETS\n\tcp \$(BUILD_DIR)/index-php /usr/local/bin/index-php"
UNINSTALL_TARGETS="$UNINSTALL_TARGETS\n\trm -f /usr/local/bin/index-php"
INSTALL_DATA_MAC="$INSTALL_DATA_MAC\n\tmkdir -p /usr/local/share/sourceminder/php/config\n\tcp php/config/*.txt /usr/local/share/sourceminder/php/config/"
INSTALL_DATA_LINUX="$INSTALL_DATA_LINUX\n\tmkdir -p /usr/share/sourceminder/php/config\n\tcp php/config/*.txt /usr/share/sourceminder/php/config/"
fi
if [ $ENABLE_PYTHON -eq 1 ]; then
INSTALL_TARGETS="$INSTALL_TARGETS\n\tcp \$(BUILD_DIR)/index-python /usr/local/bin/index-python"
UNINSTALL_TARGETS="$UNINSTALL_TARGETS\n\trm -f /usr/local/bin/index-python"
INSTALL_DATA_MAC="$INSTALL_DATA_MAC\n\tmkdir -p /usr/local/share/sourceminder/python/config\n\tcp python/config/*.txt /usr/local/share/sourceminder/python/config/"
INSTALL_DATA_LINUX="$INSTALL_DATA_LINUX\n\tmkdir -p /usr/share/sourceminder/python/config\n\tcp python/config/*.txt /usr/share/sourceminder/python/config/"
fi
if [ $ENABLE_RUST -eq 1 ]; then
INSTALL_TARGETS="$INSTALL_TARGETS\n\tcp \$(BUILD_DIR)/index-rust /usr/local/bin/index-rust"
UNINSTALL_TARGETS="$UNINSTALL_TARGETS\n\trm -f /usr/local/bin/index-rust"
INSTALL_DATA_MAC="$INSTALL_DATA_MAC\n\tmkdir -p /usr/local/share/sourceminder/rust/config\n\tcp rust/config/*.txt /usr/local/share/sourceminder/rust/config/"
INSTALL_DATA_LINUX="$INSTALL_DATA_LINUX\n\tmkdir -p /usr/share/sourceminder/rust/config\n\tcp rust/config/*.txt /usr/share/sourceminder/rust/config/"
fi
if [ $ENABLE_TS -eq 1 ]; then
INSTALL_TARGETS="$INSTALL_TARGETS\n\tcp \$(BUILD_DIR)/index-ts /usr/local/bin/index-ts"
UNINSTALL_TARGETS="$UNINSTALL_TARGETS\n\trm -f /usr/local/bin/index-ts"
INSTALL_DATA_MAC="$INSTALL_DATA_MAC\n\tmkdir -p /usr/local/share/sourceminder/typescript/config\n\tcp typescript/config/*.txt /usr/local/share/sourceminder/typescript/config/"
INSTALL_DATA_LINUX="$INSTALL_DATA_LINUX\n\tmkdir -p /usr/share/sourceminder/typescript/config\n\tcp typescript/config/*.txt /usr/share/sourceminder/typescript/config/"
fi
# Use printf to handle newlines correctly
if [ "$UNAME_S" = "Darwin" ]; then
printf "%b" "$INSTALL_TARGETS" | sed -i '' "/^@INSTALL_TARGETS@/r /dev/stdin" Makefile
sed -i '' "s|@INSTALL_TARGETS@||g" Makefile
printf "%b" "$UNINSTALL_TARGETS" | sed -i '' "/^@UNINSTALL_TARGETS@/r /dev/stdin" Makefile
sed -i '' "s|@UNINSTALL_TARGETS@||g" Makefile
printf "%b" "$INSTALL_DATA_MAC" | sed -i '' "/^@INSTALL_DATA_MAC_TARGETS@/r /dev/stdin" Makefile
sed -i '' "s|@INSTALL_DATA_MAC_TARGETS@||g" Makefile
printf "%b" "$INSTALL_DATA_LINUX" | sed -i '' "/^@INSTALL_DATA_LINUX_TARGETS@/r /dev/stdin" Makefile
sed -i '' "s|@INSTALL_DATA_LINUX_TARGETS@||g" Makefile
else
printf "%b" "$INSTALL_TARGETS" | sed -i "/^@INSTALL_TARGETS@/r /dev/stdin" Makefile
sed -i "s|@INSTALL_TARGETS@||g" Makefile
printf "%b" "$UNINSTALL_TARGETS" | sed -i "/^@UNINSTALL_TARGETS@/r /dev/stdin" Makefile
sed -i "s|@UNINSTALL_TARGETS@||g" Makefile
printf "%b" "$INSTALL_DATA_MAC" | sed -i "/^@INSTALL_DATA_MAC_TARGETS@/r /dev/stdin" Makefile
sed -i "s|@INSTALL_DATA_MAC_TARGETS@||g" Makefile
printf "%b" "$INSTALL_DATA_LINUX" | sed -i "/^@INSTALL_DATA_LINUX_TARGETS@/r /dev/stdin" Makefile
sed -i "s|@INSTALL_DATA_LINUX_TARGETS@||g" Makefile
fi
echo ""
echo "Configuration complete!"
echo ""
echo "Build configuration:"
echo " C compiler: $CC"
if [ $PORTABLE -eq 1 ]; then
echo " CPU tuning: portable (generic $(uname -m))"
else
echo " CPU tuning: native (this machine only; use --portable for distributable binaries)"
fi
echo " Languages enabled:"
[ $ENABLE_C -eq 1 ] && echo " - C"
[ $ENABLE_GO -eq 1 ] && echo " - Go"
[ $ENABLE_PERL -eq 1 ] && echo " - Perl"
[ $ENABLE_PHP -eq 1 ] && echo " - PHP"
[ $ENABLE_PYTHON -eq 1 ] && echo " - Python"
[ $ENABLE_RUST -eq 1 ] && echo " - Rust"
[ $ENABLE_TS -eq 1 ] && echo " - TypeScript"
echo ""
echo "Run 'make' to build the project."