summaryrefslogtreecommitdiff
path: root/configure.ac
blob: ef4e1563310ac71fc3d91affecddbbbe9250fadc (plain) (blame)
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
AC_INIT(evolplugin, 1.0, akaras@inbox.ru)
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_SRCDIR(src)
AC_CONFIG_MACRO_DIR([m4])

AM_INIT_AUTOMAKE([foreign])

#AC_PROG_CXX
AC_PROG_CC
AM_PROG_CC_C_O
LT_INIT
AC_PROG_LIBTOOL
AC_ENABLE_SHARED
AC_DISABLE_STATIC

AC_ARG_ENABLE(
    [sanitize],
    AC_HELP_STRING(
        [--enable-sanitize],
        [
            Enables or Disables Sanitize Address Checking (SANITIZE is disabled by default)
        ]
    ),
    [
        enable_sanitize="$enableval"
        case $enableval in
            "no");;
            "yes")
                if test -n "$CC"; then
                    case `($CC --version) 2>/dev/null` in
                      *gcc*4.4*| \
                      *gcc*4.5*| \
                      *gcc*4.6*| \
                      *gcc*4.7*| \
                      *gcc*4.8*)
                        enable_sanitize="no"
                          ;;
                      *);;
                    esac
                fi
            ;;
            *) AC_MSG_ERROR([[invalid argument --enable-sanitize=$disableval... stopping]]);;
        esac
    ],
    [enable_sanitize="no"]
)
AM_CONDITIONAL(ENABLE_SANITIZE, test x$enable_sanitize = xyes)

AC_ARG_ENABLE(
    [static-build],
    AC_HELP_STRING(
        [--enable-static-build],
        [
            Enables or Disables Statick Linking (STATIC is disabled by default)
        ]
    ),
    [
        enable_static_build="$enableval"
        case $enableval in
            "no");;
            "yes");;
            *) AC_MSG_ERROR([[invalid argument --enable-static-build=$disableval... stopping]]);;
        esac
    ],
    [enable_static_build="no"]
)
AM_CONDITIONAL(ENABLE_STATIC_BUILD, test x$enable_static_build = xyes)

AC_ARG_ENABLE(
    [gprof],
    AC_HELP_STRING(
        [--enable-gprof],
        [
            Enables or Disables Gprof (disabled by default)
        ]
    ),
    [
        enable_gprof="$enableval"
        case $enableval in
            "no");;
            "yes");;
            *) AC_MSG_ERROR([[invalid argument --enable-gprof=$disableval... stopping]]);;
        esac
    ],
    [enable_gprof="no"]
)
AM_CONDITIONAL(ENABLE_GPROF, test x$enable_gprof = xyes)

AC_ARG_ENABLE(
    [werror],
    AC_HELP_STRING(
        [--enable-werror],
        [
            Fail build if warning present]
        ]
    ),
    [
        enable_werror="$enableval"
        case $enableval in
            "no");;
            "yes");;
            *) AC_MSG_ERROR([[invalid argument --enable-werror=$disableval... stopping]]);;
        esac
    ],
    [enable_werror="no"]
)
AM_CONDITIONAL(ENABLE_WERROR, test x$enable_werror = xyes)

AC_ARG_ENABLE(
    [lto],
        AC_HELP_STRING(
        [--enable-lto],
        [
            Enables or Disables Linktime Code Optimization (LTO is disabled by default)
        ]
    ),
    [
        enable_lto="$enableval"
        case $enableval in
            "no");;
            "yes");;
            *) AC_MSG_ERROR([[invalid argument --enable-lto=$enableval... stopping]]);;
        esac
    ],
    [enable_lto="no"]
)

OLD_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -rdynamic"
AC_MSG_CHECKING([whether $CC accepts -rdynamic])
AC_LINK_IFELSE(
    [AC_LANG_SOURCE([
        int main(int argc, char **argv)
        {
            return 0;
        }
    ])],
    [
        AC_MSG_RESULT([yes])
    ],
    [
        AC_MSG_RESULT([no])
        LDFLAGS="$OLD_LDFLAGS"
    ],
    [
        AC_MSG_RESULT([guessing no])
    ]
)

