-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·135 lines (106 loc) · 2.28 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 (c) homqyy
#
#################################### global variable
G_PROJECT_DIR=`cd $( dirname $0 ); pwd`
G_KCP_SRC_DIR=$G_PROJECT_DIR/kcp-src
G_KCP_BUILD_DIR=$G_KCP_SRC_DIR/build
G_PERL_KCP_DIR=$G_PROJECT_DIR/KCP
#################################### function
function usage
{
echo "Usage: $0 [OPTIONS] [ACTION]
OPTIONS:
-h : help
ACTION: [configure|compile|test|install|clean]
configure : configure the code
compile : compile the code
test : test the code
install : pack library, header and config of cmake.
clean : clean" >& 2
}
function configure
{
echo "configure..."
cmake -B ${G_KCP_BUILD_DIR} -S ${G_KCP_SRC_DIR} -DCMAKE_C_FLAGS="-fPIC" \
|| return 1
# for kcp module
error=0
cd ${G_PERL_KCP_DIR} && perl ${G_PERL_KCP_DIR}/Makefile.PL \
|| error=1
cd -
return $error
}
function compile
{
echo "compile..."
make -C ${G_KCP_BUILD_DIR} \
|| return 1
# buildin library and header
cp $G_KCP_SRC_DIR/ikcp.h $G_KCP_BUILD_DIR/libkcp.a $G_PERL_KCP_DIR \
|| return 1
make -C ${G_PERL_KCP_DIR}
}
function test_case
{
echo "test..."
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$G_KCP_BUILD_DIR"
make -C ${G_PERL_KCP_DIR} test
}
function install
{
echo "install..."
make -C ${G_PERL_KCP_DIR} install
}
function clean
{
echo "clean..."
[ -d ${G_KCP_BUILD_DIR} ] && rm -rf ${G_KCP_BUILD_DIR}
make -C ${G_PERL_KCP_DIR} clean
}
############################################### main
while getopts :h opt
do
case $opt in
h)
usage
exit 0;
;;
'?')
error_msg "$0: invalid option -$OPTARG"
usage
exit 1
;;
esac
done
shift $(($OPTIND - 1))
if [[ $# -eq 1 ]]; then
action=$1
case $action in
configure)
configure
;;
compile)
compile
;;
test)
test_case
;;
install)
install
;;
clean)
clean
;;
*)
usage
exit 1
esac
elif [[ $# -gt 1 ]]; then
error_msg "arguments too much"
usage
exit 1
else
configure && compile && test_case && install
fi