forked from esmuellert/codediff.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·106 lines (92 loc) · 2.81 KB
/
build.sh
File metadata and controls
executable file
·106 lines (92 loc) · 2.81 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
#!/usr/bin/env bash
# Auto-generated by CMake - DO NOT EDIT MANUALLY
# This script allows building without CMake installed
set -e
cd "$(dirname "$0")/libvscode-diff"
# Detect platform for library extension
if [[ "$OSTYPE" == "darwin"* ]]; then
PLATFORM="Darwin"
LIB_EXT="dylib"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
PLATFORM="Linux"
LIB_EXT="so"
else
PLATFORM="Unknown"
LIB_EXT="so"
fi
# Auto-detect compiler (respect CC environment variable)
if [ -z "$CC" ]; then
if command -v cc >/dev/null 2>&1; then
CC="cc"
elif command -v gcc >/dev/null 2>&1; then
CC="gcc"
elif command -v clang >/dev/null 2>&1; then
CC="clang"
else
echo "Error: No C compiler found (tried: cc, gcc, clang)"
exit 1
fi
fi
echo "Building vscode_diff (standalone mode)..."
echo "Compiler: $CC"
echo "Platform: $PLATFORM"
# Compiler flags
CFLAGS="-Wall -Wextra -std=c11 -O2 -DNDEBUG -DUTF8PROC_STATIC -D_POSIX_C_SOURCE=199309L -Iinclude -Ibuild/include -Ivendor -fPIC"
LDFLAGS="-shared"
# Add -lm for math library on Unix
if [[ "$PLATFORM" != "Darwin" ]]; then
LDFLAGS="$LDFLAGS -lm"
fi
# Detect OpenMP support
USE_OPENMP=0
if [[ "$PLATFORM" == "Darwin" ]]; then
# macOS: Check for Homebrew libomp
if command -v brew >/dev/null 2>&1; then
LIBOMP_PREFIX=$(brew --prefix libomp 2>/dev/null || true)
if [ -n "$LIBOMP_PREFIX" ] && [ -f "$LIBOMP_PREFIX/lib/libomp.dylib" ]; then
USE_OPENMP=1
CFLAGS="$CFLAGS -Xpreprocessor -fopenmp -I$LIBOMP_PREFIX/include -DUSE_OPENMP"
LDFLAGS="$LDFLAGS -L$LIBOMP_PREFIX/lib -lomp"
echo "OpenMP: enabled (Homebrew libomp)"
fi
fi
else
# Linux: Check if compiler supports OpenMP
echo "int main() { return 0; }" > /tmp/omp_test.c
if $CC -fopenmp /tmp/omp_test.c -o /tmp/omp_test 2>/dev/null; then
USE_OPENMP=1
CFLAGS="$CFLAGS -fopenmp -DUSE_OPENMP"
LDFLAGS="$LDFLAGS -fopenmp"
echo "OpenMP: enabled"
fi
rm -f /tmp/omp_test.c /tmp/omp_test
fi
if [ "$USE_OPENMP" -eq 0 ]; then
echo "OpenMP: disabled (not found)"
fi
# Source files (including bundled utf8proc)
SOURCES="\
default_lines_diff_computer.c \
src/char_level.c \
src/line_level.c \
src/myers.c \
src/optimize.c \
src/sequence.c \
src/range_mapping.c \
src/string_hash_map.c \
src/utils.c \
src/print_utils.c \
src/utf8_utils.c \
vendor/utf8proc.c"
# Build
mkdir -p build
mkdir -p build/include
# Generate version.h
VERSION=$(cat ../VERSION | tr -d '[:space:]')
sed "s/@''PROJECT_VERSION@/$VERSION/g" include/version.h.in > build/include/version.h
echo "Compiling..."
$CC $CFLAGS $LDFLAGS -o libvscode_diff.$LIB_EXT $SOURCES
echo "Installing to plugin root..."
cp libvscode_diff.$LIB_EXT ../libvscode_diff.$LIB_EXT
echo "✓ Build successful: libvscode_diff.$LIB_EXT"
cd ..