forked from diffblue/2ls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_new.sh
121 lines (109 loc) · 3.16 KB
/
build_new.sh
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
#!/bin/bash
# Default values
JOBS=$(sysctl -n hw.ncpu) # Get number of CPU cores
BUILD_TYPE="Release"
COMPILER=""
CLEAN=0
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-j*)
if [[ "$1" == "-j" ]]; then
JOBS="$2"
shift
else
JOBS="${1#-j}"
fi
;;
--clean)
CLEAN=1
;;
--debug)
BUILD_TYPE="Debug"
;;
--compiler=*)
COMPILER="${1#*=}"
;;
--help)
echo "Usage: $0 [options]"
echo "Options:"
echo " -j N Use N parallel jobs for compilation"
echo " --clean Clean before building"
echo " --debug Build in debug mode"
echo " --compiler=<compiler> Specify compiler (e.g., --compiler=clang++)"
echo " --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
shift
done
# Function to check if submodule is initialized and built
check_submodule() {
local module_path="$1"
if [ ! -d "$module_path/.git" ]; then
return 1 # Not initialized
fi
return 0
}
# Function to handle errors
handle_error() {
echo "Error: $1"
exit 1
}
# Clean if requested
if [ $CLEAN -eq 1 ]; then
echo "Cleaning build..."
make -C src clean
make -C lib/cbmc/src clean
fi
# Initialize and update submodules if needed
if ! check_submodule "lib/cbmc"; then
echo "Initializing submodules..."
git submodule update --init --recursive || handle_error "Failed to initialize submodules"
fi
# Build CBMC if needed
cd lib/cbmc || handle_error "Failed to enter CBMC directory"
if [ ! -f "src/cbmc/cbmc" ]; then
git checkout $CBMC_VERSION || handle_error "Failed to checkout CBMC version"
# Check and download SAT solver
if grep '^MINISAT2' src/config.inc > /dev/null; then
echo "Downloading MiniSat2..."
make -C src minisat2-download > /dev/null || handle_error "Failed to download MiniSat2"
elif grep '^GLUCOSE' src/config.inc; then
echo "Downloading Glucose..."
make -C src glucose-download || handle_error "Failed to download Glucose"
else
handle_error "SAT solver not supported"
fi
# Build CBMC
echo "Building CBMC..."
if [ -n "$COMPILER" ]; then
make -C src CXX="$COMPILER" -j"$JOBS" || handle_error "CBMC build failed"
else
make -C src -j"$JOBS" || handle_error "CBMC build failed"
fi
else
echo "CBMC already built, skipping..."
fi
cd ../..
# Build 2LS
echo "Building 2LS..."
if [ -n "$COMPILER" ]; then
make -C src CXX="$COMPILER" -j"$JOBS" || handle_error "2LS build failed"
else
make -C src -j"$JOBS" || handle_error "2LS build failed"
fi
echo "Build completed successfully!"
echo "The executable is src/2ls/2ls"
# Print build information
echo -e "\nBuild Information:"
echo "Compiler: ${COMPILER:-default}"
echo "Jobs: $JOBS"
echo "Build Type: $BUILD_TYPE"
if [ -f "src/2ls/2ls" ]; then
echo "2LS Version: $(src/2ls/2ls --version 2>&1 | head -n1)"
fi