forked from ninja-cloudbuild/ninja2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·112 lines (96 loc) · 2.69 KB
/
build.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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Function to display success message
function success {
echo -e "${GREEN}$1${NC}"
}
# Function to display failure message
function failure {
echo -e "${RED}$1${NC}"
}
# Function to clean build directory
function clean {
if [ -d "build" ]; then
rm -rf build
success "Cleaned build directory."
else
echo "No build directory to clean."
fi
}
# Detect the OS type and install dependencies
function install_dependencies {
# Install dependencies based on the OS type
success "dependencies install begin: "
OS_ID=$(grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"')
case $OS_ID in
ubuntu|debian)
sudo apt-get update
sudo apt-get install -y git cmake g++ gcc googletest libgmock-dev libssl-dev pkg-config uuid-dev grpc++ libprotobuf-dev protobuf-compiler-grpc ninja-build libyaml-cpp-dev
;;
centos)
sudo yum update -y
sudo yum install -y epel-release
sudo yum groupinstall -y "Development Tools"
sudo yum install -y git cmake3 gtest gtest-devel openssl openssl-devel pkgconfig uuid-devel grpc-devel protobuf protobuf-devel protobuf-compiler ninja-build yaml-cpp yaml-cpp-devel
;;
fedora)
sudo dnf update -y
sudo dnf group install -y "Development Tools"
sudo dnf install -y git cmake g++ gtest gtest-devel openssl openssl-devel pkgconfig uuid-devel grpc-devel protobuf protobuf-devel protobuf-compiler ninja-build yaml-cpp yaml-cpp-devel
;;
*)
failure "Unsupported OS: $OS_ID"
exit 1
;;
esac
}
# Function to install the built ninja binary
function install {
if [ ! -f "build/bin/ninja" ]; then
failure "Ninja binary not found in build directory. Please build first."
exit 1
fi
local install_path="/usr/bin/ninja"
local backup_path="/usr/bin/ninja.prev"
# Backup existing ninja if it exists
if [ -f "$install_path" ]; then
sudo mv "$install_path" "$backup_path"
success "Backed up original ninja to $backup_path"
fi
# Install new ninja binary
sudo cp "build/bin/ninja" "$install_path"
success "New ninja installed at $install_path"
}
# Function to install dependencies and build the project
function build {
success "begin build: "
install_dependencies
clean
# Create build directory and build
mkdir -p build
cd build
cmake -G Ninja ..
ninja
success "Build succeeded. Build output is located in $(pwd)"
}
# Main script
case "$1" in
build)
build
;;
clean)
clean
;;
install)
install
;;
*)
echo "Usage: $0 {build|clean|install}"
exit 1
;;
esac