-
Notifications
You must be signed in to change notification settings - Fork 9
/
configure.ac
445 lines (361 loc) · 11.8 KB
/
configure.ac
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# Process this file with autoconf to produce a configure script.
# TODO: Unknown whether 2.64 works; was a bit of a milestone release, though
AC_PREREQ([2.64])
# TODO: required versions for automake, libtool?
AC_INIT([lightgrep], [1.5.0], [BUG-REPORT-ADDRESS])
# Set the default C and C++ compilation flags to nothing.
# Do this immediately after AC_INIT, as other macros might invoke
# AC_PROG_CC or AC_PROG_CXX and stomp our defaults.
: ${CFLAGS=''}
: ${CXXFLAGS=''}
## FIXME: Argh, there appears to be no way to distinguish between the
## flags set by mingw64-configure and ones set by the user...
#AC_MSG_NOTICE([Default CPPFLAGS: $CPPFLAGS])
#AC_MSG_NOTICE([Default CFLAGS: $CFLAGS])
#AC_MSG_NOTICE([Default CXXFLAGS: $CXXFLAGS])
#AC_MSG_NOTICE([Default LDFLAGS: $LDFLAGS])
AC_CONFIG_AUX_DIR([config])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/cmd/main.cpp])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign subdir-objects])
LT_INIT
#
# metadata
#
case "$host" in
*-*-mingw*)
LT_LANG([Windows Resource])
IS_MINGW=yes
;;
esac
AM_CONDITIONAL([BUILD_MINGW], [test "x$IS_MINGW" = "xyes"])
# Decompose the version number.
#
# We must do this rather than construct PACKAGE_VERSION from the components
# because AC_INIT rejects anything but a literal for the version number.
PACKAGE_VERSION_MAJOR=`echo "$PACKAGE_VERSION" | cut -d. -f1`
PACKAGE_VERSION_MINOR=`echo "$PACKAGE_VERSION" | cut -d. -f2`
PACKAGE_VERSION_MICRO=`echo "$PACKAGE_VERSION" | cut -d. -f3`
AC_SUBST([PACKAGE_VERSION_MAJOR])
AC_SUBST([PACKAGE_VERSION_MINOR])
AC_SUBST([PACKAGE_VERSION_MICRO])
AC_DEFINE_UNQUOTED(PACKAGE_VERSION_MAJOR, $PACKAGE_VERSION_MAJOR, [Define to the major version of this package.])
AC_DEFINE_UNQUOTED(PACKAGE_VERSION_MINOR, $PACKAGE_VERSION_MINOR, [Define to the minor version of this package.])
AC_DEFINE_UNQUOTED(PACKAGE_VERSION_MICRO, $PACKAGE_VERSION_MICRO, [Define to the micro version of this package.])
PACKAGE_YEAR=`date +%Y`
AC_SUBST([PACKAGE_YEAR])
AC_DEFINE_UNQUOTED(PACKAGE_YEAR, $PACKAGE_YEAR, [Define to the current year.])
PACKAGE_COMPANY="Stroz Friedberg, LLC"
AC_SUBST([PACKAGE_COMPANY])
AC_DEFINE_UNQUOTED(PACKAGE_COMPANY, "$PACKAGE_COMPANY", [Define to the owner of this package.])
PACKAGE_DESCRIPTION="not the worst forensics regexp engine"
AC_SUBST([PACKAGE_DESCRIPTION])
AC_DEFINE_UNQUOTED(PACKAGE_DESCRIPTION, "$PACKAGE_DESCRIPTION", [Define to the description of this package.])
#
# common
#
AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_C_O
AC_PROG_INSTALL
PKG_PROG_PKG_CONFIG
AS_IF([test "x$enable_shared" != "xyes"], [PKG_CONFIG="$PKG_CONFIG --static"])
AC_LANG([C])
AX_APPEND_COMPILE_FLAGS([-std=c11 -W -Wall -Wextra -pedantic -pipe], [LG_CFLAGS])
AC_LANG([C++])
AX_CXX_COMPILE_STDCXX_17([noext], [mandatory])
AX_APPEND_COMPILE_FLAGS([-W -Wall -Wextra -Wnon-virtual-dtor -pedantic -pipe], [LG_CXXFLAGS])
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],
[build in debug mode, with symbols and no optimization])])
AS_IF([test "x$enable_debug" = "xyes"], [OFLAGS='-Og'], [OFLAGS='-O3 -mtune=intel'])
AC_ARG_ENABLE([symbols],
[AS_HELP_STRING([--enable-symbols],
[build with debugging symbols])],
[enable_symbols=yes],
[enable_symbols=no])
AS_IF([test "x$enable_symbols" != "xno"], [SYMBOLS='-g'], [SYMBOLS=''])
AX_APPEND_COMPILE_FLAGS([$SYMBOLS $OFLAGS], [LG_CFLAGS])
AX_APPEND_COMPILE_FLAGS([$SYMBOLS $OFLAGS], [LG_CXXFLAGS])
PKG_CHECK_MODULES([GPT], [libprofiler], [], [ : ])
# FIXME: mingw defaults to -g -O2, along with a bunch of other flags which
# we want to keep.
case "$host" in
*-*-mingw*)
LG_REMOVE_FLAGS([CFLAGS], ['-O2'])
LG_REMOVE_FLAGS([CXXFLAGS], ['-O2'])
;;
esac
#
# regex grammar
# check bison is installed and print its version
#
AX_PROG_BISON([printf "bison version is... " && bison --version | head -n 1])
# libintl.h would be necessary if we used Bison's i18n setup
#AC_CHECK_HEADERS([libintl.h])
#
# Fat or thin shared library?
#
AC_ARG_ENABLE([shared-fat],
[AS_HELP_STRING([--enable-shared-fat],
[statically link liblightgrep to its dependencies (MinGW only)])])
if test "x$enable_shared_fat" = "xyes"; then
case "$host" in
*-*-mingw*)
if test "x$enable_shared" != "xyes"; then
AC_MSG_ERROR([--enable-shared-fat requires --enable-shared.])
fi
echo "Enabling fat shared lib. Your shared liblightgrep is so fat, it will contain all of its dependencies."
;;
*)
AC_MSG_ERROR([--enable-shared-fat requires building with MinGW.])
;;
esac
fi
#
# ICU
#
PKG_CHECK_MODULES([ICU], [icu-uc])
ICU_CPPFLAGS="$ICU_CFLAGS"
ICU_CFLAGS=""
AX_APPEND_COMPILE_FLAGS([ \
-DU_USING_ICU_NAMESPACE=0 \
-DU_CHARSET_IS_UTF8=1 \
-DUNISTR_FROM_CHAR_EXPLICIT=explicit \
-DUNSTR_FROM_STRING_EXPLICIT=explicit \
], [ICU_CPPFLAGS])
if test "x$enable_shared" != "xyes" -o "x$enable_shared_fat" = "xyes"; then
AX_APPEND_COMPILE_FLAGS([-DU_STATIC_IMPLEMENTATION], [ICU_CPPFLAGS])
fi
AC_SUBST([ICU_CPPFLAGS])
case "$host" in
*-*-mingw*)
for i in $ICU_LIBS ; do
ICU_LDFLAGS+=$(echo $i | grep '^-L')
done
esac
AC_SUBST([ICU_CPPFLAGS])
AC_SUBST([ICU_LDFLAGS])
#
# Boost
#
if test "x$with_boost" = "xno"; then
AC_MSG_ERROR([--without-boost specified, but Boost is mandatory.])
else
case "$host" in
*-*-mingw*)
# AX_BOOST_BASE doesn't find Boost for mingw, we help it out
if test "$with_boost" = ""; then
with_boost="/usr/${host}/sys-root/mingw"
AC_MSG_NOTICE([--with-boost not set. We are guessing ${with_boost}.])
fi
;;
esac
AX_BOOST_BASE([1.49.0],
[],
[AC_MSG_ERROR([Failed to find usable Boost headers.])])
fi
AX_BOOST_PROGRAM_OPTIONS
if test "x$ax_cv_boost_program_options" != "xyes"; then
AC_MSG_ERROR([Failed to find Boost program_options library.])
fi
#
# libasan
#
AC_ARG_WITH([asan],
[AS_HELP_STRING([--with-asan=DIR], [build with libasan])],
[],
[with_asan=no])
if test "x$with_asan" != "xno"; then
ASAN_CFLAGS="-fsanitize=address -fno-omit-frame-pointer"
ASAN_CXXFLAGS="$ASAN_CFLAGS"
ASAN_LDFLAGS="$ASAN_CFLAGS"
AC_SUBST([ASAN_CFLAGS])
AC_SUBST([ASAN_CXXFLAGS])
AC_SUBST([ASAN_LDFLAGS])
fi
AC_DEFINE_UNQUOTED(LG_TEST_DATA_DIR, "$srcdir/test/data", [Define to the path to the test data.])
#
# Threading
#
case "$host" in
*-*-mingw*)
AX_APPEND_COMPILE_FLAGS([-mthreads], [LG_CPPFLAGS])
AX_APPEND_LINK_FLAGS([-mthreads], [LG_LDFLAGS])
;;
*-apple-darwin*)
;;
*)
AX_APPEND_COMPILE_FLAGS([-pthread], [LG_CPPFLAGS])
AX_APPEND_LINK_FLAGS([-pthread], [LG_LDFLAGS])
esac
AC_SUBST([LG_CPPFLAGS])
AC_SUBST([LG_CFLAGS])
AC_SUBST([LG_CXXFLAGS])
AC_SUBST([LG_LDFLAGS])
#
# C++ library
#
case "$host" in
*-apple-darwin*)
echo " ** MacOS X builds are problematic as compilers are in transition."
echo " ** We presume you're using a recent clang and libc++."
echo " ** And we recommend only building the library and not unit tests."
echo " ** If you build the unit tests, you are entering a world of pain."
AX_APPEND_COMPILE_FLAGS([-stdlib=libc++], [STDCXX_CXXFLAGS])
# TODO: Actually linking against libc++ will require everything else down
# the chain to have been linked with libc++, including Boost, ICU, etc.
# So, don't do this just yet.
# STDCXX_LIB='-lc++'
STDCXX_LIB='-lstdc++'
;;
*)
STDCXX_LIB='-lstdc++'
;;
esac
AC_SUBST([STDCXX_LIB])
AC_SUBST([STDCXX_CXXFLAGS])
# FIXME: need to add -install_name to LDFLAGS when building a dynamic lib
# for MacOS X.
# FIXME: Is this really the right way to do this?!
# Build dynamically-linked executables if we build dynamic libs
if test "x$enable_shared" != "xyes"; then
CXXLD="$CXX -all-static"
CCLD="$CC -all-static"
case "$host" in
i686-*-mingw*)
# FIXME: Really? This looks like it's just asking for trouble...
AX_APPEND_LINK_FLAGS([-Wl,--allow-multiple-definition], [LG_LIB_LDFLAGS])
;;
esac
else
CXXLD="$CXX"
CCLD="$CC"
case "$host" in
*-*-mingw*)
# -no-undefined is a libtool flag; adding it with AX_APPEND_LINK_FLAGS
# will fail because that tries flags with LD. So don't do that.
AX_APPEND_FLAG([-no-undefined], [LG_LIB_LDFLAGS])
LG_LIB_LDFLAGS="$LG_LIB_LDFLAGS -Wl,--output-def -Wl,src/lib/.libs/$PACKAGE.def"
LT_LANG([Windows Resource])
;;
esac
fi
AC_SUBST([CXXLD])
AC_SUBST([CCLD])
AM_CONDITIONAL([BUILD_DLL], [test "x$enable_shared" = "xyes" && echo "$host" | grep -q mingw])
AC_SUBST([LG_LIB_LDFLAGS])
#
# Test Dependencies
#
AX_PKG_CHECK_MODULES([CATCH2], [], [catch2-with-main], [], [with_catch2=no])
CATCH2_CPPFLAGS="-DCATCH_CONFIG_ENABLE_ALL_STRINGMAKERS"
AC_SUBST([CATCH2_CPPFLAGS])
AX_BOOST_ASIO
if test "x$ax_cv_boost_asio" != 'xyes' -o "x$with_catch2" = 'xno'; then
AC_MSG_WARN([])
AC_MSG_WARN([You will be unable to compile and run the tests because:])
AC_MSG_WARN([])
if test "x$ax_cv_boost_asio" != 'xyes'; then
AC_MSG_WARN([ * boost::asio is unavailable])
fi
if test "x$with_catch2" = 'xno'; then
AC_MSG_WARN([ * Catch2 is unavailable])
fi
AC_MSG_WARN([])
fi
case "$host" in
*-*-mingw*)
# Boost ASIO needs ws2_32 and mswsock on Windows
BOOST_ASIO_LIB="-lws2_32 -lmswsock"
AC_SUBST([BOOST_ASIO_LIB])
;;
esac
#
# Customer name
#
AC_ARG_WITH([customer],
[AS_HELP_STRING([--with-customer=ARG], [set the customer name])],
[
escaped_customer=`echo "$withval" | sed -e 's/,/\\\\x2C/g'`
AC_DEFINE_UNQUOTED([LIGHTGREP_CUSTOMER],
[$escaped_customer],[Name of the customer.])
AC_MSG_NOTICE([customer is "$with_customer"])
]
[AC_MSG_NOTICE([no customer specified])])
# Support for check with valgrind
AX_VALGRIND_DFLT([sgcheck], [off])
AX_VALGRIND_DFLT([helgrind], [off])
AX_VALGRIND_DFLT([drd], [off])
AX_VALGRIND_DFLT([memcheck], [on])
AX_VALGRIND_CHECK
#
# Python bindings
#
AC_ARG_ENABLE([python],
[AS_HELP_STRING([--enable-python], [build Python bindings])])
AS_IF(
[test "x$enable_python" = "xyes"],
[AC_PATH_PROG([PYTHON], [python])]
)
AM_CONDITIONAL([BUILD_PYTHON], [test "x$enable_python" = "xyes"])
#
# Java bindings
#
AC_ARG_ENABLE([java],
[AS_HELP_STRING([--enable-java], [build Java bindings])])
AS_IF(
[test "x$enable_java" = "xyes"],
[
# calls AC_PATH_PROG using JAVAC; setting it here with AC_PATH_PROG messes
# up the check, so do this first
saved_JAVAC="$JAVAC"
JAVAC=
AX_JNI_INCLUDE_DIR
JAVAC="$saved_JAVAC"
for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS; do
JNI_CPPFLAGS="$JNI_CPPFLAGS -I$JNI_INCLUDE_DIR"
done
AC_SUBST([JNI_CPPFLAGS])
AC_PATH_PROG([JAVA], [java])
AC_PATH_PROG([JAR], [jar])
AC_PATH_PROG([JAVAC], [javac])
]
)
AM_CONDITIONAL([BUILD_JAVA], [test "x$enable_java" = "xyes"])
#
# Cleanup flags
#
# TODO: libtre has a nice display we can steal
AC_MSG_NOTICE([ICU_CPPFLAGS: $ICU_CPPFLAGS])
AC_MSG_NOTICE([ICU_CFLAGS: $ICU_CFLAGS])
AC_MSG_NOTICE([ICU_CXXFLAGS: $ICU_CXXFLAGS])
AC_MSG_NOTICE([ICU_LIBS: $ICU_LIBS])
AC_MSG_NOTICE([BOOST_CPPFLAGS: $BOOST_CPPFLAGS])
AC_MSG_NOTICE([BOOST_CXXFLAGS: $BOOST_CXXFLAGS])
AC_MSG_NOTICE([ASAN_CFLAGS: $ASAN_CFLAGS])
AC_MSG_NOTICE([ASAN_CXXFLAGS: $ASAN_CXXFLAGS])
AC_MSG_NOTICE([ASAN_LDFLAGS: $ASAN_LDFLAGS])
AC_MSG_NOTICE([LG_CFLAGS: $LG_CFLAGS])
AC_MSG_NOTICE([LG_CXXFLAGS: $LG_CXXFLAGS])
AC_MSG_NOTICE([CC: $CC])
AC_MSG_NOTICE([CXX: $CXX])
AC_MSG_NOTICE([CPPFLAGS: $CPPFLAGS])
AC_MSG_NOTICE([CFLAGS: $CFLAGS])
AC_MSG_NOTICE([CXXFLAGS: $CXXFLAGS])
AC_MSG_NOTICE([LDFLAGS: $LDFLAGS])
AC_MSG_NOTICE([LIBS: $LIBS])
AC_CONFIG_FILES([Makefile liblightgrep.spec mingw-liblightgrep.spec])
AC_OUTPUT
# Force static linking of dependencies for our fat DLL.
if test "x$enable_shared_fat" = "xyes"; then
# NB: This is likely to be fragile. It works only because the current
# version of libtool doesn't alter whole_archive_flag_spec and happens
# to put it in the right place in the linking command for our DLL.
sed -i '/^whole_archive_flag_spec=/s/"$/ \\${wl}-static"/' libtool
# We want NO dependencies for a fat DLL. libgcc_s is a stub for
# libgcc_s_seh-1.dll. libgcc_eh is the corresponding static lib.
sed -i '/^postdeps=/s/-lgcc_s/-lgcc_eh/g' libtool
echo 'Adjusted libtool for building fat DLL'
fi