xref: /trafficserver/configure.ac (revision 8a8dfd2a)
1# Process this file with `autoreconf -i` to create a 'configure' file.
2
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#      http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing, software
14#  distributed under the License is distributed on an "AS IS" BASIS,
15#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16#  See the License for the specific language governing permissions and
17#  limitations under the License.
18
19# Table of Contents
20# 1. INITIALIZATION
21# 2. SITE CONFIGURATION
22# 3. CHECK FOR PROGRAMS
23# 4. CHECK FOR LIBRARIES
24# 5. CHECK FOR HEADERS
25# 6. OUTPUT FILES
26# 7. autoheader TEMPLATES
27
28# -----------------------------------------------------------------------------
29# 1. INITIALIZATION
30
31# These first two version numbers are updated automatically on each release.
32# Version number is calculated as MAJOR * 1000000 + MINOR * 1000 + MICRO
33# Version string is in the form of MAJOR.MINOR.MICRO[sufix]
34#
35m4_define([TS_VERSION_S],[9.0.0])
36m4_define([TS_VERSION_N],[9000000])
37
38AC_INIT([Apache Traffic Server], TS_VERSION_S(), [dev@trafficserver.apache.org], [trafficserver],[http://trafficserver.apache.org])
39AC_PREREQ([2.59])
40AC_CONFIG_AUX_DIR([build/_aux])
41AC_CONFIG_SRCDIR([src/traffic_server/traffic_server.cc])
42AC_CONFIG_MACRO_DIR([build])
43
44# NOTE: we turn off portability warnings because the clang-tidy targets use
45# GNU make extensions to filter the sources list.
46AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability tar-ustar foreign no-installinfo no-installman subdir-objects 1.9.2])
47
48# See discussion at https://autotools.io/automake/maintainer.html.
49AM_MAINTAINER_MODE([enable])
50
51# Enable a recursive "tidy" rule for clang-tidy.
52m4_ifdef([AM_EXTRA_RECURSIVE_TARGETS], [AM_EXTRA_RECURSIVE_TARGETS([clang-tidy])])
53
54AC_CONFIG_HEADERS([include/ink_autoconf.h])
55
56# Configure with --disable-silent-rules to get verbose output. For more info, see
57# http://www.gnu.org/software/automake/manual/html_node/Automake-silent_002drules-Option.html
58m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
59
60# Libtool versioning uses different conventions on different
61# platforms.  At least on FreeBSD, libtool uses an overly complex
62# convention that attempts to solve problems that most people just
63# don't have and which just causes confusion for most end users.
64#
65TS_VERSION_MAJOR=$((TS_VERSION_N() / 1000000 ))
66TS_VERSION_MINOR=$(((TS_VERSION_N() / 1000) % 1000 ))
67TS_VERSION_MICRO=$((TS_VERSION_N() % 1000 ))
68TS_LIBTOOL_MAJOR=`echo $((${TS_VERSION_MAJOR} + ${TS_VERSION_MINOR}))`
69TS_LIBTOOL_VERSION=$TS_LIBTOOL_MAJOR:$TS_VERSION_MICRO:$TS_VERSION_MINOR
70TS_VERSION_STRING=TS_VERSION_S()
71TS_VERSION_NUMBER=TS_VERSION_N()
72
73#
74# Substitute the above version numbers into the various files below.
75#
76AC_SUBST(TS_LIBTOOL_VERSION)
77AC_SUBST(TS_VERSION_STRING)
78AC_SUBST(TS_VERSION_NUMBER)
79AC_SUBST(TS_VERSION_MAJOR)
80AC_SUBST(TS_VERSION_MINOR)
81AC_SUBST(TS_VERSION_MICRO)
82
83dnl Hard-coded top of ink_autoconf.h:
84AH_TOP([
85#pragma once
86])
87
88#
89# Generate ./config.nice for reproducing runs of configure
90#
91TS_CONFIG_NICE([config.nice])
92
93# XXX we can't just use AC_PREFIX_DEFAULT because that isn't subbed in
94# by configure until it is too late.  Is that how it should be or not?
95# Something seems broken here.
96AC_PREFIX_DEFAULT([/usr/local/trafficserver])
97
98# Get the layout here, so we can pass the required variables to Trafficserver
99TS_ENABLE_LAYOUT(TrafficServer, [cachedir docdir])
100
101# Reparse the configure arguments so we can override the layout.
102TS_PARSE_ARGUMENTS
103
104#
105# Host detection
106#
107AC_CANONICAL_HOST
108HOST_GUESS="$host"
109AC_SUBST(HOST_GUESS)
110
111AC_ARG_WITH([user],
112  [AS_HELP_STRING([--with-user],[specify the system user [default=nobody]])],
113  [
114  with_user="$withval"
115  ],[
116  with_user="nobody"
117  ]
118)
119
120default_group="`id -ng $with_user`"
121AC_ARG_WITH([group],
122  [AS_HELP_STRING([--with-group],[specify the system group [default=nobody]])],
123  [
124  with_group="$withval"
125  ],[
126  with_group=${default_group:-nobody}
127  ]
128)
129AC_SUBST([pkgsysuser],[$with_user])
130AC_SUBST([pkgsysgroup],[$with_group])
131
132AC_ARG_WITH([build-number],
133  [AS_HELP_STRING([--with-build-number],[specify a version string for this build])],
134  [ build_number="$withval" ]
135)
136
137#
138# Build environment
139#
140build_person="`id -nu | sed -e 's/\\\\/\\\\\\\\/g'`"
141build_group="`id -ng | sed -e 's/\\\\/\\\\\\\\/g'`"
142build_machine="`uname -n | sed -e 's/\\\\/\\\\\\\\/g'`"
143AC_SUBST([build_machine])
144AC_SUBST([build_person])
145AC_SUBST([build_group])
146AC_SUBST([build_number])
147
148# -----------------------------------------------------------------------------
149# 2. SITE CONFIGURATION
150
151#
152# Debug
153#
154
155AC_MSG_CHECKING([whether to enable debugging])
156AC_ARG_ENABLE([debug],
157  [AS_HELP_STRING([--enable-debug],[turn on debugging])],
158  [],
159  [enable_debug=no]
160)
161AC_MSG_RESULT([$enable_debug])
162
163AC_MSG_CHECKING([whether to enable mime sanity check])
164AC_ARG_ENABLE([mime-sanity-check],
165  [AS_HELP_STRING([--enable-mime-sanity-check],[turn on mime sanity check])],
166  [],
167  [enable_mime_sanity_check=no]
168)
169AC_MSG_RESULT([$enable_mime_sanity_check])
170
171# Enable code coverage instrumentation only if requested by the user.
172AC_MSG_CHECKING([whether to code coverage])
173AC_ARG_ENABLE([coverage],
174  [AS_HELP_STRING([--enable-coverage],[generate code coverage instrumentation])],
175  [],
176  [enable_coverage=no]
177)
178AC_MSG_RESULT([$enable_coverage])
179
180#
181# Enable -Werror. We want this enabled by default for developers, but disabled by default
182# for end users (because we don't want released versions to suffer from compiler warning hell).
183#
184AC_MSG_CHECKING([whether to enable -Werror])
185AC_ARG_ENABLE([werror],
186  [AS_HELP_STRING([--enable-werror],[turn compiler warnings into errors])],
187  [],
188  [enable_werror=no]
189)
190AC_MSG_RESULT([$enable_werror])
191
192# Enable ASAN for the builds
193AC_MSG_CHECKING([whether to enable asan])
194AC_ARG_ENABLE([asan],
195  [AS_HELP_STRING([--enable-asan],[enable Address Sanitizer])],
196  [],
197  [enable_asan=no]
198)
199AC_MSG_RESULT([$enable_asan])
200
201# Enable LSAN in stand-alone mode for the builds
202AC_MSG_CHECKING([whether to enable lsan])
203AC_ARG_ENABLE([lsan],
204  [AS_HELP_STRING([--enable-lsan],[enable stand-alone Leak Sanitizer])],
205  [],
206  [enable_lsan=no]
207)
208AC_MSG_RESULT([$enable_lsan])
209
210# Enable TSAN for the builds
211AC_MSG_CHECKING([whether to enable tsan])
212AC_ARG_ENABLE([tsan],
213  [AS_HELP_STRING([--enable-tsan],[turn on Thread Sanitizer])],
214  [],
215  [enable_tsan=no]
216)
217AC_MSG_RESULT([$enable_tsan])
218
219#
220# Fast SDK APIs, this disables the parameter checks (assert)
221# on all APIs.
222#
223
224AC_MSG_CHECKING([whether to enable fast SDK APIs])
225AC_ARG_ENABLE([fast-sdk],
226  [AS_HELP_STRING([--enable-fast-sdk],[enable fast SDK APIs (no input parameter sanity checks)])],
227  [],
228  [enable_fast_sdk=no]
229)
230AC_MSG_RESULT([$enable_fast_sdk])
231TS_ARG_ENABLE_VAR([use], [fast-sdk])
232
233# Curl support for traffic_top
234AC_MSG_CHECKING([whether to enable CURL])
235AC_ARG_ENABLE([curl],
236  [AS_HELP_STRING([--disable-curl],[turn off CURL support for traffic_top])],
237  [],
238  [enable_curl=yes]
239)
240AC_MSG_RESULT([$enable_curl])
241
242if test "x${enable_curl}" = "xyes"; then
243AX_LIB_CURL([7.19], [AC_DEFINE([HAS_CURL], [1], [Define if libcurl >= 7.19.])])
244fi
245
246#
247# Diags
248#
249
250AC_MSG_CHECKING([whether to enable diags])
251AC_ARG_ENABLE([diags],
252  [AS_HELP_STRING([--disable-diags],[turn off diags])],
253  [],
254  [enable_diags=yes]
255)
256AC_MSG_RESULT([$enable_diags])
257TS_ARG_ENABLE_VAR([use], [diags])
258
259#
260# FIPS
261#
262
263AC_MSG_CHECKING([whether to enable fips])
264AC_ARG_ENABLE([fips],
265  [AS_HELP_STRING([--enable-fips],[turn on FIPS compliance])],
266  [],
267  [enable_fips=no]
268)
269AC_MSG_RESULT([$enable_fips])
270TS_ARG_ENABLE_VAR([enable], [fips])
271
272#
273# Build regression tests?
274#
275
276AC_MSG_CHECKING([whether to enable regression tests])
277AC_ARG_ENABLE([tests],
278  [AS_HELP_STRING([--disable-tests],[turn off regression tests])],
279  [],
280  [enable_tests=yes]
281)
282AC_MSG_RESULT([$enable_tests])
283TS_ARG_ENABLE_VAR([has], [tests])
284AM_CONDITIONAL([BUILD_TESTS], [test 0 -ne $has_tests])
285
286#
287# Build documentation?
288#
289
290# Java needed only for documentation building, but making it conditional
291# makes the diagnostic output ugly and hard to follow.
292AC_ARG_VAR(JAVA, [path to java executor])
293AC_CHECK_PROG(JAVA, java, java)
294AC_MSG_RESULT([Checking whether to build documentation:])
295AC_ARG_ENABLE([docs],
296  [AS_HELP_STRING([--enable-docs],[enable documentation building])],
297  [
298    enable_doc_build=yes
299    AM_PATH_PYTHON([3.4], [
300      TS_MAN1_MANPAGES=`cd $srcdir/doc && $PYTHON manpages.py --section=1 | $AWK '{print "$(BUILDDIR)/man/" $0 }' | tr '\n' ' '`
301      TS_MAN3_MANPAGES=`cd $srcdir/doc && $PYTHON manpages.py --section=3 | $AWK '{print "$(BUILDDIR)/man/" $0 }' | tr '\n' ' '`
302      TS_MAN5_MANPAGES=`cd $srcdir/doc && $PYTHON manpages.py --section=5 | $AWK '{print "$(BUILDDIR)/man/" $0 }' | tr '\n' ' '`
303      TS_MAN8_MANPAGES=`cd $srcdir/doc && $PYTHON manpages.py --section=8 | $AWK '{print "$(BUILDDIR)/man/" $0 }' | tr '\n' ' '`
304    ], [
305      enable_doc_build=no
306      AC_ERROR([Doc building disabled, python 3.4 or better required])
307    ])
308
309    AS_IF([test -z "$JAVA"],
310      [
311        enable_doc_build=no
312        AC_ERROR([Doc building disabled, java required but not found])
313      ])
314    AC_ARG_VAR(SPHINXBUILD, [the sphinx-build documentation generator])
315    AC_ARG_VAR(SPHINXOPTS, [additional sphinx-build options])
316    AC_PATH_PROG([SPHINXBUILD], [$SPHINXBUILD], [$PYTHON -m sphinx])
317    AS_IF(["$PYTHON" "$srcdir/doc/checkvers.py" --check-version],
318      [
319        sphinx_version_check=yes
320      ],[
321        sphinx_version_check=no
322        enable_doc_build=no
323        AC_ERROR([Doc building disabled, check sphinx installation])
324      ])
325
326
327    AC_SUBST(TS_MAN1_MANPAGES)
328    AC_SUBST(TS_MAN3_MANPAGES)
329    AC_SUBST(TS_MAN5_MANPAGES)
330    AC_SUBST(TS_MAN8_MANPAGES)
331
332    AC_MSG_CHECKING([whether to build man pages])
333    AS_IF([test "x$sphinx_version_check" = "xyes" -a "x$SPHINXBUILD" != "xfalse"], [
334      build_manpages=true
335      AC_MSG_RESULT([yes])
336    ], [
337      build_manpages=false
338      AC_MSG_RESULT([no])
339    ])
340
341  ],
342  [enable_doc_build=no]
343)
344AC_MSG_RESULT([Will build documentation: $enable_doc_build])
345AM_CONDITIONAL([BUILD_DOCS], [test "xyes" = "x$enable_doc_build"])
346AM_CONDITIONAL([BUILD_MANPAGES], [test "xtrue" = "x$build_manpages"])
347
348#
349# Remote Coverity Prevent commit
350#
351AC_MSG_CHECKING([whether to commit cov defects to remote host])
352AC_ARG_ENABLE([remote-cov-commit],
353  [AS_HELP_STRING([--enable-remote-cov-commit[=HOST]], [commit cov defects to remote host [HOST=localhost]])],
354  [],
355  [enable_remote_cov_commit=localhost]
356)
357AC_MSG_RESULT([$enable_remote_cov_commit])
358AC_SUBST([enable_remote_cov_commit])
359
360#
361# WCCP
362#
363AC_MSG_CHECKING([whether to enable WCCP v2 support])
364AC_ARG_ENABLE([wccp],
365  [AS_HELP_STRING([--enable-wccp],[enable WCCP v2])],
366  [],
367  [enable_wccp=no]
368)
369AC_MSG_RESULT([$enable_wccp])
370TS_ARG_ENABLE_VAR([has],[wccp])
371AM_CONDITIONAL([BUILD_WCCP], [test 0 -ne $has_wccp])
372
373# Google profiler
374AC_MSG_CHECKING([whether to enable profiler])
375AC_ARG_WITH([profiler],
376  [AS_HELP_STRING([--with-profiler],[enable support for profiler [default=no]])],
377  [with_profiler=$withval],
378  [with_profiler=no]
379)
380AC_MSG_RESULT([$with_profiler])
381
382# Disable all static library builds
383AC_DISABLE_STATIC
384
385#
386# use eventfd() or pipes
387# Found that ec2 is using an older kernel causing eventfd errors.
388# Disable eventfd when using ATS on EC2 Fedora.
389#
390AC_MSG_CHECKING([whether to enable eventfd()])
391AC_ARG_ENABLE([eventfd],
392  [AS_HELP_STRING([--disable-eventfd],[turn off eventfd and use pipes])],
393  [],
394  [enable_eventfd="yes"]
395)
396AC_MSG_RESULT([$enable_eventfd])
397
398#
399# use POSIX capabilities instead of user ID switching.
400#
401AC_MSG_CHECKING([whether to use POSIX capabilities])
402AC_ARG_ENABLE([posix-cap],
403  [AS_HELP_STRING([--disable-posix-cap],[Use user id switching instead of POSIX capabilities])],
404  [],
405  [enable_posix_cap="auto"]
406)
407AC_MSG_RESULT([$enable_posix_cap])
408
409#
410# use hwloc library when possible (can be disabled)
411#
412AC_MSG_CHECKING([whether to use hwloc library])
413AC_ARG_ENABLE([hwloc],
414  [AS_HELP_STRING([--disable-hwloc],[Don't use the hwloc library])],
415  [],
416  [enable_hwloc="yes"]
417)
418AC_MSG_RESULT([$enable_hwloc])
419
420#
421# Enble ccache explicitly (it's disabled by default, because of build problems in some cases)
422#
423AC_MSG_CHECKING([whether to enable ccache])
424AC_ARG_ENABLE([ccache],
425  [AS_HELP_STRING([--enable-ccache],[Enable ccache (for developers)])],
426  [],
427  [enable_ccache="no"]
428)
429AC_MSG_RESULT([$enable_ccache])
430
431#
432# Enble hardening of the executables
433#
434AC_MSG_CHECKING([whether to enable hardening of the executables])
435AC_ARG_ENABLE([hardening],
436  [AS_HELP_STRING([--enable-hardening],[Enable hardening of executables])],
437  [],
438  [enable_hardening="no"]
439)
440AC_MSG_RESULT([$enable_hardening])
441
442#
443# Use TPROXY for connection transparency.
444#
445AC_MSG_CHECKING([whether to enable TPROXY based transparency])
446AC_ARG_ENABLE([tproxy],
447  [AS_HELP_STRING([--enable-tproxy[[=ARG]]],
448                  [Use TPROXY to enable connection transparency.
449                   'auto' or omitted for local system default,
450                   'no' to disable,
451                   'force' to use built in default,
452                   number to use as IP_TRANSPARENT sockopt.
453                   [default=auto]
454                  ])
455  ],
456  [],
457  [enable_tproxy="auto"]
458)
459AC_MSG_RESULT([$enable_tproxy])
460
461#
462# Configure how many stats to allocate for plugins. Default is 512.
463#
464AC_ARG_WITH([max-api-stats],
465  [AS_HELP_STRING([--with-max-api-stats],[max number of plugin stats [default=512]])],
466  [max_api_stats=$withval],
467  [max_api_stats=512]
468)
469AC_SUBST(max_api_stats)
470
471#
472# Max host name length that we deal with in URLs.
473#
474AC_ARG_WITH([max-host-name-len],
475  [AS_HELP_STRING([--with-max-host-name-len],[max host name length [default=256]])],
476  [max_host_name_len=$withval],
477  [max_host_name_len=256]
478)
479AC_SUBST(max_host_name_len)
480
481#
482# EventProcessor thread configurations
483#
484
485AC_ARG_WITH([max-event-threads],
486  [AS_HELP_STRING([--with-max-event-threads],[max number of event threads [default=4096]])],
487  [max_event_threads=$withval],
488  [max_event_threads=4096]
489)
490AC_SUBST(max_event_threads)
491
492AC_ARG_WITH([max-threads-per-type],
493  [AS_HELP_STRING([--with-max-threads-per-type],[max number of threads per event type [default=3072]])],
494  [max_threads_per_type=$withval],
495  [max_threads_per_type=3072]
496)
497AC_SUBST(max_threads_per_type)
498
499#
500# Experimental plugins
501#
502
503AC_MSG_CHECKING([whether to enable experimental plugins])
504AC_ARG_ENABLE([experimental-plugins],
505  [AS_HELP_STRING([--enable-experimental-plugins],[build experimental plugins])],
506  [],
507  [enable_experimental_plugins=no]
508)
509AC_MSG_RESULT([$enable_experimental_plugins])
510AM_CONDITIONAL([BUILD_EXPERIMENTAL_PLUGINS], [ test "x${enable_experimental_plugins}" = "xyes" ])
511
512#
513# Enable experimental/memcached_remap plugin
514#
515PKG_CHECK_MODULES([LIBMEMCACHED], [libmemcached >= 1.0], [have_libmemcached=yes], [have_libmemcached=no])
516AM_CONDITIONAL([BUILD_MEMCACHED_REMAP_PLUGIN], [test "x${have_libmemcached}" = "xyes"])
517
518#
519# Check Magick++ is available. Enable experimental/webp_transform plugin
520#
521PKG_CHECK_MODULES([LIBMAGICKCPP],[Magick++ >= 7], [
522  TS_ADDTO(LIBMAGICKCPP_CFLAGS, [-DMAGICK_VERSION=7])
523  have_libmagickcpp=yes
524  AS_IF([test "x$enable_experimental_plugins" = "xyes"], [
525    enable_image_magick_plugins=yes
526  ])
527],
528[
529  PKG_CHECK_MODULES([LIBMAGICKCPP],[Magick++ < 7], [
530    TS_ADDTO(LIBMAGICKCPP_CFLAGS, [-DMAGICK_VERSION=6])
531    have_libmagickcpp=yes
532    AS_IF([test "x$enable_experimental_plugins" = "xyes"], [
533      enable_image_magick_plugins=yes
534    ])
535  ],
536  [
537    have_libmagickcpp=no
538  ])])
539
540AM_CONDITIONAL([BUILD_IMAGE_MAGICK_PLUGINS], [test "x${enable_image_magick_plugins}" = "xyes"])
541
542#
543# Example plugins. The example plugins are only built and installed if this is enabled. Installing
544# them is useful for QA, but not useful for most users, so we default this to disabled.
545#
546
547AC_MSG_CHECKING([whether to install example plugins])
548AC_ARG_ENABLE([example-plugins],
549  [AS_HELP_STRING([--enable-example-plugins],[build and install example plugins])],
550  [],
551  [enable_example_plugins=no]
552)
553AC_MSG_RESULT([$enable_example_plugins])
554AM_CONDITIONAL([BUILD_EXAMPLE_PLUGINS], [ test "x${enable_example_plugins}" = "xyes" ])
555
556
557#
558# Test tools. The test tools are always built, but not always installed. Installing
559# them is useful for QA, but not useful for most users, so we default this to disabled.
560#
561
562AC_MSG_CHECKING([whether to install testing tools])
563AC_ARG_ENABLE([test-tools],
564  [AS_HELP_STRING([--enable-test-tools],[install testing tools])],
565  [],
566  [enable_test_tools=no]
567)
568AC_MSG_RESULT([$enable_test_tools])
569AM_CONDITIONAL([BUILD_TEST_TOOLS], [ test "x${enable_test_tools}" = "xyes" ])
570
571#
572# Check if we should allow builds on 32-bit platforms
573#
574AC_MSG_CHECKING([whether to allow 32-bit builds])
575AC_ARG_ENABLE([32bit-build],
576  [AS_HELP_STRING([--enable-32bit-build],[allow 32bit builds])],
577  [],
578  [enable_32bit=no]
579)
580AC_MSG_RESULT([$enable_32bit])
581
582
583#
584# Installation directories
585# For each var the following is evaluated
586# foo      Standard variable  eg. ${prefix}/foo
587# rel_foo  Relative to prefix eg. foo
588#
589TS_SUBST_LAYOUT_PATH([prefix])
590TS_SUBST_LAYOUT_PATH([exec_prefix])
591TS_SUBST_LAYOUT_PATH([bindir])
592TS_SUBST_LAYOUT_PATH([sbindir])
593TS_SUBST_LAYOUT_PATH([libdir])
594TS_SUBST_LAYOUT_PATH([libexecdir])
595TS_SUBST_LAYOUT_PATH([infodir])
596TS_SUBST_LAYOUT_PATH([mandir])
597TS_SUBST_LAYOUT_PATH([sysconfdir])
598TS_SUBST_LAYOUT_PATH([datadir])
599TS_SUBST_LAYOUT_PATH([installbuilddir])
600TS_SUBST_LAYOUT_PATH([includedir])
601TS_SUBST_LAYOUT_PATH([localstatedir])
602TS_SUBST_LAYOUT_PATH([runtimedir])
603TS_SUBST_LAYOUT_PATH([logdir])
604TS_SUBST_LAYOUT_PATH([cachedir])
605TS_SUBST_LAYOUT_PATH([docdir])
606
607TS_SUBST([pkgbindir])
608TS_SUBST([pkgsbindir])
609TS_SUBST([pkglibdir])
610TS_SUBST([pkglibexecdir])
611TS_SUBST([pkgsysconfdir])
612TS_SUBST([pkgdatadir])
613TS_SUBST([pkglocalstatedir])
614TS_SUBST([pkgruntimedir])
615TS_SUBST([pkglogdir])
616TS_SUBST([pkgcachedir])
617TS_SUBST([pkgdocdir])
618
619
620# -----------------------------------------------------------------------------
621# 3. CHECK FOR PROGRAMS
622
623# Compiler selection:
624#
625# Implementation note (toc)
626# 1) Get default compiler settings (case statement.)
627# 2) Check for over-rides of default compiler.
628# 3) (in first kludge mode block...) obtain any further CFLAG-type additions.
629# 4) Test compilers with all flags set.
630
631# AC_PROG can sometimes mangle CFLAGS etc.
632# in particular, on Linux they insert -g -O2, here we preserve any user CFLAGS
633_ts_saved_CFLAGS="${CFLAGS}"
634_ts_saved_CXXFLAGS="${CXXFLAGS}"
635
636# We force the compiler search list because the default GCC on Darwin cannot build
637# Traffic Server. On most (all?) platforms, cc and c++ should be the preferred default
638# compiler.
639AC_PROG_CC([cc gcc clang icc])
640AC_PROG_CXX([c++ g++ clang++ icpc])
641
642AM_PROG_CC_C_O
643AC_PROG_CPP
644AC_PROG_CXXCPP
645AM_PROG_AS
646
647AX_COMPILER_VENDOR
648
649CFLAGS="${_ts_saved_CFLAGS}"
650CXXFLAGS="${_ts_saved_CXXFLAGS}"
651
652# All compilers we support have 'gnu99' as an available C standard
653TS_ADDTO(AM_CFLAGS, [-std=gnu99])
654
655ac_save_CXX="$CXX"
656CXX="$CXX -std=c++17"
657AC_LANG_PUSH(C++)
658AC_MSG_CHECKING([checking whether $CXX supports -std=c++17])
659AC_COMPILE_IFELSE([
660    AC_LANG_PROGRAM([
661#if __cplusplus < 201703L
662#error "This is not C++17"
663#endif
664    ], []
665    )], [
666    AC_MSG_RESULT(yes)
667    ], [
668    AC_MSG_RESULT(no)
669    AC_MSG_ERROR([*** A compiler with support for -std=c++17 is required.])
670])
671AC_LANG_POP
672CXX="$ac_save_CXX"
673
674TS_ADDTO(AM_CXXFLAGS, [-std=c++17])
675
676dnl AC_PROG_SED is only available from version 2.6 (released in 2003). CentosOS
677dnl 5.9 still has an ancient version, but we have macros that require
678dnl AC_PROG_SED. The actual AC_PROG_SED macro does functional checks, but here
679dnl we define a trivial local version for times when we are running on
680dnl obsoldete autoconf.
681ifdef([AC_PROG_SED], [], [
682  AC_DEFUN([AC_PROG_SED], [
683    AC_CHECK_PROG(SED, sed, sed)
684  ])
685])
686
687
688# Various OS specific setup. Note that on Solaris, 32-bit is always the
689# default, even on a box that with 64-bit architecture.
690# This also sets up a "normalized" variable and define $host_os_def.
691case $host_os in
692  linux*)
693    host_os_def="linux"
694    AM_LDFLAGS="-rdynamic"
695    ;;
696  darwin*)
697    host_os_def="darwin"
698    ;;
699  freebsd*)
700    host_os_def="freebsd"
701    AM_LDFLAGS="-rdynamic"
702    TS_ADDTO(TS_INCLUDES, [-I/usr/local/include])
703    TS_ADDTO(AM_CPPFLAGS, [-D_GLIBCXX_USE_C99])
704    TS_ADDTO(AM_CPPFLAGS, [-D_GLIBCXX_USE_C99_MATH])
705    TS_ADDTO(AM_CPPFLAGS, [-D_GLIBCXX_USE_C99_MATH_TR1])
706    ;;
707  kfreebsd*)
708    host_os_def="freebsd"
709    AM_LDFLAGS="-rdynamic"
710    TS_ADDTO(TS_INCLUDES, [-I/usr/local/include])
711    TS_ADDTO(AM_CPPFLAGS, [-Dkfreebsd])
712    ;;
713  openbsd*)
714    host_os_def="openbsd"
715    ;;
716  solaris*)
717    host_os_def="solaris"
718    case "`isalist`" in
719      *amd64*)
720        TS_ADDTO(AM_CFLAGS, [-m64])
721        TS_ADDTO(AM_CXXFLAGS, [-m64])
722        TS_ADDTO(LUAJIT_LDFLAGS, [-m64])
723        ;;
724    esac
725    ;;
726  *)
727    AM_LDFLAGS="-rdynamic"
728    host_os_def=unknown
729    ;;
730esac
731
732TS_ADDTO(AM_CPPFLAGS, [-D$host_os_def])
733
734dnl AM_PROG_AR is not always available, but it doesn't seem to be needed in older versions.
735ifdef([AM_PROG_AR],
736      [AM_PROG_AR])
737
738AC_PROG_AWK
739AC_PROG_SED
740AC_PROG_LN_S
741AC_PROG_INSTALL
742AC_PROG_LIBTOOL
743AC_CHECK_PROG(RM, rm, rm)
744AC_CHECK_PROG(ASCPP, cpp, cpp)
745AC_CHECK_TOOL(AR, ar, ar)
746AC_ISC_POSIX
747
748AC_ARG_VAR(RPATH, [path to be added to rpath])
749
750AC_ARG_VAR([CLANG_TIDY], [clang-tidy command])
751
752# Default CLANG_TIDY to "clang-tidy", or "false" if it is not present.
753AC_PATH_PROG([CLANG_TIDY], [clang-tidy],[false])
754
755# Do bison check by hand because we must do a version check.
756# Use YACC because it makes autotools shut up.
757BISON_MAJOR=2
758BISON_MINOR=4
759BISON_POINT=1
760AC_CHECK_PROG([YACC],[bison],[bison])
761AS_IF([test -n "$YACC"],
762      [ bison_version_check=`$YACC --version 2>&1 | \
763        $SED -n '/bison/s/^[[^0-9]]*\([[0-9]][[0-9.]]*\).*$/\1/p' | \
764        $AWK "{ if (\\$1 > $BISON_MAJOR || (\\$1 == $BISON_MAJOR && (\\$2 > $BISON_MINOR || (\\$2 == $BISON_MINOR && (NR == 2 || \\$3 >= $BISON_POINT))))) print \"yes\"; else printf(\"version %d.%d.%d\",\\$1,\\$2,\\$3); }" FS=. \
765        `
766        AS_IF([test "x$bison_version_check" != "xyes"],
767          [ YACC=''
768            AS_IF([test -z "$bison_version_check"],
769              [bison_version_check='no version data']
770            )
771          ]
772        )
773      ],
774      [ YACC=''
775        bison_version_check="nothing"
776      ]
777)
778# Check lex/flex by hand because we need flex of a sufficient version.
779FLEX_MAJOR=2
780FLEX_MINOR=5
781FLEX_POINT=33
782dnl ylwrap requires the lexer executable to be an absolute path or in the srcdir.
783dnl but we need various other LEX values.
784AC_PROG_LEX
785AS_IF([test -n "$LEX"],
786      [ flex_version_check=`$LEX --version 2>&1 | \
787        $SED -n '/flex/s/^[[^0-9]]*\([[0-9]][[0-9.]]*\)[[^0-9]]*.*$/\1/p' | \
788        $AWK "{ if (\\$1 > $FLEX_MAJOR || (\\$1 == $FLEX_MAJOR && (\\$2 > $FLEX_MINOR || (\\$2 == $FLEX_MINOR && (NR == 2 || \\$3 >= $FLEX_POINT))))) print \"yes\"; else printf(\"version %d.%d.%d\",\\$1,\\$2,\\$3); }" FS=. \
789        `
790        AS_IF([test "x$flex_version_check" != "xyes"],
791          [ LEX=''
792            AS_IF([test -z "$flex_version_check"],
793              [flex_version_check='no version data']
794            )
795          ]
796        )
797      ],
798      [ LEX=''
799        flex_version_check="nothing"
800      ]
801)
802
803# Generated files checked in, only build them if the local OS has the necessary support.
804# Otherwise just use the checked in version.
805AM_CONDITIONAL([BUILD_TSCONFIG_GRAMMAR], [ test -n "$LEX" && test -n "$YACC" ])
806
807# Check for Perl and Doxygen
808AC_PATH_PROG([DOXYGEN], [doxygen]) # needed for Doxygen
809AC_PATH_PROG([PERL], [perl],[not found])
810AS_IF([test "x$PERL" = "xnot found"],
811  [AC_MSG_ERROR([check for perl failed. Have you installed perl?])]
812)
813AC_ARG_VAR([DOXYGEN], [full path of Doxygen executable])
814AC_ARG_VAR([PERL], [full path of Perl executable])
815
816# Check if MakeMaker is available
817AX_PROG_PERL_MODULES([ExtUtils::MakeMaker], AM_CONDITIONAL([BUILD_PERL_LIB], [true]),
818                                            AM_CONDITIONAL([BUILD_PERL_LIB], [false])
819)
820
821# Check for GNU-style -On optimization flags
822AC_MSG_CHECKING([checking whether to auto-set compiler optimization flags])
823has_optimizer_flags=`echo "$CFLAGS $CXXFLAGS" | ${AWK} '$0 !~ /-O.?/{print "no"}'`
824AS_IF([test "x${has_optimizer_flags}" = "xno"],
825        [
826                optimizing_flags='-O3'
827                AC_MSG_RESULT([yes ${optimizing_flags}])
828        ],
829        [
830                has_optimizer_flags='yes'
831                optimizing_flags=''
832                AC_MSG_RESULT([no])
833        ]
834)
835
836case $host_os_def in
837  linux)
838    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xintel"], [
839      # -Wall is overzealous for us, so need to turn this off for now:
840      #
841      #  #873 is "has no corresponding operator delete"
842      #  #279 is "controlling expression is constant" (which is e.g. TSReleaseAssert(!"Unexpected Event");
843      common_opt="-pipe -Wall -wd873 -wd279"
844      debug_opt="-g $common_opt"
845      release_opt="-g $common_opt $optimization_flags -axsse4.2 -fno-strict-aliasing"
846      cxx_opt="-Wno-invalid-offsetof"
847    ])
848
849    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xclang"], [
850      common_opt="-pipe -Wall -Wno-deprecated-declarations -Qunused-arguments -Wextra -Wno-ignored-qualifiers -Wno-unused-parameter"
851      debug_opt="-ggdb3 $common_opt -Qunused-arguments"
852      release_opt="-g $common_opt $optimizing_flags -fno-strict-aliasing -Qunused-arguments"
853      cxx_opt="-Wno-invalid-offsetof"
854    ])
855
856    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xgnu"], [
857      # This is useful for finding odd conversions
858      #    common_opt="-pipe -Wall -Wconversion -Wno-sign-conversion -Wno-format-truncation"
859      common_opt="-pipe -Wall -Wextra -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-format-truncation -Wno-cast-function-type -Wno-stringop-overflow"
860      debug_opt="-ggdb3 $common_opt"
861      release_opt="-g $common_opt $optimizing_flags -feliminate-unused-debug-symbols -fno-strict-aliasing"
862      cxx_opt="-Wno-invalid-offsetof -Wno-noexcept-type"
863      # Special options for flex generated .c files
864      flex_cflags="-Wno-unused-parameter"
865    ])
866
867    TS_ADDTO([AM_LDFLAGS], [-Wl,--as-needed])
868
869    ;; # linux)
870
871  darwin)
872    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xclang"], [
873      common_opt="-pipe -Wall -Wno-deprecated-declarations -Qunused-arguments -Wextra -Wno-ignored-qualifiers -Wno-unused-parameter"
874      debug_opt="-g $common_opt"
875      release_opt="-g $common_opt $optimizing_flags -fno-strict-aliasing"
876      cxx_opt="-Wno-invalid-offsetof"
877    ], [
878      AC_MSG_WARN([clang is the only supported compiler on Darwin])
879    ])
880
881    # NOTE: This seems semi-kludgy, but useful for MacPorts I think.
882    AS_IF([test -d /opt/local/include], [
883      TS_ADDTO(TS_INCLUDES, [-I/opt/local/include])
884    ])
885    AS_IF([test -d /opt/local/lib], [
886      TS_ADDTO(AM_LDFLAGS, [-L/opt/local/lib])
887    ])
888
889    ;; # darwin)
890
891  freebsd|kfreebsd)
892    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xclang"], [
893      common_opt="-pipe -Wall -Wno-deprecated-declarations -Qunused-arguments -Wextra -Wno-ignored-qualifiers -Wno-unused-parameter"
894      debug_opt="-ggdb3 $common_opt"
895      release_opt="-g $common_opt $optimizing_flags -fno-strict-aliasing"
896      cxx_opt="-Wno-invalid-offsetof"
897    ])
898
899    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xgnu"], [
900      common_opt="-pipe -Wall -Wextra -Wno-ignored-qualifiers -Wno-unused-parameter"
901      debug_opt="-ggdb3 $common_opt"
902      release_opt="-g $common_opt $optimizing_flags -feliminate-unused-debug-symbols -fno-strict-aliasing"
903      cxx_opt="-Wno-invalid-offsetof"
904    ])
905
906    AS_IF([test -d /usr/local/lib], [
907      TS_ADDTO(AM_LDFLAGS, [-L/usr/local/lib])
908    ])
909
910    ;; # freebsd|kfreebsd)
911
912  solaris)
913    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xgnu"], [
914      common_opt="-pipe -Wall -Wextra -Wno-ignored-qualifiers -Wno-unused-parameter"
915      debug_opt="-ggdb3 $common_opt"
916      release_opt="-g $common_opt $optimizing_flags -feliminate-unused-debug-symbols -fno-strict-aliasing"
917      cxx_opt="-Wno-invalid-offsetof"
918    ])
919
920    ;; # solaris)
921
922  *)
923    # Not sure what platform this is, but take a stab at some general GCC options ...
924    AS_IF([test "x$ax_cv_c_compiler_vendor" = "xgnu"], [
925      common_opt="-pipe -Wall -Wextra -Wno-ignored-qualifiers -Wno-unused-parameter"
926      debug_opt="-ggdb3 $common_opt"
927      release_opt="-g $common_opt $optimizing_flags -feliminate-unused-debug-symbols -fno-strict-aliasing"
928      cxx_opt="-Wno-invalid-offsetof"
929    ])
930esac
931
932AS_IF([test x"$enable_coverage" = "xyes"], [
933  # Map per-compiler code coverage instrumentation flags.  Note that
934  # we don't test whether the compiler actually support these options
935  # (we don't do that in general). The user is expected to use a modern,
936  # supported compiler to test coverage.
937  AS_CASE("$ax_cv_c_compiler_vendor",
938    [clang], [
939      TS_ADDTO(AM_CXXFLAGS, "-fprofile-instr-generate")
940      TS_ADDTO(AM_CXXFLAGS, "-fcoverage-mapping")
941      TS_ADDTO(AM_CFLAGS, "-fprofile-instr-generate")
942      TS_ADDTO(AM_CFLAGS, "-fcoverage-mapping")
943    ], [gnu], [
944      TS_ADDTO(AM_CXXFLAGS, "--coverage")
945      TS_ADDTO(AM_CFLAGS, "--coverage")
946      TS_ADDTO(LIBS, "-lgcov")
947  ])
948])
949
950# Only add -Werror if the user has requested it. We enable this by default for
951# development, disable it by default for release.
952AS_IF([test x"$enable_werror" = "xyes"], [
953  TS_ADDTO(release_opt, -Werror)
954  TS_ADDTO(debug_opt, -Werror)
955])
956
957cc_oflag_opt=$release_opt
958cc_oflag_dbg=$debug_opt
959cxx_oflag_opt="$release_opt $cxx_opt $cxx_rel"
960cxx_oflag_dbg="$debug_opt $cxx_opt $cxx_dbg"
961
962# Special compiler flag hacks for various pieces of the code
963AC_SUBST([FLEX_CFLAGS], $flex_cflags)
964
965#
966# _Here_ is where we go ahead and add the _optimizations_ to already
967#  existing CFLAGS/CXXFLAGS if some special values had been set.
968#
969if test "x${enable_debug}" = "xyes"; then
970  TS_ADDTO(AM_CFLAGS, [${cc_oflag_dbg}])
971  TS_ADDTO(AM_CXXFLAGS, [${cxx_oflag_dbg}])
972  TS_ADDTO(AM_CPPFLAGS, [-DDEBUG -D_DEBUG])
973  if test "x${enable_mime_sanity_check}" = "xyes"; then
974    TS_ADDTO(AM_CPPFLAGS, [-DENABLE_MIME_SANITY_CHECK])
975  fi
976else
977  TS_ADDTO(AM_CFLAGS, [${cc_oflag_opt}])
978  TS_ADDTO(AM_CXXFLAGS, [${cxx_oflag_opt}])
979fi
980
981# Flags for ASAN
982if test "x${enable_asan}" = "xyes"; then
983  if test "x${enable_tsan}" = "xyes"; then
984    AC_ERROR([Cannot have ASAN and TSAN options at the same time, pick one])
985  fi
986  TS_ADDTO(AM_CFLAGS, [-fno-omit-frame-pointer -fsanitize=address])
987  TS_ADDTO(AM_CXXFLAGS, [-fno-omit-frame-pointer -fsanitize=address])
988fi
989
990# Flags for LSAN stand-alone mode
991if test "x${enable_lsan}" = "xyes"; then
992  if test "x${enable_asan}" = "xyes"; then
993    AC_ERROR([ASAN already specified, --enable-lsan is meant only for lsan stand-alone mode])
994  fi
995  TS_ADDTO(AM_CFLAGS, [-fno-omit-frame-pointer -fsanitize=leak])
996  TS_ADDTO(AM_CXXFLAGS, [-fno-omit-frame-pointer -fsanitize=leak])
997fi
998
999# Flags for TSAN
1000if test "x${enable_tsan}" = "xyes"; then
1001  TS_ADDTO(AM_CFLAGS, [-fsanitize=thread])
1002  TS_ADDTO(AM_CXXFLAGS, [-fsanitize=thread])
1003fi
1004
1005# Checks for pointer size.
1006# TODO: Later this is irrelevant, and we should just bail on 32-bit platforms always
1007AC_CHECK_SIZEOF([void*])
1008if test "x$ac_cv_sizeof_voidp" == "x"; then
1009  AC_ERROR([Cannot determine size of void*])
1010fi
1011
1012# Right now, 32-bit platform is a build error, unless we've forced it with --enable-32bit-build
1013if test "${ac_cv_sizeof_voidp}" = "4"; then
1014   AS_IF([test x"$enable_32bit_build" = "xyes"], [
1015     AC_MSG_NOTICE([Explicitly building on a 32-bit platform, this might be unsupported soon!])
1016   ], [
1017     AC_ERROR([You are trying to build on a 32-bit platform, which is unsupported.])
1018   ])
1019fi
1020
1021
1022#
1023# Here are all the extra linux-specific C(XX)FLAGS additions and
1024# so forth.
1025# TODO cpu architecture settings separate from operating system settings
1026#
1027cpu_architecture=""
1028# GCC: add a default march if there is not one set
1029if test "x${GCC}" = "xyes"; then
1030  if test "${ac_cv_sizeof_voidp}" = "4"; then
1031    case "$host_cpu" in
1032      i?86* | k[5-8]* | pentium* | athlon)
1033        cpu_architecture="-march=i586"
1034      ;;
1035    esac
1036  else
1037    case "$host_cpu" in
1038      x86_64 | amd64)
1039        # XXX: Any need for 64-bit arch flags?
1040        # cpu_architecture="-march=native"
1041      ;;
1042    esac
1043  fi
1044fi
1045
1046# Overrride detected architecture with the user suplied one
1047#
1048AC_ARG_WITH(architecture, [AC_HELP_STRING([--with-architecture=ARCH],[use a specific CPU architecture])],
1049[
1050  if test "x$withval" != "xyes" && test "x$withval" != "xno"; then
1051    case "$withval" in
1052      -*)
1053        # TODO: In case we are cross compiling some of the provided flags
1054        #       should be added to the LDFLAGS
1055        cpu_architecture="$withval"
1056      ;;
1057      *)
1058        cpu_architecture="-march=$withval"
1059      ;;
1060    esac
1061  elif test "x$withval" = "x"; then
1062    AC_MSG_ERROR([--with-architecture requires an param])
1063  fi
1064])
1065
1066if test "x$cpu_architecture" != "x"; then
1067  TS_ADDTO(AM_CFLAGS, [$cpu_architecture])
1068  TS_ADDTO(AM_CXXFLAGS, [$cpu_architecture])
1069fi
1070
1071# 64-bit LFS support
1072#
1073TS_ADDTO(AM_CPPFLAGS, [-D_LARGEFILE64_SOURCE=1])
1074if test "${ac_cv_sizeof_voidp}" = "8"; then
1075  TS_ADDTO(AM_CPPFLAGS, [-D_COMPILE64BIT_SOURCE=1])
1076else
1077  TS_ADDTO(AM_CPPFLAGS, [-D_FILE_OFFSET_BITS=64])
1078fi
1079TS_ADDTO(CPPFLAGS, [-D_GNU_SOURCE])
1080TS_ADDTO(AM_CPPFLAGS, [-D_REENTRANT])
1081TS_ADDTO(AM_CPPFLAGS, [-D__STDC_LIMIT_MACROS=1])
1082TS_ADDTO(AM_CPPFLAGS, [-D__STDC_FORMAT_MACROS=1])
1083
1084AC_MSG_NOTICE([Build for host OS: $host_os, arch: $host_cpu, optimization: $host_os_def])
1085
1086# Add hardening options to flags
1087AS_IF([test "x${enable_hardening}" = "xyes"], [
1088  TS_ADDTO(AM_CPPFLAGS, [-D_FORTIFY_SOURCE=2])
1089  TS_ADDTO(AM_CXXFLAGS, [-fPIE -fstack-protector])
1090  TS_ADDTO(AM_CFLAGS, [-fPIE -fstack-protector])
1091  AS_CASE("$host_os_def",
1092    [linux], [TS_ADDTO(AM_LDFLAGS, [-pie -Wl,-z,relro -Wl,-z,now])]
1093  )
1094])
1095
1096#
1097# Note:  These are site-specific macro's that do various tests
1098#         on the selected compilers.  There was some tunning
1099#         associated with our not wanting to use GNU for _everything_.
1100# Note:  This macro may set certain parameters when run.
1101#
1102
1103# Check for ccache (if explicitly enabled)
1104if test "x$enable_ccache" = "xyes"; then
1105    AC_CHECK_PROG([CCACHE],[ccache],[ccache],[])
1106    if test "x${CCACHE}" = "xccache"; then
1107        CC="$CCACHE $CC"
1108        CXX="$CCACHE $CXX"
1109    fi
1110fi
1111
1112# -----------------------------------------------------------------------------
1113# 4. CHECK FOR LIBRARIES
1114
1115AC_SEARCH_LIBS([socket], [socket], [], [])
1116AC_SEARCH_LIBS([gethostbyname], [nsl], [], [])
1117AC_SEARCH_LIBS([clock_gettime], [rt posix4], [], [])
1118
1119dnl We check for dlsym here instead of e.g. dlopen() because ASAN hijacks the latter.
1120AC_SEARCH_LIBS([dlsym], [dl], [], [])
1121
1122dnl Linux has pthread symbol stubss in both libc and libpthread, so it's important to test
1123dnl specifically for pthread_yield() here. In addition, ASAN hijacks pthread_create() so
1124dnl we can't use that anymore.
1125AC_SEARCH_LIBS([pthread_yield], [pthread], [], [])
1126AC_CHECK_FUNCS([pthread_mutexattr_settype])
1127
1128dnl XXX The following check incorrectly causes the build to succeed
1129dnl on Darwin. We should be using AC_SEARCH_LIBS, but rest_init is
1130dnl actually present in libsystem. We are searching for the library
1131dnl that contains the full Bind 9 API (which is acutally libresolv).
1132dnl However, the resolv API uses macros to rename it's APIs to per-version
1133dnl symbols, so standard autoconf macros cannot reasonably be used to
1134dnl check for it. We need to write custom macros to detect it properly.
1135AC_CHECK_LIB([resolv],[res_init],[AC_SUBST([LIBRESOLV],["-lresolv"])])
1136AC_CHECK_LIB([resolv],[__putlong],[AC_SUBST([LIBRESOLV],["-lresolv"])])
1137
1138# Test for ncurses. We need to turn off -Werror because the C code in the
1139# ncurses compile tests does not generate unused variable warnings.
1140__saved_CFLAGS="$CFLAGS"
1141TS_REMOVEFROM(CFLAGS, -Werror)
1142
1143dnl Red Hat 6 requires special flags for curses to work.
1144if test -r /etc/system-release ; then
1145  case `cat /etc/system-release` in
1146    Red\ Hat*release\ 6.*)
1147      TS_ADDTO(CFLAGS, [-Wl,--add-needed])
1148      curses_ldflags="-Wl,--add-needed"
1149    ;;
1150  esac
1151fi
1152
1153AX_WITH_CURSES
1154CFLAGS="$__saved_CFLAGS"
1155AC_SUBST([CURSES_LDFLAGS],[$curses_ldflags])
1156
1157#
1158# Check for -latomic need (at least for mips arch)
1159TS_CHECK_ATOMIC
1160TS_ADDTO([LDFLAGS], [$ATOMIC_LIBS])
1161
1162#
1163# Check for SSL presence and usability
1164#
1165TS_CHECK_CRYPTO
1166
1167# Check for OpenSSL Version
1168TS_CHECK_CRYPTO_VERSION
1169
1170# Check for openssl ASYNC jobs
1171TS_CHECK_CRYPTO_ASYNC
1172
1173# Check for the client hello callback
1174TS_CHECK_CRYPTO_HELLO_CB
1175
1176# Check for SSL_set0_rbio call
1177TS_CHECK_CRYPTO_SET_RBIO
1178
1179# Check for DH_get_2048_256
1180TS_CHECK_CRYPTO_DH_GET_2048_256
1181
1182# Check for OCSP
1183TS_CHECK_CRYPTO_OCSP
1184
1185# Check for SSL_CTX_set_ciphersuites call
1186TS_CHECK_CRYPTO_SET_CIPHERSUITES
1187
1188saved_LIBS="$LIBS"
1189TS_ADDTO([LIBS], ["$OPENSSL_LIBS"])
1190
1191AC_CHECK_FUNCS([ \
1192  BIO_meth_new \
1193  BIO_sock_non_fatal_error \
1194  CRYPTO_set_mem_functions \
1195  HMAC_CTX_new \
1196  X509_get0_signature \
1197])
1198
1199AC_CHECK_FUNC([ASN1_STRING_get0_data], [],
1200              [AC_DEFINE([ASN1_STRING_get0_data], [ASN1_STRING_data], [Added in OpenSSL 1.1])])
1201
1202AC_CHECK_FUNC([BIO_set_data], [],
1203              [AC_DEFINE([BIO_set_data(a, _ptr)], [((a)->ptr = (_ptr))], [Added in OpenSSL 1.1])])
1204AC_CHECK_FUNC([BIO_get_data], [],
1205              [AC_DEFINE([BIO_get_data(a)], [((a)->ptr)], [Added in OpenSSL 1.1])])
1206AC_CHECK_FUNC([BIO_get_shutdown], [],
1207              [AC_DEFINE([BIO_get_shutdown(a)], [((a)->shutdown)], [Added in OpenSSL 1.1])])
1208AC_CHECK_FUNC([BIO_meth_get_ctrl], [],
1209              [AC_DEFINE([BIO_meth_get_ctrl(biom)], [((biom)->ctrl)], [Added in OpenSSL 1.1])])
1210AC_CHECK_FUNC([BIO_meth_get_create], [],
1211              [AC_DEFINE([BIO_meth_get_create(biom)], [((biom)->create)], [Added in OpenSSL 1.1])])
1212AC_CHECK_FUNC([BIO_meth_get_destroy], [],
1213              [AC_DEFINE([BIO_meth_get_destroy(biom)], [((biom)->destroy)], [Added in OpenSSL 1.1])])
1214
1215AC_CHECK_FUNC([EVP_MD_CTX_new], [],
1216              [AC_DEFINE([EVP_MD_CTX_new], [EVP_MD_CTX_create], [Renamed in OpenSSL 1.1])])
1217AC_CHECK_FUNC([EVP_MD_CTX_reset], [],
1218              [AC_DEFINE([EVP_MD_CTX_reset], [EVP_MD_CTX_cleanup], [Renamed in OpenSSL 1.1])])
1219AC_CHECK_FUNC([EVP_MD_CTX_free], [],
1220              [AC_DEFINE([EVP_MD_CTX_free], [EVP_MD_CTX_destroy], [Renamed in OpenSSL 1.1])])
1221
1222LIBS="$saved_LIBS"
1223
1224#
1225# Check OpenSSL version for JA3 Fingerprint
1226#
1227AC_MSG_CHECKING([for JA3 compatible OpenSSL version])
1228AC_EGREP_CPP(yes, [
1229  #include <openssl/opensslv.h>
1230  #if (OPENSSL_VERSION_NUMBER < 0x010100000L)
1231  yes
1232  #elif (OPENSSL_VERSION_NUMBER >= 0x010101000L)
1233  yes
1234  #endif
1235  ], [
1236    AC_MSG_RESULT(yes)
1237    AS_IF([test "x${enable_experimental_plugins}" = "xyes"], [
1238      enable_ja3_plugin=yes
1239    ])
1240  ], [AC_MSG_RESULT(no)])
1241
1242AM_CONDITIONAL([BUILD_JA3_PLUGIN], [test "x${enable_ja3_plugin}" = "xyes"])
1243
1244#
1245# Check for zlib presence and usability
1246TS_CHECK_ZLIB
1247
1248#
1249# Check for lzma presence and usability
1250TS_CHECK_LZMA
1251
1252AC_CHECK_FUNCS([clock_gettime kqueue epoll_ctl posix_fadvise posix_madvise posix_fallocate inotify_init])
1253AC_CHECK_FUNCS([port_create strlcpy strlcat sysconf sysctlbyname getpagesize])
1254AC_CHECK_FUNCS([getreuid getresuid getresgid setreuid setresuid getpeereid getpeerucred])
1255AC_CHECK_FUNCS([strsignal psignal psiginfo accept4])
1256
1257# Check for eventfd() and sys/eventfd.h (both must exist ...)
1258AC_CHECK_HEADERS([sys/eventfd.h], [
1259  AS_IF([test "x$enable_eventfd" = "xyes"], [
1260    AC_CHECK_FUNCS([eventfd])
1261  ]
1262)])
1263
1264AC_CHECK_FUNCS(eventfd)
1265
1266#
1267# Check for mcheck_pedantic(3)
1268#
1269AC_CHECK_HEADERS(mcheck.h)
1270AC_CHECK_FUNCS(mcheck_pedantic)
1271
1272#
1273# Check for malloc_usable_size()
1274#
1275AC_CHECK_FUNCS(malloc_usable_size)
1276
1277#
1278# Check for pcre library
1279#
1280TS_CHECK_PCRE
1281if test "x${enable_pcre}" != "xyes"; then
1282  AC_MSG_ERROR([Cannot find pcre library. Configure --with-pcre=DIR])
1283fi
1284
1285# Check for optional brotli library
1286TS_CHECK_BROTLI
1287
1288# Check for optional luajit library
1289TS_CHECK_LUAJIT
1290
1291#
1292# Enable experimental/uri_singing plugin
1293# This is here, instead of above, because it needs to know if PCRE is available.
1294#
1295
1296#### Check for optional jansson library (uri_signing)
1297TS_CHECK_JANSSON
1298
1299AC_CHECK_LIB([crypto],[HMAC],[has_libcrypto=1],[has_libcrypto=0])
1300
1301#### Check for optional cjose library (uri_signing)
1302TS_CHECK_CJOSE
1303
1304AM_CONDITIONAL([BUILD_URI_SIGNING_PLUGIN], [test ! -z "${LIBCJOSE}" -a ! -z "${LIBJANSSON}" -a "x${enable_pcre}" = "xyes" -a "x${has_libcrypto}" = "x1"])
1305AC_SUBST([LIBCJOSE])
1306AC_SUBST([LIBJANSSON])
1307
1308# Check for yaml-cpp library
1309#
1310TS_CHECK_YAML_CPP
1311AM_CONDITIONAL([BUILD_YAML_CPP], [test x"$has_yaml_cpp" = x"no"])
1312
1313# Check for optional hiredis library
1314TS_CHECK_HIREDIS
1315
1316AM_CONDITIONAL([BUILD_SSL_SESSION_REUSE_PLUGIN], [test ! -z "${LIB_HIREDIS}" -a "x${has_hiredis}" = "x1" ])
1317
1318# Check for backtrace() support
1319has_backtrace=0
1320AC_CHECK_HEADERS([execinfo.h], [has_backtrace=1],[])
1321if test "${has_backtrace}" = "1"; then
1322  # FreeBSD requires '/usr/ports/devel/libexecinfo' for gdb style backtrace() support
1323  AC_SEARCH_LIBS([backtrace], [execinfo], [have_backtrace_lib=yes])
1324else
1325  AC_MSG_WARN([No backtrace() support found])
1326fi
1327AC_SUBST(has_backtrace)
1328
1329#
1330# use unwind library when possible (can be disabled)
1331#
1332AC_MSG_CHECKING([whether to use unwind library])
1333AC_ARG_ENABLE([unwind],
1334  AS_HELP_STRING([--disable-unwind],[Don't use the unwind library]), [
1335  ], [
1336    enable_unwind="yes"
1337    enable_unwind_default="yes"
1338])
1339AC_MSG_RESULT([$enable_unwind])
1340
1341AS_IF([test "x$enable_unwind" = "xyes"], [
1342  # Remote process unwinding is only implemented on Linux because it depends on various Linux-specific
1343  # features such as /proc filesystem nodes, ptrace(2) and waitpid(2) extensions.
1344  AS_IF([test "$host_os_def" = "linux"], [
1345    PKG_CHECK_MODULES([LIBUNWIND], [libunwind-ptrace], [
1346      enable_remote_unwinding=yes
1347    ], [
1348      AS_IF([test "x$enable_unwind_default" = "xyes"], [
1349        AC_MSG_WARN([unwind not found, try disabling it --disable-unwind])
1350      ], [
1351        AC_MSG_ERROR([unwind not found, try disabling it --disable-unwind])
1352      ])
1353    ])], [
1354    AS_IF([test "x$enable_unwind_default" = "xyes"], [
1355      AC_MSG_WARN([unwind only available on linux, try disabling it --disable-unwind])
1356    ], [
1357      AC_MSG_ERROR([unwind only available on linux, try disabling it --disable-unwind])
1358    ])
1359  ])
1360])
1361TS_ARG_ENABLE_VAR([use], [remote_unwinding])
1362
1363# Find the appropriate event handling interface. This can be forced on
1364# platforms that support 2 or more of our supported interfaces. It
1365# could also (in the future?) be used to enable other event systems
1366# such as libev.
1367AC_ARG_WITH([event-interface],
1368  [AS_HELP_STRING([--with-event-interface=epoll|kqueue|port],[event interface to use [default=auto]])],
1369  [event_interface=$withval],
1370  [event_interface="auto"]
1371)
1372
1373use_epoll=0
1374use_kqueue=0
1375use_port=0
1376
1377AS_IF([test "x$event_interface" = "xauto"], [
1378  if test "$ac_cv_func_port_create" = "yes"; then
1379    use_port=1
1380    have_good_poller=1
1381    AC_MSG_NOTICE([Using port event interface])
1382  elif test "$ac_cv_func_epoll_ctl" = "yes"; then
1383    use_epoll=1
1384    have_good_poller=1
1385    AC_MSG_NOTICE([Using epoll event interface])
1386  elif test "$ac_cv_func_kqueue" = "yes"; then
1387    use_kqueue=1
1388    have_good_poller=1
1389    AC_MSG_NOTICE([Using kqueue event interface])
1390  else
1391    AC_MSG_FAILURE([No suitable polling interface found])
1392  fi
1393],[
1394  case "x$event_interface" in
1395    xepoll)
1396      use_epoll=1
1397      AC_MSG_RESULT([forced to epoll])
1398      ;;
1399    xport)
1400      use_port=1
1401      AC_MSG_RESULT([forced to port])
1402      ;;
1403    xkqueue)
1404      use_kqueue=1
1405      AC_MSG_RESULT([forced to port])
1406      ;;
1407    *)
1408      AC_MSG_RESULT([failed])
1409      AC_MSG_FAILURE([unknown event system])
1410  esac
1411])
1412
1413AC_SUBST(use_epoll)
1414AC_SUBST(use_kqueue)
1415AC_SUBST(use_port)
1416
1417
1418# Profiler support
1419has_profiler=0
1420if test "x${with_profiler}" = "xyes"; then
1421  AC_CHECK_LIB([profiler], [ProfilerStart],
1422    [AC_SUBST([LIBPROFILER], ["-lprofiler"])
1423     has_profiler=1
1424    ],
1425    [AC_MSG_FAILURE([check for profiler failed. Have you installed google-perftools-devel?])],
1426  )
1427fi
1428AC_SUBST(has_profiler)
1429
1430AC_MSG_CHECKING(for 128bit CAS support)
1431AC_LANG_PUSH([C++])
1432
1433# We need to save and restore compiler flags around this whole block.
1434# TS_TRY_COMPILE_NO_WARNING will save and restore flags, so if we do that in the
1435# middle, then we can accidentally restore modified flags.
1436__saved_CXXFLAGS="${CXXFLAGS}"
1437__saved_CFLAGS="${CFLAGS}"
1438
1439has_128bit_cas=0
1440
1441TS_TRY_COMPILE_NO_WARNING([],[
1442    __int128_t x = 0;
1443    __sync_bool_compare_and_swap(&x,0,10);
1444  ], [
1445    AC_MSG_RESULT(yes)
1446    has_128bit_cas=1
1447  ], [
1448    dnl If 128bit CAS fails, try again with the -mcx16 option. GCC needs this;
1449    dnl clang doesn't; icc does not support -mcx16 (but gives a non-fatal warning).
1450    TS_ADDTO(CXXFLAGS, [-mcx16])
1451    TS_ADDTO(CFLAGS, [-mcx16])
1452    TS_TRY_COMPILE_NO_WARNING([],[
1453        __int128_t x = 0;
1454        __sync_bool_compare_and_swap(&x,0,10);
1455      ], [
1456        AC_MSG_RESULT(yes)
1457        has_128bit_cas=1
1458      ], [
1459        AC_MSG_RESULT(no)
1460    ])
1461])
1462
1463CXXFLAGS="${__saved_CXXFLAGS}"
1464CFLAGS="${__saved_CFLAGS}"
1465AC_LANG_POP
1466AC_SUBST(has_128bit_cas)
1467
1468AS_IF([test "x$has_128bit_cas" = "x1"], [
1469  AS_IF([test "x$ax_cv_c_compiler_vendor" != "xintel"], [
1470    TS_ADDTO(AM_CFLAGS, [-mcx16])
1471    TS_ADDTO(AM_CXXFLAGS, [-mcx16])
1472  ])
1473])
1474
1475# Check for POSIX capabilities library.
1476# If we don't find it, disable checking for header.
1477use_posix_cap=0
1478AS_IF([test "x$enable_posix_cap" != "xno"],
1479  AC_CHECK_LIB([cap], [cap_set_proc],
1480    [AC_SUBST([LIBCAP], ["-lcap"])
1481     use_posix_cap=1
1482    ],[
1483     AS_IF([test "x$enable_posix_cap" == "xyes"], [
1484      AC_MSG_FAILURE([POSIX capabilities enabled but system library not found.])
1485     ],[
1486      [enable_posix_cap=no]
1487    ]    )
1488   ]
1489  )
1490)
1491AC_SUBST(use_posix_cap)
1492
1493#
1494# If the OS is linux, we can use the '--enable-experimental-linux-native-aio' option to
1495# replace the aio thread mode. Effective only on the linux system.
1496#
1497
1498AC_MSG_CHECKING([whether to enable Linux native AIO])
1499AC_ARG_ENABLE([experimental-linux-native-aio],
1500  [AS_HELP_STRING([--enable-experimental-linux-native-aio], [WARNING this is experimental and has known issues enable native Linux AIO support @<:@default=no@:>@])],
1501  [enable_linux_native_aio="${enableval}"],
1502  [enable_linux_native_aio=no]
1503)
1504
1505AS_IF([test "x$enable_linux_native_aio" = "xyes"], [
1506  if test $host_os_def  != "linux"; then
1507    AC_MSG_ERROR([Linux native AIO can only be enabled on Linux systems])
1508  fi
1509
1510  AC_CHECK_HEADERS([libaio.h], [],
1511    [AC_MSG_ERROR([Linux native AIO requires libaio.h])]
1512  )
1513
1514  AC_SEARCH_LIBS([io_submit], [aio], [],
1515    [AC_MSG_ERROR([Linux native AIO requires libaio])]
1516  )
1517])
1518
1519AC_MSG_RESULT([$enable_linux_native_aio])
1520TS_ARG_ENABLE_VAR([use], [linux_native_aio])
1521
1522# Check for hwloc library.
1523# If we don't find it, disable checking for header.
1524use_hwloc=0
1525AS_IF([test "x$enable_hwloc" = "xyes"], [
1526  # Use pkg-config, because some distros (*cough* Ubuntu) put hwloc in unusual places.
1527  PKG_CHECK_MODULES([HWLOC], [hwloc], [
1528    SAVE_LIBS="$LIBS"
1529    LIBS="-lhwloc"
1530    AC_LANG_PUSH([C++])
1531    AC_MSG_CHECKING([for hwloc C++ linking])
1532    AC_LINK_IFELSE([
1533      AC_LANG_PROGRAM([#include <hwloc.h>],[hwloc_topology_t t; hwloc_topology_init(&t); hwloc_get_type_depth(t, HWLOC_OBJ_SOCKET);])],[
1534      use_hwloc=1
1535      AC_SUBST([HWLOC_CFLAGS])
1536      AC_SUBST([HWLOC_LIBS])
1537      AC_MSG_RESULT([yes])
1538      # Old versions of libhwloc don't have HWLOC_OBJ_PU.
1539      AC_CHECK_DECL(HWLOC_OBJ_PU,
1540        [AC_DEFINE(HAVE_HWLOC_OBJ_PU, 1, [Whether HWLOC_OBJ_PU is available])], [],
1541        [#include <hwloc.h>]
1542      )
1543    ], [
1544      AC_MSG_RESULT([no])
1545      AC_MSG_WARN([hwloc not linkable, try --disable-hwloc])
1546      AC_SUBST([HWLOC_CFLAGS],[""])
1547      AC_SUBST([HWLOC_LIBS],[""])
1548    ])
1549    AC_LANG_POP()
1550    LIBS="$SAVE_LIBS"
1551  ], [
1552    AC_MSG_WARN([hwloc not found, try --disable-hwloc])
1553    AC_SUBST([HWLOC_CFLAGS],[""])
1554    AC_SUBST([HWLOC_LIBS],[""])
1555  ])
1556])
1557
1558AC_SUBST(use_hwloc)
1559
1560#
1561# Check for Maxmind APIs / includes. TODO: Long term, it might make sense to support
1562# GeoIP as a "helper" plugin, which other plugins can then use. Such a plugin could
1563# then manage which libraries to use via explicit dlopen()'s.
1564#
1565AC_CHECK_HEADERS([GeoIP.h], [
1566  AC_CHECK_LIB([GeoIP], [GeoIP_new], [
1567    AC_SUBST([GEO_LIBS], ["-lGeoIP"])
1568  ], [
1569    AC_SUBST([GEO_LIBS], [""])
1570  ])
1571])
1572
1573
1574# Right now, the healthcheck plugins requires inotify_init (and friends)
1575AM_CONDITIONAL([BUILD_HEALTHCHECK_PLUGIN], [ test "$ac_cv_func_inotify_init" = "yes" ])
1576
1577#
1578# Check for tcmalloc and jemalloc
1579TS_CHECK_JEMALLOC
1580TS_CHECK_TCMALLOC
1581
1582#
1583# Check for libreadline/libedit
1584AX_LIB_READLINE
1585
1586# We should be able to build http_load if epoll(2) is available.
1587AM_CONDITIONAL([BUILD_HTTP_LOAD], [test x"$ac_cv_func_epoll_ctl" = x"yes"])
1588
1589# We should only build traffic_top if we have curses
1590AM_CONDITIONAL([BUILD_TRAFFIC_TOP], [test "x$ax_cv_curses" = "xyes"])
1591
1592AC_CHECK_HEADERS([mysql/mysql.h], [has_mysql=1],[has_mysql=0])
1593AC_CHECK_LIB([mysqlclient],[mysql_info],[AC_SUBST([LIB_MYSQLCLIENT],["-lmysqlclient"])],[has_mysql=0])
1594AC_SUBST(has_mysql)
1595AM_CONDITIONAL([HAS_MYSQL], [ test "x${has_mysql}" = "x1" ])
1596
1597AC_CHECK_HEADERS([kclangc.h], [
1598  AC_CHECK_LIB([kyotocabinet], [kcdbopen], [
1599    AC_SUBST([LIB_KYOTOCABINET], ["-lkyotocabinet"])
1600    has_kyotocabinet=1
1601  ], [
1602    has_kyotocabinet=0
1603  ])
1604],
1605[has_kyotocabinet=0]
1606)
1607AC_SUBST(has_kyotocabinet)
1608AM_CONDITIONAL([HAS_KYOTOCABINET], [ test "x${has_kyotocabinet}" = "x1" ])
1609
1610# -----------------------------------------------------------------------------
1611# 5. CHECK FOR HEADER FILES
1612
1613AC_CHECK_HEADERS([sys/types.h \
1614                  sys/uio.h \
1615                  sys/mman.h \
1616                  sys/epoll.h \
1617                  sys/event.h \
1618                  sys/param.h \
1619                  sys/pset.h \
1620                  sched.h \
1621                  pthread.h \
1622                  sys/endian.h \
1623                  machine/endian.h \
1624                  endian.h \
1625                  sys/sysinfo.h \
1626                  sys/systeminfo.h \
1627                  netinet/in.h \
1628                  netinet/in_systm.h \
1629                  netinet/tcp.h \
1630                  sys/ioctl.h \
1631                  sys/byteorder.h \
1632                  sys/sockio.h \
1633                  sys/prctl.h \
1634                  arpa/nameser.h \
1635                  arpa/nameser_compat.h \
1636                  execinfo.h \
1637                  netdb.h \
1638                  ctype.h \
1639                  siginfo.h \
1640                  malloc.h \
1641                  float.h \
1642                  libgen.h \
1643                  values.h \
1644                  alloca.h \
1645                  cpio.h \
1646                  stropts.h \
1647                  sys/param.h \
1648                  sys/sysmacros.h \
1649                  stdint.h \
1650                  stdbool.h \
1651                  sysexits.h \
1652                  net/ppp_defs.h \
1653                  ifaddrs.h\
1654                  readline/readline.h \
1655                  editline/readline.h \
1656                  ucred.h ])
1657
1658# On OpenBSD, pthread.h must be included before pthread_np.h
1659AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])
1660AC_CHECK_HEADERS([sys/statfs.h sys/statvfs.h sys/disk.h sys/disklabel.h])
1661AC_CHECK_HEADERS([linux/hdreg.h linux/fs.h linux/major.h])
1662
1663AC_CHECK_HEADERS([sys/sysctl.h], [], [],
1664                 [[#ifdef HAVE_SYS_PARAM_H
1665                    #include <sys/param.h>
1666                   #endif
1667                 ]])
1668
1669AC_CHECK_HEADERS([sys/cpuset.h], [], [],
1670                 [[#ifdef HAVE_SYS_PARAM_H
1671                    #include <sys/param.h>
1672                   #endif
1673                 ]])
1674
1675AC_CHECK_HEADERS([sys/mount.h], [], [],
1676                 [[#ifdef HAVE_SYS_PARAM_H
1677                    #include <sys/param.h>
1678                   #endif
1679                 ]])
1680
1681AC_CHECK_HEADERS([arpa/inet.h], [], [],
1682                 [[#ifdef HAVE_SYS_TYPES_H
1683                    #include <sys/types.h>
1684                   #endif
1685                   #ifdef HAVE_NETINET_IN_H
1686                    #include <netinet/in.h>
1687                   #endif
1688                 ]])
1689
1690AC_CHECK_HEADERS([netinet/ip.h], [], [],
1691                 [[#ifdef HAVE_SYS_TYPES_H
1692                    #include <sys/types.h>
1693                   #endif
1694                   #ifdef HAVE_NETINET_IN_H
1695                    #include <netinet/in.h>
1696                   #endif
1697                   #ifdef HAVE_NETINET_IN_SYSTM_H
1698                    #include <netinet/in_systm.h>
1699                   #endif
1700                 ]])
1701
1702AC_CHECK_HEADERS([netinet/ip_icmp.h], [], [],
1703                 [[#ifdef HAVE_SYS_TYPES_H
1704                    #include <sys/types.h>
1705                   #endif
1706                   #ifdef HAVE_NETINET_IN_H
1707                    #include <netinet/in.h>
1708                   #endif
1709                   #ifdef HAVE_NETINET_IP_H
1710                    #include <netinet/ip.h>
1711                   #endif
1712                   #ifdef HAVE_NETINET_IN_SYSTM_H
1713                    #include <netinet/in_systm.h>
1714                   #endif
1715                 ]])
1716
1717
1718# Test for additional pthread interfaces.
1719
1720# Darwin pthread_setname_np:
1721AC_MSG_CHECKING([for 1-parameter version of pthread_setname_np()])
1722AC_LINK_IFELSE([
1723    AC_LANG_PROGRAM([
1724#if HAVE_PTHREAD_H
1725#include <pthread.h>
1726#endif
1727#if PTHREAD_NP_H
1728#include <pthread_np.h>
1729#endif
1730      ], [
1731        pthread_setname_np("conftest");
1732    ])
1733  ], [
1734    AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_1, 1, [Whether the 1 parameter version of pthread_setname_np() is available])
1735    AC_MSG_RESULT([yes])
1736  ], [
1737    AC_MSG_RESULT([no])
1738])
1739
1740# Linux pthread_setname_np:
1741AC_MSG_CHECKING([for 2-parameter version of pthread_setname_np()])
1742AC_LINK_IFELSE([
1743    AC_LANG_PROGRAM([
1744#if HAVE_PTHREAD_H
1745#include <pthread.h>
1746#endif
1747#if PTHREAD_NP_H
1748#include <pthread_np.h>
1749#endif
1750      ], [
1751        pthread_setname_np(pthread_self(), "conftest");
1752    ])
1753  ], [
1754    AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_2, 1, [Whether the 2 parameter version of pthread_setname_np() is available])
1755    AC_MSG_RESULT([yes])
1756  ], [
1757    AC_MSG_RESULT([no])
1758])
1759
1760# BSD pthread_set_name_np:
1761AC_MSG_CHECKING([for 2-parameter version of pthread_set_name_np()])
1762AC_LINK_IFELSE([
1763    AC_LANG_PROGRAM([
1764#if HAVE_PTHREAD_H
1765#include <pthread.h>
1766#endif
1767#if PTHREAD_NP_H
1768#include <pthread_np.h>
1769#endif
1770      ], [
1771        pthread_set_name_np(pthread_self(), "conftest");
1772    ])
1773  ], [
1774    AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP_2, 1, [Whether the 2 parameter version of pthread_set_name_np() is available])
1775    AC_MSG_RESULT([yes])
1776  ], [
1777    AC_MSG_RESULT([no])
1778])
1779
1780# pthread_getname_np / pthread_get_name_np:
1781AC_MSG_CHECKING([pthread_getname_np()])
1782AC_LINK_IFELSE([
1783    AC_LANG_PROGRAM([
1784#if HAVE_PTHREAD_H
1785#include <pthread.h>
1786#endif
1787#if PTHREAD_NP_H
1788#include <pthread_np.h>
1789#endif
1790      ], [
1791        char name[[32]];
1792        pthread_getname_np(pthread_self(), name, sizeof(name));
1793    ])
1794  ], [
1795    AC_DEFINE(HAVE_PTHREAD_GETNAME_NP, 1, [Whether pthread_getname_np() is available])
1796    AC_MSG_RESULT([yes])
1797  ], [
1798    AC_MSG_RESULT([no])
1799    AC_MSG_CHECKING([pthread_get_name_np()])
1800    AC_LINK_IFELSE([
1801        AC_LANG_PROGRAM([
1802    #if HAVE_PTHREAD_H
1803    #include <pthread.h>
1804    #endif
1805    #if PTHREAD_NP_H
1806    #include <pthread_np.h>
1807    #endif
1808          ], [
1809            char name[[32]];
1810            pthread_get_name_np(pthread_self(), name, sizeof(name));
1811        ])
1812      ], [
1813        AC_DEFINE(HAVE_PTHREAD_GET_NAME_NP, 1, [Whether pthread_get_name_np() is available])
1814        AC_MSG_RESULT([yes])
1815      ], [
1816        AC_MSG_RESULT([no])
1817    ])
1818])
1819
1820# BSD-derived systems populate the socket length in the structure itself. It's
1821# redundant to check all of these, but hey, I need the typing practice. Also, we
1822# check for the linux updated version of tcp.h, in linux/tcp.h
1823AC_CHECK_MEMBER([struct sockaddr.sa_len], [], [], [#include <netinet/in.h>])
1824AC_CHECK_MEMBER([struct sockaddr_in.sin_len], [], [], [#include <netinet/in.h>])
1825AC_CHECK_MEMBER([struct sockaddr_in6.sin6_len], [], [], [#include <netinet/in.h>])
1826AC_CHECK_MEMBER([struct tcp_info.tcpi_data_segs_out], [], [], [#include <linux/tcp.h>])
1827
1828if test "x${ac_cv_member_struct_sockaddr_sa_len}" = "xyes"; then
1829    AC_DEFINE(HAVE_STRUCT_SOCKADDR_SA_LEN, 1,
1830            [Whether struct sockaddr_in has the sa_len member])
1831fi
1832
1833if test "x${ac_cv_member_struct_sockaddr_in_sin_len}" = "xyes"; then
1834AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN, 1,
1835            [Whether struct sockaddr_in has the sin_len member])
1836fi
1837
1838if test "x${ac_cv_member_struct_sockaddr_in6_sin6_len}" = "xyes"; then
1839    AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN, 1,
1840            [Whether struct sockaddr_in6 has the sin6_len member])
1841fi
1842
1843if test "x${ac_cv_member_struct_tcp_info_tcpi_data_segs_out}" = "xyes"; then
1844    AC_DEFINE(HAVE_STRUCT_LINUX_TCP_INFO, 1,
1845            [Whether struct tcp_info have the tcpi_data_segs_{in,out} member])
1846fi
1847
1848if test "x${with_profiler}" = "xyes"; then
1849AC_CHECK_HEADERS([google/profiler.h \
1850                  ], [], [])
1851fi
1852
1853if test "x${enable_posix_cap}" != "xno"; then
1854  AC_CHECK_HEADERS([sys/capability.h],
1855    [],
1856    [AC_MSG_FAILURE([Found POSIX capabilities library but not the header sys/capability.h. POSIX capabilities are not a required feature, you can disable then with --disable-posix-cap])],
1857    []
1858  )
1859fi
1860
1861# Check for high-resolution timestamps in struct stat
1862AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec])
1863AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec])
1864
1865
1866#
1867# Configure sockopt value for TPROXY. Look at the enable flag.
1868# Value 'no' means user forced disable, don't check anything else.
1869#       'auto' means user didn't say, so silently enable/disable
1870#              based on success.
1871#       A numeric value means enable, don't check, use that value.
1872#       Anything else means user forced, fail if value not found
1873#       in header file.
1874# We can't just include linux/in.h because it's incompatible with
1875# netinet/in.h.
1876# Verify the file exists (is readable), scan for the value we need,
1877# if found export the value and enable use of the value.
1878#
1879ip_transparent=0
1880use_tproxy=0
1881tproxy_header=/usr/include/linux/in.h
1882tproxy_usage_enable="
1883    --enable-tproxy Enable the feature and validate."
1884tproxy_usage_default="
1885    --enable-tproxy=force Enable using default sockopt value, no validation."
1886tproxy_usage_numeric="
1887    --enable-tproxy=X where X is numeric
1888                      Enable, use X for sockopt value, no validation."
1889tproxy_usage_disable="
1890    --disable-tproxy Disable feature, no validation."
1891proxy_usage="$tproxy_usage_enable$tproxy_usage_default$tproxy_usage_numeric$tproxy_usage_disable"
1892
1893AC_MSG_CHECKING([whether to enable transparent proxy])
1894AS_IF([test "x$enable_tproxy" != "xno"], [
1895  AS_IF([test "$use_posix_cap" -eq 0], [
1896    AS_IF([test "x$enable_tproxy" = xauto], [
1897      AC_MSG_RESULT([no])
1898    ],[
1899      AC_MSG_FAILURE([TPROXY feature requires POSIX capabilities.])
1900    ])
1901  ],[
1902    AC_MSG_CHECKING([for TPROXY sockopt IP_TRANSPARENT])
1903    case "$enable_tproxy" in
1904      [[0-9][0-9]*])
1905        ip_transparent=$enable_tproxy
1906        use_tproxy=1
1907        AC_MSG_RESULT([forced to $ip_transparent])
1908        ;;
1909      force)
1910        ip_transparent=19
1911        use_tproxy=1
1912        AC_MSG_RESULT([forced to $ip_transparent])
1913        ;;
1914      yes|auto)
1915        AS_IF([test -r $tproxy_header], [
1916          ip_transparent=`$AWK "/^#define[ \t]+IP_TRANSPARENT[ \t]+[0-9]+/{print \\$3}" $tproxy_header`
1917          AS_IF([test "x$ip_transparent" != "x"], [
1918            use_tproxy=1
1919            AC_MSG_RESULT([set to $ip_transparent])
1920          ],[
1921            ip_transparent=0
1922            AS_IF([test "x$enable_tproxy" = xauto], [
1923             AC_MSG_RESULT([no])
1924            ],[
1925              AC_MSG_RESULT([failed])
1926              AC_MSG_FAILURE([tproxy feature enabled but the sockopt value was not found in $tproxy_header. Try one of$tproxy_usage_default$tproxy_usage_numeric$tproxy_usage_disable])
1927            ])
1928          ])
1929        ],[
1930          AS_IF([test "x$enable_tproxy" = xauto], [
1931            AC_MSG_RESULT([no])
1932          ],[
1933            AC_MSG_RESULT([failed])
1934            AC_MSG_FAILURE([tproxy feature enabled but the header file $tproxy_header was not readable. Try one of$tproxy_usage_default$tproxy_usage_numeric$tproxy_usage_disable])
1935          ])
1936        ])
1937        ;;
1938      *)
1939        AC_MSG_RESULT([failed])
1940        AC_MSG_FAILURE([Invalid argument to feature tproxy.$tproxy_usage])
1941        ;;
1942      esac
1943  ])
1944])
1945
1946AC_SUBST(use_tproxy)
1947AC_SUBST(ip_transparent)
1948
1949TS_CHECK_SOCKOPT(SO_PEERCRED, [has_so_peercred=1], [has_so_peercred=0])
1950TS_CHECK_SOCKOPT(SO_MARK, [has_so_mark=1], [has_so_mark=0])
1951TS_CHECK_SOCKOPT(IP_TOS, [has_ip_tos=1], [has_ip_tos=0])
1952
1953AC_SUBST(has_so_mark)
1954AC_SUBST(has_ip_tos)
1955AC_SUBST(has_so_peercred)
1956
1957TS_CHECK_LOOPBACK_IFACE
1958TS_CHECK_MACRO_IN6_IS_ADDR_UNSPECIFIED
1959
1960AC_CHECK_TYPE([struct tcp_info],
1961  [AC_DEFINE(HAVE_STRUCT_TCP_INFO, 1, [whether struct tcp_info is available])],
1962  [],
1963  [[
1964   #include <netinet/in.h>
1965   #include <netinet/tcp.h>
1966  ]]
1967)
1968
1969# See if we can build the remap_stats plugin
1970AS_IF([test "x$enable_experimental_plugins" = "xyes"],
1971  [
1972    AC_CHECK_HEADERS([search.h])
1973    AS_IF([test "x$ac_cv_header_search_h" = "xyes"],
1974      [
1975        AC_CHECK_TYPE([struct hsearch_data],[],[],[[#include <search.h>]])
1976        AC_CHECK_FUNCS([hcreate_r hsearch_r])
1977      ])
1978  ])
1979AM_CONDITIONAL([BUILD_REMAP_STATS_PLUGIN],
1980  [ test "x$enable_experimental_plugins" = "xyes" -a "x$ac_cv_header_search_h" = "xyes" -a "x$ac_cv_type_struct_hsearch_data" = "xyes" -a "x$ac_cv_func_hcreate_r" = "xyes" -a "x$ac_cv_func_hsearch_r" = "xyes" ])
1981
1982AC_ARG_WITH([default-stack-size],
1983  [AS_HELP_STRING([--with-default-stack-size],[specify the default stack size in bytes [default=1048576]])],
1984  [
1985  with_default_stack_size="$withval"
1986  ],[
1987  with_default_stack_size="1048576"
1988  ]
1989)
1990
1991AC_SUBST([default_stack_size], [$with_default_stack_size])
1992
1993#
1994# use modular IOCORE
1995#
1996iocore_include_dirs="\
1997-I\$(abs_top_srcdir)/iocore/eventsystem \
1998-I\$(abs_top_srcdir)/iocore/net \
1999-I\$(abs_top_srcdir)/iocore/aio \
2000-I\$(abs_top_srcdir)/iocore/hostdb \
2001-I\$(abs_top_srcdir)/iocore/cache \
2002-I\$(abs_top_srcdir)/iocore/utils \
2003-I\$(abs_top_srcdir)/iocore/dns"
2004
2005AC_SUBST([AM_CPPFLAGS])
2006AC_SUBST([AM_CFLAGS])
2007AC_SUBST([AM_CXXFLAGS])
2008AC_SUBST([AM_LDFLAGS])
2009AC_SUBST([iocore_include_dirs])
2010
2011# NOTE: All additions to the default include path must be added to
2012# TS_INCLUDES *not* to AM_CPPFLAGS. If you add then to AM_CPPFLAGS
2013# then they are always prepended to the local AM_CPPFLAGS which risks
2014# name collisions with in-tree files. We always want the in-tree files
2015# to have precendence.
2016AC_SUBST([TS_INCLUDES])
2017
2018AS_IF([test "x$RPATH" != "x"], [
2019       TS_ADDTO_RPATH([$RPATH])
2020])
2021
2022# -----------------------------------------------------------------------------
2023# 6. OUTPUT FILES
2024
2025AC_CONFIG_FILES([
2026  Makefile
2027  src/Makefile
2028  configs/Makefile
2029  configs/body_factory/Makefile
2030  configs/body_factory/default/Makefile
2031  configs/records.config.default
2032  configs/storage.config.default
2033  doc/Makefile
2034  doc/ext/local-config.py
2035  doc/uml/Makefile
2036  example/Makefile
2037  example/plugins/Makefile
2038  example/plugins/c-api/Makefile
2039  example/plugins/cpp-api/Makefile
2040  include/Makefile
2041  include/ts/Makefile
2042  include/tscpp/api/Makefile
2043  include/tscpp/util/Makefile
2044  iocore/Makefile
2045  iocore/aio/Makefile
2046  iocore/cache/Makefile
2047  iocore/dns/Makefile
2048  iocore/eventsystem/Makefile
2049  iocore/hostdb/Makefile
2050  iocore/net/Makefile
2051  iocore/utils/Makefile
2052  lib/Makefile
2053  src/tscpp/api/Makefile
2054  lib/perl/Makefile
2055  lib/perl/lib/Apache/TS.pm
2056  lib/records/Makefile
2057  include/ts/apidefs.h
2058  include/tscore/ink_config.h
2059  src/wccp/Makefile
2060  lib/yamlcpp/Makefile
2061  mgmt/Makefile
2062  mgmt/api/Makefile
2063  mgmt/api/include/Makefile
2064  mgmt/utils/Makefile
2065  plugins/Makefile
2066  proxy/Makefile
2067  proxy/hdrs/Makefile
2068  proxy/http/Makefile
2069  proxy/http/remap/Makefile
2070  proxy/http2/Makefile
2071  proxy/logging/Makefile
2072  proxy/shared/Makefile
2073  rc/Makefile
2074  rc/trafficserver
2075  rc/trafficserver.conf
2076  rc/trafficserver.service
2077  rc/trafficserver.xml
2078  src/tscpp/util/Makefile
2079  src/tscore/Makefile
2080  tools/Makefile
2081  tools/trafficserver.pc
2082  tools/tsxs
2083  tests/unit_tests/Makefile
2084])
2085
2086# -----------------------------------------------------------------------------
2087# 7. autoheader TEMPLATES
2088
2089AC_OUTPUT
2090
2091AC_MSG_NOTICE([Build option summary:
2092    CC:                 $CC
2093    CXX:                $CXX
2094    CPP:                $CPP
2095    CFLAGS:             $CFLAGS
2096    CXXFLAGS:           $CXXFLAGS
2097    CPPFLAGS:           $CPPFLAGS
2098    LDFLAGS:            $LDFLAGS
2099    AM@&t@_CFLAGS:          $AM_CFLAGS
2100    AM@&t@_CXXFLAGS:        $AM_CXXFLAGS
2101    AM@&t@_CPPFLAGS:        $AM_CPPFLAGS
2102    AM@&t@_LDFLAGS:         $AM_LDFLAGS
2103    TS_INCLUDES:        $TS_INCLUDES
2104    OPENSSL_LDFLAGS:    $OPENSSL_LDFLAGS
2105    OPENSSL_INCLUDES:   $OPENSSL_INCLUDES
2106    YAMLCPP_LDFLAGS:    $YAMLCPP_LDFLAGS
2107    YAMLCPP_INCLUDES:   $YAMLCPP_INCLUDES
2108])
2109