-
Notifications
You must be signed in to change notification settings - Fork 16
/
common.ac
346 lines (298 loc) · 11.9 KB
/
common.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
# This file is a part of SEAPT, Samsung Extended Autotools Project Template
# Copyright 2012,2013 Samsung R&D Institute Russia
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AC_PREREQ(2.68)
AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_HEADERS([src/config.h])
AC_DEFINE([INLINE], [static __attribute__((always_inline)) inline],
[Set modifiers to always inline the code])
AC_DEFINE([UNUSED], [__attribute__((unused))],
[Mark parameters as unused to avoid warnings])
AC_DEFINE([MALLOC], [__attribute__ ((__malloc__))],
[malloc() function attribute])
AC_DEFINE([WARN_UNUSED_RESULT], [__attribute__ ((__warn_unused_result__))],
[warn about unused result function attribute])
AC_DEFINE([NOTNULL(...)], [__attribute__ ((__nonnull__ (__VA_ARGS__)))],
[Mark pointer parameters which must not be NULL])
AC_ARG_ENABLE([android],
AS_HELP_STRING([--enable-android], [generate Android.mk and Application.mk in \"android\" subdirectory])
)
ANDROID_CFLAGS=
ANDROID_CPPFLAGS=
m4_include([android.ac])
AC_SUBST([ANDROID_CFLAGS])
AC_SUBST([ANDROID_CPPFLAGS])
# Check for debug configuration
AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [use debug configuration]),
[DEBUG_FLAGS="-g -O0 -DDEBUG -Wextra -Werror" ANDROID_OPTIM="debug"],
[DEBUG_FLAGS="-O2 -D_FORTIFY_SOURCE=2" ANDROID_OPTIM="release"])
AC_SUBST([ANDROID_OPTIM])
AS_IF([test "x$enable_android" == "xyes"], [
AC_CONFIG_FILES(android/Android.mk android/Application.mk)
AC_OUTPUT
rm -f android/jni
ln -s . android/jni
exit
])
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_CANONICAL_SYSTEM
AC_ARG_VAR(SYSROOT, [override your compiler's default sysroot (--sysroot)])
AS_IF([test "x$SYSROOT" != "x" ],
AM_CPPFLAGS="$AM_CPPFLAGS --sysroot=$SYSROOT"
LDFLAGS="$LDFLAGS --sysroot=$SYSROOT"
)
OLD_CXXFLAGS=$CXXFLAGS
OLD_CFLAGS=$CFLAGS
AC_GNU_SOURCE
AC_PROG_CC
AC_PROG_CXX
CXXFLAGS=$OLD_CXXFLAGS
CFLAGS=$OLD_CFLAGS
AC_HEADER_STDC
AC_C_BIGENDIAN([AC_MSG_ERROR([Big endian hosts are not supported.])])
# Initialize automake
AM_INIT_AUTOMAKE([1.11 dist-xz foreign color-tests subdir-objects])
# Nicely formatted make output
AM_SILENT_RULES([yes])
# Rebuild everything be default
AM_MAINTAINER_MODE([enable])
# This allows us specify individual linker flags for each target
AM_PROG_CC_C_O
# Check for GCC/Clang version
AC_MSG_CHECKING([whether gcc version is >= 4.6.0 / clang version is >= 3.1])
AC_EGREP_CPP(passed, [
#ifdef __GNUC__
#if !(__GNUC__ < 4 || __GNUC_MINOR__ < 6 || __GNUC_PATCHLEVEL__ < 0)
passed
#endif
#endif
#ifdef __clang__
#if !(__clang_major__ < 3 || __clang_minor__ < 1)
passed
#endif
#endif
], [AC_MSG_RESULT([yes])], [
AC_MSG_RESULT([no])
AC_MSG_ERROR([Building this project requires GCC >= 4.6.0 or clang >= 3.1])
])
# Initialize Libtool
LT_INIT
# Enable pkg-config
m4_ifndef([PKG_PROG_PKG_CONFIG], AC_MSG_ERROR([Configuration requires pkg-config to be installed]))
PKG_PROG_PKG_CONFIG
# Check whether to build subdirectories in parallel
AC_ARG_ENABLE([parallel_build],
AS_HELP_STRING([--enable-parallel-build], [build subdirectories in parallel])
)
AM_CONDITIONAL([PARALLEL_BUILD], [test "x$enable_parallel_build" = "xyes"])
# Use fancy make output by default
AC_ARG_ENABLE([colors],
AS_HELP_STRING([--disable-colors], [do not use enhanced colored make output])
)
AS_IF([test "x$enable_colors" != "xno"], [
am__v_CXX_0="@echo -e \" \\033@<:@01;32m\$(CXX)\\033@<:@00m \" \$@;"
am__v_CC_0="@echo -e \" \\033@<:@01;32m\$(CC)\\033@<:@00m \" \$@;"
am__v_CXXLD_0="@echo -e \" \\033@<:@01;31m\$(CXXLD)\\033@<:@00m \" \$@;"
am__v_CCLD_0="@echo -e \" \\033@<:@01;31m\$(CCLD)\\033@<:@00m \" \$@;"
am__v_GEN_0="@echo -e \" \\033@<:@01;36mGEN\\033@<:@00m \" \$@;"
], [
am__v_CXX_0="@echo \" CXX \" \$@;"
am__v_CC_0="@echo \" CC \" \$@;"
am__v_CXXLD_0="@echo \" CXXLD \" \$@;"
am__v_CCLD_0="@echo \" CCLD \" \$@;"
am__v_GEN_0="@echo \" GEN \" \$@;"
])
AC_SUBST([am__v_CXX_0])
AC_SUBST([am__v_CC_0])
AC_SUBST([am__v_CCLD_0])
AC_SUBST([am__v_CXXLD_0])
AC_SUBST([am__v_GEN_0])
# Check for Doxygen
AC_ARG_ENABLE([doxygen],
AS_HELP_STRING([--disable-doxygen], [do not build HTML documentation with Doxygen])
)
AS_IF([test "x$enable_doxygen" != "xno"], [
# If Doxygen is enabled...
AC_PATH_PROG([DOXYGEN], [doxygen], "")
AS_IF([test -z "$DOXYGEN"],
AC_MSG_WARN([Doxygen was not found - continuing without building the documentation])
)
AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
AM_COND_IF([HAVE_DOXYGEN], [
AC_CONFIG_FILES([docs/Doxyfile
docs/Makefile])
DOCS_DIR=docs
# Doxygen will require htags tools from GNU Global
AC_PATH_PROG(GLOBAL, [htags], "")
AS_IF([test -z "$GLOBAL"],
AC_MSG_ERROR([Doxygen requires GNU GLOBAL to be installed])
)
# Doxygen will require dot tool from Graphviz
AC_ARG_VAR(DOT, path to Graphviz dot)
AC_PATH_PROG(DOT, [dot], "")
AS_IF([test -z "$DOT"],
AC_MSG_ERROR([Doxygen requires Graphviz to be installed])
)
])
],[
AM_CONDITIONAL([HAVE_DOXYGEN], [false])
])
AC_SUBST([DOCS_DIR])
AM_CONDITIONAL(DEBUG, test "x$enable_debug" = "xyes")
# Enable/disable LTO
AC_ARG_ENABLE([lto],
AS_HELP_STRING([--enable-lto], [build with link-time optimizations (-flto)])
)
AS_IF([test "x$enable_lto" = "xyes"], [
AM_CPPFLAGS="$AM_CPPFLAGS -flto" LDFLAGS="-flto $LDFLAGS"
])
# Enable/disable fast math
AC_ARG_ENABLE([fast-math],
AS_HELP_STRING([--enable-fast-math], [build with unsafe floating point math optimizations (-ffast-math)])
)
AS_IF([test "x$enable_fast_math" = "xyes"], [
AM_CPPFLAGS="$AM_CPPFLAGS -ffast-math"
])
# Enable/disable OpenMP
AC_ARG_ENABLE([openmp],
AS_HELP_STRING([--disable-openmp], [disable parallel OpenMP code (-fopenmp)])
)
AS_IF([test "x$enable_openmp" != "xno"], [
AM_CPPFLAGS="$AM_CPPFLAGS -fopenmp"
LDFLAGS="-fopenmp $LDFLAGS"
])
# Enable/disable Valgrind detection
AC_ARG_ENABLE([valgrind],
AS_HELP_STRING([--enable-valgrind], [detect whether the code is running under Valgrind])
)
AS_IF([test "x$enable_valgrind" = "xyes"], [
PKG_CHECK_MODULES([VALGRIND], [valgrind >= 3.0])
AM_CPPFLAGS="$AM_CPPFLAGS -DVALGRIND $VALGRIND_CFLAGS"
])
# Check whether to build tests
AC_ARG_ENABLE([tests],
AS_HELP_STRING([--disable-tests], [do not build the tests])
)
AM_CONDITIONAL(TESTS, test "x$enable_tests" != "xno")
# Check whether to generate test coverage
AC_ARG_ENABLE([test-coverage],
AS_HELP_STRING([--enable-test-coverage],
[build with code coverage generation (this option depends on debug and tests switches)])
)
AS_IF([test "x$enable_test_coverage" = "xyes" -a "x$enable_debug" = "xyes" -a "x$enable_tests" != "xno"], [
AM_CPPFLAGS="$AM_CPPFLAGS --coverage"
LDFLAGS="-lgcov $LDFLAGS"
])
# Security flags
SECURITYFLAGS="-fstack-protector --param=ssp-buffer-size=4 -Wall -Wno-comment -Wformat-security"
AM_CPPFLAGS="$AM_CPPFLAGS $SECURITYFLAGS"
LDFLAGS="-Wl,-z,relro -Wl,--hash-style=gnu $LDFLAGS"
# Compile with -rdynamic
LDFLAGS="-rdynamic $LDFLAGS"
# Use the latest C++ standard
AM_CXXFLAGS="$AM_CXXFLAGS -std=c++0x -fno-deduce-init-list"
# Use C99 standard
AM_CFLAGS="$AM_CFLAGS -std=c99"
# Warn of unused precompiled headers
AM_CXXFLAGS="$AM_CXXFLAGS -Winvalid-pch"
# Some extra useful C++ warnings
AM_CXXFLAGS="$AM_CXXFLAGS -Wold-style-cast -Wnon-virtual-dtor"
# All include paths should be relative to source root or includes directory
AM_CPPFLAGS="$AM_CPPFLAGS -I\$(top_srcdir) -I\$(top_srcdir)/inc -I\$(top_builddir)"
# Append debug flags
AM_CPPFLAGS="$AM_CPPFLAGS $DEBUG_FLAGS"
# Use the best march
arch=$(echo $host | cut -d '-' -f 1)
AS_IF([test $arch = i686 -o $arch = x86_64], [
AM_CPPFLAGS="$AM_CPPFLAGS -march=native"
], [
AS_IF([test $arch = arm], [
AM_CPPFLAGS="$AM_CPPFLAGS -march=armv7-a -mfpu=neon"
])
])
AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_CPPFLAGS])
AC_SUBST([AM_CFLAGS])
# Link with Makefile.am in source directories
AC_CONFIG_FILES(Makefile $PACKAGE_NAME.pc
inc/Makefile
src/Makefile)
AM_COND_IF([TESTS], [
TESTS_DIR=tests
AC_CONFIG_FILES(tests/Makefile
tests/google/Makefile)
], [
# Default visibility of symbols is hidden
AM_CPPFLAGS="$AM_CPPFLAGS -fvisibility=hidden"
])
AC_SUBST([TESTS_DIR])
COLOR_RED='\033@<:@01;31m'
COLOR_GREEN='\033@<:@01;32m'
COLOR_YELLOW='\033@<:@01;33m'
COLOR_PURPLE='\033@<:@01;35m'
COLOR_CYAN='\033@<:@01;36m'
COLOR_WHITE='\033@<:@01;37m'
COLOR_RESET='\033@<:@00m'
function color_yes_no {
AS_IF([test $1 = yes], [
printf "${COLOR_GREEN}yes${COLOR_RESET}"
], [
printf "${COLOR_RED}no${COLOR_RESET}"
])
}
function left_trim {
printf -- "$@" | sed 's/^ *//g'
}
AC_DEFUN([COMMON_PRINT_STATUS], [
echo
echo -e "${COLOR_WHITE}-----------------${COLOR_RESET}"
echo -e "${COLOR_WHITE}- Configuration -${COLOR_RESET}"
echo -e "${COLOR_WHITE}-----------------${COLOR_RESET}"
echo
echo -e "${COLOR_WHITE}Compilation:${COLOR_RESET}"
echo -e " CFLAGS.............: ${COLOR_CYAN}"$(left_trim "$CFLAGS $AM_CFLAGS")"${COLOR_RESET}"
echo -e " CPPFLAGS...........: ${COLOR_CYAN}"$(left_trim "$CPPFLAGS $AM_CPPFLAGS")"${COLOR_RESET}"
echo -e " CXXFLAGS...........: ${COLOR_CYAN}"$(left_trim "$CXXFLAGS $AM_CXXFLAGS")"${COLOR_RESET}"
echo -e " LDFLAGS............: ${COLOR_CYAN}"$(left_trim "$LDFLAGS $AM_LDFLAGS")"${COLOR_RESET}"
echo
echo -e "${COLOR_WHITE}Installation:${COLOR_RESET}"
echo -e " Prefix.............: ${COLOR_CYAN}${prefix}${COLOR_RESET}"
echo -e " Host...............: ${COLOR_CYAN}${host}${COLOR_RESET}"
echo -e " Shared.............: $(color_yes_no ${enable_shared:-yes})"
echo -e " Static.............: $(color_yes_no ${enable_static:-yes})"
echo
echo -e "${COLOR_WHITE}Common options:${COLOR_RESET}"
echo -e " parallel_build.....: $(color_yes_no ${enable_parallel_build:-no})"
echo -e " colors.............: $(color_yes_no ${enable_colors:-yes})"
echo -e " debug..............: $(color_yes_no ${enable_debug:-no})"
echo -e " shared.............: $(color_yes_no ${enable_shared:-yes})"
echo -e " static.............: $(color_yes_no ${enable_static:-yes})"
echo -e " doxygen............: $(color_yes_no ${enable_doxygen:-yes})"
echo -e " lto................: $(color_yes_no ${enable_lto:-no})"
echo -e " fast_math..........: $(color_yes_no ${enable_fast_math:-no})"
echo -e " openmp.............: $(color_yes_no ${enable_openmp:-yes})"
echo -e " valgrind...........: $(color_yes_no ${enable_valgrind:-no})"
echo -e " tests..............: $(color_yes_no ${enable_tests:-yes})"
echo -e " test_coverage......: $(color_yes_no ${enable_test_coverage:-no})"
])