Blob


1 AC_INIT([kamid], [0.2], [kamid@omarpolo.com], [],
2 [https://kamid.omarpolo.com])
3 AC_CONFIG_AUX_DIR(etc)
4 AC_CONFIG_LIBOBJ_DIR(compat)
5 AM_INIT_AUTOMAKE([foreign subdir-objects])
7 KAMID_RELEASE=No
9 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
10 AC_SUBST(VERSION)
11 AC_SUBST(KAMID_RELEASE)
13 AC_CANONICAL_HOST
15 # When CFLAGS isn't set at this stage and gcc is detected by the macro below,
16 # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
17 # empty default.
18 : ${CFLAGS=""}
20 # Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because
21 # AC_CHECK_HEADER doesn't give us any other way to update the include
22 # paths. But for Makefile.am we want to use AM_CPPFLAGS and friends.
23 SAVED_CFLAGS="$CFLAGS"
24 SAVED_CPPFLAGS="$CPPFLAGS"
25 SAVED_LDFLAGS="$LDFLAGS"
27 # Checks for programs.
28 AC_PROG_CC
29 AC_PROG_CPP
30 AC_PROG_INSTALL
31 AC_PROG_LN_S
32 AC_PROG_MAKE_SET
33 AC_PROG_RANLIB
34 AC_PROG_YACC
35 PKG_PROG_PKG_CONFIG
36 AC_USE_SYSTEM_EXTENSIONS
38 # Some functions can be in libbsd. Thanks to lldpb for the inspiration :)
39 AC_ARG_WITH([libbsd],
40 AS_HELP_STRING([--with-libbsd], [Use libbsd @<:@default=auto@:>@]),
41 [],
42 [with_libbsd=auto])
43 if test x"$with_libbsd" != x"no"; then
44 PKG_CHECK_MODULES([libbsd], [libbsd-overlay libbsd-ctor], [
45 AM_CFLAGS="$AM_CFLAGS $libbsd_CFLAGS"
46 LIBS="$LIBS $libbsd_LIBS"
47 ], [
48 if test x"$with_libbsd" = x"yes"; then
49 AC_MSG_FAILURE([*** no libbsd support found])
50 fi
51 with_libbsd=no
52 ])
53 fi
55 AC_REPLACE_FUNCS([
56 asprintf \
57 errc \
58 freezero \
59 getdtablecount \
60 getdtablesize \
61 getprogname \
62 memmem \
63 reallocarray \
64 recallocarray \
65 setproctitle \
66 setprogname \
67 strlcat \
68 strlcpy \
69 strsep \
70 strtonum \
71 vis \
72 ])
74 AC_MSG_CHECKING([for sys/queue.h with TAILQ_FOREACH_SAFE and STAILQ_ENTRY])
75 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
76 #include <sys/queue.h>
77 #include <stddef.h>
78 ], [
79 TAILQ_HEAD(tailhead, entry) head;
80 struct entry {
81 TAILQ_ENTRY(entry) entries;
82 } *np, *nt;
83 TAILQ_INIT(&head);
84 TAILQ_FOREACH_SAFE(np, &head, entries, nt) {
85 /* nop */ ;
86 }
88 STAILQ_HEAD(listhead, qentry) qhead = STAILQ_HEAD_INITIALIZER(qhead);
89 struct qentry {
90 STAILQ_ENTRY(qentry) entries;
91 } foo;
93 return 0;
94 ])], [
95 AC_MSG_RESULT(yes)
96 AC_DEFINE([HAVE_QUEUE_H], 1, [QUEUE_H])
97 ], AC_MSG_RESULT(no))
99 AC_MSG_CHECKING([for usable sys/tree.h])
100 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
101 #include <sys/tree.h>
102 #include <stdio.h>
104 struct client {
105 int id;
106 SPLAY_ENTRY(client) sp_entry;
107 };
108 SPLAY_HEAD(clients_tree_id, client) clients;
110 static inline int
111 clients_tree_cmp(struct client *a, struct client *b)
113 if (a->id == b->id)
114 return 0;
115 else if (a->id < b->id)
116 return -1;
117 else
118 return +1;
121 SPLAY_PROTOTYPE(clients_tree_id, client, sp_entry, clients_tree_cmp);
122 SPLAY_GENERATE(clients_tree_id, client, sp_entry, clients_tree_cmp);
123 ], [
124 return 0;
125 ])], [
126 AC_MSG_RESULT(yes)
127 AC_DEFINE([HAVE_SYS_TREE_H], 1, [TREE_H])
128 ], AC_MSG_RESULT(no))
130 AC_CHECK_HEADER([endian.h], [AC_DEFINE(HAVE_ENDIAN_H, 1, [have endian.h])], [
131 AC_CHECK_HEADER([sys/endian.h],
132 [AC_DEFINE(HAVE_SYS_ENDIAN_H, 1, [have sys/endian.h])], [
133 AC_CHECK_HEADERS([libkern/OSByteOrder.h],
134 [AC_DEFINE(HAVE_LIBKERN_OSBYTEORDER_H, 1, [have OSByteOrder.h])],
135 [AC_MSG_ERROR([can't find compatible endian.h header])],
136 [#include <machine/endian.h>])
137 ])
138 ])
140 AC_CHECK_DECL(PR_SET_NAME, AC_DEFINE([HAVE_PR_SET_NAME], 1, [pr_set_name]), [],
141 [[#include <sys/prctl.h>]])
143 AC_CHECK_LIB([crypto], [RAND_add], [], [
144 AC_MSG_ERROR([requires openssl])
145 ])
147 AC_CHECK_LIB(tls, tls_init, [], [
148 AC_MSG_ERROR([requires libtls])
149 ])
151 AS_CASE([$host_os],
152 [*openbsd*], [AC_CHECK_LIB([event], [event_init], [],
153 [AC_MSG_ERROR([requires libevent])])],
154 [PKG_CHECK_MODULES([libevent2], [libevent_core >= 2],
156 AC_DEFINE([HAVE_EVENT2], 1, [1 if using event2])
157 AM_CFLAGS="$libevent2_CFLAGS $AM_CFLAGS"
158 LIBS="$libevent2_LIBS $LIBS"
159 ], [AC_MSG_ERROR([requires libevent])])])
161 AC_CHECK_LIB(util, imsg_init, [], [
162 AC_LIBOBJ(fmt_scaled)
163 AC_LIBOBJ(imsg)
164 AC_LIBOBJ(imsg-buffer)
165 AC_LIBOBJ(ohash)
166 ])
168 # Check for readline
169 AS_CASE([$host_os],
170 [*openbsd*], [
171 AC_DEFINE([HAVE_READLINE], 1, [1 if readline found])
172 READLINE_CFLAGS=''
173 READLINE_LIBS='-lreadline'
174 ], [
175 PKG_CHECK_MODULES([READLINE], [readline], [
176 AC_DEFINE([HAVE_READLINE], 1, [])
177 ], [
178 AC_DEFINE([HAVE_READLINE], 0, [])
179 ])
182 AC_SUBST(READLINE_CFLAGS)
183 AC_SUBST(READLINE_LIBS)
185 # check compiler flags
186 AC_DEFUN([CC_ADD_CHECK_FLAGS], [
187 AC_MSG_CHECKING([if $CC supports $1 flag])
188 old_AM_CFLAGS="$AM_CFLAGS"
189 AM_CFLAGS="$AM_CFLAGS $1"
190 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
191 AC_MSG_RESULT(yes), [
192 AC_MSG_RESULT(no)
193 AM_CFLAGS="$old_AM_CFLAGS"
194 ])
195 ])
196 CC_ADD_CHECK_FLAGS([-Wall])
197 CC_ADD_CHECK_FLAGS([-Wextra])
198 CC_ADD_CHECK_FLAGS([-Wmissing-declarations])
199 CC_ADD_CHECK_FLAGS([-Wmissing-prototypes])
200 CC_ADD_CHECK_FLAGS([-Wstrict-prototypes])
201 CC_ADD_CHECK_FLAGS([-Wwrite-strings])
202 CC_ADD_CHECK_FLAGS([-Wno-unused-parameter])
203 CC_ADD_CHECK_FLAGS([-Wpointer-arith])
204 CC_ADD_CHECK_FLAGS([-Wsign-compare])
205 CC_ADD_CHECK_FLAGS([-Wcast-align])
206 CC_ADD_CHECK_FLAGS([-Wno-pointer-sign])
208 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
209 # variables.
210 AC_SUBST(AM_CPPFLAGS)
211 CPPFLAGS="$SAVED_CPPFLAGS"
212 AC_SUBST(AM_CFLAGS)
213 CFLAGS="$SAVED_CFLAGS"
214 AC_SUBST(AM_LDFLAGS)
215 LDFLAGS="$SAVED_LDFLAGS"
217 AC_CONFIG_HEADERS([config.h])
218 AC_CONFIG_FILES([
219 Makefile
220 compat/Makefile
221 contrib/Makefile
222 kamictl/Makefile
223 kamid/Makefile
224 kamiftp/Makefile
225 kamiproxy/Makefile
226 kamirepl/Makefile
227 ninepscript/Makefile
228 regress/Makefile
229 regress/lisp/Makefile
230 regress/ninepscript/Makefile
231 ])
233 AC_OUTPUT