-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·101 lines (89 loc) · 2.73 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
#!/bin/bash
MacOs=darwin
CentOs=yum
Ubuntu=apt-get
CmakeV=3.21.3
arch=""
win_build=false
# Function to show usage
usage() {
echo "Usage: $0 [--win] [--arch x64|arm64]"
exit 1
}
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--win)
win_build=true ;;
--arch)
if [[ "$2" == "x86_64" || "$2" == "arm64" ]]; then
arch="$2"
shift
else
echo "Invalid value for --arch. Must be 'x86_64' or 'arm64'."
usage
fi
;;
*) echo "Unknown parameter: $1" ; usage ;;
esac
shift
done
# If no --arch specified, detect the architecture
if [[ -z "$arch" ]]; then
arch=$(uname -m)
fi
# Handle dependencies
if $win_build; then
echo win build
else
# macOS
if [[ "$OSTYPE" =~ ^$MacOs ]]; then
# Dependencies
brew install zip unzip
brew install openssl cmake
fi
# CentOS
if [ -x /usr/bin/$CentOs ]; then
arch=$(uname -i)
# Dependencies
yum install openssl-devel -y;
yum install wget zip unzip -y
yum group install "Development Tools" -y
# Installing Cmake latest
wget -qO- "https://cmake.org/files/v3.21/cmake-$CmakeV-linux-$arch.tar.gz" | \
tar --strip-components=1 -xz -C /usr/local
fi
# Ubuntu
if [ -x /usr/bin/$Ubuntu ]; then
arch=$(uname -i)
# Dependencies
sudo apt-get install wget zip unzip build-essential checkinstall zlib1g-dev libssl-dev -y
# Installing Cmake latest
wget -qO- "https://cmake.org/files/v3.21/cmake-$CmakeV-linux-arm64.tar.gz" | \
tar --strip-components=1 -xz -C /usr/local
fi
fi
# Build
if $win_build; then
echo Building for Windows.
mkdir -p build;
x86_64-w64-mingw32-g++ *.cpp SourceFiles/*.cpp -o build/zsign.exe -I../mman-win32 -I../openssl/include/ -L../openssl -L../mman-win32 -lmman -lcrypto -lgdi32 -std=c++11 -DWINDOWS -m64 -static-libgcc -static-libstdc++
echo Build files have been written to ./build/zsign.exe
else
# Compile zsign using cmake
if [[ "$OSTYPE" =~ ^$MacOs && "$arch" == "x86_64" ]]; then
echo Building for macOS x86_64
mkdir -p build && cd build
cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 ..
make
elif [[ "$OSTYPE" =~ ^$MacOs && "$arch" == "arm64" ]]; then
echo Building for macOS arm64
mkdir -p build
g++ *.cpp SourceFiles/*.cpp -lcrypto -I/opt/homebrew/Cellar/openssl@3/3.2.1/include -L/opt/homebrew/Cellar/openssl@3/3.2.1/lib -O3 -o build/zsign
else
mkdir -p build && cd build
echo Building for Linux $arch
cmake ..
make
fi
fi