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 err \
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_CHECK_HEADERS([sys/tree.h])
101 AC_CHECK_HEADER([endian.h], [AC_DEFINE(HAVE_ENDIAN_H, 1, [have endian.h])], [
102 AC_CHECK_HEADER([sys/endian.h],
103 [AC_DEFINE(HAVE_SYS_ENDIAN_H, 1, [have sys/endian.h])], [
104 AC_CHECK_HEADERS([libkern/OSByteOrder.h],
105 [AC_DEFINE(HAVE_LIBKERN_OSBYTEORDER_H, 1, [have OSByteOrder.h])],
106 [AC_MSG_ERROR([can't find compatible endian.h header])],
107 [#include <machine/endian.h>])
108 ])
109 ])
111 AC_CHECK_DECL(PR_SET_NAME, AC_DEFINE([HAVE_PR_SET_NAME], 1, [pr_set_name]), [],
112 [[#include <sys/prctl.h>]])
114 AC_CHECK_LIB([crypto], [RAND_add], [], [
115 AC_MSG_ERROR([requires openssl])
116 ])
118 AC_CHECK_LIB(tls, tls_init, [], [
119 AC_MSG_ERROR([requires libtls])
120 ])
122 AS_CASE([$host_os],
123 [*openbsd*], [AC_CHECK_LIB([event], [event_init], [],
124 [AC_MSG_ERROR([requires libevent])])],
125 [PKG_CHECK_MODULES([libevent2], [libevent_core >= 2],
127 AC_DEFINE([HAVE_EVENT2], 1, [1 if using event2])
128 AM_CFLAGS="$libevent2_CFLAGS $AM_CFLAGS"
129 LIBS="$libevent2_LIBS $LIBS"
130 ], [AC_MSG_ERROR([requires libevent])])])
132 AC_CHECK_LIB(util, imsg_init, [], [
133 AC_LIBOBJ(fmt_scaled)
134 AC_LIBOBJ(imsg)
135 AC_LIBOBJ(imsg-buffer)
136 AC_LIBOBJ(ohash)
137 ])
139 # Check for readline
140 AS_CASE([$host_os],
141 [*openbsd*], [
142 AC_DEFINE([HAVE_READLINE], 1, [1 if readline found])
143 READLINE_CFLAGS=''
144 READLINE_LIBS='-lreadline'
145 ], [
146 PKG_CHECK_MODULES([READLINE], [readline], [
147 AC_DEFINE([HAVE_READLINE], 1, [])
148 ], [
149 AC_DEFINE([HAVE_READLINE], 0, [])
150 ])
153 AC_SUBST(READLINE_CFLAGS)
154 AC_SUBST(READLINE_LIBS)
156 # check compiler flags
157 AC_DEFUN([CC_ADD_CHECK_FLAGS], [
158 AC_MSG_CHECKING([if $CC supports $1 flag])
159 old_AM_CFLAGS="$AM_CFLAGS"
160 AM_CFLAGS="$AM_CFLAGS $1"
161 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
162 AC_MSG_RESULT(yes), [
163 AC_MSG_RESULT(no)
164 AM_CFLAGS="$old_AM_CFLAGS"
165 ])
166 ])
167 CC_ADD_CHECK_FLAGS([-Wall])
168 CC_ADD_CHECK_FLAGS([-Wextra])
169 CC_ADD_CHECK_FLAGS([-Wmissing-declarations])
170 CC_ADD_CHECK_FLAGS([-Wmissing-prototypes])
171 CC_ADD_CHECK_FLAGS([-Wstrict-prototypes])
172 CC_ADD_CHECK_FLAGS([-Wwrite-strings])
173 CC_ADD_CHECK_FLAGS([-Wno-unused-parameter])
174 CC_ADD_CHECK_FLAGS([-Wpointer-arith])
175 CC_ADD_CHECK_FLAGS([-Wsign-compare])
176 CC_ADD_CHECK_FLAGS([-Wcast-align])
178 # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
179 # variables.
180 AC_SUBST(AM_CPPFLAGS)
181 CPPFLAGS="$SAVED_CPPFLAGS"
182 AC_SUBST(AM_CFLAGS)
183 CFLAGS="$SAVED_CFLAGS"
184 AC_SUBST(AM_LDFLAGS)
185 LDFLAGS="$SAVED_LDFLAGS"
187 AC_CONFIG_HEADERS([config.h])
188 AC_CONFIG_FILES([
189 Makefile
190 compat/Makefile
191 contrib/Makefile
192 kamictl/Makefile
193 kamid/Makefile
194 kamiftp/Makefile
195 kamiproxy/Makefile
196 kamirepl/Makefile
197 ninepscript/Makefile
198 regress/Makefile
199 regress/lisp/Makefile
200 regress/ninepscript/Makefile
201 ])
203 AC_OUTPUT