-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·213 lines (194 loc) · 4.52 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#! /bin/bash
CC=""
CXX=""
MAKE=""
QMAKE=""
PROJECT=""
config_gcc() {
echo "Checking gcc."
dpkg -s gcc &> /dev/null
if [[ $? -ne 0 ]]; then
echo "A 'gcc' package not found. Set 'gcc' path as the second parameter or install 'gcc'."
exit 1
else
gcc_version="$(gcc -dumpversion)"
regex='^[5-9]{1}\.[0-9]+\.[0-9]+$'
if [[ $gcc_version =~ $regex ]]; then
CC="gcc"
else
echo "You need 'gcc' 5 version and more."
exit 1
fi
unset regex
unset gcc_version
fi
}
config_gpp() {
echo "Checking gcc."
dpkg -s g++ &> /dev/null
if [[ $? -ne 0 ]]; then
echo "A 'g++' package not found. Set 'g++' path as the second parameter or install 'gcc'."
exit 1
else
gxx_version="$(g++ -dumpversion)"
regex='^[5-9]{1}\.[0-9]+\.[0-9]+$'
if [[ $gxx_version =~ $regex ]]; then
CXX="g++"
else
echo "You need 'g++' 5 version and more."
exit 1
fi
unset regex
unset gxx_version
fi
}
config_make() {
echo "Checking make."
dpkg -s make &> /dev/null
if [[ $? -ne 0 ]]; then
echo "A 'make' package not found. Set make path as the third parameter or install 'make'."
exit 1
else
make_version="$(make -v | grep "^GNU Make [4-9]\.[0-9]*")"
if [[ $make_version ]]; then
MAKE="make"
else
echo "You need 'make' 4 version and more."
exit 1
fi
unset make_version
fi
}
config_qmake() {
echo "Checking qmake."
qmake_version="$(qmake -v | grep "^QMake version [3-9]\.[0-9]*")"
if [[ $qmake_version ]]; then
QMAKE="qmake"
else
echo "QMake not found. Check your Qt version."
exit 1
fi
unset qmake_version
}
build_project() {
if ! [[ $QMAKE ]]; then
config_qmake
fi
if ! [[ $MAKE ]]; then
config_make
fi
if ! [[ $CC ]]; then
config_gcc
fi
if ! [[ $CXX ]]; then
config_gpp
fi
if [[ $QMAKE ]] && [[ $MAKE ]] && [[ $CC ]] && [[ $CXX ]]; then
qmake_command="$QMAKE $PROJECT -spec linux-g++"
eval $qmake_command
if [[ $? -ne 0 ]]; then
echo "QMake error."
exit 2
fi
make_command="$MAKE CC=$CC CXX=$CXX"
eval $make_command
if [[ $? -ne 0 ]]; then
echo "Make error."
exit 2
fi
clean="$MAKE clean"
eval $clean
if [[ $? -ne 0 ]]; then
echo "Not clean."
fi
unset clean
unset make_command
unset qmake_command
else
echo "Unknown error."
exit 128
fi
}
usage() {
echo "Usage: ./build.sh [options] file.pro
Options:
--help Display this information.
Build options:
-qmake QMake special path.
-make Make special path.
-gcc A special path to the C compiler.
-g++ A special path to the C++ compiler."
}
if [[ $# -eq 1 ]]; then
if [[ $1 == "--help" ]]; then
usage
exit 1
fi
if [[ $1 ]]; then
if [[ -f $1 ]]; then
PROJECT=$1
else
echo "The project not found."
exit 1
fi
else
echo "No project for build."
exit 1
fi
# The C compiler configuration.
config_gcc
# The C++ compiler configuration.
config_gpp
# Make configuration.
config_make
# QMake confugiration.
config_qmake
# Build a project.
build_project
elif [[ $# -ge 1 ]]; then
for arg in "$@"; do
case $arg in
-qmake=*)
QMAKE="${arg#*=}"
shift
;;
-make=*)
MAKE="${arg#*=}"
shift
;;
-gcc=*)
CC="${arg#*=}"
shift
;;
-g++=*)
CXX="${arg#*=}"
shift
;;
--help)
usage
exit 1
;;
-*)
echo "Unknown option."
exit 128
;;
*)
;;
esac
done
if [[ -f $arg ]]; then
PROJECT=$arg
else
echo "The project not found."
exit 1
fi
# Build a project.
build_project
else
echo ""
fi
unset CC
unset CXX
unset MAKE
unset QMAKE
unset PROJECT