summaryrefslogtreecommitdiff
path: root/configure.ac
blob: a953f8ef92e901edd0fc2a6928fd12989a6574f7 (plain)
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
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT([weighttp],[0.4])
AC_CONFIG_SRCDIR([src/weighttp.c])
AC_CONFIG_HEADER([src/config.h])

AM_INIT_AUTOMAKE([-Wall -Werror foreign dist-xz no-dist-gzip])

# Checks for programs.
AC_PROG_CC

dnl @synopsis TRY_CFLAGS [compiler flags]
dnl @summary check whether C compiler supports given flags and adds them to CFLAGS
AC_DEFUN([TRY_CFLAGS],
[dnl
  AC_MSG_CHECKING([if $CC supports $1])
  AC_LANG_PUSH([C])
  ac_try_cflags_saved_cflags="${CFLAGS}"
  CFLAGS="${CFLAGS} $1"
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
    [AC_MSG_RESULT([yes])],
    [
      AC_MSG_ERROR([no])
      # options not supported, remove them:
      CFLAGS="${ac_try_cflags_saved_cflags}"
    ]
  )
  AC_LANG_POP([C])
])


## solaris needs -lsocket
AC_SEARCH_LIBS([socket],[socket])


## pthread
AC_MSG_CHECKING([for pthread support])
AC_SEARCH_LIBS([pthread_create], [pthread], [
  CFLAGS="-pthread ${CFLAGS}"
  LDFLAGS="-pthread ${LDFLAGS}"
])


## libev
AC_MSG_CHECKING([for libev support])
AC_ARG_WITH([libev],
    [AS_HELP_STRING([--with-libev@<:@=PATH@:>@],[Search for libev in PATH/include and PATH/lib])],
    [WITH_LIBEV=$withval],[WITH_LIBEV=yes])

LIBEV_CFLAGS=""
LIBEV_LIBS=""

PKG_CHECK_MODULES([LIBEV], [libev], [], [
  # no pkg-config for libev, searching manually:

  if test "$WITH_LIBEV" != "yes"; then
    LIBEV_CFLAGS="-I$WITH_LIBEV/include"
    LIBEV_LIBS="-L$WITH_LIBEV/lib -lev"
  else
    AC_CHECK_HEADERS([ev.h],[
      AC_CHECK_LIB([ev], [ev_time], [
          LIBEV_LIBS="-lev"
        ],[
          AC_MSG_ERROR([libev not found])
        ]
      )],[
        AC_MSG_ERROR([libev not found])
      ]
    )
  fi
])

AC_SUBST([LIBEV_CFLAGS])
AC_SUBST([LIBEV_LIBS])

# libev has (compiler warning) problems with strict aliasing... - just disable it
TRY_CFLAGS([-fno-strict-aliasing])
TRY_CFLAGS([-fPIC])

# check for extra compiler options (warning options)
if test "${GCC}" = "yes"; then
  TRY_CFLAGS([-Wall -W -Wshadow -pedantic])
  TRY_CFLAGS([-std=gnu99])
fi

AC_ARG_ENABLE(extra-warnings,
 AC_HELP_STRING([--enable-extra-warnings],[enable extra warnings (gcc specific)]),
 [case "${enableval}" in
   yes) extrawarnings=true ;;
    no) extrawarnings=false ;;
     *) AC_MSG_ERROR(bad value ${enableval} for --enable-extra-warnings) ;;
  esac],[extrawarnings=false])

if test x$extrawarnings = xtrue; then
  TRY_CFLAGS([-g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wcast-align -Winline -Wsign-compare -Wnested-externs -Wpointer-arith -Wl,--as-needed -D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security])
fi

AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT