-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_script.sh
More file actions
73 lines (58 loc) · 2.45 KB
/
build_script.sh
File metadata and controls
73 lines (58 loc) · 2.45 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
#!/bin/bash
set -e # Exit on error
echo "Building vsort library..."
# Check for Command Line Tools installation
if ! xcode-select -p &>/dev/null; then
echo "Error: Xcode Command Line Tools not found."
echo "Please install them using: xcode-select --install"
exit 1
fi
# Detect available SDK paths
MACOS_SDK_PATH=""
POSSIBLE_SDK_PATHS=(
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
"/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk"
"/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk"
"/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk"
"/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk"
)
for SDK in "${POSSIBLE_SDK_PATHS[@]}"; do
if [ -d "$SDK" ]; then
MACOS_SDK_PATH="$SDK"
break
fi
done
if [ -z "$MACOS_SDK_PATH" ]; then
echo "Warning: Could not find MacOS SDK. Will try to continue without specifying SDK."
SDK_FLAGS=""
else
echo "Using MacOS SDK at: $MACOS_SDK_PATH"
SDK_FLAGS="-isysroot $MACOS_SDK_PATH"
fi
# Standard compiler flags with SDK path
CFLAGS="-O3 -ffast-math -march=native -fomit-frame-pointer -flto -Wall -DVSORT_VERSION=\"0.5.0\" -I. $SDK_FLAGS"
LDFLAGS="-flto"
# Detect if running on Apple Silicon
if [ "$(uname -m)" = "arm64" ]; then
CFLAGS="$CFLAGS -mcpu=apple-a14 -DUSE_APPLE_SILICON_OPTIMIZATIONS"
fi
# Add optimization flags
CFLAGS="$CFLAGS -ffast-math -ftree-vectorize -funroll-loops"
# Compile source files
echo "Compiling with flags: $CFLAGS"
clang $CFLAGS -c -o vsort.o vsort.c
clang $CFLAGS -c -o vsort_logger.o vsort_logger.c
# Create the static library
echo "Creating static library..."
ar rcs libvsort.a vsort.o vsort_logger.o
echo "Building tests..."
# Build test_basic with the same flags
clang $CFLAGS $LDFLAGS -o tests/test_basic tests/test_basic.c -framework Foundation -framework CoreFoundation -L. -lvsort -lm
# Build other tests as needed
# clang $CFLAGS $LDFLAGS -o tests/test_performance tests/test_performance.c -framework Foundation -framework CoreFoundation -L. -lvsort -lm
# clang $CFLAGS $LDFLAGS -o tests/test_apple_silicon tests/test_apple_silicon.c -framework Foundation -framework CoreFoundation -L. -lvsort -lm
echo "Building examples..."
# Build basic example
clang $CFLAGS $LDFLAGS -o examples/basic_example examples/basic_example.c -framework Foundation -framework CoreFoundation -L. -lvsort -lm
echo "Build completed successfully!"