-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure
executable file
·135 lines (109 loc) · 3.03 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
#!/bin/bash
###############################################################################
# FUNCTIONS ###################################################################
###############################################################################
die() {
echo "ERROR: ${@}" 1>&2
exit 1
}
show_help() {
echo "USAGE: configure [options]"
echo ""
echo "OPTIONS:"
echo " --debug"
echo " Build with debugging symbols and turn optimizations off."
echo " --prefix=<prefix>"
echo " Set the install prefix."
echo " --cxx=<cxx>"
echo " Set the C++ compiler to use."
echo " --devel"
echo " Turn on compiler warnings."
echo " --test"
echo " Enable unit testing."
echo ""
}
###############################################################################
# OPTION PARSING ##############################################################
###############################################################################
CONFIG_FLAGS="-DCMAKE_VERBOSE_MAKEFILE=1"
# default values
CMAKE="$(which cmake)"
BUILDDIR="build/$(uname -s)-$(uname -m)"
# parse arguments
for i in "${@}"; do
case "${i}" in
# help
-h|--help)
show_help
exit 0
;;
# debug
--debug)
CONFIG_FLAGS="${CONFIG_FLAGS} -DDEBUG=1"
;;
# prefix
--prefix=*)
CONFIG_FLAGS="${CONFIG_FLAGS} -DCMAKE_INSTALL_PREFIX=${i#*=}"
;;
# devel
--devel)
CONFIG_FLAGS="${CONFIG_FLAGS} -DDEVEL=1"
;;
# cxx
--cxx=*)
CONFIG_FLAGS="${CONFIG_FLAGS} -DCMAKE_CXX_COMPILER=${i#*=}"
;;
# testing
--test)
CONFIG_FLAGS="${CONFIG_FLAGS} -DTESTS=1"
;;
# bad argument
*)
die "Unknown option '${i}'"
;;
esac
done
# check if cmake exists
if [[ ! -x "${CMAKE}" ]]; then
die "Could not find usable cmake: '${CMAKE}'"
else
echo "Found CMAKE: '${CMAKE}'"
echo "--> $("${CMAKE}" --version)"
fi
# clean out build directory if it exists
if [[ -d "${BUILDDIR}" ]]; then
echo "Removing old build directory '${BUILDDIR}'..."
rm -rf "${BUILDDIR}"
fi
# create build directory
mkdir -vp "${BUILDDIR}" || \
die "Failed to create build directory: '${BUILDDIR}'"
###############################################################################
# RUN CMAKE ###################################################################
###############################################################################
ROOTDIR="${PWD}"
pushd "${BUILDDIR}"
echo "Calling cmake with arguments '${CONFIG_FLAGS}'"
"${CMAKE}" "${ROOTDIR}" ${CONFIG_FLAGS}
if [[ "$?" != "0" ]]; then
echo "CMake failed with '$?'" 1>&2
exit $?
fi
popd
# create proxy makefile
(
echo "#######################################################################"
echo "# Makefile generated by '$0' at $(date)"
echo "# Using flags:"
for d in ${CONFIG_FLAGS}; do
echo "# ${d}"
done
echo "#######################################################################"
echo ""
echo "all test clean install:"
echo " make -C ${BUILDDIR} \$@ \$(MAKEFLAGS)"
echo ""
echo "distclean:"
echo " rm -rvf ${BUILDDIR} Makefile"
echo ""
) > Makefile