-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfigure.ac
More file actions
317 lines (257 loc) · 10 KB
/
configure.ac
File metadata and controls
317 lines (257 loc) · 10 KB
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
AC_PREREQ([2.69])
AC_INIT(
[libasdf], [0.1.0a2],
[https://github.com/asdf-format/libasdf/issues],
[],
[https://github.com/asdf-format/libasdf],
)
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign subdir-objects])
# needed for strptime, at the very least...
AC_USE_SYSTEM_EXTENSIONS
LT_INIT([disable-static])
# silent make https://autotools.io/automake/silent.html
# silent rules enabled by default with 'yes'
# disable silent runles with ./configure --disable-silent-rules
AM_SILENT_RULES([yes]) # less verbose make output
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_MACRO_DIR([m4])
AC_LANG([C])
AC_PROG_CC
AS_IF([test "x$ac_cv_prog_cc_c11" = "xno"],
[AC_MSG_ERROR([C11 support is required but not available])])
AC_PROG_INSTALL
AC_HEADER_ASSERT # ./configure --disable-assert to define NDEBUG
# Check headers
AC_CHECK_HEADER([stdlib.h])
AX_CHECK_ENDIAN_DECL([be64toh])
AX_CHECK_ENDIAN_DECL([be32toh])
AX_CHECK_ENDIAN_DECL([htobe16])
AX_CHECK_ENDIAN_DECL([htobe32])
AX_CHECK_ENDIAN_DECL([htobe64])
AX_CHECK_ENDIAN_DECL([le32toh])
AX_CHECK_ENDIAN_DECL([htole32])
# Check functions
AC_CHECK_FUNCS([strptime])
# Check for userfaultfd (for lazy decompression support, Linux only currently)
AC_CHECK_HEADERS([linux/userfaultfd.h], [], [])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
#include <linux/userfaultfd.h>
]], [[
struct uffdio_api api;
api.api = UFFD_API;
]])],
[have_userfaultfd=yes],
[have_userfaultfd=no]
)
AM_CONDITIONAL([HAVE_USERFAULTFD], [test "x$have_userfaultfd" = "xyes"])
AS_IF([test "x$have_userfaultfd" = "xyes"], [
AC_DEFINE([HAVE_USERFAULTFD], [1],
[Define to 1 if userfaultfd support is available])
])
AC_CHECK_DECLS([SYS_userfaultfd], [], [], [[#include <sys/syscall.h>]])
# http://www.gnu.org/software/autoconf-archive/ax_valgrind_check.html
# - make check-valgrind
AX_VALGRIND_CHECK
# http://www.gnu.org/software/autoconf-archive/ax_code_coverage.html#ax_code_coverage
# - make check-code-coverage generates coverage report
AX_CODE_COVERAGE
# Check and add compiler flags
AX_CHECK_COMPILE_FLAG([-Wall], [ASDF_CFLAGS="$ASDF_CFLAGS -Wall"])
AX_CHECK_COMPILE_FLAG([-Wextra], [ASDF_CFLAGS="$ASDF_CFLAGS -Wextra"])
AX_CHECK_COMPILE_FLAG([-Wparentheses], [ASDF_CFLAGS="$ASDF_CFLAGS -Wparentheses"])
AX_CHECK_COMPILE_FLAG([-Wpointer-sign], [ASDF_CFLAGS="$ASDF_CFLAGS -Wpointer-sign"])
AX_CHECK_COMPILE_FLAG([-Wshadow], [ASDF_CFLAGS="$ASDF_CFLAGS -Wshadow"])
# Check whether the linker supports --wrap (GNU ld / lld only; Apple ld does not)
AC_MSG_CHECKING([whether linker supports -Wl,--wrap])
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -Wl,--wrap=malloc"
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
[have_linker_wrap=yes],
[have_linker_wrap=no])
LDFLAGS="$save_LDFLAGS"
AC_MSG_RESULT([$have_linker_wrap])
AM_CONDITIONAL([HAVE_LINKER_WRAP], [test "x$have_linker_wrap" = "xyes"])
# Additional enable flags
# --enable-debug
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug], [Enable debug build (-g -O0)])],
[enable_debug=yes],
[enable_debug=no]
)
ASDF_BUILD_MODE=
AS_IF([test "x$enable_debug" = "xyes"], [
ASDF_CFLAGS="$ASDF_CFLAGS -g -O0"
AC_DEFINE([DEBUG], [1], [Define if debugging is enabled])
ASDF_BUILD_MODE="${ASDF_BUILD_MODE}debug "
])
AM_CONDITIONAL([DEBUG], [test "x$enable_debug" = "xyes"])
# --disable-tool
AC_ARG_ENABLE([tool],
[AS_HELP_STRING([--disable-tool], [Do not build the asdf command-line tool])],
[asdf_build_tool=$enableval],
[asdf_build_tool=yes])
AM_CONDITIONAL([ASDF_BUILD_TOOL], [test "x$asdf_build_tool" = xyes])
# --with-asan
AC_ARG_WITH([asan],
[AS_HELP_STRING([--with-asan], [Build with AddressSanitizer support])],
[with_asan=yes],
[with_asan=no])
AS_IF([test "x$with_asan" = "xyes"], [
ASDF_CFLAGS="$ASDF_CFLAGS -O1 -g -fsanitize=address -fno-omit-frame-pointer"
ASDF_LDFLAGS="$ASDF_LDFLAGS -fsanitize=address"
AC_DEFINE([WITH_ASAN], [1], [Defined if building with AddressSanitizer])
ASDF_BUILD_MODE="${ASDF_BUILD_MODE}asan "
])
# Logging flags
AC_ARG_ENABLE([logging],
[AS_HELP_STRING([--enable-logging], [Enable logging (default: yes)])],
[enable_logging=$enableval],
[enable_logging=yes]
)
AS_IF([test "x$enable_logging" = "xyes"],
[AC_DEFINE([ASDF_LOG_ENABLED], [1], [Enable logging])]
)
AC_ARG_ENABLE([log-color],
[AS_HELP_STRING([--enable-log-color],
[Enable color output in logs (default: yes)])],
[enable_log_color=$enableval],
[enable_log_color=yes]
)
if test "x$enable_log_color" = "xyes"; then
AC_DEFINE([ASDF_LOG_COLOR], [1], [Enable color output in logs])
fi
AC_ARG_WITH([log-default],
[AS_HELP_STRING([--with-log-default=LEVEL], [Set default runtime log level])],
[AS_CASE([$with_log_default],
[TRACE|DEBUG|INFO|WARN|ERROR|FATAL|NONE], [],
[AC_MSG_ERROR([Invalid log level: $with_log_default])])],
[with_log_default=WARN]
)
AC_DEFINE_UNQUOTED([ASDF_LOG_DEFAULT_LEVEL], [ASDF_LOG_$with_log_default],
[Default runtime log level])
AC_ARG_WITH([log-min],
[AS_HELP_STRING([--with-log-min=LEVEL], [Set compile-time minimum log level])],
[AS_CASE([$with_log_min],
[TRACE|DEBUG|INFO|WARN|ERROR|FATAL|NONE], [],
[AC_MSG_ERROR([Invalid min log level: $with_log_min])])],
[with_log_min=TRACE]
)
AC_DEFINE_UNQUOTED([ASDF_LOG_MIN_LEVEL], [ASDF_LOG_$with_log_min],
[Compile-time minimum log level])
# Initalize submodules needed for the build
AS_IF([test ! -f "$srcdir/third_party/STC/LICENSE"],
[AC_MSG_NOTICE([Initializing submodule third_party/STC...])
(cd "$srcdir" && git submodule update --init third_party/STC && \
git config submodule.third_party/STC.ignore untracked || \
AC_MSG_ERROR([Failed to init submodule third_party/STC]))])
# Checks for libraries.
# Preferably using pkg-config, could fall back on AC_SEARCH_LIBS if not
AC_PATH_PROG([PKG_CONFIG], [pkg-config], [no])
if test "$PKG_CONFIG" = "no"; then
AC_MSG_ERROR([pkg-config is required but was not found])
fi
PKG_CHECK_MODULES([FYAML], [libfyaml], [], [
AC_MSG_ERROR([libfyaml is required but was not found])
])
dnl Workaround for https://github.com/pantoniou/libfyaml/pull/275
dnl This can be deleted if libfyaml is fixed upstream, though system
dnl packagers are likely to fix this too
FYAML_LIBS=$(printf '%s\n' "$FYAML_LIBS" | sed 's/none required//g')
# Check for libstatgrab
AC_ARG_WITH([libstatgrab],
[AS_HELP_STRING([--with-libstatgrab],
[Use libstatgrab for system memory info (default: yes)])],
[with_libstatgrab=$withval],
[with_libstatgrab=yes])
AS_IF([test "x$with_libstatgrab" = "xyes"], [
PKG_CHECK_MODULES([STATGRAB], [libstatgrab], [
AC_DEFINE([HAVE_STATGRAB], [1], [Define if libstatgrab is available])
], [
AC_MSG_ERROR([libstatgrab is required but was not found])
])
], [
AC_MSG_NOTICE([libstatgrab disabled])
])
# Compression libraries
PKG_CHECK_MODULES([ZLIB], [zlib], [], [
AC_MSG_ERROR([zlib is required but was not found])
])
# Annoyingly my system does not provide a pc file for bzip2, so fall back on
# checking without pkg-config (should probably do same for the other deps)
PKG_CHECK_MODULES([BZIP2], [bzip2], [], [
AC_CHECK_HEADER([bzlib.h], [have_bzip2_h=yes], [have_bzip2_h=no])
AC_CHECK_LIB([bz2], [BZ2_bzCompressInit],
[have_bzip2_lib=yes; BZIP2_LIBS="-lbz2"],
[have_bzip2_lib=no])
AS_IF([test "x$have_bzip2_h" = xyes && test "x$have_bzip2_lib" = xyes], [
AC_DEFINE([HAVE_BZIP2], [1], [Define if bzip2 is available])
BZIP2_CFLAGS=""
], [
AC_MSG_ERROR([bz2 is required but was not found])
])
])
PKG_CHECK_MODULES([LZ4], [liblz4], [], [
AC_MSG_ERROR([liblz4 is required but was not found])
])
# Detect support for md5.h from libmd (libbsd on older systems);
# should try other options as well e.g. openssl
AC_CHECK_HEADERS([md5.h], [have_md5_h=yes], [have_md5_h=no])
AS_IF([test "x$have_md5_h" = "xyes"], [
AC_CHECK_FUNCS([MD5Init], [have_md5=yes], [have_md5=no])
AS_IF([test "x$have_md5" = "xno"], [
AC_MSG_NOTICE([MD5Init not found, trying with -lmd])
unset ac_cv_func_MD5Init
save_LIBS="$LIBS"
LIBS="-lmd $LIBS"
AC_CHECK_FUNCS([MD5Init], [have_md5=yes], [have_md5=no])
LIBS="$save_LIBS"
AS_IF([test "x$have_md5" = "xyes"], [
md5_libs="-lmd"
])
])
], [
AC_MSG_WARN([libbsd is required for MD5 support; compiling without checksum support])
])
AS_IF([test "x$have_md5" = "xyes"], [
AC_DEFINE([HAVE_MD5], [1], [Define if MD5 support is available])
])
AM_CONDITIONAL([HAVE_MD5], [test "x$have_md5" = "xyes"])
AC_SUBST([MD5_LIBS], [$md5_libs])
# Check for homebrew packages in macOS
AS_IF([test "x$asdf_build_tool" = "xyes"], [
ASDF_CHECK_HOMEBREW_PKG([argp-standalone])
# Shouldn't be needed with glibc but is if we're using the homebrew package, e.g.
AC_CHECK_LIB([argp], [argp_parse], [
AC_SUBST([ARGP_LIBS], [-largp])
])
])
ASDF_LIBS="$FYAML_LIBS $ZLIB_LIBS $BZIP2_LIBS $LZ4_LIBS $STATGRAB_LIBS $MD5_LIBS"
AC_SUBST([ASDF_LIBS])
# ------ Optional features ---------------------------------------------------
# Enable/check doc build requirements
ASDF_CHECK_SPHINX
# Check for Python--used to generate some of the tests if available
AC_PATH_PROG([PYTHON3], [python3], [no])
AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON3" != "no"])
AC_SUBST([PYTHON3])
AC_SUBST([ASDF_CFLAGS])
AC_SUBST([ASDF_LDFLAGS])
AC_CONFIG_HEADERS([config.h]) # use config.h instead of passing -D in the command line
AC_CONFIG_FILES([Makefile include/Makefile tests/Makefile third_party/Makefile docs/Makefile libasdf.pc])
AC_OUTPUT
# Report
CC_VERSION=`$CC --version | head -n 1`
FYAML_VERSION=`$PKG_CONFIG --modversion libfyaml`
printf "\n===================== Configuration Summary =====================\n"
printf " %18s %s\n" "$PACKAGE_NAME version:" "$VERSION"
printf " %18s %s\n" "compiler version:" "$CC_VERSION"
printf " %18s %s\n" "libfyaml version:" "$FYAML_VERSION"
AS_IF([test "x$ASDF_BUILD_MODE" != "x"], [
printf " %18s %s\n" "build:" "$ASDF_BUILD_MODE"
])
AS_IF([test "x$ASDF_OPTIONAL" != "x"], [
printf " %18s %s\n" "optional:" "$ASDF_OPTIONAL"
])
printf "=================================================================\n\n"