-
Notifications
You must be signed in to change notification settings - Fork 2
/
compile.sh
executable file
·197 lines (175 loc) · 5.72 KB
/
compile.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
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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
SUDO=""
if [ -f "/usr/bin/sudo" ]; then
SUDO="/usr/bin/sudo"
fi
PKGMGR=""
if [ -f "/usr/bin/dnf" ]; then
PKGMGR="/usr/bin/dnf"
elif [ -f "/usr/bin/yum" ]; then
PKGMGR="/usr/bin/yum"
fi
# Function to get the distribution name from /etc/os-release
get_distro_name() {
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "$NAME"
elif [ -f /etc/redhat-release ]; then
# Older versions of CentOS might use /etc/redhat-release
cat /etc/redhat-release
else
echo "Unknown"
fi
}
OS=$(uname)
distro_name=""
distro_type=""
if [ "$OS" = "Linux" ]; then
if [ "$PKGMGR" = "" ]; then
echo "ERROR: No package manager found, dnf and yum don't exist!!!"
exit 1
fi
distro_name=$(get_distro_name)
distro_type="unknown"
if [[ "$distro_name" == *"CentOS"* ]]; then
echo "This is a CentOS system."
distro_type="centos"
elif [[ "$distro_name" == *"AlmaLinux"* ]]; then
echo "This is an AlmaLinux system."
distro_type="alma"
else
echo "This is a Linux system, but not CentOS or AlmaLinux."
fi
fi
FEATURES=
if [ "$1" != "" ]; then
FEATURES="--features $1"
fi
if [ "$BUILD" == "" ]; then
echo "Using default build profile."
BUILD=release-with-debug
else
echo "Using build profile: $BUILD"
fi
PREFIX=/opt/rsprobe
LD_LIBRARY_PATH=$PREFIX/lib:$PREFIX/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
# Assuming your pkg-config files are in /opt/rsprobe/lib64/pkgconfig
PKG_CONFIG_PATH=/opt/rsprobe/lib64/pkgconfig:/opt/rsprobe/lib/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH
# Function to prompt for installation
prompt_install() {
while true; do
read -p "Do you wish to install $1? [Y/n] " yn
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer yes or no.";;
esac
done
}
# Function to install Rust
install_rust() {
if prompt_install "Rust"; then
echo "Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
else
echo "Rust installation skipped. Exiting."
exit 1
fi
}
# Function to run a command within the SCL environment for CentOS
run_with_scl() {
export PKG_CONFIG_PATH=/opt/rsprobe/lib64/pkgconfig:/opt/rsprobe/lib/pkgconfig:$PKG_CONFIG_PATH
if [ "$distro_type" = "centos" ]; then
scl enable devtoolset-11 rh-python38 llvm-toolset-7.0 -- "$@"
else
"$@"
fi
}
# Check for Rust and install if missing
if ! command -v cargo &> /dev/null
then
echo "Installing Rust"
install_rust
source ~/.profile
fi
# CentOS 7 specific setup
if [ "$OS" = "Linux" ]; then
export RUSTFLAGS="-C link-args=-Wl,-rpath,$PREFIX/lib:$PREFIX/lib64"
if [ "$distro_type" = "centos" ]; then
echo "CentOS detected."
# Check for SCL and install if missing
if ! command -v scl &> /dev/null; then
if prompt_install "Software Collections (SCL)"; then
echo "Installing Software Collections..."
sudo yum install centos-release-scl -y
sudo yum install devtoolset-11 -y
else
echo "SCL installation skipped. Exiting."
exit 1
fi
fi
elif [ "$distro_type" = "alma" ]; then
echo "Alma Linux Detected"
fi
# Build with SCL
echo "Building on Linux ($BUILD) with Features [$FEATURES] ..."
if [ "$BUILD" = "release" ]; then
run_with_scl cargo build $FEATURES --release --jobs 1
elif [ "$BUILD" = "release-with-debug" ]; then
run_with_scl cargo build $FEATURES --profile=release-with-debug --jobs 1
else
run_with_scl cargo build $FEATURES --jobs 1
fi
# Add elif blocks here for other specific Linux distributions
elif [ "$OS" = "Darwin" ]; then
#export RUSTFLAGS="-C link-args=-Wl,-rpath,$PREFIX/lib -Wl,-rpath,$PREFIX/lib64"
echo "macOS detected."
# Brew RPMs
# check if brew binary exists
if ! command -v brew &> /dev/null; then
echo "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# check if xcode-select is installed, if not install it
# Check if Xcode Command Line Tools are installed
xcode-select -p &> /dev/null
if [ $? -eq 0 ]; then
echo "Xcode Command Line Tools are installed."
else
echo "Xcode Command Line Tools are not installed."
echo "Installing Xcode Command Line Tools..."
xcode-select --install
# Note: The user will need to continue the installation process manually if required.
fi
export CXXFLAGS="-stdlib=libc++"
export LDFLAGS="-lc++"
# macOS specific setup
# Build on macOS
echo "Building on macOS ($BUILD) with Features [$FEATURES]..."
if [ "$BUILD" = "release" ]; then
cargo build $FEATURES --release --jobs 1
elif [ "$BUILD" == "release-with-debug" ]; then
cargo build $FEATURES --profile=release-with-debug --jobs 1
else
cargo build $FEATURES --jobs 1
fi
else
export RUSTFLAGS="-C link-args=-Wl,-rpath,$PREFIX/lib:$PREFIX/lib64"
echo "Generic Unix-like OS detected."
# Generic Unix/Linux setup
# Build for generic Unix/Linux
echo "Building on Unix ($BUILD) with Features [$FEATURES]..."
if [ "$BUILD" = "release" ]; then
cargo build $FEATURES --release --jobs 1
elif [ "$BUILD" == "release-with-debug" ]; then
cargo build $FEATURES --profile=release-with-debug --jobs 1
else
cargo build $FEATURES --jobs 1
fi
fi
echo "Build completed successfully."