1# nghttp3
2#
3# Copyright (c) 2019 nghttp3 contributors
4# Copyright (c) 2016 ngtcp2 contributors
5# Copyright (c) 2012 nghttp2 contributors
6#
7# Permission is hereby granted, free of charge, to any person obtaining
8# a copy of this software and associated documentation files (the
9# "Software"), to deal in the Software without restriction, including
10# without limitation the rights to use, copy, modify, merge, publish,
11# distribute, sublicense, and/or sell copies of the Software, and to
12# permit persons to whom the Software is furnished to do so, subject to
13# the following conditions:
14#
15# The above copyright notice and this permission notice shall be
16# included in all copies or substantial portions of the Software.
17#
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25AC_PREREQ(2.61)
26AC_INIT([nghttp3], [0.1.0.g20211117], [t-tujikawa@users.sourceforge.net])
27AC_CONFIG_AUX_DIR([.])
28AC_CONFIG_MACRO_DIR([m4])
29AC_CONFIG_HEADERS([config.h])
30AC_USE_SYSTEM_EXTENSIONS
31
32LT_PREREQ([2.2.6])
33LT_INIT()
34
35AC_CANONICAL_BUILD
36AC_CANONICAL_HOST
37AC_CANONICAL_TARGET
38
39AM_INIT_AUTOMAKE([subdir-objects])
40
41m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
42
43# See versioning rule:
44#  https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
45AC_SUBST(LT_CURRENT, 0)
46AC_SUBST(LT_REVISION, 0)
47AC_SUBST(LT_AGE, 0)
48
49# from nghttp2
50major=`echo $PACKAGE_VERSION |cut -d. -f1 | sed -e "s/[^0-9]//g"`
51minor=`echo $PACKAGE_VERSION |cut -d. -f2 | sed -e "s/[^0-9]//g"`
52patch=`echo $PACKAGE_VERSION |cut -d. -f3 | cut -d- -f1 | sed -e "s/[^0-9]//g"`
53
54PACKAGE_VERSION_NUM=`printf "0x%02x%02x%02x" "$major" "$minor" "$patch"`
55
56AC_SUBST(PACKAGE_VERSION_NUM)
57
58# Checks for command-line options
59AC_ARG_ENABLE([werror],
60    [AS_HELP_STRING([--enable-werror],
61                    [Turn on compile time warnings])],
62    [werror=$enableval], [werror=no])
63
64AC_ARG_ENABLE([debug],
65    [AS_HELP_STRING([--enable-debug],
66                    [Turn on debug output])],
67    [debug=$enableval], [debug=no])
68
69if test "x${debug}" = "xyes"; then
70  DEBUGCFLAGS="-O0 -g3"
71  AC_SUBST([DEBUGCFLAGS])
72  AC_DEFINE([DEBUGBUILD], [1], [Define to 1 to enable debug output.])
73fi
74
75AC_ARG_ENABLE(asan,
76    AS_HELP_STRING([--enable-asan],
77                   [Enable AddressSanitizer (ASAN)]),
78    [asan=$enableval], [asan=no])
79
80AC_ARG_ENABLE([lib-only],
81    [AS_HELP_STRING([--enable-lib-only],
82                    [Build libnghttp3 only.])],
83    [lib_only=$enableval], [lib_only=no])
84
85AC_ARG_WITH([cunit],
86    [AS_HELP_STRING([--with-cunit],
87                    [Use cunit [default=check]])],
88    [request_cunit=$withval], [request_cunit=check])
89
90# Checks for programs
91AC_PROG_CC
92AC_PROG_CXX
93AC_PROG_CPP
94AC_PROG_INSTALL
95AC_PROG_LN_S
96AC_PROG_MAKE_SET
97AC_PROG_MKDIR_P
98
99PKG_PROG_PKG_CONFIG([0.20])
100
101AX_CXX_COMPILE_STDCXX([17], [noext], [optional])
102
103# Checks for libraries.
104
105# cunit
106have_cunit=no
107if test "x${request_cunit}" != "xno"; then
108  PKG_CHECK_MODULES([CUNIT], [cunit >= 2.1], [have_cunit=yes], [have_cunit=no])
109  # If pkg-config does not find cunit, check it using AC_CHECK_LIB.  We
110  # do this because Debian (Ubuntu) lacks pkg-config file for cunit.
111  if test "x${have_cunit}" = "xno"; then
112    AC_MSG_WARN([${CUNIT_PKG_ERRORS}])
113    AC_CHECK_LIB([cunit], [CU_initialize_registry],
114                 [have_cunit=yes], [have_cunit=no])
115    if test "x${have_cunit}" = "xyes"; then
116      CUNIT_LIBS="-lcunit"
117      CUNIT_CFLAGS=""
118      AC_SUBST([CUNIT_LIBS])
119      AC_SUBST([CUNIT_CFLAGS])
120    fi
121  fi
122  if test "x${have_cunit}" = "xyes"; then
123    # cunit in Mac OS X requires ncurses. Note that in Mac OS X, test
124    # program can be built without -lncurses, but it emits runtime
125    # error.
126    case "${build}" in
127      *-apple-darwin*)
128        CUNIT_LIBS="$CUNIT_LIBS -lncurses"
129        AC_SUBST([CUNIT_LIBS])
130        ;;
131    esac
132  fi
133fi
134
135if test "x${request_cunit}" = "xyes" &&
136   test "x${have_cunit}" != "xyes"; then
137  AC_MSG_ERROR([cunit was requested (--with-cunit) but not found])
138fi
139
140AM_CONDITIONAL([HAVE_CUNIT], [ test "x${have_cunit}" = "xyes" ])
141
142enable_examples=yes
143if test "x${lib_only}" = "xyes"; then
144  enable_examples=no
145fi
146
147AM_CONDITIONAL([ENABLE_EXAMPLES], [ test "x${enable_examples}" = "xyes" ])
148
149# Checks for header files.
150AC_CHECK_HEADERS([ \
151  arpa/inet.h \
152  stddef.h \
153  stdint.h \
154  stdlib.h \
155  string.h \
156  unistd.h \
157  sys/endian.h \
158  endian.h \
159  byteswap.h \
160])
161
162# Checks for typedefs, structures, and compiler characteristics.
163AC_TYPE_SIZE_T
164AC_TYPE_SSIZE_T
165AC_TYPE_UINT8_T
166AC_TYPE_UINT16_T
167AC_TYPE_UINT32_T
168AC_TYPE_UINT64_T
169AC_TYPE_INT8_T
170AC_TYPE_INT16_T
171AC_TYPE_INT32_T
172AC_TYPE_INT64_T
173AC_TYPE_OFF_T
174AC_TYPE_PID_T
175AC_TYPE_UID_T
176AC_CHECK_TYPES([ptrdiff_t])
177AC_C_BIGENDIAN
178AC_C_INLINE
179AC_SYS_LARGEFILE
180
181# Checks for library functions.
182AC_CHECK_FUNCS([ \
183  memmove \
184  memset \
185])
186
187# Checks for symbols.
188AC_CHECK_DECLS([be64toh], [], [], [[
189#ifdef HAVE_ENDIAN_H
190#  include <endian.h>
191#endif
192#ifdef HAVE_SYS_ENDIAN_H
193#  include <sys/endian.h>
194#endif
195]])
196
197AC_CHECK_DECLS([bswap_64], [], [], [[
198#include <byteswap.h>
199]])
200
201# More compiler flags from nghttp2.
202save_CFLAGS=$CFLAGS
203save_CXXFLAGS=$CXXFLAGS
204
205CFLAGS=
206CXXFLAGS=
207
208if test "x$werror" != "xno"; then
209    # For C compiler
210    AX_CHECK_COMPILE_FLAG([-Wall], [CFLAGS="$CFLAGS -Wall"])
211    AX_CHECK_COMPILE_FLAG([-Wextra], [CFLAGS="$CFLAGS -Wextra"])
212    AX_CHECK_COMPILE_FLAG([-Werror], [CFLAGS="$CFLAGS -Werror"])
213    AX_CHECK_COMPILE_FLAG([-Wmissing-prototypes], [CFLAGS="$CFLAGS -Wmissing-prototypes"])
214    AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes], [CFLAGS="$CFLAGS -Wstrict-prototypes"])
215    AX_CHECK_COMPILE_FLAG([-Wmissing-declarations], [CFLAGS="$CFLAGS -Wmissing-declarations"])
216    AX_CHECK_COMPILE_FLAG([-Wpointer-arith], [CFLAGS="$CFLAGS -Wpointer-arith"])
217    AX_CHECK_COMPILE_FLAG([-Wdeclaration-after-statement], [CFLAGS="$CFLAGS -Wdeclaration-after-statement"])
218    AX_CHECK_COMPILE_FLAG([-Wformat-security], [CFLAGS="$CFLAGS -Wformat-security"])
219    AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"])
220    AX_CHECK_COMPILE_FLAG([-Wshadow], [CFLAGS="$CFLAGS -Wshadow"])
221    AX_CHECK_COMPILE_FLAG([-Winline], [CFLAGS="$CFLAGS -Winline"])
222    AX_CHECK_COMPILE_FLAG([-Wnested-externs], [CFLAGS="$CFLAGS -Wnested-externs"])
223    AX_CHECK_COMPILE_FLAG([-Wfloat-equal], [CFLAGS="$CFLAGS -Wfloat-equal"])
224    AX_CHECK_COMPILE_FLAG([-Wundef], [CFLAGS="$CFLAGS -Wundef"])
225    AX_CHECK_COMPILE_FLAG([-Wendif-labels], [CFLAGS="$CFLAGS -Wendif-labels"])
226    AX_CHECK_COMPILE_FLAG([-Wempty-body], [CFLAGS="$CFLAGS -Wempty-body"])
227    AX_CHECK_COMPILE_FLAG([-Wcast-align], [CFLAGS="$CFLAGS -Wcast-align"])
228    AX_CHECK_COMPILE_FLAG([-Wclobbered], [CFLAGS="$CFLAGS -Wclobbered"])
229    AX_CHECK_COMPILE_FLAG([-Wvla], [CFLAGS="$CFLAGS -Wvla"])
230    AX_CHECK_COMPILE_FLAG([-Wpragmas], [CFLAGS="$CFLAGS -Wpragmas"])
231    AX_CHECK_COMPILE_FLAG([-Wunreachable-code], [CFLAGS="$CFLAGS -Wunreachable-code"])
232    AX_CHECK_COMPILE_FLAG([-Waddress], [CFLAGS="$CFLAGS -Waddress"])
233    AX_CHECK_COMPILE_FLAG([-Wattributes], [CFLAGS="$CFLAGS -Wattributes"])
234    AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"])
235    AX_CHECK_COMPILE_FLAG([-Wshorten-64-to-32], [CFLAGS="$CFLAGS -Wshorten-64-to-32"])
236
237    AX_CHECK_COMPILE_FLAG([-Wconversion], [CFLAGS="$CFLAGS -Wconversion"])
238    AX_CHECK_COMPILE_FLAG([-Wextended-offsetof], [CFLAGS="$CFLAGS -Wextended-offsetof"])
239    AX_CHECK_COMPILE_FLAG([-Wformat-nonliteral], [CFLAGS="$CFLAGS -Wformat-nonliteral"])
240    AX_CHECK_COMPILE_FLAG([-Wlanguage-extension-token], [CFLAGS="$CFLAGS -Wlanguage-extension-token"])
241    AX_CHECK_COMPILE_FLAG([-Wmissing-field-initializers], [CFLAGS="$CFLAGS -Wmissing-field-initializers"])
242    AX_CHECK_COMPILE_FLAG([-Wmissing-noreturn], [CFLAGS="$CFLAGS -Wmissing-noreturn"])
243    AX_CHECK_COMPILE_FLAG([-Wmissing-variable-declarations], [CFLAGS="$CFLAGS -Wmissing-variable-declarations"])
244    # Not used because we cannot change public structs
245    # AX_CHECK_COMPILE_FLAG([-Wpadded], [CFLAGS="$CFLAGS -Wpadded"])
246    AX_CHECK_COMPILE_FLAG([-Wsign-conversion], [CFLAGS="$CFLAGS -Wsign-conversion"])
247    # Not used because this basically disallows default case
248    # AX_CHECK_COMPILE_FLAG([-Wswitch-enum], [CFLAGS="$CFLAGS -Wswitch-enum"])
249    AX_CHECK_COMPILE_FLAG([-Wunreachable-code-break], [CFLAGS="$CFLAGS -Wunreachable-code-break"])
250    AX_CHECK_COMPILE_FLAG([-Wunused-macros], [CFLAGS="$CFLAGS -Wunused-macros"])
251    AX_CHECK_COMPILE_FLAG([-Wunused-parameter], [CFLAGS="$CFLAGS -Wunused-parameter"])
252    AX_CHECK_COMPILE_FLAG([-Wredundant-decls], [CFLAGS="$CFLAGS -Wredundant-decls"])
253    # Only work with Clang for the moment
254    AX_CHECK_COMPILE_FLAG([-Wheader-guard], [CFLAGS="$CFLAGS -Wheader-guard"])
255    AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CFLAGS="$CFLAGS -Wsometimes-uninitialized"])
256
257    # Only work with gcc7 for the moment
258    AX_CHECK_COMPILE_FLAG([-Wduplicated-branches], [CFLAGS="$CFLAGS -Wduplicated-branches"])
259
260    # This is required because we pass format string as "const char*.
261    AX_CHECK_COMPILE_FLAG([-Wno-format-nonliteral], [CFLAGS="$CFLAGS -Wno-format-nonliteral"])
262
263    # For C++ compiler
264    AC_LANG_PUSH(C++)
265    AX_CHECK_COMPILE_FLAG([-Wall], [CXXFLAGS="$CXXFLAGS -Wall"])
266    # TODO separate option for -Werror and warnings?
267    #AX_CHECK_COMPILE_FLAG([-Werror], [CXXFLAGS="$CXXFLAGS -Werror"])
268    AX_CHECK_COMPILE_FLAG([-Wformat-security], [CXXFLAGS="$CXXFLAGS -Wformat-security"])
269    AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CXXFLAGS="$CXXFLAGS -Wsometimes-uninitialized"])
270    # Disable noexcept-type warning of g++-7.  This is not harmful as
271    # long as all source files are compiled with the same compiler.
272    AX_CHECK_COMPILE_FLAG([-Wno-noexcept-type], [CXXFLAGS="$CXXFLAGS -Wno-noexcept-type"])
273    AC_LANG_POP()
274fi
275
276WARNCFLAGS=$CFLAGS
277WARNCXXFLAGS=$CXXFLAGS
278
279CFLAGS=$save_CFLAGS
280CXXFLAGS=$save_CXXFLAGS
281
282AC_SUBST([WARNCFLAGS])
283AC_SUBST([WARNCXXFLAGS])
284
285if test "x$asan" != "xno"; then
286    # Assume both C and C++ compiler either support ASAN or not.
287    LDFLAGS_saved="$LDFLAGS"
288    LDFLAGS="$LDFLAGS -fsanitize=address"
289    AX_CHECK_COMPILE_FLAG([-fsanitize=address],
290                          [CFLAGS="$CFLAGS -fsanitize=address"; CXXFLAGS="$CXXFLAGS -fsanitize=address"],
291                          [LDFLAGS="$LDFLAGS_saved"])
292fi
293
294# extra flags for API function visibility
295EXTRACFLAG=
296AX_CHECK_COMPILE_FLAG([-fvisibility=hidden], [EXTRACFLAG="-fvisibility=hidden"])
297
298AC_SUBST([EXTRACFLAG])
299
300AC_CONFIG_FILES([
301  Makefile
302  lib/Makefile
303  lib/libnghttp3.pc
304  lib/includes/Makefile
305  lib/includes/nghttp3/version.h
306  tests/Makefile
307  doc/Makefile
308  doc/source/conf.py
309  examples/Makefile
310])
311AC_OUTPUT
312
313AC_MSG_NOTICE([summary of build options:
314
315    Package version: ${VERSION}
316    Library version: $LT_CURRENT:$LT_REVISION:$LT_AGE
317    Install prefix:  ${prefix}
318    System types:
319      Build:         ${build}
320      Host:          ${host}
321      Target:        ${target}
322    Compiler:
323      C preprocessor: ${CPP}
324      CPPFLAGS:       ${CPPFLAGS}
325      C compiler:     ${CC}
326      CFLAGS:         ${CFLAGS}
327      C++ compiler:   ${CXX}
328      CXXFLAGS:       ${CXXFLAGS}
329      LDFLAGS:        ${LDFLAGS}
330      WARNCFLAGS:     ${WARNCFLAGS}
331      WARNCXXFLAGS:   ${WARNCXXFLAGS}
332      EXTRACFLAG:     ${EXTRACFLAG}
333      LIBS:           ${LIBS}
334    Library:
335      Shared:         ${enable_shared}
336      Static:         ${enable_static}
337    Test:
338      CUnit:          ${have_cunit} (CFLAGS='${CUNIT_CFLAGS}' LIBS='${CUNIT_LIBS}')
339    Debug:
340      Debug:          ${debug} (CFLAGS='${DEBUGCFLAGS}')
341    Library only:     ${lib_only}
342    Examples:         ${enable_examples}
343])
344