-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure
executable file
·236 lines (214 loc) · 7.58 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
233
234
235
236
#!/bin/sh
######################################################
# PROJECT : htmltop #
# VERSION : 0.2.0 #
# DATE : 12/2017 #
# AUTHOR : Valat Sébastien #
# LICENSE : CeCILL-C #
######################################################
######################################################
# This script provide a simple wrapper to cmake to fix
# the missing --help equivalent to autotools. And it
# may be more intuitive for users to use the well
# known ./configure & make & make install procedure.
######################################################
#script setup
PROJECT_NAME='htopml'
# State variables
PREFIX='/usr/local'
CMAKE='cmake'
EXTRA_CXX=''
EXTRA_CXXFLAGS=''
EXTRA_LDFLAGS=''
BUILD_TYPE='Release'
#features
ENABLE_DISPLAY_COMMAND='false'
ENABLE_GCC_COVERAGE=''
ENABLE_JUNIT_OUT=''
ENABLE_VALGRIND=''
ENABLE_RPATH=''
ENABLE_LISTEN_ALL=''
DISABLE_TESTS=''
#prefix
LIB_SUFFIX=''
HWLOC_PREFIX=''
SVUNITTEST_PREFIX=''
######################################################
#Find default source dir
SOURCE_DIR="`dirname \"$0\"`"
######################################################
HELP_MESSAGE="'configure' is a cmake wrapper to build ${PROJECT_NAME}
For more control, prefer to use cmake directely, this wrapper only aims
to ease your life for standard cases.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--srcdir=DIR find the sources in DIR [configure dir or '${SOURCE_DIR}']
Installation directories:
--prefix=PREFIX install files in PREFIX [${PREFIX}]
--lib-suffix=SUFFIX used to force suffix for lib directory. [empty].
By default, 'make install' will install all the files in
'/usr/local/bin', '/usr/local/lib' etc. You can specify
an installation prefix other than '/usr/local' using '--prefix',
for instance '--prefix=$HOME'.
Optional Features:
--enable-debug Enable debugging support (-DCMAKE_BUILD_TYPE=Debug).
--enable-gcc-coverage Enable GCC option to generate test coverage of the lib.
--enable-junit-output Save test output in JUnit format (only in self-test mode).
--enable-listen-all Listent on all network interface instead of 127.0.0.1.
--enable-valgrind Generate valgrind report while running the test suite.
--disable-tests Disable unit tests of the lib (-DDISABLE_UNIT_TESTS=yes).
--enable-rpath Enable rpath to all deps at install time (-DENABLE_RPATH=yes).
To find libs and commands :
--with-cmake={command} Define the cmake command to use [cmake].
--with-hwloc={prefix} Define the hwloc prefix if available [/usr].
--with-svunittest={prefix} Define the svUnitTest prefix if available [/usr].
To get the generated cmake command :
--show Display the cmake command and didn't execute it.
Some influential environment variables:
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
CXX C++ compiler command
CXXFLAGS C++ compiler flags"
######################################################
#Function to extract value from args. It split on equals
#Params :
# $1 : user argument with option
# $2 : Option (--prefix)
get_arg_value()
{
echo "$1" | sed -e "s/^$2=//g"
}
######################################################
#Convert enable/disable options into yes/no status
# $1 : user arguement (--enable-.... or --disable-....)
# $2 : Optional argument. Use value INVERT to permut yes/no mapping.
enabl_disabl_to_yes_no()
{
case "$1" in
--enable-*)
if [ "$2" = 'INVERT' ]; then echo 'no'; else echo 'yes'; fi
;;
--disable-*)
if [ "$2" = 'INVERT' ]; then echo 'yes'; else echo 'no'; fi
;;
*)
echo "Invalid value in enabl_disabl_to_yes_no(), require --disable-* or --enable-*." 1>&2
echo 'unknown'
;;
esac
}
######################################################
#parse arguments
for arg in "$@"
do
case "$arg" in
-h | --help)
echo "$HELP_MESSAGE"
exit 0
;;
--prefix=*)
PREFIX="-DCMAKE_INSTALL_PREFIX=`get_arg_value \"$arg\" --prefix`"
;;
--srcdir=*)
SOURCE_DIR="`get_arg_value \"$arg\" --srcdir`"
;;
--lib-suffix=*)
LIB_SUFFIX="`get_arg_value \"$arg\" --lib-suffix`"
if [ ! -z "${LIB_SUFFIX}" ]; then LIB_SUFFIX="-DLIB_SUFFIX=${LIB_SUFFIX}"; fi
;;
--with-cmake=*)
CMAKE="`get_arg_value \"$arg\" --with-cmake`"
;;
--with-hwloc=*)
HWLOC_PREFIX="-DHWLOC_PREFIX=`get_arg_value \"$arg\" --with-hwloc`"
;;
--with-svunittest=*)
SVUNITTEST_PREFIX="-DSVUNITTEST_PREFIX=`get_arg_value \"$arg\" --with-svunittest`"
;;
--enable-debug)
BUILD_TYPE='Debug'
;;
--enable-gcc-coverage)
ENABLE_GCC_COVERAGE="-DENABLE_GCC_COVERAGE=`enabl_disabl_to_yes_no $arg`";
BUILD_TYPE='Debug'
;;
--enable-junit-output | --disable-junit-output)
ENABLE_JUNIT_OUT="-DENABLE_JUNIT_OUTPUT=`enabl_disabl_to_yes_no $arg`"
;;
--enable-valgrind | --disable-valgrind)
ENABLE_VALGRIND="-DENABLE_VALGRIND=`enabl_disabl_to_yes_no $arg`"
;;
--enable-rpath | --disable-rpath)
ENABLE_RPATH="-DENABLE_RPATH=`enabl_disabl_to_yes_no $arg`"
;;
--enable-listen-all | --disable-listent-call)
ENABLE_LISTEN_ALL="-DENABLE_LISTEN_ALL=`enabl_disabl_to_yes_no $arg`"
;;
--disable-tests | --enable-tests)
DISABLE_TESTS="-DDISABLE_TESTS=`enabl_disabl_to_yes_no $arg 'INVERT'`";
;;
--show)
ENABLE_DISPLAY_COMMAND='true'
;;
CXX=*)
EXTRA_CXX="`get_arg_value \"$arg\" CXX`"
;;
CXXFLAGS=*)
EXTRA_CXXFLAGS="`get_arg_value \"$arg\" CXXFLAGS`"
;;
LDFLAGS=*)
EXTRA_LDFLAGS="`get_arg_value \"$arg\" CFLAGS`"
;;
*)
echo "Invalid argument : $arg, please check in --help." 1>&2
exit 1
;;
esac
done
######################################################
#Check current directory
if [ -f 'CMakeLists.txt' ] && [ -f 'configure' ]; then
echo "ERROR : CMake isn't adapted to support build directely in source"
echo "directory. Prefer to create a subdirectory to build."
echo ""
echo "Example : mkdir build && cd build && ../configure"
exit 1
fi
######################################################
#Gen CC/CXX/LDFLAGS commands
if [ ! -z "$EXTRA_CXX" ]; then EXTRA_CXX="-DCMAKE_CXX_COMPILER=${EXTRA_CXX}" ; fi
if [ ! -z "$EXTRA_CXXFLAGS" ]; then EXTRA_CXXFLAGS="-DCMAKE_CXX_FLAGS=${EXTRA_CXXFLAGS}" ; fi
if [ ! -z "$EXTRA_LDFLAGS" ]; then EXTRA_LDFLAGS="-DCMAKE_EXE_LINKER_FLAGS=${EXTRA_LDFLAGS}" ; fi
######################################################
#Function to gen clean command
#Params : {command} [args...]
gen_clean_command()
{
res=""
for tmp in "$@"
do
if [ ! -z "${tmp}" ]; then
res="${res} '${tmp}'"
fi
done
echo "${res}"
}
######################################################
#Gen final command
COMMAND="`gen_clean_command "${CMAKE}" "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" "${PREFIX}" "${EXTRA_CXX}" \
"${EXTRA_CXXFLAGS}" "${EXTRA_LDFLAGS}" "${ENABLE_SELF_TEST}" "${ENABLE_JUNIT_OUT}" "${ENABLE_VALGRIND}" \
"${DISABLE_TESTS}" "${DISABLE_CPPUNIT}" "${LIB_SUFFIX}" "${HWLOC_PREFIX}" "${SVUNITTEST_PREFIX}" "${ENABLE_GCC_COVERAGE}" \
"${ENABLE_RPATH}" "${ENABLE_LISTEN_ALL}" "${SOURCE_DIR}"`"
######################################################
#execute or display
if [ "${ENABLE_DISPLAY_COMMAND}" = 'true' ]; then
echo "${COMMAND}"
else
echo ">>${COMMAND}"
eval "${COMMAND}"
exit $?
fi