-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·232 lines (191 loc) · 8.54 KB
/
configure
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/sh
################################################################################
# Copyright (C) 2015, Jean-Yves VET, contact [at] jean-yves [dot] vet #
# #
# This software is licensed as described in the file LICENCE, which you should #
# have received as part of this distribution. You may opt to use, copy, #
# modify, merge, publish, distribute and/or sell copies of the Software, and #
# permit persons to whom the Software is furnished to do so, under the terms #
# of the LICENCE file. #
# #
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY #
# KIND, either express or implied. #
# #
##----[ DESCRIPTION ]---------------------------------------------------------##
# A simple wrapper to provide cmake with: #
# * a --help argument (similar to autotools) #
# * a more intuitive ./configure & make & make install procedure #
# #
##----[ ARGUMENTS ]-----------------------------------------------------------##
# -h, --help : Print help. #
# --prefix=PREFIX : Install files in PREFIX [${PREFIX}] #
# --enable-tests : Build also unit tests. #
# --enable-debug : Enable debug support. #
# #
################################################################################
##----[ GLOBAL VARIABLES ]----------------------------------------------------##
ENABLE_TESTS='false'
ENABLE_COLORS='false'
BUILD_DIR=$PWD
SOURCE_DIR="`dirname "$0"`"
##----[ ERRORS ]--------------------------------------------------------------##
ERROR_MISSING_CMAKE="Cmake is not installed. Please install the package."
ERROR_INVALID_ARG="Please check --help. Invalid argument: "
##----[ HELP MESSAGE ]--------------------------------------------------------##
HELP="'configure' is a cmake wrapper. For a better control,
prefer to use cmake directly.
Usage: ./configure [OPTIONS]
Configuration:
-h, --help Display this help and exit
Installation directory:
--prefix=PREFIX Install files in PREFIX
By default, 'make install' will install all the files
in '/usr/local'. You may specify another installation
prefix by using '--prefix' for instance :
'--prefix=$HOME/usr/bin'.
Optional Features:
--enable-tests Build also unit tests.
--enable-debug Enable debug support.
"
##----[ FUNCTIONS ]-----------------------------------------------------------##
############################################################################
# Print error in stderr. #
# Args: #
# -$1: Error code. #
# Result: Print error and quit. #
print_error_and_stop()
{
# Extract argument
error_msg=${1}
error_arg=${2}
# Check if colors are enabled and display the error
if [ ${ENABLE_COLORS} = "true" ]; then
echo "\033[1;31mERROR:\033[0m \033[31m${error_msg}" \
"${error_arg}\033[0m" 1>&2
else
echo "ERROR: ${error_msg}${arror_arg}" 1>&2
fi
exit 1
}
############################################################################
# Check if Cmake is installed. #
# Args: #
# None #
# Result: . #
check_cmake_install()
{
# Check if jq is installed
command -v cmake >/dev/null 2>&1 \
|| print_error_and_stop "${ERROR_MISSING_CMAKE}"
}
############################################################################
# Check build and source directories. #
# Args: #
# None #
# Result: . #
check_directories()
{
if [ "${SOURCE_DIR}" != "." ];
then
SOURCE_DIR=$(cd `dirname "$0"` && pwd)
else
SOURCE_DIR="${PWD}"
fi
# Avoid to build locally
if [ "${BUILD_DIR}" = "${SOURCE_DIR}" ];
then
#check if build directory exist
if [ ! -d "${PWD}/build" ];
then
mkdir -p build
fi
BUILD_DIR="${PWD}/build"
SOURCE_DIR="${PWD}"
fi
}
############################################################################
# Check if we may activate colors. #
# Args: #
# None #
# Result: . #
check_colors()
{
if [ -t 1 ]; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
ENABLE_COLORS='true'
fi
fi
}
############################################################################
# Parge all arguments. #
# Args: #
# -$*: All arguments. #
# Result: set configuration #
parse_arguments()
{
for arg in "$@"
do
case "$arg" in
-h | --help)
echo "${HELP}"
exit 0
;;
--prefix=*)
res=`echo "$arg" | sed -e "s/^--prefix=//g"`
PARAM="-DCMAKE_INSTALL_PREFIX=${res}"
;;
--enable-debug)
PARAM="${PARAM} -DDEBUG:BOOL=TRUE"
;;
--enable-tests)
PARAM="${PARAM} -DBUILD_TESTS:BOOL=TRUE"
ENABLE_TESTS='true'
;;
*)
print_error_and_stop "${ERROR_INVALID_ARG}" "${arg}"
;;
esac
done
}
############################################################################
# Execute cmake. #
# Args: #
# None #
# Result: . #
exec_cmake()
{
cd ${BUILD_DIR}
cmake ${PARAM} ${SOURCE_DIR}
cd ${SOURCE_DIR}
}
############################################################################
# Generate Makefile to call the one created by cmake. #
# Args: #
# None #
# Result: . #
generate_makefile()
{
cat > Makefile << EOF
all:
@make --no-print-directory -C ${BUILD_DIR} all
install:
@make --no-print-directory -C ${BUILD_DIR} install
clean:
@make --no-print-directory -C ${BUILD_DIR} clean
test:
@cd ${BUILD_DIR} && ctest
distclean:
@rm -rf ${BUILD_DIR}
@rm -rf ${SOURCE_DIR}/bin
@rm ${SOURCE_DIR}/Makefile
EOF
}
##----[ MAIN ]----------------------------------------------------------------##
check_cmake_install
check_directories
check_colors
parse_arguments $*
exec_cmake
generate_makefile
exit $?