-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·136 lines (119 loc) · 3.49 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# Copyright 2024 Mengning Software All rights reserved.
# 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/ninja2.tar.gz" ]; then
failure "Please build and package first."
exit 1
fi
cp "install.sh" "build/bin/"
(cd "build/bin/" && ./install.sh start)
}
# Function to package the built ninja binary
function package {
if [ ! -f "build/bin/ninja" ]; then
failure "Ninja binary not found in build directory. Please build first."
exit 1
fi
# package new ninja binary
mkdir -p build/bin/ninja2
cp "build/bin/ninja" "build/bin/ninja2/"
# 在Ubuntu22.04中缺失的so文件
cp $(ldd ./build/bin/ninja | awk '{print $3}' | grep -E 'libcares\.so\.2|libssl\.so\.1\.1|libprotobuf\.so\.17|libcrypto\.so\.1\.1|libgrpc\+\+.so\.1|libyaml\-cpp\.so\.0\.6|libgrpc\.so\.6') ./build/bin/ninja2/
cat <<EOL > "build/bin/ninja2/ninja2.conf"
# Copyright 2024 Mengning Software All rights reserved.
# /etc/ninja2.conf example
cloudbuild: false
grpc_url: "grpc://localhost:1985"
sharebuild: false
EOL
(cd build/bin/ && tar -zcvf ninja2.tar.gz ninja2/* && rm -rf ninja2)
success "New Ninja2 package ninja2.tar.gz at build/bin/"
}
# Function to install dependencies and build the project
function build {
# Create build directory and build
mkdir -p build
if [ ! -f "build/build.ninja" ]; then
(cd build && cmake -G Ninja ..)
fi
(cd build && ninja)
success "Build successfully. Build output is located in build/bin/"
}
# Main script
case "$1" in
all)
install_dependencies
clean
build
package
install
;;
build)
build
;;
package|pkg)
package
;;
install)
install
;;
clean)
clean
;;
*)
echo "Usage: $0 {all|build|package|install|clean}"
success "Please use ./build.sh all for the first compilation."
exit 1
;;
esac