-
Notifications
You must be signed in to change notification settings - Fork 333
/
make.sh
executable file
·151 lines (121 loc) · 3.67 KB
/
make.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
#!/bin/bash
set -e
PATH_ROOT=$(cd "$(dirname "$0")"; pwd)
#CFG_FILE=config.json
function check_cfg_file
{
if [ ! -f "./${CFG_FILE}" ] ; then
on_error_begin "\`${CFG_FILE}\` does not exists."
echo "please copy \`config.json.in\` into \`${CFG_FILE}\`"
echo "and modify it to fit your condition, then try again."
on_error_end
fi
}
function build_win
{
check_cfg_file
# find pyexec from json file
pyexec=$(grep -P '"pyexec":' ./${CFG_FILE} | grep -Po '(?<="pyexec":)([[:space:]]*)"(.*)"')
# remove left "
pyexec=${pyexec#*\"}
# remove right "
pyexec=${pyexec%\"*}
# make sure configuration item exists.
if [ "${pyexec}-x" = "-x" ] ; then
on_error "\`pyexec\` not set, please check your \`${CFG_FILE}\`"
fi
pyexec=$(cygpath -u ${pyexec})
if [ ! -f "${pyexec}" ] ; then
pyexec=$(cygpath -m ${pyexec})
on_error "Sorry, need Python 3.7 or above (x86 version) to\nbuild Teleport on Windows Platform.\n\nPython interpreter not exists: ${pyexec}"
fi
# check version and architecture of python.
# version should >= 3.7
$("${pyexec}" -c "import platform;import sys;pyv=platform.python_version_tuple();ret=0 if int(pyv[0])>=3 and int(pyv[1])>=7 else 1;sys.exit(ret)")
if [ $? -ne 0 ]; then
on_error "Sorry, need x86 version of Python 3.7 or above."
fi
# and must be x86 version.
$("${pyexec}" -c "import platform;import sys;ret=0 if platform.architecture()[0]=='32bit' else 1;sys.exit(ret)")
if [ $? -ne 0 ]; then
on_error "Sorry, need x86 version of Python 3.7 or above."
fi
${pyexec} -B "${PATH_ROOT}/build/build.py" $@
}
function build_linux
{
check_cfg_file
if [ `id -u` -eq 0 ]; then
on_error "Do not build as root."
fi
if [ ! -f "/etc/centos-release" ] ; then
on_error "Sorry, build script works on CentOS 7 only."
fi
PYEXEC=${PATH_ROOT}/external/linux/release/bin/python3.7
PYSTATIC=${PATH_ROOT}/external/linux/release/lib/libpython3.7m.a
if [ ! -f "${PYSTATIC}" ] ; then
X=$(yum list installed | grep "libffi-devel")
if [ "$X-x" = "-x" ] ; then
on_error "Need libffi-devel to build Python, try:\r\n sudo yum install libffi-devel"
fi
X=$(yum list installed | grep "zlib-devel")
if [ "$X-x" = "-x" ] ; then
on_error "Need zlib-devel to build Python, try:\r\n sudo yum install zlib-devel"
fi
echo "python static not found, now build it..."
"${PATH_ROOT}/build/build-py-static.sh"
if [ ! -f "${PYSTATIC}" ] ; then
on_error "can not build python static."
fi
fi
${PYEXEC} -B "${PATH_ROOT}/build/build.py" $@
}
function build_macos
{
check_cfg_file
python3 -B "${PATH_ROOT}/build/build.py" $@
}
function on_error()
{
echo -e "\033[01m\033[31m"
echo "==================[ !! ERROR !! ]=================="
echo ""
echo -e $1
echo ""
echo "==================================================="
echo -e "\033[0m"
exit 1
}
function on_error_begin()
{
echo ""
echo -e "\033[01m\033[31mERROR: ${1}\033[0m"
echo ""
}
function on_error_end()
{
exit 1
}
##############################################
# main
##############################################
export TP_BUILD_SYSTEM="start"
SYS_NAME=`uname -s`
SYS_NAME=${SYS_NAME:0:4} # cut first 4 char.
# echo ${SYS_NAME}
# SYSTEM=${SYSTEM^^} # upper case
if [ ${SYS_NAME} = "Linu" ] ; then
export CFG_FILE=config.linux.json
build_linux $@
elif [ ${SYS_NAME} = "Darw" ] ; then
export CFG_FILE=config.macos.json
build_macos $@
elif [ ${SYS_NAME} == "MSYS" ] ; then
export CFG_FILE=config.windows.json
build_win $@
else
on_error_begin "Unsupported platform."
echo "To build teleport on Windows, please read document at:"
echo " https://docs.tp4a.com/develop/windows"
on_error_end
fi