summaryrefslogtreecommitdiffstats
path: root/configure.ac
blob: 690def86544f60d8ec5f91ddbba506ebf8267ec2 (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
AC_PREREQ([2.69])
AC_INIT([[lem]], [[0.3]], [[esmil@mailme.dk]])
builtin_lua_version='5.3'

AC_LANG(C)

AC_SUBST([headers], ['lem.h lem-parsers.h'])
AC_SUBST([objects], ['bin/lem.o'])
AC_SUBST([CPPFLAGS_ADD], ['-Iinclude'])
AC_SUBST([SHARED], ['-shared'])

AS_IF([test "x$CFLAGS" = 'x'], CFLAGS='-O2 -g -Wall -Wextra')

AC_ARG_WITH([ev],
  [AS_HELP_STRING([--with-ev],
    [check or builtin @<:@default=check@:>@])],
  [],
  [with_ev=check])

AC_ARG_WITH([lua],
  [AS_HELP_STRING([--with-lua],
    [check, builtin or pkg-config name @<:@default=check@:>@])],
  [],
  [with_lua=check])

AC_SUBST([lmoddir])
AC_ARG_WITH([lmoddir],
  [AS_HELP_STRING([--with-lmoddir],
    [Lua module installation directory])],
  [lmoddir="$with_lmoddir"])

AC_SUBST([cmoddir])
AC_ARG_WITH([cmoddir],
  [AS_HELP_STRING([--with-cmoddir],
    [Lua C module installation directory])],
  [cmoddir="$with_cmoddir"])

PKG_INSTALLDIR
AC_CANONICAL_TARGET

# Checks for programs.
AC_PROG_CC_C99
AC_PROG_INSTALL
AC_PROG_SED
AC_PATH_TARGET_TOOL([STRIP],[strip])
PKG_PROG_PKG_CONFIG

# Target specific fixes
AS_CASE(["x$target_os"],
  [xdarwin*],
  [ac_cv_func_kqueue=no] # kqueue seems to be broken on OSX
  [SHARED='-dynamiclib -Wl,-undefined,dynamic_lookup']
  [STRIP="$STRIP -x"])

# Check for pthread library
AC_SEARCH_LIBS([pthread_create], [pthread])

# Checks for header files.
AC_CHECK_HEADERS([stddef.h stdlib.h string.h unistd.h sys/time.h time.h pthread.h])
AC_CHECK_HEADERS([sys/eventfd.h sys/epoll.h sys/event.h])

# Configure libev
AS_CASE(["x$with_ev"],
  [xbuiltin],
  [],
  [xcheck],
  [AC_SEARCH_LIBS([ev_run], [ev], [], [with_ev=builtin])],
  [AC_MSG_ERROR([--with-ev must be check or builtin, not '$with_ev'])])

AS_IF([test "x$with_ev" = 'xbuiltin'],
  [AC_CONFIG_HEADERS([libev/ev-config.h:ev-config.h.in])]
  [objects="bin/libev.o $objects"]
  [headers="ev-config.h ev.h $headers"]
  [CPPFLAGS_ADD="$CPPFLAGS_ADD -Ilibev"]

  [AS_IF([test "x$ac_cv_header_sys_eventfd_h" = 'xyes'],
    [AC_CHECK_FUNC([eventfd],
      [AC_DEFINE([EV_USE_EVENTFD], 1)],
      [AC_DEFINE([EV_USE_EVENTFD], 0)])],
    [AC_DEFINE([EV_USE_EVENTFD], 0)])]

  [AC_CHECK_FUNC([nanosleep],
    [AC_DEFINE([EV_USE_NANOSLEEP], 1)],
    [AC_DEFINE([EV_USE_NANOSLEEP], 0)])]

  [AC_CHECK_FUNCS([poll select epoll_ctl kqueue])]

  [AS_IF([test "x$ac_cv_func_epoll_ctl" = 'xyes'],
    [AC_DEFINE([EV_USE_SELECT], 0)]
    [AC_DEFINE([EV_USE_POLL],   0)]
    [AC_DEFINE([EV_USE_EPOLL],  1)]
    [AC_DEFINE([EV_USE_KQUEUE], 0)],
  [AS_IF([test "x$ac_cv_func_kqueue" = 'xyes'],
    [AC_DEFINE([EV_USE_SELECT], 0)]
    [AC_DEFINE([EV_USE_POLL],   0)]
    [AC_DEFINE([EV_USE_EPOLL],  0)]
    [AC_DEFINE([EV_USE_KQUEUE], 1)],
  [AS_IF([test "x$ac_cv_func_select" = 'xyes'],
    [AC_DEFINE([EV_USE_SELECT], 1)]
    [AC_DEFINE([EV_USE_POLL],   0)]
    [AC_DEFINE([EV_USE_EPOLL],  0)]
    [AC_DEFINE([EV_USE_KQUEUE], 0)],
  [AS_IF([test "x$ac_cv_func_poll" = 'xyes'],
    [AC_DEFINE([EV_USE_SELECT], 0)]
    [AC_DEFINE([EV_USE_POLL],   1)]
    [AC_DEFINE([EV_USE_EPOLL],  0)]
    [AC_DEFINE([EV_USE_KQUEUE], 0)],
  [AC_MSG_ERROR([neither poll or select found])])])])])])

# Configure Lua
AS_CASE(["x$with_lua"],
  [xbuiltin],
  [],
  [xcheck],
  [PKG_CHECK_MODULES([Lua], [lua5.3], [with_lua=lua5.3],
    [PKG_CHECK_MODULES([Lua], [lua53],  [with_lua=lua53],
      [PKG_CHECK_MODULES([Lua], [lua],
        [AS_IF([test "x$($PKG_CONFIG --variable=V lua)" = 'x5.3'],
          [with_lua=lua],
          [with_lua=builtin])],
        [with_lua=builtin])])])],
  [PKG_CHECK_MODULES([Lua], ["$with_lua"], [],
    [AC_MSG_ERROR([pkg-config package '$with_lua' not found])])])

AS_IF([test "x$with_lua" = 'xbuiltin'],
  [AC_SEARCH_LIBS([sin], [m])]
  [AC_SEARCH_LIBS([dlopen], [dl])]
  [objects="bin/lua.o $objects"]
  [headers="luaconf.h lua.h lauxlib.h $headers"]
  [CPPFLAGS_ADD="$CPPFLAGS_ADD -Ilua"]
  [Lua_CFLAGS='']
  [Lua_LIBS='']
  [ac_cv_func_luaL_traceback=yes]
  [AS_IF([test "x$lmoddir" = 'x'], [lmoddir="\${datarootdir}/lua/$builtin_lua_version"])]
  [AS_IF([test "x$cmoddir" = 'x'], [cmoddir="\${libdir}/lua/$builtin_lua_version"])])

CPPFLAGS_ADD="$CPPFLAGS_ADD $Lua_CFLAGS"
LIBS="$Lua_LIBS $LIBS"
AS_IF([test "x$lmoddir" = 'x'], [lmoddir="`$PKG_CONFIG --variable=INSTALL_LMOD $with_lua`"])
AS_IF([test "x$cmoddir" = 'x'], [cmoddir="`$PKG_CONFIG --variable=INSTALL_CMOD $with_lua`"])

AS_IF([test "x$lmoddir" = 'x'],
  [AC_MSG_ERROR([unable to deduce Lua module directory, please use --with-lmoddir=path])])
AS_IF([test "x$cmoddir" = 'x'],
  [AC_MSG_ERROR([unable to deduce Lua C module directory, please use --with-cmoddir=path])])

AC_CONFIG_FILES([Makefile])
AC_OUTPUT