AC_DEFUN([AC_CHECK_COMPILER_WFLAG],
    [
        AC_MSG_CHECKING([whether $CC supports -W$1])
        OLD_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS -Werror -W$1"
        AC_COMPILE_IFELSE(
            [AC_LANG_SOURCE([int foo;])],
            [
                AC_MSG_RESULT([yes])
                CFLAGS="$OLD_CFLAGS -W$1"
                # Optionally, run a test
                if test "x$2" != "x"; then
                    AC_MSG_CHECKING([whether $CC can actually use -W$1])
                    CFLAGS="$OLD_CFLAGS -Werror -W$1"
                    AC_COMPILE_IFELSE(
                        [AC_LANG_SOURCE([$2])],
                        [
                            AC_MSG_RESULT([no])
                            CFLAGS="$OLD_CFLAGS"
                        ]
                        [
                            AC_MSG_RESULT([yes])
                            CFLAGS="$OLD_CFLAGS -W$1"
                        ],
                    )
                fi
            ],
            [
                AC_MSG_RESULT([no])
                CFLAGS="$OLD_CFLAGS"
            ]
        )
    ]
)

if test "$enable_lto" != "no" ; then
    OLD_CFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS -flto -ffat-lto-objects"

    OLD_LDFLAGS="$LDFLAGS"
    LDFLAGS="$LDFLAGS -flto -ffat-lto-objects"

    AC_MSG_CHECKING([whether $CC supports -flto])
    AC_RUN_IFELSE(
        [AC_LANG_SOURCE([
            int main(int argc, char **argv){
                return 0;
            }
        ])],
        [
            if test -n "$CC"; then
                case `($CC --version) 2>/dev/null` in
                  *gcc*4.9-*| \
                  *gcc*4.9.0*| \
                  *gcc*4.9.1*| \
                  *gcc*4.9.2*)
                    AC_MSG_RESULT([no])
                    CFLAGS="$OLD_CFLAGS"
                    LDFLAGS="$OLD_LDFLAGS"
                      ;;
                  *)
                    AC_MSG_RESULT([yes])
                esac
            fi
        ],
        [
            AC_MSG_RESULT([no])
            CFLAGS="$OLD_CFLAGS"
            LDFLAGS="$OLD_LDFLAGS"
        ],
        [
            AC_MSG_RESULT([guessing no])
        ]
    )
fi

AC_DEFUN([AC_CHECK_SANITIZER_FLAG],
    [
        AC_MSG_CHECKING([whether $CC supports -fsanitize=$1])
        OLD_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS -fsanitize=$1"
        OLD_LDFLAGS="$LDFLAGS"
        LDFLAGS="$LDFLAGS -fsanitize=$1"
        AC_COMPILE_IFELSE(
            [AC_LANG_SOURCE([int foo;])],
            [
                AC_MSG_RESULT([yes])
            ],
            [
                AC_MSG_RESULT([no])

                AC_MSG_CHECKING([whether $CC requires -fsanitize-undefined-trap-on-error for -fsanitize=$1])
                CFLAGS="$CFLAGS -fsanitize-undefined-trap-on-error"
                AC_COMPILE_IFELSE(
                    [AC_LANG_SOURCE([int foo;])],
                    [
                        AC_MSG_RESULT([yes])
                    ],
                    [
                        AC_MSG_RESULT([no])
                        CFLAGS="$OLD_CFLAGS"
                        LDFLAGS="$OLD_LDFLAGS"
                    ]
                )
            ],
            [
                AC_MSG_RESULT([guessing no])
                CFLAGS="$OLD_CFLAGS"
                LDFLAGS="$OLD_LDFLAGS"
            ]
        )
    ]
)

if test "$enable_sanitize" != "no" ; then
    AC_CHECK_SANITIZER_FLAG(address)
    # skipped because server have multiple issues: -fsanitize=alignment
    AC_CHECK_SANITIZER_FLAG(shift)
    AC_CHECK_SANITIZER_FLAG(integer-divide-by-zero)
    AC_CHECK_SANITIZER_FLAG(unreachable)
    AC_CHECK_SANITIZER_FLAG(vla-bound)
    AC_CHECK_SANITIZER_FLAG(null)
    AC_CHECK_SANITIZER_FLAG(return)
    AC_CHECK_SANITIZER_FLAG(signed-integer-overflow)
    AC_CHECK_SANITIZER_FLAG(bounds)
    AC_CHECK_SANITIZER_FLAG(bounds-strict)
    AC_CHECK_SANITIZER_FLAG(object-size)
    AC_CHECK_SANITIZER_FLAG(float-divide-by-zero)
    AC_CHECK_SANITIZER_FLAG(float-cast-overflow)
    AC_CHECK_SANITIZER_FLAG(nonnull-attribute)
    AC_CHECK_SANITIZER_FLAG(returns-nonnull-attribute)
    AC_CHECK_SANITIZER_FLAG(bool)
    AC_CHECK_SANITIZER_FLAG(enum)
    AC_CHECK_SANITIZER_FLAG(vptr)
fi

AC_CHECK_COMPILER_WFLAG(empty-body)
AC_CHECK_COMPILER_WFLAG(newline-eof)
AC_CHECK_COMPILER_WFLAG(int-conversion)
AC_CHECK_COMPILER_WFLAG(init-self)
AC_CHECK_COMPILER_WFLAG(pointer-arith)
AC_CHECK_COMPILER_WFLAG(switch-bool)
AC_CHECK_COMPILER_WFLAG(enum-conversion)
AC_CHECK_COMPILER_WFLAG(shorten-64-to-32)
AC_CHECK_COMPILER_WFLAG(constant-conversion)
AC_CHECK_COMPILER_WFLAG(bool-conversion)
AC_CHECK_COMPILER_WFLAG(format-security)
AC_CHECK_COMPILER_WFLAG(format)
AC_CHECK_COMPILER_WFLAG(format-signedness)
AC_CHECK_COMPILER_WFLAG(format-y2k)
AC_CHECK_COMPILER_WFLAG(missing-include-dirs)
AC_CHECK_COMPILER_WFLAG(suggest-attribute=noreturn)
AC_CHECK_COMPILER_WFLAG(undef)
# disabled for now
#AC_CHECK_COMPILER_WFLAG(cast-qual)
AC_CHECK_COMPILER_WFLAG(logical-op)
AC_CHECK_COMPILER_WFLAG(nested-externs)
AC_CHECK_COMPILER_WFLAG(old-style-definition)
AC_CHECK_COMPILER_WFLAG(overlength-strings)
AC_CHECK_COMPILER_WFLAG(redundant-decls)
#AC_CHECK_COMPILER_WFLAG(unused)
AC_CHECK_COMPILER_WFLAG(unused-but-set-parameter)
AC_CHECK_COMPILER_WFLAG(unused-but-set-variable)
AC_CHECK_COMPILER_WFLAG(unreachable-code)
AC_CHECK_COMPILER_WFLAG(unused-const-variable=2)
AC_CHECK_COMPILER_WFLAG(unused-function)
AC_CHECK_COMPILER_WFLAG(unused-local-typedefs)
AC_CHECK_COMPILER_WFLAG(unused-macros)
AC_CHECK_COMPILER_WFLAG(unused-parameter)
AC_CHECK_COMPILER_WFLAG(unused-result)
AC_CHECK_COMPILER_WFLAG(unused-value)
AC_CHECK_COMPILER_WFLAG(unused-variable)
#AC_CHECK_COMPILER_WNOFLAG(format-nonliteral)
#AC_CHECK_COMPILER_WNOFLAG(switch)
#AC_CHECK_COMPILER_WNOFLAG(missing-field-initializers)

AC_CHECK_FUNC([strnlen],[CFLAGS="$CFLAGS -DHAVE_STRNLEN"])
AC_CHECK_FUNC([setrlimit],[CLAGS="$CFLAGS -DHAVE_SETRLIMIT"])

AC_MSG_CHECKING([PCRE library])
AC_CHECK_HEADER([pcre.h], [], [AC_MSG_ERROR([PCRE header not found])])
AC_SEARCH_LIBS([pcre_study], [pcre], [], AC_MSG_ERROR([PCRE not found or incompatible]))

AC_OUTPUT(Makefile src/Makefile)