Fix #5753 - roojspacker force dependancy on JSON for the time being
[roojspacker] / configure
1 #!/bin/sh
2
3 # Autotools-style (./configure) wrapper for CMake
4 # <https://github.com/nemequ/configure-cmake>
5 #
6 #   *** IMPORTANT ***
7 #
8 #   You must include the GNUInstallDirs module (which comes with
9 #   CMake) in your project.  Just put "include (GNUInstallDirs)" in
10 #   you CMakeLists.txt and you should be good.
11 #
12 # This script was originally written for Squash
13 # <https://quixdb.github.io/squash/> by Evan Nemerson
14 # <evan@nemerson.com>, but has been spun off into a separate
15 # repository.  Please feel free to copy it into your own repository,
16 # though I would appreciate it if you would post improvements, bugs,
17 # feature requests, etc. to the issue tracker at
18 # <https://github.com/nemequ/configure-cmake/issues>.
19 #
20 # To the extent possible under law, the author(s) hereby waive all
21 # copyright and related or neighboring rights to this work.  For
22 # details, see <https://creativecommons.org/publicdomain/zero/1.0/>
23
24 TOP_SRCDIR="$(dirname $0)"
25 CMAKE_CMD="cmake ${TOP_SRCDIR}"
26
27 BUILD_TYPE="Debug"
28 PREFIX=/usr
29 DATA_DIR=${PREFIX}/share
30 LIBDIR=
31 CMAKE_ARGS=
32
33 if [ -e "${TOP_SRCDIR}/.configure-custom.sh" ]; then
34     . "${TOP_SRCDIR}/.configure-custom.sh"
35 fi
36
37 quote() {
38     echo "$1" | sed -e "s|'|'\\\\''|g; 1s/^/'/; \$s/\$/'/"
39 }
40
41 extract_var_string() {
42     VAR_NAME=$1
43     VAR_NAME=$(echo $1 | sed -e 's/[ \t]*$//')
44     if [ "x$2" != "x" ]; then
45         VAR_VALUE=$2
46     else
47         VAR_VALUE=yes
48     fi
49
50     if [ "x$3" != "x" ]; then
51         VAR_UC_NAME=$3
52     else
53         VAR_UC_NAME=$(echo "$1" | tr '[:lower:]' '[:upper:]' | tr -c '[:alnum:]' '_' | sed 's/_$//g')
54     fi
55 }
56
57 set_config_var() {
58     is_with=n
59     case "$1" in
60         "--enable-"*)
61             name="${1#--enable-}"
62             cfg="${ENABLE_VARS}"
63             ;;
64         "--disable-"*)
65             name="${1#--disable-}";
66             cfg="${DISABLE_VARS}";
67             ;;
68         "--with-"*)
69             # IFS="=" read -ra WITHARGS <<< "${1}"
70             name="${1#--with-}"
71             cfg="${WITH_VARS}"
72             is_with=y
73             ;;
74     esac
75
76     found=n
77     for varstring in $cfg; do
78         extract_var_string $(echo "${varstring}" | tr '|' ' ')
79         if [ "x$VAR_NAME" = "x$name" ]; then
80             found=y
81             break;
82         fi
83     done
84
85     if [ "$found" = "y" ]; then
86         if [ "x$is_with" = "xy" ]; then
87             CMAKE_ARGS="$CMAKE_ARGS -D${VAR_UC_NAME}=$(quote "$2")"
88         else
89             CMAKE_ARGS="$CMAKE_ARGS -D${VAR_UC_NAME}=$(quote "${VAR_VALUE}")"
90         fi
91     else
92         echo "Unknown parameter: ${1}"
93         exit 1
94     fi
95 }
96
97 prefix_to_offset() {
98     expr $(echo "${1}" | awk '{ print length }') + 1
99 }
100
101 print_help() {
102     cat <<EOF >&2
103   -h, --help              display this help and exit
104   --disable-debug         disable debugging mode
105   --pass-thru             pass remaining arguments through to CMake
106   --prefix=PREFIX         install architecture-independent files in PREFIX
107                           [$PREFIX]
108   --bindir=DIR            user executables [PREFIX/bin]
109   --sbindir=DIR           system admin executables [PREFIX/sbin]
110   --libexecdir=DIR        program executables [PREFIX/libexec]
111   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
112   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
113   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
114   --libdir=DIR            object code libraries [PREFIX/lib]
115   --includedir=DIR        C header files [PREFIX/include]
116   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
117   --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
118   --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
119   --infodir=DIR           info documentation [DATAROOTDIR/info]
120   --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
121   --mandir=DIR            man documentation [DATAROOTDIR/man]
122   --docdir=DIR            documentation root [DATAROOTDIR/doc/PROJECT_NAME]
123 EOF
124
125     first=y
126     for varstring in ${ENABLE_VARS}; do
127         if [ $first = 'y' ]; then
128             echo ""
129             first=n
130         fi
131         extract_var_string $(echo "${varstring}" | tr '|' ' ')
132         var_doc_name="ENABLE_${VAR_UC_NAME}_DOC"
133         eval "docstring=\$$var_doc_name"
134         if [ "x${docstring}" = "x" ]; then
135             printf "  --enable-%-14s enable %s support\n" "${VAR_NAME}" "$(echo -n "${VAR_NAME}" | tr '-' ' ')"
136         else
137             printf "  --enable-%-14s %s\n" "${VAR_NAME}" "$docstring"
138         fi
139     done
140
141     first=y
142     for varstring in ${DISABLE_VARS}; do
143         if [ $first = 'y' ]; then
144             echo ""
145             first=n
146         fi
147         extract_var_string $(echo "${varstring}" | tr '|' ' ')
148         var_doc_name="DISABLE_${VAR_UC_NAME}_DOC"
149         eval "docstring=\$$var_doc_name"
150         if [ "x${docstring}" = "x" ]; then
151             printf "  --disable-%-13s disable %s support\n" "${VAR_NAME}" "$(echo -n "${VAR_NAME}" | tr '-' ' ')"
152         else
153             printf "  --disable-%-13s %s\n" "${VAR_NAME}" "$docstring"
154         fi
155     done
156
157     first=y
158     for varstring in ${WITH_VARS}; do
159         if [ $first = 'y' ]; then
160             echo ""
161             first=n
162         fi
163         extract_var_string $(echo "${varstring}" | tr '|' ' ')
164         var_doc_name="WITH_${VAR_UC_NAME}_DOC"
165         eval "docstring=\$$var_doc_name"
166         paraminfo="${VAR_NAME}=${VAR_VALUE}"
167         if [ "x${docstring}" = "x" ]; then
168             printf "  --with-%-16s enable %s support\n" "$paraminfo" "$(echo -n "${VAR_NAME}" | tr '-' ' ')"
169         else
170             printf "  --with-%-16s %s\n" "$paraminfo" "$docstring"
171         fi
172     done
173
174     exit 0
175 }
176
177 while [ $# != 0 ]; do
178     case "$1" in
179         "--prefix="*)
180             PREFIX="${1#*=}";;
181         "--prefix")
182             PREFIX="${2}"; shift;;
183         "--bindir="*)
184             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_BINDIR=$(quote "${1#*=}")";;
185         "--bindir")
186             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_BINDIR=$(quote "$2")"; shift;;
187         "--sbindir="*)
188             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SBINDIR=$(quote "${1#*=}")";;
189         "--sbindir")
190             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SBINDIR=$(quote "$2")"; shift;;
191         "--libexecdir="*)
192             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LIBEXECDIR=$(quote "${1#*=}")";;
193         "--libexecdir")
194             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LIBEXECDIR=$(quote "$2")"; shift;;
195         "--sysconfdir="*)
196             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SYSCONFDIR=$(quote "${1#*=}")";;
197         "--sysconfdir")
198             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SYSCONFDIR=$(quote "$2")"; shift;;
199         "--sharedstatedir="*)
200             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SHAREDSTATEDIR=$(quote "${1#*=}")";;
201         "--sharedstatedir")
202             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SHAREDSTATEDIR=$(quote "$2")"; shift;;
203         "--localstatedir="*)
204             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALSTATEDIR=$(quote "${1#*=}")";;
205         "--localstatedir")
206             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALSTATEDIR=$(quote "$2")"; shift;;
207         "--libdir="*)
208             LIBDIR="${1#*=}";;
209         "--libdir")
210             LIBDIR="${2}"; shift;;
211         "--includedir="*)
212             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INCLUDEDIR=$(quote "${1#*=}")";;
213         "--includedir")
214             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INCLUDEDIR=$(quote "$2")"; shift;;
215         "--oldincludedir="*)
216             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_OLDINCLUDEDIR=$(quote "${1#*=}")";;
217         "--oldincludedir")
218             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_OLDINCLUDEDIR=$(quote "$2")"; shift;;
219         "--datarootdir="*)
220             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DATAROOTDIR=$(quote "${1#*=}")";;
221         "--datarootdir")
222             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DATAROOTDIR=$(quote "$2")"; shift;;
223         "--datadir="*)
224             DATA_DIR="$(quote "${1#*=}")"; shift;;
225         "--datadir")
226             DATA_DIR="$(quote "$2")"; shift;;
227         "--infodir="*)
228             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INFODIR=$(quote "${1#*=}")";;
229         "--infodir")
230             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INFODIR=$(quote "$2")"; shift;;
231         "--localedir="*)
232             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALEDIR=$(quote "${1#*=}")";;
233         "--localedir")
234             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALEDIR=$(quote "$2")"; shift;;
235         "--mandir="*)
236             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_MANDIR=$(quote "${1#*=}")";;
237         "--mandir")
238             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_MANDIR=$(quote "$2")"; shift;;
239         "--docdir="*)
240             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DOCDIR=$(quote "${1#*=}")";;
241         "--docdir")
242             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DOCDIR=$(quote "$2")"; shift;;
243
244         "CC="*)
245             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER=$(quote "${1#*=}")";;
246         "CXX="*)
247             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_COMPILER=$(quote "${1#*=}")";;
248         "CFLAGS="*)
249             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_FLAGS=$(quote "${1#*=}")";;
250         "CXXFLAGS="*)
251             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_FLAGS=$(quote "${1#*=}")";;
252         "LDFLAGS="*)
253             LDFLAGS="$LDFLAGS ${1#*=}";;
254
255         "--help")
256             print_help;;
257         "-h")
258             print_help;;
259
260         # This flag is the only one which may be a bit surprising to
261         # people.  Autotools always builds with debugging symbols enabled
262         # (AFAIK), but for cmake you have to do -DCMAKE_BUILD_TYPE=Debug.
263         # Unfortunately this can change other things as well, so although
264         # I realize there is no --disable-debug flag I thought it would be
265         # prudent to support one here.
266         "--disable-debug")
267             BUILD_TYPE="Release";;
268
269         "--pass-thru")
270             shift;
271             while [ $# != 0 ]; do
272                 CMAKE_ARGS="$CMAKE_ARGS $(quote "${1}")";
273                 shift;
274             done;;
275
276         "--enable-"*)
277             set_config_var "$1"
278             ;;
279
280         "--disable-"*)
281             set_config_var "$1"
282             ;;
283
284         "--with-"*)
285             name=$(echo "${1#--with-}" | awk '{split($1,v,"="); print v[1]}')
286             case "${1}" in
287                 "--with-${name}="*)
288                     set_config_var "--with-${name}" "${1#--with-${name}=}";;
289                 "--with-${name}")
290                     set_config_var "$1" "$2";
291                     shift;;
292             esac
293             ;;
294
295         *)
296             echo "$0: error: unrecognized option: \`$1'" >&2
297             echo "Try \`$0 --help' for more information" >&2
298             exit -1
299     esac;
300     shift
301 done
302
303 if [ "x${LIBDIR}" = "x" ]; then
304     LIBDIR="${PREFIX}/lib"
305 fi
306
307 # Unlike CFLAGS/CXXFLAGS/CC/CXX, LDFLAGS isn't handled by CMake, so we
308 # need to parse it here.
309 if [ "x${LDFLAGS}" != "x" ]; then
310     for varname in EXE MODULE SHARED STATIC; do
311         CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_${varname}_LINKER_FLAGS=$(quote "$LDFLAGS")"
312     done
313 fi
314
315 eval "cmake -Bbuild -H${TOP_SRCDIR} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_INSTALL_DATADIR=${DATA_DIR} -DCMAKE_INSTALL_LIBDIR=${LIBDIR} ${CMAKE_ARGS}"